org.restlet.representation
Class ObjectRepresentation<T extends Serializable>

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.StreamRepresentation
                  extended by org.restlet.representation.OutputRepresentation
                      extended by org.restlet.representation.ObjectRepresentation<T>
Type Parameters:
T - The class to serialize, see Serializable

public class ObjectRepresentation<T extends Serializable>
extends OutputRepresentation

Representation based on a serializable Java object.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
ObjectRepresentation(Representation serializedRepresentation)
          Constructor reading the object from a serialized representation.
ObjectRepresentation(T object)
          Constructor for the MediaType.APPLICATION_JAVA_OBJECT type.
ObjectRepresentation(T object, MediaType mediaType)
          Constructor for either the MediaType.APPLICATION_JAVA_OBJECT type or the MediaType.APPLICATION_XML type.
 
Method Summary
 T getObject()
          Returns the represented object.
 void release()
          Releases the represented object.
 void setObject(T object)
          Sets the represented object.
 void write(OutputStream outputStream)
          Writes the representation to a byte stream.
 
Methods inherited from class org.restlet.representation.OutputRepresentation
getStream
 
Methods inherited from class org.restlet.representation.StreamRepresentation
getChannel, getReader, write, 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
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectRepresentation

public ObjectRepresentation(Representation serializedRepresentation)
                     throws IOException,
                            ClassNotFoundException,
                            IllegalArgumentException
Constructor reading the object from a serialized representation. This representation must have the proper media type: "application/x-java-serialized-object".

Parameters:
serializedRepresentation - The serialized representation.
Throws:
IOException
ClassNotFoundException
IllegalArgumentException

ObjectRepresentation

public ObjectRepresentation(T object)
Constructor for the MediaType.APPLICATION_JAVA_OBJECT type.

Parameters:
object - The serializable object.

ObjectRepresentation

public ObjectRepresentation(T object,
                            MediaType mediaType)
Constructor for either the MediaType.APPLICATION_JAVA_OBJECT type or the MediaType.APPLICATION_XML type. In the first case, the Java Object Serialization mechanism is used, based on ObjectOutputStream. In the latter case, the JavaBeans XML serialization is used, based on XMLEncoder.

Parameters:
object - The serializable object.
mediaType - The media type.
Method Detail

getObject

public T getObject()
                                 throws IOException
Returns the represented object.

Returns:
The represented object.
Throws:
IOException

release

public void release()
Releases the represented object.

Overrides:
release in class Representation

setObject

public void setObject(T object)
Sets the represented object.

Parameters:
object - The represented object.

write

public void write(OutputStream outputStream)
           throws IOException
Description copied from class: Representation
Writes the representation to a byte stream. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.

Note that the class implementing this method shouldn't flush or close the given OutputStream after writing to it as this will be handled by the Restlet connectors automatically.

Specified by:
write in class Representation
Parameters:
outputStream - The output stream.
Throws:
IOException


Copyright © 2005-2011 Noelios Technologies.