Package org.restlet.ext.jaxb.internal
Class Marshaller<T>
- java.lang.Object
-
- org.restlet.ext.jaxb.internal.Marshaller<T>
-
public class Marshaller<T> extends java.lang.ObjectThis is a utility class to assist in marshaling Java content trees into XML. Eachmarshalmethod 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.ClassLoaderclassLoaderThe JAXB classloader.private java.lang.StringcontextPathThe JAXB context path.private JaxbRepresentation<T>jaxbRepresentationThe parent JAXB representation.private java.lang.ThreadLocal<javax.xml.bind.Marshaller>marshallerUse thread identity to preserve safety of access to marshalers.
-
Constructor Summary
Constructors Constructor Description Marshaller(JaxbRepresentation<T> jaxbRepresentation)Marshaller(JaxbRepresentation<T> jaxbRepresentation, java.lang.String contextPath, java.lang.ClassLoader classLoader)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoadergetClassLoader()Returns the JAXB classloader.java.lang.StringgetContextPath()Returns the JAXB context path.JaxbRepresentation<T>getJaxbRepresentation()Returns the parent JAXB representation.private javax.xml.bind.MarshallergetMarshaller()Returns the JAXB marshaller.voidmarshal(java.lang.Object jaxbElement, java.io.OutputStream stream)Marshals the content tree rooted atjaxbElementinto an output stream.voidmarshal(java.lang.Object jaxbElement, java.io.Writer writer)Marshal the content tree rooted atjaxbElementinto a writer.
-
-
-
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)
-
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.JAXBExceptionReturns 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.JAXBExceptionMarshals the content tree rooted atjaxbElementinto 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.JAXBExceptionMarshal the content tree rooted atjaxbElementinto 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.
-
-