javax.ws.rs.ext
Interface Providers


public interface Providers

An injectable interface providing runtime lookup of provider instances.

See Also:
Context, MessageBodyReader, MessageBodyWriter, ContextResolver, ExceptionMapper

Method Summary
<T> ContextResolver<T>
getContextResolver(java.lang.Class<T> contextType, java.lang.Class<?> objectType, MediaType mediaType)
          Get a context resolver for a particular type of context for a class of object.
<T> ExceptionMapper<T>
getExceptionMapper(java.lang.Class<T> type)
          Get an exception mapping provider for a particular class of exception.
<T> MessageBodyReader<T>
getMessageBodyReader(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType)
          Get a message body reader that matches a set of criteria.
<T> MessageBodyWriter<T>
getMessageBodyWriter(java.lang.Class<T> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] annotations, MediaType mediaType)
          Get a message body writer that matches a set of criteria.
 

Method Detail

getMessageBodyReader

<T> MessageBodyReader<T> getMessageBodyReader(java.lang.Class<T> type,
                                              java.lang.reflect.Type genericType,
                                              java.lang.annotation.Annotation[] annotations,
                                              MediaType mediaType)
Get a message body reader that matches a set of criteria.

Parameters:
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.
type - the class of object to be produced.
genericType - 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.
annotations - 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.
Returns:
a MessageBodyReader that matches the supplied criteria or null if none is found.

getMessageBodyWriter

<T> MessageBodyWriter<T> getMessageBodyWriter(java.lang.Class<T> type,
                                              java.lang.reflect.Type genericType,
                                              java.lang.annotation.Annotation[] annotations,
                                              MediaType mediaType)
Get a message body writer that matches a set of criteria.

Parameters:
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.
type - the class of object that is to be written.
genericType - 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.
annotations - 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:
a MessageBodyReader that matches the supplied criteria or null if none is found.

getExceptionMapper

<T> ExceptionMapper<T> getExceptionMapper(java.lang.Class<T> type)
Get an exception mapping provider for a particular class of exception. Returns the provider whose generic type is the nearest superclass of type.

Parameters:
type - the class of exception
Returns:
an ExceptionMapper for the supplied type or null if none is found.

getContextResolver

<T> ContextResolver<T> getContextResolver(java.lang.Class<T> contextType,
                                          java.lang.Class<?> objectType,
                                          MediaType mediaType)
Get a context resolver for a particular type of context for a class of object. Returns a ContextResolver whose generic type is assignable to contextType and that returns a non-null value from getContext(objectType).

Parameters:
contextType - the class of context desired
objectType - the class of object for which the context is desired
mediaType - the media type of data for which a context is required. The value is compared to the values of Produces for each candidate and only matching providers will be considered. A null value is equivalent to MediaType.WILDCARD_TYPE.
Returns:
a matching context resolver or null if none is found.
See Also:
ContextResolver.getContext(java.lang.Class)


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