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
Direct Known Subclasses:
DigestRepresentation

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
See Also:
The decorator (aka wrapper) pattern

Field Summary
 
Fields inherited from class org.restlet.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
WrapperRepresentation(Representation wrappedRepresentation)
          Constructor.
 
Method Summary
 boolean checkDigest()
          Check that the digest computed from the representation content and the digest declared by the representation are the same.
Since this method relies on the Representation.computeDigest(String) method, and since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient.
 boolean checkDigest(java.lang.String algorithm)
          Check that the digest computed from the representation content and the digest declared by the representation are the same.
 Digest computeDigest(java.lang.String algorithm)
          Compute the representation digest according to the given algorithm.
Since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient.
 long exhaust()
          Exhauts the content of the representation by reading it and silently discarding anything read.
 long getAvailableSize()
          Returns the size effectively available.
 java.nio.channels.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.
 Digest getDigest()
          Returns the representation digest if any.
 java.lang.String getDownloadName()
          Returns the suggested download file name for this representation.
 java.util.List<Encoding> getEncodings()
          Returns the modifiable list of encodings applied to the entity-body.
 java.util.Date getExpirationDate()
          Returns the future date when this representation expire.
 Reference getIdentifier()
          Returns an optional identifier.
 java.util.List<Language> getLanguages()
          Returns the modifiable list of languages.
 MediaType getMediaType()
          Returns the media type.
 java.util.Date getModificationDate()
          Returns the last date when this representation was modified.
 Range getRange()
          Returns the range where in the full content the partial content available should be applied.
 java.io.Reader getReader()
          Returns a characters reader with the representation's content.
 long getSize()
          Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
 java.io.InputStream getStream()
          Returns a stream with the representation's content.
 Tag getTag()
          Returns the tag.
 java.lang.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 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 isAvailable)
          Indicates if some fresh content is available.
 void setCharacterSet(CharacterSet characterSet)
          Sets the character set or null if not applicable.
 void setDigest(Digest digest)
          Sets the representation digest.
 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 setEncodings(java.util.List<Encoding> encodings)
          Sets the list of encodings applied to the entity-body.
 void setExpirationDate(java.util.Date expirationDate)
          Sets the future date when this representation expire.
 void setIdentifier(Reference identifier)
          Sets the optional identifier.
 void setIdentifier(java.lang.String identifierUri)
          Sets the identifier from a URI string.
 void setLanguages(java.util.List<Language> languages)
          Sets the list of languages.
 void setMediaType(MediaType mediaType)
          Sets the media type.
 void setModificationDate(java.util.Date modificationDate)
          Sets the last date when this representation was modified.
 void setRange(Range range)
          Sets the range where in the full content the partial content available should be applied.
 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(java.io.OutputStream outputStream)
          Writes the representation to a byte stream.
 void write(java.nio.channels.WritableByteChannel writableChannel)
          Writes the representation to a byte channel.
 void write(java.io.Writer writer)
          Writes the representation to a characters writer.
 
Methods inherited from class org.restlet.resource.Representation
createEmpty
 
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

checkDigest

public boolean checkDigest()
Description copied from class: Representation
Check that the digest computed from the representation content and the digest declared by the representation are the same.
Since this method relies on the Representation.computeDigest(String) method, and since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient. Representation.isTransient

Overrides:
checkDigest in class Representation
Returns:
True if both digests are not null and equals.

checkDigest

public boolean checkDigest(java.lang.String algorithm)
Description copied from class: Representation
Check that the digest computed from the representation content and the digest declared by the representation are the same. It also first checks that the algorithms are the same.
Since this method relies on the Representation.computeDigest(String) method, and since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient. Representation.isTransient

Overrides:
checkDigest in class Representation
Parameters:
algorithm - The algorithm used to compute the digest to compare with. See constant values in Digest.
Returns:
True if both digests are not null and equals.

computeDigest

public Digest computeDigest(java.lang.String algorithm)
Description copied from class: Representation
Compute the representation digest according to the given algorithm.
Since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient. Representation.isTransient

Overrides:
computeDigest in class Representation
Parameters:
algorithm - The algorithm used to compute the digest. See constant values in Digest.
Returns:
The computed digest or null if the digest cannot be computed.

exhaust

public long exhaust()
             throws java.io.IOException
Description copied from class: Representation
Exhauts the content of the representation by reading it and silently discarding anything read.

Overrides:
exhaust in class Representation
Returns:
The number of bytes consumed or -1 if unknown.
Throws:
java.io.IOException

getAvailableSize

public long getAvailableSize()
Description copied from class: Representation
Returns the size effectively available. This returns the same value as Representation.getSize() if no range is defined, otherwise it returns the size of the range using Range.getSize().

Overrides:
getAvailableSize in class Representation
Returns:
The available size.

getChannel

public java.nio.channels.ReadableByteChannel getChannel()
                                                 throws java.io.IOException
Description copied from class: Representation
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:
java.io.IOException

getCharacterSet

public CharacterSet getCharacterSet()
Description copied from class: Variant
Returns the character set or null if not applicable.

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

getDigest

public Digest getDigest()
Description copied from class: Representation
Returns the representation digest if any.

Overrides:
getDigest in class Representation
Returns:
The representation digest or null.

getDownloadName

public java.lang.String getDownloadName()
Description copied from class: Representation
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.

Overrides:
getDownloadName in class Representation
Returns:
The suggested file name for this representation.

getEncodings

public java.util.List<Encoding> getEncodings()
Description copied from class: Variant
Returns the modifiable list of encodings applied to the entity-body. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null encoding to this list.

Overrides:
getEncodings in class Variant
Returns:
The list of encodings applied to the entity-body.

getExpirationDate

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

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

getIdentifier

public Reference getIdentifier()
Description copied from class: Variant
Returns an optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.

Overrides:
getIdentifier in class Variant
Returns:
The identifier.

getLanguages

public java.util.List<Language> getLanguages()
Description copied from class: Variant
Returns the modifiable list of languages. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null language to this list.

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

getMediaType

public MediaType getMediaType()
Description copied from class: Variant
Returns the media type.

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

getModificationDate

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

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

getRange

public Range getRange()
Description copied from class: Representation
Returns the range where in the full content the partial content available should be applied.

Overrides:
getRange in class Representation
Returns:
The content range or null if the full content is available.

getReader

public java.io.Reader getReader()
                         throws java.io.IOException
Description copied from class: Representation
Returns a characters reader with the representation's content. This method is ensured to return a fresh reader for each invocation unless it is a transient representation, in which case null is returned. If the representation has no character set defined, the system's default one will be used.

Specified by:
getReader in class Representation
Returns:
A reader with the representation's content.
Throws:
java.io.IOException

getSize

public long getSize()
Description copied from class: Representation
Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise.

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

getStream

public java.io.InputStream getStream()
                              throws java.io.IOException
Description copied from class: Representation
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:
java.io.IOException

getTag

public Tag getTag()
Description copied from class: Representation
Returns the tag.

Overrides:
getTag in class Representation
Returns:
The tag.

getText

public java.lang.String getText()
                         throws java.io.IOException
Description copied from class: Representation
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:
java.io.IOException

getWrappedRepresentation

public Representation getWrappedRepresentation()
Returns the wrapped representation.

Returns:
The wrapped representation.

isAvailable

public boolean isAvailable()
Description copied from class: Representation
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.

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

isDownloadable

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

Overrides:
isDownloadable in class Representation
Returns:
True if the representation's content is downloadable.

isTransient

public boolean isTransient()
Description copied from class: Representation
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.

release

public void release()
Description copied from class: Representation
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.

Overrides:
release in class Representation

setAvailable

public void setAvailable(boolean isAvailable)
Description copied from class: Representation
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)
Description copied from class: Variant
Sets the character set or null if not applicable.

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

setDigest

public void setDigest(Digest digest)
Description copied from class: Representation
Sets the representation digest.

Overrides:
setDigest in class Representation
Parameters:
digest - The representation digest.

setDownloadable

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

Overrides:
setDownloadable in class Representation
Parameters:
downloadable - True if the representation's content is downloadable.

setDownloadName

public void setDownloadName(java.lang.String fileName)
Description copied from class: Representation
Set the suggested download file name for this representation.

Overrides:
setDownloadName in class Representation
Parameters:
fileName - The suggested file name.

setEncodings

public void setEncodings(java.util.List<Encoding> encodings)
Description copied from class: Variant
Sets the list of encodings applied to the entity-body.

Overrides:
setEncodings in class Variant
Parameters:
encodings - The list of encodings applied to the entity-body.

setExpirationDate

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

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

setIdentifier

public void setIdentifier(Reference identifier)
Description copied from class: Variant
Sets the optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.

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

setIdentifier

public void setIdentifier(java.lang.String identifierUri)
Description copied from class: Variant
Sets the identifier from a URI string.

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

setLanguages

public void setLanguages(java.util.List<Language> languages)
Description copied from class: Variant
Sets the list of languages.

Overrides:
setLanguages in class Variant
Parameters:
languages - The list of languages.

setMediaType

public void setMediaType(MediaType mediaType)
Description copied from class: Variant
Sets the media type.

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

setModificationDate

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

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

setRange

public void setRange(Range range)
Description copied from class: Representation
Sets the range where in the full content the partial content available should be applied.

Overrides:
setRange in class Representation
Parameters:
range - The content range.

setSize

public void setSize(long expectedSize)
Description copied from class: Representation
Sets the expected size in bytes if known, -1 otherwise.

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

setTag

public void setTag(Tag tag)
Description copied from class: Representation
Sets the tag.

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

setTransient

public void setTransient(boolean isTransient)
Description copied from class: Representation
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(java.io.OutputStream outputStream)
           throws java.io.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.

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

write

public void write(java.nio.channels.WritableByteChannel writableChannel)
           throws java.io.IOException
Description copied from class: Representation
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:
java.io.IOException

write

public void write(java.io.Writer writer)
           throws java.io.IOException
Description copied from class: Representation
Writes the representation to a characters writer. 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:
writer - The characters writer.
Throws:
java.io.IOException


Copyright © 2005-2008 Noelios Technologies.