Class Marshaller<T>


  • public class Marshaller<T>
    extends java.lang.Object
    This is a utility class to assist in marshaling Java content trees into XML. Each marshal method takes a different target for the XML. This class is a factory that constructs an instance of itself for multiple uses. The created instance is thread safe and is optimized to be used for multiple, possibly concurrent calls.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader classLoader
      The JAXB classloader.
      private java.lang.String contextPath
      The JAXB context path.
      private JaxbRepresentation<T> jaxbRepresentation
      The parent JAXB representation.
      private java.lang.ThreadLocal<javax.xml.bind.Marshaller> marshaller
      Use thread identity to preserve safety of access to marshalers.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.ClassLoader getClassLoader()
      Returns the JAXB classloader.
      java.lang.String getContextPath()
      Returns the JAXB context path.
      JaxbRepresentation<T> getJaxbRepresentation()
      Returns the parent JAXB representation.
      private javax.xml.bind.Marshaller getMarshaller()
      Returns the JAXB marshaller.
      void marshal​(java.lang.Object jaxbElement, java.io.OutputStream stream)
      Marshals the content tree rooted at jaxbElement into an output stream.
      void marshal​(java.lang.Object jaxbElement, java.io.Writer writer)
      Marshal the content tree rooted at jaxbElement into a writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • classLoader

        private final java.lang.ClassLoader classLoader
        The JAXB classloader.
      • contextPath

        private final java.lang.String contextPath
        The JAXB context path.
      • jaxbRepresentation

        private final JaxbRepresentation<T> jaxbRepresentation
        The parent JAXB representation.
      • marshaller

        private final java.lang.ThreadLocal<javax.xml.bind.Marshaller> marshaller
        Use thread identity to preserve safety of access to marshalers.
    • Constructor Detail

      • Marshaller

        public Marshaller​(JaxbRepresentation<T> jaxbRepresentation,
                          java.lang.String contextPath,
                          java.lang.ClassLoader classLoader)
        Constructor.
        Parameters:
        jaxbRepresentation - The JAXB representation to marshal.
        contextPath - The JAXB context path.
        classLoader - The JAXB classloader.
    • Method Detail

      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Returns the JAXB classloader.
        Returns:
        The JAXB classloader.
      • getContextPath

        public java.lang.String getContextPath()
        Returns the JAXB context path.
        Returns:
        The JAXB context path.
      • getJaxbRepresentation

        public JaxbRepresentation<T> getJaxbRepresentation()
        Returns the parent JAXB representation.
        Returns:
        The parent JAXB representation.
      • getMarshaller

        private javax.xml.bind.Marshaller getMarshaller()
                                                 throws javax.xml.bind.JAXBException
        Returns the JAXB marshaller.
        Returns:
        The JAXB marshaller.
        Throws:
        javax.xml.bind.JAXBException
      • marshal

        public void marshal​(java.lang.Object jaxbElement,
                            java.io.OutputStream stream)
                     throws javax.xml.bind.JAXBException
        Marshals the content tree rooted at jaxbElement into an output stream.
        Parameters:
        jaxbElement - The root of the content tree to be marshalled.
        stream - The target output stream write the XML to.
        Throws:
        javax.xml.bind.JAXBException - If any unexpected problem occurs during marshalling.
      • marshal

        public void marshal​(java.lang.Object jaxbElement,
                            java.io.Writer writer)
                     throws javax.xml.bind.JAXBException
        Marshal the content tree rooted at jaxbElement into a writer.
        Parameters:
        jaxbElement - The root of the content tree to be marshaled.
        writer - The target writer to write the XML to.
        Throws:
        javax.xml.bind.JAXBException - If any unexpected problem occurs during marshaling.