fr.cnes.sitools.common
Class SitoolsXStreamRepresentation<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 fr.cnes.sitools.common.SitoolsXStreamRepresentation<T>
Type Parameters:
T - The type to wrap.

public final class SitoolsXStreamRepresentation<T>
extends org.restlet.representation.WriterRepresentation

Representation based on the XStream library. It can serialize and deserialize automatically in XML. It also supports a bridge to JSON leveraging the Jettison library.

Author:
Jerome Louvel
See Also:
XStream project

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
SitoolsXStreamRepresentation(org.restlet.data.MediaType mediaType, T object)
          Constructor.
SitoolsXStreamRepresentation(org.restlet.representation.Representation representation)
          Constructor.
SitoolsXStreamRepresentation(T object)
          Constructor.
 
Method Summary
 java.lang.String convertStreamToString(java.io.InputStream is)
          Convert InputStream to String.
 java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> getJsonDriverClass()
          Returns the XStream JSON driver class.
 T getObject()
          Get the object
 T getObject(java.lang.String rootNode)
          FIXME Adding rootNode cause streaming to stop
 java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> getXmlDriverClass()
          Returns the XStream XML driver class.
 com.thoughtworks.xstream.XStream getXstream()
          Returns the modifiable XStream object.
 void setJsonDriverClass(java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> jsonDriverClass)
          Sets the XStream JSON driver class.
 void setXmlDriverClass(java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> xmlDriverClass)
          Sets the XStream XML driver class.
 void setXstream(com.thoughtworks.xstream.XStream xstream)
          Sets the XStream object.
 void write(java.io.Writer writer)
           
 
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader, release, write
 
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write
 
Methods inherited from class org.restlet.representation.Representation
checkDigest, checkDigest, computeDigest, createEmpty, exhaust, getAvailableSize, getDigest, getDisposition, getDownloadName, getExpirationDate, getRange, getSize, getText, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, setDisposition, setDownloadable, setDownloadName, setExpirationDate, 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, getIdentifier, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SitoolsXStreamRepresentation

public SitoolsXStreamRepresentation(org.restlet.data.MediaType mediaType,
                                    T object)
Constructor.

Parameters:
mediaType - The target media type.
object - The object to format.

SitoolsXStreamRepresentation

public SitoolsXStreamRepresentation(org.restlet.representation.Representation representation)
Constructor.

Parameters:
representation - The representation to parse.

SitoolsXStreamRepresentation

public SitoolsXStreamRepresentation(T object)
Constructor. Uses the MediaType.APPLICATION_XML media type by default.

Parameters:
object - The object to format.
Method Detail

getJsonDriverClass

public java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> getJsonDriverClass()
Returns the XStream JSON driver class.

Returns:
TXStream JSON driver class.

getObject

public T getObject()
Get the object

Returns:
the object

getObject

public T getObject(java.lang.String rootNode)
FIXME Adding rootNode cause streaming to stop

Parameters:
rootNode - the root node
Returns:
Object of generic type

getXmlDriverClass

public java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> getXmlDriverClass()
Returns the XStream XML driver class.

Returns:
The XStream XML driver class.

getXstream

public com.thoughtworks.xstream.XStream getXstream()
Returns the modifiable XStream object. Useful to customize mappings.

Returns:
The modifiable XStream object.

setJsonDriverClass

public void setJsonDriverClass(java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> jsonDriverClass)
Sets the XStream JSON driver class.

Parameters:
jsonDriverClass - The XStream JSON driver class.

setXmlDriverClass

public void setXmlDriverClass(java.lang.Class<? extends com.thoughtworks.xstream.io.HierarchicalStreamDriver> xmlDriverClass)
Sets the XStream XML driver class.

Parameters:
xmlDriverClass - The XStream XML driver class.

setXstream

public void setXstream(com.thoughtworks.xstream.XStream xstream)
Sets the XStream object.

Parameters:
xstream - The XStream object.

write

public void write(java.io.Writer writer)
           throws java.io.IOException
Specified by:
write in class org.restlet.representation.Representation
Throws:
java.io.IOException

convertStreamToString

public java.lang.String convertStreamToString(java.io.InputStream is)
                                       throws java.io.IOException
Convert InputStream to String. To convert the InputStream to String we use the BufferedReader.readLine() method. We iterate until the BufferedReader return null which means there's no more data to read. Each line will appended to a StringBuilder and returned as String.

Parameters:
is - the stream to convert
Returns:
String the string representing the stream
Throws:
java.io.IOException - when reading error occurs


Copyright © 2010-2013 CNES. All Rights Reserved.