com.sun.jersey.multipart
Class FormDataBodyPart

java.lang.Object
  extended by com.sun.jersey.multipart.BodyPart
      extended by com.sun.jersey.multipart.FormDataBodyPart
Direct Known Subclasses:
FileDataBodyPart

public class FormDataBodyPart
extends BodyPart

Subclass of BodyPart with specialized support for media type multipart/form-data. See RFC 2388 for the formal definition of this media type.

For a server side application wishing to process an incoming multipart/form-data message, the following features are provided:

For a client side application wishing to construct an outgoing multipart/form-data message, the following features are provided:

Author:
Craig.McClanahan@Sun.COM, Paul.Sandoz@Sun.Com, imran@smartitengineering.com

Field Summary
 
Fields inherited from class com.sun.jersey.multipart.BodyPart
cd
 
Constructor Summary
FormDataBodyPart()
          FormDataBodyPart with a mediaType of text/plain.
FormDataBodyPart(FormDataContentDisposition fdcd, Object entity, MediaType mediaType)
          Instantiate a named FormDataBodyPart with the specified characteristics.
FormDataBodyPart(FormDataContentDisposition fdcd, String value)
          Instantiate a named FormDataBodyPart with the specified characteristics.
FormDataBodyPart(MediaType mediaType)
          Instantiate an unnamed FormDataBodyPart with the specified characteristics.
FormDataBodyPart(Object entity, MediaType mediaType)
          Instantiate an unnamed FormDataBodyPart with the specified characteristics.
FormDataBodyPart(String name, Object entity, MediaType mediaType)
          Instantiate a named FormDataBodyPart with the specified characteristics.
FormDataBodyPart(String name, String value)
          Instantiate a named FormDataBodyPart with a media type of text/plain and String value.
 
Method Summary
 ContentDisposition getContentDisposition()
          Override the behaviour on BodyPart to ensure that only instances of FormDataContentDisposition can be obtained.
 FormDataContentDisposition getFormDataContentDisposition()
          Get the form data content disposition.
 String getName()
          Get the control name.
 String getValue()
          Get the field value for this body part.
<T> T
getValueAs(Class<T> clazz)
          Get the field value after appropriate conversion to the requested type.
 boolean isSimple()
           
 void setContentDisposition(ContentDisposition cd)
          Override the behaviour on BodyPart to ensure that only instances of FormDataContentDisposition can be set.
 void setFormDataContentDisposition(FormDataContentDisposition cd)
          Set the form data content disposition.
 void setName(String name)
          Set the control name.
 void setValue(MediaType mediaType, Object value)
          Set the field media type and value for this body part.
 void setValue(String value)
          Set the field value for this body part.
 
Methods inherited from class com.sun.jersey.multipart.BodyPart
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setEntity, setMediaType, setParent, setProviders, type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormDataBodyPart

public FormDataBodyPart()
FormDataBodyPart with a mediaType of text/plain.


FormDataBodyPart

public FormDataBodyPart(MediaType mediaType)
Instantiate an unnamed FormDataBodyPart with the specified characteristics.

Parameters:
mediaType - The MediaType for this body part

FormDataBodyPart

public FormDataBodyPart(Object entity,
                        MediaType mediaType)
Instantiate an unnamed FormDataBodyPart with the specified characteristics.

Parameters:
entity - The entity for this body part
mediaType - The MediaType for this body part

FormDataBodyPart

public FormDataBodyPart(String name,
                        String value)
Instantiate a named FormDataBodyPart with a media type of text/plain and String value.

Parameters:
name - the control name for this body part
value - the value for this body part

FormDataBodyPart

public FormDataBodyPart(String name,
                        Object entity,
                        MediaType mediaType)
Instantiate a named FormDataBodyPart with the specified characteristics.

Parameters:
name - the control name for this body part
entity - the entity for this body part
mediaType - the MediaType for this body part

FormDataBodyPart

public FormDataBodyPart(FormDataContentDisposition fdcd,
                        String value)
Instantiate a named FormDataBodyPart with the specified characteristics.

Parameters:
fdcd - the content disposition header for this body part.
value - the value for this body part

FormDataBodyPart

public FormDataBodyPart(FormDataContentDisposition fdcd,
                        Object entity,
                        MediaType mediaType)
Instantiate a named FormDataBodyPart with the specified characteristics.

Parameters:
fdcd - the content disposition header for this body part.
entity - The entity for this body part
mediaType - The MediaType for this body part
Method Detail

getFormDataContentDisposition

public FormDataContentDisposition getFormDataContentDisposition()
Get the form data content disposition.

Returns:
the form data content disposition.

setFormDataContentDisposition

public void setFormDataContentDisposition(FormDataContentDisposition cd)
Set the form data content disposition.

Parameters:
cd - the form data content disposition.

getContentDisposition

public ContentDisposition getContentDisposition()
Override the behaviour on BodyPart to ensure that only instances of FormDataContentDisposition can be obtained.

Overrides:
getContentDisposition in class BodyPart
Returns:
the content disposition.
Throws:
IllegalArgumentException - if the content disposition header cannot be parsed.

setContentDisposition

public void setContentDisposition(ContentDisposition cd)
Override the behaviour on BodyPart to ensure that only instances of FormDataContentDisposition can be set.

Overrides:
setContentDisposition in class BodyPart
Parameters:
cd - the content disposition which must be an instance of FormDataContentDisposition.
Throws:
IllegalArgumentException - if the content disposition is not an instance of FormDataContentDisposition.

getName

public String getName()
Get the control name.

Returns:
the control name.

setName

public void setName(String name)
Set the control name.

Parameters:
name - the control name.

getValue

public String getValue()
Get the field value for this body part. This should be called only on body parts representing simple field values.

Returns:
the simple field value.
Throws:
IllegalStateException - if called on a body part with a media type other than text/plain

getValueAs

public <T> T getValueAs(Class<T> clazz)
Get the field value after appropriate conversion to the requested type. This is useful only when the containing FormDataMultiPart instance has been received, which causes the providers property to have been set.

Type Parameters:
T - the type of the field value.
Parameters:
clazz - Desired class into which the field value should be converted
Returns:
the field value
Throws:
IllegalArgumentException - if no MessageBodyReader can be found to perform the requested conversion
IllegalStateException - if this method is called when the providers property has not been set or when the entity instance is not the unconverted content of the body part entity

setValue

public void setValue(String value)
Set the field value for this body part. This should be called only on body parts representing simple field values.

Parameters:
value - the field value
Throws:
IllegalStateException - if called on a body part with a media type other than text/plain

setValue

public void setValue(MediaType mediaType,
                     Object value)
Set the field media type and value for this body part.

Parameters:
mediaType - the media type for this field value
value - the field value as a Java object

isSimple

public boolean isSimple()
Returns:
true if this body part represents a simple, string-based, field value, otherwise false.


Copyright © 2013 Oracle Corporation. All Rights Reserved.