com.sun.jersey.core.spi.factory
Class MessageBodyFactory

java.lang.Object
  extended by com.sun.jersey.core.spi.factory.MessageBodyFactory
All Implemented Interfaces:
MessageBodyWorkers

public class MessageBodyFactory
extends java.lang.Object
implements MessageBodyWorkers

A factory for managing MessageBodyReader and MessageBodyWriter instances.

Author:
[email protected]

Constructor Summary
MessageBodyFactory(ProviderServices providerServices, boolean deprecatedProviderPrecedence)
           
 
Method Summary
<T> MessageBodyReader<T>
getMessageBodyReader(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, MediaType mediaType)
          Get a message body reader that matches a set of criteria.
<T> MessageBodyWriter<T>
getMessageBodyWriter(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, MediaType mediaType)
          Get a message body writer that matches a set of criteria.
<T> MediaType
getMessageBodyWriterMediaType(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as, java.util.List<MediaType> acceptableMediaTypes)
          Get the most acceptable media type supported for a Java type given a set of acceptable media types.
<T> java.util.List<MediaType>
getMessageBodyWriterMediaTypes(java.lang.Class<T> c, java.lang.reflect.Type t, java.lang.annotation.Annotation[] as)
          Get the list of media types supported for a Java type.
 java.util.Map<MediaType,java.util.List<MessageBodyReader>> getReaders(MediaType mediaType)
          Get the map of media type to list of message body writers that are compatible with a media type.
 java.util.Map<MediaType,java.util.List<MessageBodyWriter>> getWriters(MediaType mediaType)
          Get the map of media type to list of message body writers that are compatible with a media type.
 void init()
           
 java.lang.String readersToString(java.util.Map<MediaType,java.util.List<MessageBodyReader>> readers)
          Convert a map media type to list of message body readers to a string.
 java.lang.String writersToString(java.util.Map<MediaType,java.util.List<MessageBodyWriter>> writers)
          Convert a map media type to list of message body writers to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageBodyFactory

public MessageBodyFactory(ProviderServices providerServices,
                          boolean deprecatedProviderPrecedence)
Method Detail

init

public void init()

getReaders

public java.util.Map<MediaType,java.util.List<MessageBodyReader>> getReaders(MediaType mediaType)
Description copied from interface: MessageBodyWorkers
Get the map of media type to list of message body writers that are compatible with a media type.

Specified by:
getReaders in interface MessageBodyWorkers
Parameters:
mediaType - the compatible media type.
Returns:
the map of media type to list of message body writers.

getWriters

public java.util.Map<MediaType,java.util.List<MessageBodyWriter>> getWriters(MediaType mediaType)
Description copied from interface: MessageBodyWorkers
Get the map of media type to list of message body writers that are compatible with a media type.

Specified by:
getWriters in interface MessageBodyWorkers
Parameters:
mediaType - the compatible media type.
Returns:
the map of media type to list of message body writers.

readersToString

public java.lang.String readersToString(java.util.Map<MediaType,java.util.List<MessageBodyReader>> readers)
Description copied from interface: MessageBodyWorkers
Convert a map media type to list of message body readers to a string.

Specified by:
readersToString in interface MessageBodyWorkers
Parameters:
readers - the map media type to list of message body readers
Returns:
the string representation.

writersToString

public java.lang.String writersToString(java.util.Map<MediaType,java.util.List<MessageBodyWriter>> writers)
Description copied from interface: MessageBodyWorkers
Convert a map media type to list of message body writers to a string.

Specified by:
writersToString in interface MessageBodyWorkers
Parameters:
writers - the map media type to list of message body readers
Returns:
the string representation.

getMessageBodyReader

public <T> MessageBodyReader<T> getMessageBodyReader(java.lang.Class<T> c,
                                                     java.lang.reflect.Type t,
                                                     java.lang.annotation.Annotation[] as,
                                                     MediaType mediaType)
Description copied from interface: MessageBodyWorkers
Get a message body reader that matches a set of criteria.

Specified by:
getMessageBodyReader in interface MessageBodyWorkers
Type Parameters:
T - the type of object to be read.
Parameters:
c - the class of object to be read.
t - the type of object to be produced. E.g. if the message body is to be converted into a method parameter, this will be the formal type of the method parameter as returned by Class.getGenericParameterTypes.
as - an array of the annotations on the declaration of the artifact that will be initialized with the produced instance. E.g. if the message body is to be converted into a method parameter, this will be the annotations on that parameter returned by Class.getParameterAnnotations.
mediaType - the media type of the data that will be read, this will be compared to the values of Consumes for each candidate reader and only matching readers will be queried.
Returns:
a MessageBodyReader that matches the supplied criteria or null if none is found.

getMessageBodyWriter

public <T> MessageBodyWriter<T> getMessageBodyWriter(java.lang.Class<T> c,
                                                     java.lang.reflect.Type t,
                                                     java.lang.annotation.Annotation[] as,
                                                     MediaType mediaType)
Description copied from interface: MessageBodyWorkers
Get a message body writer that matches a set of criteria.

Specified by:
getMessageBodyWriter in interface MessageBodyWorkers
Type Parameters:
T - the type of the object that is to be written.
Parameters:
c - the class of object that is to be written.
t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
mediaType - the media type of the data that will be written, this will be compared to the values of Produces for each candidate writer and only matching writers will be queried.
Returns:
a MessageBodyReader that matches the supplied criteria or null if none is found.

getMessageBodyWriterMediaTypes

public <T> java.util.List<MediaType> getMessageBodyWriterMediaTypes(java.lang.Class<T> c,
                                                                    java.lang.reflect.Type t,
                                                                    java.lang.annotation.Annotation[] as)
Description copied from interface: MessageBodyWorkers
Get the list of media types supported for a Java type.

Specified by:
getMessageBodyWriterMediaTypes in interface MessageBodyWorkers
Type Parameters:
T - the type of object that is to be written.
Parameters:
c - the class of object that is to be written.
t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
Returns:
the list of supported media types, the list is ordered as follows: a/b < a/* < \*\/*

getMessageBodyWriterMediaType

public <T> MediaType getMessageBodyWriterMediaType(java.lang.Class<T> c,
                                                   java.lang.reflect.Type t,
                                                   java.lang.annotation.Annotation[] as,
                                                   java.util.List<MediaType> acceptableMediaTypes)
Description copied from interface: MessageBodyWorkers
Get the most acceptable media type supported for a Java type given a set of acceptable media types.

Specified by:
getMessageBodyWriterMediaType in interface MessageBodyWorkers
Type Parameters:
T - the type of object that is to be written.
Parameters:
c - the class of object that is to be written.
t - the type of object to be written. E.g. if the message body is to be produced from a field, this will be the declared type of the field as returned by Field.getGenericType.
as - an array of the annotations on the declaration of the artifact that will be written. E.g. if the message body is to be produced from a field, this will be the annotations on that field returned by Field.getDeclaredAnnotations.
acceptableMediaTypes - the list of acceptable media types, sorted according to the quality with the media type of highest quality occurring first first.
Returns:
the best media types


Copyright © 2011 Oracle Corporation. All Rights Reserved.