com.sun.jersey.multipart
Class FormDataBodyPart

java.lang.Object
  extended by com.sun.jersey.multipart.BodyPart
      extended by com.sun.jersey.multipart.FormDataBodyPart

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:


Constructor Summary
FormDataBodyPart()
          Instantiate an unnamed new FormDataBodyPart with a mediaType of text/plain.
FormDataBodyPart(javax.ws.rs.core.MediaType mediaType)
          Instantiate an unnamed FormDataBodyPart with the specified characteristics.
FormDataBodyPart(java.lang.Object entity, javax.ws.rs.core.MediaType mediaType)
          Instantiate an unnamed FormDataBodyPart with the specified characteristics.
FormDataBodyPart(java.lang.String name, java.lang.Object entity, javax.ws.rs.core.MediaType mediaType)
          Instantiate a named FormDataBodyPart with the specified characteristics.
FormDataBodyPart(java.lang.String name, java.lang.String value)
          Instantiate a named FormDataBodyPart with a media type of text/plain and String value.
 
Method Summary
 java.lang.String getName()
          Return the field name for this body part, or null if no name has been established yet.
 java.lang.String getValue()
          Return the field value for this body part.
<T> T
getValueAs(java.lang.Class<T> clazz)
          Return the field value after appropriate conversion to the requested type.
 boolean isSimple()
          Return a flag indicating whether this FormDataBodyPart represents a simple String-valued field.
 void setName(java.lang.String name)
          Set the field name for this body part.
 void setValue(javax.ws.rs.core.MediaType mediaType, java.lang.Object value)
          Set the field media type and value for this body part.
 void setValue(java.lang.String value)
          Set the field value for this body part.
 
Methods inherited from class com.sun.jersey.multipart.BodyPart
cleanup, 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()

Instantiate an unnamed new FormDataBodyPart with a mediaType of text/plain.


FormDataBodyPart

public FormDataBodyPart(javax.ws.rs.core.MediaType mediaType)

Instantiate an unnamed FormDataBodyPart with the specified characteristics.

Parameters:
mediaType - The MediaType for this body part

FormDataBodyPart

public FormDataBodyPart(java.lang.Object entity,
                        javax.ws.rs.core.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(java.lang.String name,
                        java.lang.String value)

Instantiate a named FormDataBodyPart with a media type of text/plain and String value.

Parameters:
name - Field name for this body part
value - Field value for this body part

FormDataBodyPart

public FormDataBodyPart(java.lang.String name,
                        java.lang.Object entity,
                        javax.ws.rs.core.MediaType mediaType)

Instantiate a named FormDataBodyPart with the specified characteristics.

Parameters:
name - Field name for this body part
entity - The entity for this body part
mediaType - The MediaType for this body part
Method Detail

getName

public java.lang.String getName()

Return the field name for this body part, or null if no name has been established yet.


getValue

public java.lang.String getValue()

Return the field value for this body part. This should be called only on body parts representing simple field values.

Throws:
java.lang.IllegalStateException - if called on a body part with a media type other than text/plain

getValueAs

public <T> T getValueAs(java.lang.Class<T> clazz)

Return 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.

Parameters:
clazz - Desired class into which the field value should be converted
Throws:
java.lang.IllegalArgumentException - if no MessageBodyReader can be found to perform the requested conversion
java.lang.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

isSimple

public boolean isSimple()

Return a flag indicating whether this FormDataBodyPart represents a simple String-valued field.


setName

public void setName(java.lang.String name)

Set the field name for this body part.

Parameters:
name - New field name for this body part

setValue

public void setValue(java.lang.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 new field value
Throws:
java.lang.IllegalStateException - if called on a body part with a media type other than text/plain

setValue

public void setValue(javax.ws.rs.core.MediaType mediaType,
                     java.lang.Object value)

Set the field media type and value for this body part.

Parameters:
mediaType - Media type for this field value
value - Field value as a Java object


Copyright © 2009 Sun Microsystems, Inc. All Rights Reserved.