Package org.restlet.ext.jaxb
Class JaxbRepresentation<T>
- java.lang.Object
-
- Type Parameters:
T- The type to wrap.
public class JaxbRepresentation<T> extends WriterRepresentation
An XML representation based on JAXB that provides easy translation between XML and JAXB element class trees.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ClassLoaderclassLoaderThe classloader to use for JAXB annotated classes.private java.lang.StringcontextPathThe list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes.private static java.util.Map<java.lang.String,javax.xml.bind.JAXBContext>contextsImproves performance by caching contexts which are expensive to create.private booleanexpandingEntityRefsSpecifies that the parser will expand entity reference nodes.private booleanformattedOutputIndicates if the resulting XML data should be formatted with line breaks and indentation.private booleanfragmentIndicates whether or not document level events will be generated by the Marshaller.private com.sun.xml.bind.marshaller.NamespacePrefixMappernamespacePrefixMapperAn optional namespace prefix mapper for marshalling.private java.lang.StringnoNamespaceSchemaLocationThe "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.private TobjectThe wrapped Java object.private java.lang.StringschemaLocationThe "xsi:schemaLocation" attribute in the generated XML dataprivate booleansecureProcessingLimits potential XML overflow attacks.private booleanvalidatingDtdIndicates the desire for validating this type of XML representations against a DTD.private javax.xml.bind.ValidationEventHandlervalidationEventHandlerThe JAXB validation event handler.private booleanxIncludeAwareIndicates the desire for processing XInclude if found in this type of XML representations.private RepresentationxmlRepresentationThe source XML representation.-
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description JaxbRepresentation(MediaType mediaType, T object)Creates a JAXB representation from an existing JAXB content tree.JaxbRepresentation(MediaType mediaType, T object, java.lang.ClassLoader classloader)Creates a JAXB representation from an existing JAXB content tree.JaxbRepresentation(Representation xmlRepresentation, java.lang.Class<T> type)Creates a new JAXB representation, converting the input XML into a Java content tree.JaxbRepresentation(Representation xmlRepresentation, java.lang.Class<T> type, javax.xml.bind.ValidationEventHandler validationHandler)Creates a new JAXB representation, converting the input XML into a Java content tree.JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath)Creates a new JAXB representation, converting the input XML into a Java content tree.JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath, javax.xml.bind.ValidationEventHandler validationHandler)Creates a new JAXB representation, converting the input XML into a Java content tree.JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath, javax.xml.bind.ValidationEventHandler validationHandler, java.lang.ClassLoader classLoader)Creates a new JAXB representation, converting the input XML into a Java content tree.JaxbRepresentation(T object)Creates a JAXB representation from an existing JAXB content tree withMediaType.APPLICATION_XML.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoadergetClassLoader()Returns the classloader to use for JAXB annotated classes.javax.xml.bind.JAXBContextgetContext()Returns the JAXB context.static javax.xml.bind.JAXBContextgetContext(java.lang.String contextPath)Returns the JAXB context, if possible from the cached contexts.static javax.xml.bind.JAXBContextgetContext(java.lang.String contextPath, java.lang.ClassLoader classLoader)Returns the JAXB context, if possible from the cached contexts.java.lang.StringgetContextPath()Returns the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classesjavax.xml.bind.util.JAXBSourcegetJaxbSource()Returns a JAXB SAX source.com.sun.xml.bind.marshaller.NamespacePrefixMappergetNamespacePrefixMapper()Returns the optional namespace prefix mapper for marshalling.java.lang.StringgetNoNamespaceSchemaLocation()Returns the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.TgetObject()Returns the wrapped Java object.java.lang.StringgetSchemaLocation()Returns the "xsi:schemaLocation" attribute in the generated XML data.javax.xml.bind.ValidationEventHandlergetValidationEventHandler()Returns the optional validation event handler.booleanisExpandingEntityRefs()Indicates if the parser will expand entity reference nodes.booleanisFormattedOutput()Indicates if the resulting XML data should be formatted with line breaks and indentation.booleanisFragment()Indicates whether or not document level events will be generated by the Marshaller.booleanisSecureProcessing()Indicates if it limits potential XML overflow attacks.booleanisValidatingDtd()Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.booleanisXIncludeAware()Indicates the desire for processing XInclude if found in this type of XML representations.voidsetClassLoader(java.lang.ClassLoader classLoader)Sets the classloader to use for JAXB annotated classes.voidsetContextPath(java.lang.String contextPath)Sets the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes.voidsetExpandingEntityRefs(boolean expandEntityRefs)Indicates if the parser will expand entity reference nodes.voidsetFormattedOutput(boolean formattedOutput)Indicates if the resulting XML data should be formatted with line breaks and indentation.voidsetFragment(boolean fragment)Indicates whether or not document level events will be generated by the Marshaller.voidsetNamespacePrefixMapper(com.sun.xml.bind.marshaller.NamespacePrefixMapper namespacePrefixMapper)Sets the optional namespace prefix mapper for marshalling.voidsetNoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)Sets the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.voidsetObject(T object)Sets the wrapped Java object.voidsetSchemaLocation(java.lang.String schemaLocation)Sets the "xsi:schemaLocation" attribute in the generated XML data.voidsetSecureProcessing(boolean secureProcessing)Indicates if it limits potential XML overflow attacks.voidsetValidatingDtd(boolean validating)Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.voidsetValidationEventHandler(javax.xml.bind.ValidationEventHandler validationEventHandler)Sets the validation event handler.voidsetXIncludeAware(boolean includeAware)Indicates the desire for processing XInclude if found in this type of XML representations.voidwrite(java.io.Writer writer)Writes the representation to a stream of characters.-
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
-
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
-
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
-
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
-
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
-
-
-
Field Detail
-
contexts
private static final java.util.Map<java.lang.String,javax.xml.bind.JAXBContext> contexts
Improves performance by caching contexts which are expensive to create.
-
classLoader
private volatile java.lang.ClassLoader classLoader
The classloader to use for JAXB annotated classes.
-
contextPath
private volatile java.lang.String contextPath
The list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes.
-
expandingEntityRefs
private volatile boolean expandingEntityRefs
Specifies that the parser will expand entity reference nodes. By default the value of this is set to true.
-
formattedOutput
private volatile boolean formattedOutput
Indicates if the resulting XML data should be formatted with line breaks and indentation. Defaults to false.
-
fragment
private volatile boolean fragment
Indicates whether or not document level events will be generated by the Marshaller.
-
namespacePrefixMapper
private volatile com.sun.xml.bind.marshaller.NamespacePrefixMapper namespacePrefixMapper
An optional namespace prefix mapper for marshalling.
-
noNamespaceSchemaLocation
private volatile java.lang.String noNamespaceSchemaLocation
The "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
-
object
private volatile T object
The wrapped Java object.
-
schemaLocation
private volatile java.lang.String schemaLocation
The "xsi:schemaLocation" attribute in the generated XML data
-
secureProcessing
private boolean secureProcessing
Limits potential XML overflow attacks.
-
validatingDtd
private volatile boolean validatingDtd
Indicates the desire for validating this type of XML representations against a DTD. Note that for XML schema or Relax NG validation, use the "schema" property instead.- See Also:
DocumentBuilderFactory.setValidating(boolean)
-
validationEventHandler
private volatile javax.xml.bind.ValidationEventHandler validationEventHandler
The JAXB validation event handler.
-
xIncludeAware
private volatile boolean xIncludeAware
Indicates the desire for processing XInclude if found in this type of XML representations. By default the value of this is set to false.- See Also:
DocumentBuilderFactory.setXIncludeAware(boolean)
-
xmlRepresentation
private volatile Representation xmlRepresentation
The source XML representation.
-
-
Constructor Detail
-
JaxbRepresentation
public JaxbRepresentation(MediaType mediaType, T object)
Creates a JAXB representation from an existing JAXB content tree.- Parameters:
mediaType- The representation's media type.object- The Java object.
-
JaxbRepresentation
public JaxbRepresentation(MediaType mediaType, T object, java.lang.ClassLoader classloader)
Creates a JAXB representation from an existing JAXB content tree.- Parameters:
mediaType- The representation's media type.object- The Java object.classloader- The classloader to use for JAXB annotated classes.
-
JaxbRepresentation
public JaxbRepresentation(Representation xmlRepresentation, java.lang.Class<T> type)
Creates a new JAXB representation, converting the input XML into a Java content tree. The XML is validated.- Parameters:
xmlRepresentation- The XML wrapped in a representation.type- The type to convert to.- Throws:
javax.xml.bind.JAXBException- If the incoming XML does not validate against the schema.java.io.IOException- If unmarshalling XML fails.
-
JaxbRepresentation
public JaxbRepresentation(Representation xmlRepresentation, java.lang.Class<T> type, javax.xml.bind.ValidationEventHandler validationHandler)
Creates a new JAXB representation, converting the input XML into a Java content tree. The XML is validated.- Parameters:
xmlRepresentation- The XML wrapped in a representation.type- The type to convert to.validationHandler- A handler for dealing with validation failures.- Throws:
javax.xml.bind.JAXBException- If the incoming XML does not validate against the schema.java.io.IOException- If unmarshalling XML fails.
-
JaxbRepresentation
public JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath)
Creates a new JAXB representation, converting the input XML into a Java content tree. The XML is validated.- Parameters:
xmlRepresentation- The XML wrapped in a representation.contextPath- The list of Java package names for JAXB.- Throws:
javax.xml.bind.JAXBException- If the incoming XML does not validate against the schema.java.io.IOException- If unmarshalling XML fails.
-
JaxbRepresentation
public JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath, javax.xml.bind.ValidationEventHandler validationHandler)
Creates a new JAXB representation, converting the input XML into a Java content tree. The XML is validated.- Parameters:
xmlRepresentation- The XML wrapped in a representation.contextPath- The list of Java package names for JAXB.validationHandler- A handler for dealing with validation failures.- Throws:
javax.xml.bind.JAXBException- If the incoming XML does not validate against the schema.java.io.IOException- If unmarshalling XML fails.
-
JaxbRepresentation
public JaxbRepresentation(Representation xmlRepresentation, java.lang.String contextPath, javax.xml.bind.ValidationEventHandler validationHandler, java.lang.ClassLoader classLoader)
Creates a new JAXB representation, converting the input XML into a Java content tree. The XML is validated.- Parameters:
xmlRepresentation- The XML wrapped in a representation.contextPath- The list of Java package names for JAXB.validationHandler- A handler for dealing with validation failures.classLoader- The classloader to use for JAXB annotated classes.- Throws:
javax.xml.bind.JAXBException- If the incoming XML does not validate against the schema.java.io.IOException- If unmarshalling XML fails.
-
JaxbRepresentation
public JaxbRepresentation(T object)
Creates a JAXB representation from an existing JAXB content tree withMediaType.APPLICATION_XML.- Parameters:
object- The Java object.
-
-
Method Detail
-
getContext
public static javax.xml.bind.JAXBContext getContext(java.lang.String contextPath) throws javax.xml.bind.JAXBExceptionReturns the JAXB context, if possible from the cached contexts.- Parameters:
contextPath- The JAXB context path.- Returns:
- The JAXB context.
- Throws:
javax.xml.bind.JAXBException
-
getContext
public static javax.xml.bind.JAXBContext getContext(java.lang.String contextPath, java.lang.ClassLoader classLoader) throws javax.xml.bind.JAXBExceptionReturns the JAXB context, if possible from the cached contexts.- Parameters:
contextPath- The JAXB context path.classLoader- The JAXB classloader to use for annotated JAXB classes.- Returns:
- The JAXB context.
- Throws:
javax.xml.bind.JAXBException
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns the classloader to use for JAXB annotated classes.- Returns:
- The classloader to use for JAXB annotated classes.
-
getContext
public javax.xml.bind.JAXBContext getContext() throws javax.xml.bind.JAXBExceptionReturns the JAXB context.- Returns:
- The JAXB context.
- Throws:
javax.xml.bind.JAXBException
-
getContextPath
public java.lang.String getContextPath()
Returns the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes- Returns:
- The list of Java package names.
-
getJaxbSource
public javax.xml.bind.util.JAXBSource getJaxbSource() throws java.io.IOExceptionReturns a JAXB SAX source.- Returns:
- A JAXB SAX source.
- Throws:
java.io.IOException
-
getNamespacePrefixMapper
public com.sun.xml.bind.marshaller.NamespacePrefixMapper getNamespacePrefixMapper()
Returns the optional namespace prefix mapper for marshalling.- Returns:
- The optional namespace prefix mapper for marshalling.
-
getNoNamespaceSchemaLocation
public java.lang.String getNoNamespaceSchemaLocation()
Returns the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.- Returns:
- The "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
-
getObject
public T getObject() throws java.io.IOException
Returns the wrapped Java object.- Returns:
- The wrapped Java object.
- Throws:
java.io.IOException
-
getSchemaLocation
public java.lang.String getSchemaLocation()
Returns the "xsi:schemaLocation" attribute in the generated XML data.- Returns:
- The "xsi:schemaLocation" attribute in the generated XML data.
-
getValidationEventHandler
public javax.xml.bind.ValidationEventHandler getValidationEventHandler()
Returns the optional validation event handler.- Returns:
- The optional validation event handler.
-
isExpandingEntityRefs
public boolean isExpandingEntityRefs()
Indicates if the parser will expand entity reference nodes. By default the value of this is set to true.- Returns:
- True if the parser will expand entity reference nodes.
-
isFormattedOutput
public boolean isFormattedOutput()
Indicates if the resulting XML data should be formatted with line breaks and indentation. Defaults to false.- Returns:
- the formattedOutput
-
isFragment
public boolean isFragment()
Indicates whether or not document level events will be generated by the Marshaller.- Returns:
- True if the document level events will be generated by the Marshaller.
-
isSecureProcessing
public boolean isSecureProcessing()
Indicates if it limits potential XML overflow attacks.- Returns:
- True if it limits potential XML overflow attacks.
-
isValidatingDtd
public boolean isValidatingDtd()
Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.- Returns:
- True if the schema-based validation is enabled.
-
isXIncludeAware
public boolean isXIncludeAware()
Indicates the desire for processing XInclude if found in this type of XML representations. By default the value of this is set to false.- Returns:
- The current value of the xIncludeAware flag.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the classloader to use for JAXB annotated classes.- Parameters:
classLoader- The classloader to use for JAXB annotated classes.
-
setContextPath
public void setContextPath(java.lang.String contextPath)
Sets the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes.- Parameters:
contextPath- The JAXB context path.
-
setExpandingEntityRefs
public void setExpandingEntityRefs(boolean expandEntityRefs)
Indicates if the parser will expand entity reference nodes. By default the value of this is set to true.- Parameters:
expandEntityRefs- True if the parser will expand entity reference nodes.
-
setFormattedOutput
public void setFormattedOutput(boolean formattedOutput)
Indicates if the resulting XML data should be formatted with line breaks and indentation.- Parameters:
formattedOutput- True if the resulting XML data should be formatted.
-
setFragment
public void setFragment(boolean fragment)
Indicates whether or not document level events will be generated by the Marshaller.- Parameters:
fragment- True if the document level events will be generated by the Marshaller.
-
setNamespacePrefixMapper
public void setNamespacePrefixMapper(com.sun.xml.bind.marshaller.NamespacePrefixMapper namespacePrefixMapper)
Sets the optional namespace prefix mapper for marshalling.- Parameters:
namespacePrefixMapper- The optional namespace prefix mapper for marshalling.
-
setNoNamespaceSchemaLocation
public void setNoNamespaceSchemaLocation(java.lang.String noNamespaceSchemaLocation)
Sets the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.- Parameters:
noNamespaceSchemaLocation- The "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
-
setObject
public void setObject(T object)
Sets the wrapped Java object.- Parameters:
object- The Java object to set.
-
setSchemaLocation
public void setSchemaLocation(java.lang.String schemaLocation)
Sets the "xsi:schemaLocation" attribute in the generated XML data.- Parameters:
schemaLocation- The "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
-
setSecureProcessing
public void setSecureProcessing(boolean secureProcessing)
Indicates if it limits potential XML overflow attacks.- Parameters:
secureProcessing- True if it limits potential XML overflow attacks.
-
setValidatingDtd
public void setValidatingDtd(boolean validating)
Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.- Parameters:
validating- The new validation flag to set.
-
setValidationEventHandler
public void setValidationEventHandler(javax.xml.bind.ValidationEventHandler validationEventHandler)
Sets the validation event handler.- Parameters:
validationEventHandler- The optional validation event handler.
-
setXIncludeAware
public void setXIncludeAware(boolean includeAware)
Indicates the desire for processing XInclude if found in this type of XML representations. By default the value of this is set to false.- Parameters:
includeAware- The new value of the xIncludeAware flag.
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionWrites the representation to a stream of characters.- Specified by:
writein classRepresentation- Parameters:
writer- The writer to use when writing.- Throws:
java.io.IOException- If any error occurs attempting to write the stream.
-
-