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
public abstract class AbstractJaxbProvider<T> extends AbstractMessageReaderWriterProvider<T>
A base class for implementing JAXB-based readers and writers.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanfixedResolverMediaTypeprivate Value<java.lang.Boolean>formattedOutputprivate static java.util.Map<java.lang.Class<?>,java.lang.ref.WeakReference<javax.xml.bind.JAXBContext>>jaxbContextsprivate javax.ws.rs.ext.ProvidersjaxrsProvidersprivate Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.JAXBContext>>mtContextprivate Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.Marshaller>>mtMarshallerprivate Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.Unmarshaller>>mtUnmarshallerprivate Value<java.lang.Boolean>xmlRootElementProcessing-
Fields inherited from class org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider
UTF8
-
-
Constructor Summary
Constructors Constructor Description AbstractJaxbProvider(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private javax.xml.bind.JAXBContextgetJAXBContext(java.lang.Class type)private javax.xml.bind.JAXBContextgetJAXBContext(java.lang.Class type, javax.ws.rs.core.MediaType mt)private javax.xml.bind.MarshallergetMarshaller(java.lang.Class type)protected javax.xml.bind.MarshallergetMarshaller(java.lang.Class type, javax.ws.rs.core.MediaType mediaType)Get the JAXB marshaller for the given class and media type.protected static javax.xml.transform.sax.SAXSourcegetSAXSource(javax.xml.parsers.SAXParserFactory spf, java.io.InputStream entityStream)Create newSAXSourcefor a given entity input stream.protected javax.xml.bind.JAXBContextgetStoredJaxbContext(java.lang.Class type)Retrieve cached JAXB context capable of handling the given Java type.private javax.xml.bind.UnmarshallergetUnmarshaller(java.lang.Class type)protected javax.xml.bind.UnmarshallergetUnmarshaller(java.lang.Class type, javax.ws.rs.core.MediaType mediaType)Get the JAXB unmarshaller for the given class and media type.protected booleanisFormattedOutput()protected booleanisSupported(javax.ws.rs.core.MediaType mediaType)Check if the given media type is supported by this JAXB entity provider.protected booleanisXmlRootElementProcessing()voidsetConfiguration(javax.ws.rs.core.Configuration config)protected voidsetHeader(javax.xml.bind.Marshaller marshaller, java.lang.annotation.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, writeToAsString
-
-
-
-
Field Detail
-
jaxbContexts
private static final java.util.Map<java.lang.Class<?>,java.lang.ref.WeakReference<javax.xml.bind.JAXBContext>> jaxbContexts
-
jaxrsProviders
private final javax.ws.rs.ext.Providers jaxrsProviders
-
fixedResolverMediaType
private final boolean fixedResolverMediaType
-
mtContext
private final Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.JAXBContext>> mtContext
-
mtUnmarshaller
private final Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.Unmarshaller>> mtUnmarshaller
-
mtMarshaller
private final Value<javax.ws.rs.ext.ContextResolver<javax.xml.bind.Marshaller>> mtMarshaller
-
formattedOutput
private Value<java.lang.Boolean> formattedOutput
-
xmlRootElementProcessing
private Value<java.lang.Boolean> xmlRootElementProcessing
-
-
Constructor Detail
-
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 Detail
-
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 javax.xml.bind.Unmarshaller getUnmarshaller(java.lang.Class type, javax.ws.rs.core.MediaType mediaType) throws javax.xml.bind.JAXBExceptionGet 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:
javax.xml.bind.JAXBException- in case retrieving the unmarshaller fails with a JAXB exception.
-
getUnmarshaller
private javax.xml.bind.Unmarshaller getUnmarshaller(java.lang.Class type) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
getMarshaller
protected final javax.xml.bind.Marshaller getMarshaller(java.lang.Class type, javax.ws.rs.core.MediaType mediaType) throws javax.xml.bind.JAXBExceptionGet 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:
javax.xml.bind.JAXBException- in case retrieving the marshaller fails with a JAXB exception.
-
getMarshaller
private javax.xml.bind.Marshaller getMarshaller(java.lang.Class type) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
getJAXBContext
private javax.xml.bind.JAXBContext getJAXBContext(java.lang.Class type, javax.ws.rs.core.MediaType mt) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
getJAXBContext
private javax.xml.bind.JAXBContext getJAXBContext(java.lang.Class type) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
getStoredJaxbContext
protected javax.xml.bind.JAXBContext getStoredJaxbContext(java.lang.Class type) throws javax.xml.bind.JAXBExceptionRetrieve cached JAXB context capable of handling the given Java type.- Parameters:
type- Java type .- Returns:
- JAXB context associated with the Java type.
- Throws:
javax.xml.bind.JAXBException- in case the JAXB context retrieval fails.
-
getSAXSource
protected static javax.xml.transform.sax.SAXSource getSAXSource(javax.xml.parsers.SAXParserFactory spf, java.io.InputStream entityStream) throws javax.xml.bind.JAXBExceptionCreate 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:
javax.xml.bind.JAXBException- in case SAX source creation fails.
-
isFormattedOutput
protected boolean isFormattedOutput()
-
isXmlRootElementProcessing
protected boolean isXmlRootElementProcessing()
-
setHeader
protected void setHeader(javax.xml.bind.Marshaller marshaller, java.lang.annotation.Annotation[] annotations)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.
-
-