org.restlet.util
Class WrapperRepresentation

java.lang.Object
  extended by org.restlet.resource.Variant
      extended by org.restlet.resource.Representation
          extended by org.restlet.util.WrapperRepresentation

public class WrapperRepresentation
extends Representation

Representation wrapper. Useful for application developer who need to enrich the representation with application related properties and behavior.

Author:
Jerome Louvel (contact@noelios.com)
See Also:
The decorator (aka wrapper) pattern

Field Summary
 
Fields inherited from class org.restlet.resource.Variant
UNKNOWN_SIZE
 
Constructor Summary
WrapperRepresentation(Representation wrappedRepresentation)
          Constructor.
 
Method Summary
 ReadableByteChannel getChannel()
          Returns a channel with the representation's content.
If it is supported by a file, a read-only instance of FileChannel is returned.
This method is ensured to return a fresh channel for each invocation unless it is a transient representation, in which case null is returned.
 CharacterSet getCharacterSet()
          Returns the character set or null if not applicable.
 List<Encoding> getEncodings()
          Returns the list of encodings.
 Date getExpirationDate()
          Returns the future date when this representation expire.
 Reference getIdentifier()
          Returns the official identifier.
 List<Language> getLanguages()
          Returns the list of languages.
 MediaType getMediaType()
          Returns the media type.
 Date getModificationDate()
          Returns the last date when this representation was modified.
 long getSize()
          Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
 InputStream getStream()
          Returns a stream with the representation's content.
 Tag getTag()
          Returns the tag.
 String getText()
          Converts the representation to a string value.
 Representation getWrappedRepresentation()
          Returns the wrapped representation.
 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 isTransient()
          Indicates if the representation's content is transient, which means that it can be obtained only once.
 void setAvailable(boolean isAvailable)
          Indicates if some fresh content is available.
 void setCharacterSet(CharacterSet characterSet)
          Sets the character set or null if not applicable.
 void setExpirationDate(Date expirationDate)
          Sets the future date when this representation expire.
 void setIdentifier(Reference identifier)
          Sets the official identifier.
 void setIdentifier(String identifierUri)
          Sets the official identifier from a URI string.
 void setMediaType(MediaType mediaType)
          Sets the media type.
 void setModificationDate(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.
 void write(OutputStream outputStream)
          Writes the representation to a byte stream.
 void write(WritableByteChannel writableChannel)
          Writes the representation to a byte channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrapperRepresentation

public WrapperRepresentation(Representation wrappedRepresentation)
Constructor.

Parameters:
wrappedRepresentation - The wrapped representation.
Method Detail

getChannel

public ReadableByteChannel getChannel()
                               throws IOException
Returns a channel with the representation's content.
If it is supported by a file, a read-only instance of FileChannel is returned.
This method is ensured to return a fresh channel for each invocation unless it is a transient representation, in which case null is returned.

Specified by:
getChannel in class Representation
Returns:
A channel with the representation's content.
Throws:
IOException

getCharacterSet

public CharacterSet getCharacterSet()
Returns the character set or null if not applicable.

Overrides:
getCharacterSet in class Variant
Returns:
The character set or null if not applicable.

getEncodings

public List<Encoding> getEncodings()
Returns the list of encodings.

Overrides:
getEncodings in class Variant
Returns:
The list of encodings.

getExpirationDate

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

Overrides:
getExpirationDate in class Variant
Returns:
The expiration date.

getIdentifier

public Reference getIdentifier()
Returns the official identifier.

Overrides:
getIdentifier in class Variant
Returns:
The official identifier.

getLanguages

public List<Language> getLanguages()
Returns the list of languages.

Overrides:
getLanguages in class Variant
Returns:
The list of languages.

getMediaType

public MediaType getMediaType()
Returns the media type.

Overrides:
getMediaType in class Variant
Returns:
The media type.

getModificationDate

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

Overrides:
getModificationDate in class Variant
Returns:
The modification date.

getSize

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

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

getStream

public InputStream getStream()
                      throws IOException
Returns a stream with the representation's content. This method is ensured to return a fresh stream for each invocation unless it is a transient representation, in which case null is returned.

Specified by:
getStream in class Representation
Returns:
A stream with the representation's content.
Throws:
IOException

getTag

public Tag getTag()
Returns the tag.

Overrides:
getTag in class Variant
Returns:
The tag.

getText

public String getText()
               throws IOException
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.

Overrides:
getText in class Representation
Returns:
The representation as a string value.
Throws:
IOException

getWrappedRepresentation

public Representation getWrappedRepresentation()
Returns the wrapped representation.

Returns:
The wrapped representation.

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.

Overrides:
isAvailable in class Representation
Returns:
True if some fresh content is available.

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.

Overrides:
isTransient in class Representation
Returns:
True if the representation's content is transient.

setAvailable

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

Overrides:
setAvailable in class Representation
Parameters:
isAvailable - True if some fresh content is available.

setCharacterSet

public void setCharacterSet(CharacterSet characterSet)
Sets the character set or null if not applicable.

Overrides:
setCharacterSet in class Variant
Parameters:
characterSet - The character set or null if not applicable.

setExpirationDate

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

Overrides:
setExpirationDate in class Variant
Parameters:
expirationDate - The expiration date.

setIdentifier

public void setIdentifier(Reference identifier)
Sets the official identifier.

Overrides:
setIdentifier in class Variant
Parameters:
identifier - The official identifier.

setIdentifier

public void setIdentifier(String identifierUri)
Sets the official identifier from a URI string.

Overrides:
setIdentifier in class Variant
Parameters:
identifierUri - The official identifier to parse.

setMediaType

public void setMediaType(MediaType mediaType)
Sets the media type.

Overrides:
setMediaType in class Variant
Parameters:
mediaType - The media type.

setModificationDate

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

Overrides:
setModificationDate in class Variant
Parameters:
modificationDate - The modification date.

setSize

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

Overrides:
setSize in class Variant
Parameters:
expectedSize - The expected size in bytes if known, -1 otherwise.

setTag

public void setTag(Tag tag)
Sets the tag.

Overrides:
setTag in class Variant
Parameters:
tag - The tag.

setTransient

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

Overrides:
setTransient in class Representation
Parameters:
isTransient - True if the representation's content is transient.

write

public void write(OutputStream outputStream)
           throws IOException
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.

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

write

public void write(WritableByteChannel writableChannel)
           throws IOException
Writes the representation to a byte channel. 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.

Specified by:
write in class Representation
Parameters:
writableChannel - A writable byte channel.
Throws:
IOException


Copyright © 2005-2007 Noelios Consulting.