com.sun.jersey.multipart
Class BodyPart

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

public class BodyPart
extends java.lang.Object

A mutable model representing a body part nested inside a MIME MultiPart entity.


Field Summary
protected  ContentDisposition cd
           
 
Constructor Summary
BodyPart()
          Instantiate a new BodyPart with a mediaType of text/plain.
BodyPart(javax.ws.rs.core.MediaType mediaType)
          Instantiate a new BodyPart with the specified characteristics.
BodyPart(java.lang.Object entity, javax.ws.rs.core.MediaType mediaType)
          Instantiate a new BodyPart with the specified characteristics.
 
Method Summary
 void cleanup()
          Perform any necessary cleanup at the end of processing this BodyPart.
 BodyPart contentDisposition(ContentDisposition cd)
           
 BodyPart entity(java.lang.Object entity)
          Builder pattern method to return this BodyPart after additional configuration.
 ContentDisposition getContentDisposition()
          Get the content disposition.
 java.lang.Object getEntity()
          Return the entity object to be unmarshalled from a request, or to be marshalled on a response.
<T> T
getEntityAs(java.lang.Class<T> clazz)
          Return the entity after appropriate conversion to the requested type.
 javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getHeaders()
          Return a mutable map of HTTP header value(s) for this BodyPart, keyed by the header name.
 javax.ws.rs.core.MediaType getMediaType()
          Return the MediaType for this BodyPart.
 javax.ws.rs.core.MultivaluedMap<java.lang.String,ParameterizedHeader> getParameterizedHeaders()
          Return an immutable map of parameterized HTTP header value(s) for this BodyPart, keyed by header name.
 MultiPart getParent()
          Return the parent MultiPart (if any) for this BodyPart.
 javax.ws.rs.ext.Providers getProviders()
          Return the configured Providers for this BodyPart.
 void setContentDisposition(ContentDisposition cd)
          Set the content disposition.
 void setEntity(java.lang.Object entity)
          Set the entity object to be unmarshalled from a request, or to be marshalled on a response.
 void setMediaType(javax.ws.rs.core.MediaType mediaType)
          Set the MediaType for this BodyPart.
 void setParent(MultiPart parent)
          Set the parent MultiPart (if any) for this BodyPart.
 void setProviders(javax.ws.rs.ext.Providers providers)
          Set the configured Providers for this BodyPart.
 BodyPart type(javax.ws.rs.core.MediaType type)
          Builder pattern method to return this BodyPart after additional configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cd

protected ContentDisposition cd
Constructor Detail

BodyPart

public BodyPart()

Instantiate a new BodyPart with a mediaType of text/plain.


BodyPart

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

Instantiate a new BodyPart with the specified characteristics.

Parameters:
mediaType - The MediaType for this body part

BodyPart

public BodyPart(java.lang.Object entity,
                javax.ws.rs.core.MediaType mediaType)

Instantiate a new BodyPart with the specified characteristics.

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

getEntity

public java.lang.Object getEntity()

Return the entity object to be unmarshalled from a request, or to be marshalled on a response.

Throws:
java.lang.IllegalStateException - if this method is called on a MultiPart instance; access the underlying BodyParts instead

setEntity

public void setEntity(java.lang.Object entity)

Set the entity object to be unmarshalled from a request, or to be marshalled on a response.

Parameters:
entity - The new entity object
Throws:
java.lang.IllegalStateException - if this method is called on a MultiPart instance; access the underlying BodyParts instead

getHeaders

public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getHeaders()

Return a mutable map of HTTP header value(s) for this BodyPart, keyed by the header name. Key comparisons in the returned map must be case-insensitive.

Note that, per the MIME specifications, only headers that match Content-* should be included on a BodyPart.


getParameterizedHeaders

public javax.ws.rs.core.MultivaluedMap<java.lang.String,ParameterizedHeader> getParameterizedHeaders()
                                                                                              throws java.text.ParseException

Return an immutable map of parameterized HTTP header value(s) for this BodyPart, keyed by header name. Key comparisons in the returned map must be case-insensitive. If you wish to modify the headers map for this BodyPart, modify the map returned by getHeaders() instead.

Throws:
java.text.ParseException

getContentDisposition

public ContentDisposition getContentDisposition()
Get the content disposition.

The "Content-Disposition" header, if present, will be parsed.

Returns:
the content disposition, will be null if not present.
Throws:
java.lang.IllegalArgumentException - if the content disposition header cannot be parsed.

setContentDisposition

public void setContentDisposition(ContentDisposition cd)
Set the content disposition.

Parameters:
cd - the content disposition.

getMediaType

public javax.ws.rs.core.MediaType getMediaType()

Return the MediaType for this BodyPart. If never set, the default MediaType MUST be text/plain.


setMediaType

public void setMediaType(javax.ws.rs.core.MediaType mediaType)

Set the MediaType for this BodyPart.

Parameters:
mediaType - The new MediaType
Throws:
java.lang.IllegalArgumentException - if the mediaType is null.

getParent

public MultiPart getParent()

Return the parent MultiPart (if any) for this BodyPart.


setParent

public void setParent(MultiPart parent)

Set the parent MultiPart (if any) for this BodyPart.

Parameters:
parent - The new parent

getProviders

public javax.ws.rs.ext.Providers getProviders()

Return the configured Providers for this BodyPart.


setProviders

public void setProviders(javax.ws.rs.ext.Providers providers)

Set the configured Providers for this BodyPart.

Parameters:
providers - The new Providers

cleanup

public void cleanup()

Perform any necessary cleanup at the end of processing this BodyPart.


entity

public BodyPart entity(java.lang.Object entity)

Builder pattern method to return this BodyPart after additional configuration.

Parameters:
entity - Entity to set for this BodyPart

getEntityAs

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

Return the entity after appropriate conversion to the requested type. This is useful only when the containing MultiPart instance has been received, which causes the providers property to have been set.

Parameters:
clazz - Desired class into which the entity 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

type

public BodyPart type(javax.ws.rs.core.MediaType type)

Builder pattern method to return this BodyPart after additional configuration.

Parameters:
type - Media type to set for this BodyPart

contentDisposition

public BodyPart contentDisposition(ContentDisposition cd)


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