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

java.lang.Object
  extended by org.restlet.resource.Variant
      extended by org.restlet.resource.Representation
          extended by org.restlet.resource.StreamRepresentation
              extended by org.restlet.resource.OutputRepresentation
                  extended by org.restlet.resource.XmlRepresentation
                      extended by org.restlet.ext.jaxb.JaxbRepresentation<T>
Type Parameters:
T - The type to wrap.
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

public class JaxbRepresentation<T>
extends XmlRepresentation

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.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
JaxbRepresentation(MediaType mediaType, T object)
          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, 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, ValidationEventHandler validationHandler)
          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
 java.lang.Object evaluate(java.lang.String expression, javax.xml.namespace.QName returnType)
           
 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
 T getObject()
          Returns the wrapped Java object.
 javax.xml.transform.sax.SAXSource getSaxSource()
          Returns a JAXB SAX source.
 ValidationEventHandler getValidationEventHandler()
          Returns the optional validation event handler.
 boolean isFormattedOutput()
          Indicates if the resulting XML data should be formatted with line breaks and indentation.
 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.
 void setFormattedOutput(boolean formattedOutput)
          Indicates if the resulting XML data should be formatted with line breaks and indentation.
 void setObject(T object)
          Sets the wrapped Java object.
 void write(java.io.OutputStream outputStream)
          Writes the representation to a byte stream.
 
Methods inherited from class org.restlet.resource.XmlRepresentation
getBoolean, getDocumentBuilder, getDomSource, getNamespaceURI, getNode, getNodes, getNumber, getPrefix, getPrefixes, getSaxSource, getStreamSource, getText, isNamespaceAware, putNamespace, release, setNamespaceAware, validate, validate, validate, validate
 
Methods inherited from class org.restlet.resource.OutputRepresentation
getStream
 
Methods inherited from class org.restlet.resource.StreamRepresentation
getChannel, getReader, write, write
 
Methods inherited from class org.restlet.resource.Representation
checkDigest, checkDigest, computeDigest, createEmpty, exhaust, getAvailableSize, getDigest, getDownloadName, getExpirationDate, getModificationDate, getRange, getSize, getTag, getText, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, setDownloadable, setDownloadName, setExpirationDate, setModificationDate, setRange, setSize, setTag, setTransient
 
Methods inherited from class org.restlet.resource.Variant
getCharacterSet, getEncodings, getIdentifier, getLanguages, getMediaType, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setMediaType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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(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:
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,
                          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.
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:
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,
                          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.
java.io.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

evaluate

public java.lang.Object evaluate(java.lang.String expression,
                                 javax.xml.namespace.QName returnType)
                          throws java.lang.Exception
Specified by:
evaluate in class XmlRepresentation
Throws:
java.lang.Exception

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.

getObject

public T getObject()
            throws java.io.IOException
Returns the wrapped Java object.

Returns:
The wrapped Java object.
Throws:
java.io.IOException

getSaxSource

public javax.xml.transform.sax.SAXSource getSaxSource()
                                               throws java.io.IOException
Returns a JAXB SAX source.

Overrides:
getSaxSource in class XmlRepresentation
Returns:
A JAXB SAX source.
Throws:
java.io.IOException

getValidationEventHandler

public ValidationEventHandler getValidationEventHandler()
Returns the optional validation event handler.

Returns:
The optional validation event handler.

isFormattedOutput

public boolean isFormattedOutput()
Indicates if the resulting XML data should be formatted with line breaks and indentation. Defaults to false.

Returns:
the formattedOutput

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.

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.

setObject

public void setObject(T object)
Sets the wrapped Java object.

Parameters:
object - The Java object to set.

write

public void write(java.io.OutputStream outputStream)
           throws java.io.IOException
Writes the representation to a byte stream.

Specified by:
write in class Representation
Parameters:
outputStream - The output stream.
Throws:
java.io.IOException - If any error occurs attempting to write the stream.


Copyright © 2005-2008 Noelios Technologies.