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 Details

    • jaxbContexts

      private static final Map<Class<?>,WeakReference<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<JAXBContext>> mtContext
    • mtUnmarshaller

      private final Value<javax.ws.rs.ext.ContextResolver<Unmarshaller>> mtUnmarshaller
    • mtMarshaller

      private final Value<javax.ws.rs.ext.ContextResolver<Marshaller>> mtMarshaller
    • formattedOutput

      private Value<Boolean> formattedOutput
    • xmlRootElementProcessing

      private Value<Boolean> 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:
      true if the media type is supported by the entity provider, false otherwise.
    • 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

      private Unmarshaller getUnmarshaller(Class type) throws JAXBException
      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

      private Marshaller getMarshaller(Class type) throws JAXBException
      Throws:
      JAXBException
    • getJAXBContext

      private JAXBContext getJAXBContext(Class type, javax.ws.rs.core.MediaType mt) throws JAXBException
      Throws:
      JAXBException
    • getJAXBContext

      private JAXBContext getJAXBContext(Class type) throws JAXBException
      Throws:
      JAXBException
    • getStoredJaxbContext

      protected JAXBContext getStoredJaxbContext(Class type) throws JAXBException
      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 new SAXSource for a given entity input stream.
      Parameters:
      spf - SAX parser factory to be used to create the SAX source.
      entityStream - entity input stream.
      Returns:
      new SAXSource representing the entity input stream.
      Throws:
      JAXBException - in case SAX source creation fails.
    • isFormattedOutput

      protected boolean isFormattedOutput()
    • isXmlRootElementProcessing

      protected boolean isXmlRootElementProcessing()
    • setHeader

      protected void setHeader(Marshaller marshaller, Annotation[] annotations)
      Set the custom XML header on a JAXB marshaller if specified via XmlHeader annotation, present in the supplied array of annotations.
      Parameters:
      marshaller - JAXB marshaller.
      annotations - array of annotations that MAY contain a XmlHeader annotation instance.