org.restlet.ext.jibx
Class JibxRepresentation<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.jibx.JibxRepresentation<T>
Type Parameters:
T - The type to wrap.
All Implemented Interfaces:
javax.xml.namespace.NamespaceContext

public class JibxRepresentation<T>
extends XmlRepresentation

An XML representation based on JIBX that provides easy translation between XML representations and Java objects with JIBX bindings.

Author:
Florian Schwarz
See Also:
JiBX project

Field Summary
 
Fields inherited from class org.restlet.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
JibxRepresentation(MediaType mediaType, T object)
          Creates a JIBX representation from an existing Java object.
JibxRepresentation(MediaType mediaType, T object, java.lang.String bindingName)
          Creates a JIBX representation from an existing Java object.
JibxRepresentation(Representation xmlRepresentation, java.lang.Class bindingClass)
          Creates a new JIBX representation, that can be used to convert the input XML into a Java object.
JibxRepresentation(Representation xmlRepresentation, java.lang.Class bindingClass, java.lang.String bindingName)
          Creates a new JIBX representation, that can be used to convert the input XML into a Java object.
 
Method Summary
 java.lang.Object evaluate(java.lang.String expression, javax.xml.namespace.QName returnType)
           
 java.lang.String getEncoding()
          Returns the document encoding to use for marshalling.
 T getObject()
          Returns the wrapped Java object.
 void setEncoding(java.lang.String encoding)
           
 void setObject(T object)
          Sets the wrapped Java object.
 void write(java.io.OutputStream outputStream)
          Marshals the document and 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, 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

JibxRepresentation

public JibxRepresentation(MediaType mediaType,
                          T object)
Creates a JIBX representation from an existing Java object. This allows a translation from a Java object to a XML representation.

Parameters:
mediaType - The representation's media type (usually MediaType.APPLICATION_XML or MediaType.TEXT_XML).
object - The Java object.

JibxRepresentation

public JibxRepresentation(MediaType mediaType,
                          T object,
                          java.lang.String bindingName)
Creates a JIBX representation from an existing Java object. This allows a translation from a Java object to a XML representation.

Parameters:
mediaType - The representation's media type (usually MediaType.APPLICATION_XML or MediaType.TEXT_XML).
object - The Java object.
bindingName - The name of the JIBX binding to use.

JibxRepresentation

public JibxRepresentation(Representation xmlRepresentation,
                          java.lang.Class bindingClass)
Creates a new JIBX representation, that can be used to convert the input XML into a Java object. The XML is not validated.

Parameters:
xmlRepresentation - The XML wrapped in a representation.
bindingClass - The Target Java class for binding.

JibxRepresentation

public JibxRepresentation(Representation xmlRepresentation,
                          java.lang.Class bindingClass,
                          java.lang.String bindingName)
Creates a new JIBX representation, that can be used to convert the input XML into a Java object. The XML is not validated.

Parameters:
xmlRepresentation - The XML wrapped in a representation.
bindingClass - The Target Java class for binding.
bindingName - The name of the JIBX binding to use.
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

getEncoding

public java.lang.String getEncoding()
Returns the document encoding to use for marshalling. The default value is UTF-8.

Returns:
The document encoding to use for marshalling.

getObject

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

Returns:
The wrapped Java object.
Throws:
JiBXException - If unmarshalling XML with JIBX fails.
java.io.IOException - If any error occurs attempting to get the stream of the xmlRepresentation.

setEncoding

public void setEncoding(java.lang.String encoding)

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
Marshals the document and 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.