org.restlet.gwt.resource
Class Representation

java.lang.Object
  extended by org.restlet.gwt.resource.Variant
      extended by org.restlet.gwt.resource.Representation
Direct Known Subclasses:
JsonRepresentation, StringRepresentation, XmlRepresentation

public abstract class Representation
extends Variant

Current or intended state of a resource. The content of a representation can be retrieved several times if there is a stable and accessible source, like a local file or a string. When the representation is obtained via a temporary source like a network socket, its content can only be retrieved once. The "transient" and "available" properties are available to help you figure out those aspects at runtime.

For performance purpose, it is essential that a minimal overhead occurs upon initialization. The main overhead must only occur during invocation of content processing methods (write, getStream, getChannel and toString).

"REST components perform actions on a resource by using a representation to capture the current or intended state of that resource and transferring that representation between components. A representation is a sequence of bytes, plus representation metadata to describe those bytes. Other commonly used but less precise names for a representation include: document, file, and HTTP message entity, instance, or variant." Roy T. Fielding

Author:
Jerome Louvel
See Also:
Source dissertation

Field Summary
static long UNKNOWN_SIZE
          Indicates that the size of the representation can't be known in advance.
 
Constructor Summary
Representation()
          Default constructor.
Representation(MediaType mediaType)
          Constructor.
 
Method Summary
static Representation createEmpty()
          Returns a new empty representation with no content.
 java.lang.String getDownloadName()
          Returns the suggested download file name for this representation.
 java.util.Date getExpirationDate()
          Returns the future date when this representation expire.
 java.util.Date getModificationDate()
          Returns the last date when this representation was modified.
 long getSize()
          Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
 Tag getTag()
          Returns the tag.
abstract  java.lang.String getText()
          Converts the representation to a string value.
 boolean isAvailable()
          Indicates if some fresh content is available, without having to actually call one of the content manipulation method like getStream() that would actually consume it.
 boolean isDownloadable()
          Indicates if the representation is downloadable which means that it can be obtained via a download dialog box.
 boolean isTransient()
          Indicates if the representation's content is transient, which means that it can be obtained only once.
 void release()
          Releases the representation's content and all associated objects like sockets, channels or files.
 void setAvailable(boolean available)
          Indicates if some fresh content is available.
 void setDownloadable(boolean downloadable)
          Indicates if the representation is downloadable which means that it can be obtained via a download dialog box.
 void setDownloadName(java.lang.String fileName)
          Set the suggested download file name for this representation.
 void setExpirationDate(java.util.Date expirationDate)
          Sets the future date when this representation expire.
 void setModificationDate(java.util.Date modificationDate)
          Sets the last date when this representation was modified.
 void setSize(long expectedSize)
          Sets the expected size in bytes if known, -1 otherwise.
 void setTag(Tag tag)
          Sets the tag.
 void setTransient(boolean isTransient)
          Indicates if the representation's content is transient.
 
Methods inherited from class org.restlet.gwt.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
 

Field Detail

UNKNOWN_SIZE

public static final long UNKNOWN_SIZE
Indicates that the size of the representation can't be known in advance.

See Also:
Constant Field Values
Constructor Detail

Representation

public Representation()
Default constructor.


Representation

public Representation(MediaType mediaType)
Constructor.

Parameters:
mediaType - The media type.
Method Detail

createEmpty

public static Representation createEmpty()
Returns a new empty representation with no content.

Returns:
A new empty representation.

getDownloadName

public java.lang.String getDownloadName()
Returns the suggested download file name for this representation. This is mainly used to suggest to the client a local name for a downloaded representation.

Returns:
The suggested file name for this representation.

getExpirationDate

public java.util.Date getExpirationDate()
Returns the future date when this representation expire. If this information is not known, returns null.

Returns:
The expiration date.

getModificationDate

public java.util.Date getModificationDate()
Returns the last date when this representation was modified. If this information is not known, returns null.

Returns:
The modification date.

getSize

public long getSize()
Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise.

Returns:
The size in bytes if known, UNKNOWN_SIZE (-1) otherwise.

getTag

public Tag getTag()
Returns the tag.

Returns:
The tag.

getText

public abstract java.lang.String getText()
Converts the representation to a string value. Be careful when using this method as the conversion of large content to a string fully stored in memory can result in OutOfMemoryErrors being thrown.

Returns:
The representation as a string value.

isAvailable

public boolean isAvailable()
Indicates if some fresh content is available, without having to actually call one of the content manipulation method like getStream() that would actually consume it. This is especially useful for transient representation whose content can only be accessed once and also when the size of the representation is not known in advance.

Returns:
True if some fresh content is available.

isDownloadable

public boolean isDownloadable()
Indicates if the representation is downloadable which means that it can be obtained via a download dialog box.

Returns:
True if the representation's content is downloadable.

isTransient

public boolean isTransient()
Indicates if the representation's content is transient, which means that it can be obtained only once. This is often the case with representations transmitted via network sockets for example. In such case, if you need to read the content several times, you need to cache it first, for example into memory or into a file.

Returns:
True if the representation's content is transient.

release

public void release()
Releases the representation's content and all associated objects like sockets, channels or files. If the representation is transient and hasn't been read yet, all the remaining content will be discarded, any open socket, channel, file or similar source of content will be immediately closed. The representation is also no more available.


setAvailable

public void setAvailable(boolean available)
Indicates if some fresh content is available.

Parameters:
available - True if some fresh content is available.

setDownloadable

public void setDownloadable(boolean downloadable)
Indicates if the representation is downloadable which means that it can be obtained via a download dialog box.

Parameters:
downloadable - True if the representation's content is downloadable.

setDownloadName

public void setDownloadName(java.lang.String fileName)
Set the suggested download file name for this representation.

Parameters:
fileName - The suggested file name.

setExpirationDate

public void setExpirationDate(java.util.Date expirationDate)
Sets the future date when this representation expire. If this information is not known, pass null.

Parameters:
expirationDate - The expiration date.

setModificationDate

public void setModificationDate(java.util.Date modificationDate)
Sets the last date when this representation was modified. If this information is not known, pass null.

Parameters:
modificationDate - The modification date.

setSize

public void setSize(long expectedSize)
Sets the expected size in bytes if known, -1 otherwise.

Parameters:
expectedSize - The expected size in bytes if known, -1 otherwise.

setTag

public void setTag(Tag tag)
Sets the tag.

Parameters:
tag - The tag.

setTransient

public void setTransient(boolean isTransient)
Indicates if the representation's content is transient.

Parameters:
isTransient - True if the representation's content is transient.


Copyright © 2005-2008 Noelios Technologies.