org.restlet.ext.jaxb
Class JaxbRepresentation<T>

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.CharacterRepresentation
                  extended by org.restlet.representation.WriterRepresentation
                      extended by org.restlet.ext.jaxb.JaxbRepresentation<T>
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.

Author:
Overstock.com, Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
JaxbRepresentation(MediaType mediaType, T object)
          Creates a JAXB representation from an existing JAXB content tree.
JaxbRepresentation(MediaType mediaType, T object, ClassLoader classloader)
          Creates a JAXB representation from an existing JAXB content tree.
JaxbRepresentation(Representation xmlRepresentation, Class<T> type)
          Creates a new JAXB representation, converting the input XML into a Java content tree.
JaxbRepresentation(Representation xmlRepresentation, Class<T> type, ValidationEventHandler validationHandler)
          Creates a new JAXB representation, converting the input XML into a Java content tree.
JaxbRepresentation(Representation xmlRepresentation, String contextPath)
          Creates a new JAXB representation, converting the input XML into a Java content tree.
JaxbRepresentation(Representation xmlRepresentation, String contextPath, ValidationEventHandler validationHandler)
          Creates a new JAXB representation, converting the input XML into a Java content tree.
JaxbRepresentation(Representation xmlRepresentation, String contextPath, ValidationEventHandler validationHandler, 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 with MediaType.APPLICATION_XML.
 
Method Summary
 ClassLoader getClassLoader()
          Returns the classloader to use for JAXB annotated classes.
 JAXBContext getContext()
          Returns the JAXB context.
static JAXBContext getContext(String contextPath)
          Returns the JAXB context, if possible from the cached contexts.
static JAXBContext getContext(String contextPath, ClassLoader classLoader)
          Returns the JAXB context, if possible from the cached contexts.
 String getContextPath()
          Returns the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes
 JAXBSource getJaxbSource()
          Returns a JAXB SAX source.
 String getNoNamespaceSchemaLocation()
          Returns the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
 T getObject()
          Returns the wrapped Java object.
 String getSchemaLocation()
          Returns the "xsi:schemaLocation" attribute in the generated XML data.
 ValidationEventHandler getValidationEventHandler()
          Returns the optional validation event handler.
 boolean isExpandingEntityRefs()
          Indicates if the parser will expand entity reference nodes.
 boolean isFormattedOutput()
          Indicates if the resulting XML data should be formatted with line breaks and indentation.
 boolean isFragment()
          Indicates whether or not document level events will be generated by the Marshaller.
 boolean isSecureProcessing()
          Indicates if it limits potential XML overflow attacks.
 boolean isValidatingDtd()
          Indicates the desire for validating this type of XML representations against an XML schema if one is referenced within the contents.
 boolean isXIncludeAware()
          Indicates the desire for processing XInclude if found in this type of XML representations.
 void setClassLoader(ClassLoader classLoader)
          Sets the classloader to use for JAXB annotated classes.
 void setContextPath(String contextPath)
          Sets the list of Java package names that contain schema derived class and/or Java to schema (JAXB-annotated) mapped classes.
 void setExpandingEntityRefs(boolean expandEntityRefs)
          Indicates if the parser will expand entity reference nodes.
 void setFormattedOutput(boolean formattedOutput)
          Indicates if the resulting XML data should be formatted with line breaks and indentation.
 void setFragment(boolean fragment)
          Indicates whether or not document level events will be generated by the Marshaller.
 void setNoNamespaceSchemaLocation(String noNamespaceSchemaLocation)
          Sets the "xsi:noNamespaceSchemaLocation" attribute in the generated XML data.
 void setObject(T object)
          Sets the wrapped Java object.
 void setSchemaLocation(String schemaLocation)
          Sets the "xsi:schemaLocation" attribute in the generated XML data.
 void setSecureProcessing(boolean secureProcessing)
          Indicates if it limits potential XML overflow attacks.
 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.
 void setValidationEventHandler(ValidationEventHandler validationEventHandler)
          Sets the validation event handler.
 void setXIncludeAware(boolean includeAware)
          Indicates the desire for processing XInclude if found in this type of XML representations.
 void write(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, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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,
                          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,
                          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:
JAXBException - If the incoming XML does not validate against the schema.
IOException - If unmarshalling XML fails.

JaxbRepresentation

public JaxbRepresentation(Representation xmlRepresentation,
                          Class<T> type,
                          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:
JAXBException - If the incoming XML does not validate against the schema.
IOException - If unmarshalling XML fails.

JaxbRepresentation

public JaxbRepresentation(Representation xmlRepresentation,
                          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:
JAXBException - If the incoming XML does not validate against the schema.
IOException - If unmarshalling XML fails.

JaxbRepresentation

public JaxbRepresentation(Representation xmlRepresentation,
                          String contextPath,
                          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:
JAXBException - If the incoming XML does not validate against the schema.
IOException - If unmarshalling XML fails.

JaxbRepresentation

public JaxbRepresentation(Representation xmlRepresentation,
                          String contextPath,
                          ValidationEventHandler validationHandler,
                          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:
JAXBException - If the incoming XML does not validate against the schema.
IOException - If unmarshalling XML fails.

JaxbRepresentation

public JaxbRepresentation(T object)
Creates a JAXB representation from an existing JAXB content tree with MediaType.APPLICATION_XML.

Parameters:
object - The Java object.
Method Detail

getContext

public static JAXBContext getContext(String contextPath)
                              throws JAXBException
Returns the JAXB context, if possible from the cached contexts.

Parameters:
contextPath - The JAXB context path.
Returns:
The JAXB context.
Throws:
JAXBException

getContext

public static JAXBContext getContext(String contextPath,
                                     ClassLoader classLoader)
                              throws JAXBException
Returns 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:
JAXBException

getClassLoader

public ClassLoader getClassLoader()
Returns the classloader to use for JAXB annotated classes.

Returns:
The classloader to use for JAXB annotated classes.

getContext

public JAXBContext getContext()
                       throws JAXBException
Returns the JAXB context.

Returns:
The JAXB context.
Throws:
JAXBException

getContextPath

public 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 JAXBSource getJaxbSource()
                         throws IOException
Returns a JAXB SAX source.

Returns:
A JAXB SAX source.
Throws:
IOException

getNoNamespaceSchemaLocation

public 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 IOException
Returns the wrapped Java object.

Returns:
The wrapped Java object.
Throws:
IOException

getSchemaLocation

public String getSchemaLocation()
Returns the "xsi:schemaLocation" attribute in the generated XML data.

Returns:
The "xsi:schemaLocation" attribute in the generated XML data.

getValidationEventHandler

public 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(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(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.

setNoNamespaceSchemaLocation

public void setNoNamespaceSchemaLocation(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(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(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(Writer writer)
           throws IOException
Writes the representation to a stream of characters.

Specified by:
write in class Representation
Parameters:
writer - The writer to use when writing.
Throws:
IOException - If any error occurs attempting to write the stream.


Copyright © 2005-2013 Restlet.