Class AbstractJaxbProvider<T>
java.lang.Object
org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider<T>
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider<T>
- Type Parameters:
T- Java type supported by the provider.
- All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<T>,javax.ws.rs.ext.MessageBodyWriter<T>
- Direct Known Subclasses:
AbstractCollectionJaxbProvider,AbstractJaxbElementProvider,AbstractRootElementJaxbProvider,XmlRootObjectJaxbProvider
A base class for implementing JAXB-based readers and writers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate static final Map<Class<?>, WeakReference<JAXBContext>> private final javax.ws.rs.ext.Providersprivate final Value<javax.ws.rs.ext.ContextResolver<JAXBContext>> private final Value<javax.ws.rs.ext.ContextResolver<Marshaller>> private final Value<javax.ws.rs.ext.ContextResolver<Unmarshaller>> Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8 -
Constructor Summary
ConstructorsConstructorDescriptionAbstractJaxbProvider(javax.ws.rs.ext.Providers providers) Inheritance constructor.AbstractJaxbProvider(javax.ws.rs.ext.Providers providers, javax.ws.rs.core.MediaType resolverMediaType) Inheritance constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate JAXBContextgetJAXBContext(Class type) private JAXBContextgetJAXBContext(Class type, javax.ws.rs.core.MediaType mt) private MarshallergetMarshaller(Class type) protected final MarshallergetMarshaller(Class type, javax.ws.rs.core.MediaType mediaType) Get the JAXB marshaller for the given class and media type.protected static SAXSourcegetSAXSource(SAXParserFactory spf, InputStream entityStream) Create newSAXSourcefor a given entity input stream.protected JAXBContextgetStoredJaxbContext(Class type) Retrieve cached JAXB context capable of handling the given Java type.private UnmarshallergetUnmarshaller(Class type) protected final UnmarshallergetUnmarshaller(Class type, javax.ws.rs.core.MediaType mediaType) Get the JAXB unmarshaller for the given class and media type.protected booleanprotected booleanisSupported(javax.ws.rs.core.MediaType mediaType) Check if the given media type is supported by this JAXB entity provider.protected booleanvoidsetConfiguration(javax.ws.rs.core.Configuration config) protected voidsetHeader(Marshaller marshaller, Annotation[] annotations) Set the custom XML header on a JAXB marshaller if specified viaXmlHeaderannotation, present in the supplied array of annotations.Methods inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
getCharset, getSize, readFromAsString, writeTo, writeTo, writeToAsStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.ws.rs.ext.MessageBodyReader
isReadable, readFromMethods inherited from interface javax.ws.rs.ext.MessageBodyWriter
isWriteable, writeTo
-
Field Details
-
jaxbContexts
-
jaxrsProviders
private final javax.ws.rs.ext.Providers jaxrsProviders -
fixedResolverMediaType
private final boolean fixedResolverMediaType -
mtContext
-
mtUnmarshaller
-
mtMarshaller
-
formattedOutput
-
xmlRootElementProcessing
-
-
Constructor Details
-
AbstractJaxbProvider
public AbstractJaxbProvider(javax.ws.rs.ext.Providers providers) Inheritance constructor.- Parameters:
providers- JAX-RS providers.
-
AbstractJaxbProvider
public AbstractJaxbProvider(javax.ws.rs.ext.Providers providers, javax.ws.rs.core.MediaType resolverMediaType) Inheritance constructor.- Parameters:
providers- JAX-RS providers.resolverMediaType- JAXB component context resolver media type to be used.
-
-
Method Details
-
setConfiguration
@Context public void setConfiguration(javax.ws.rs.core.Configuration config) -
isSupported
protected boolean isSupported(javax.ws.rs.core.MediaType mediaType) Check if the given media type is supported by this JAXB entity provider.Subclasses can override this method. Default implementation always returns
true.- Parameters:
mediaType- media type to be checked for support.- Returns:
trueif the media type is supported by the entity provider,falseotherwise.
-
getUnmarshaller
protected final Unmarshaller getUnmarshaller(Class type, javax.ws.rs.core.MediaType mediaType) throws JAXBException Get the JAXB unmarshaller for the given class and media type.In case this provider instance has been
created with a fixed resolver media type, the supplied media type argument will be ignored.- Parameters:
type- Java type to be unmarshalled.mediaType- entity media type.- Returns:
- JAXB unmarshaller for the requested Java type, media type combination.
- Throws:
JAXBException- in case retrieving the unmarshaller fails with a JAXB exception.
-
getUnmarshaller
- Throws:
JAXBException
-
getMarshaller
protected final Marshaller getMarshaller(Class type, javax.ws.rs.core.MediaType mediaType) throws JAXBException Get the JAXB marshaller for the given class and media type.In case this provider instance has been
created with a fixed resolver media type, the supplied media type argument will be ignored.- Parameters:
type- Java type to be marshalled.mediaType- entity media type.- Returns:
- JAXB marshaller for the requested Java type, media type combination.
- Throws:
JAXBException- in case retrieving the marshaller fails with a JAXB exception.
-
getMarshaller
- Throws:
JAXBException
-
getJAXBContext
- Throws:
JAXBException
-
getJAXBContext
- Throws:
JAXBException
-
getStoredJaxbContext
Retrieve cached JAXB context capable of handling the given Java type.- Parameters:
type- Java type .- Returns:
- JAXB context associated with the Java type.
- Throws:
JAXBException- in case the JAXB context retrieval fails.
-
getSAXSource
protected static SAXSource getSAXSource(SAXParserFactory spf, InputStream entityStream) throws JAXBException Create newSAXSourcefor a given entity input stream.- Parameters:
spf- SAX parser factory to be used to create the SAX source.entityStream- entity input stream.- Returns:
- new
SAXSourcerepresenting the entity input stream. - Throws:
JAXBException- in case SAX source creation fails.
-
isFormattedOutput
protected boolean isFormattedOutput() -
isXmlRootElementProcessing
protected boolean isXmlRootElementProcessing() -
setHeader
Set the custom XML header on a JAXB marshaller if specified viaXmlHeaderannotation, present in the supplied array of annotations.- Parameters:
marshaller- JAXB marshaller.annotations- array of annotations that MAY contain aXmlHeaderannotation instance.
-