org.opentox.error
Class ErrorRepresentation

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.opentox.error.ErrorRepresentation

public class ErrorRepresentation
extends org.restlet.representation.OutputRepresentation

An error representation is the web representation of an exception that is thrown by a method during following some HTTP request.

Version:
1.3.3 (Last update: Dec 24, 2009)
Author:
OpenTox - http://www.opentox.org/, Sopasakis Pantelis, Sarimveis Harry

Field Summary
private  org.restlet.data.Status internalStatus
          Internal Status of the error representation.
private  java.util.Map<java.lang.String,java.lang.Throwable> map
          Maps a Throwable to a corresponding explanation.
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
ErrorRepresentation()
          Constructor for a new ErrorRepresentation.
ErrorRepresentation(java.util.Map<java.lang.String,java.lang.Throwable> map, org.restlet.data.Status status)
          Constructs a new ErrorRepresentation, given a set of Trowable-Explanation pairs, materialized by a Map and a Status characterization of the Representation, i.e.
ErrorRepresentation(java.lang.Throwable throwable, java.lang.String message, org.restlet.data.Status status)
          Constructs a new ErrorRepresentation given a Throwable - the error or exception - a Status and an explanatory message that contains instructions to the client such as if it is recommended that the client repeats the same request etc.
 
Method Summary
 ErrorRepresentation append(ErrorRepresentation other)
          Concatenates two Error Representations by mixing together their explanatory messages and their lists of Throwables.
 ErrorRepresentation append(java.lang.Throwable throwable, java.lang.String message, org.restlet.data.Status status)
          Adds a Throwable and an explanatory message for it to the current ErrorRepresentation.
 int getErrorLevel()
          The Error Level is defined to be the number of Error or exception in this object.
 java.util.Set<java.lang.String> getMessages()
          The explanatory messages about the errors.
 org.restlet.data.Status getStatus()
          Returns the status that accompanies the ErrorRepresentaiton.
 java.io.InputStream getStream()
          Returns a stream with the content of the representation.
 java.lang.String getText()
          Returns the representation as plain text.
 ErrorRepresentation updateStatus(org.restlet.data.Status newStatus)
          Updates the (internal) status.The status can be updated only in the following cases: The current status is less than 300, i.e.
 void write(java.io.OutputStream outputStream)
          Writes the representation to an output stream.
 
Methods inherited from class org.restlet.representation.OutputRepresentation
release
 
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, finalize, getAvailableSize, getDigest, getDigester, getDigester, getDownloadName, getExpirationDate, getRange, getSize, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, 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, getCharacterSet, getEncodings, getIdentifier, getLanguages, getMediaType, isCompatible, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setMediaType
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private java.util.Map<java.lang.String,java.lang.Throwable> map
Maps a Throwable to a corresponding explanation.


internalStatus

private volatile org.restlet.data.Status internalStatus
Internal Status of the error representation.

Constructor Detail

ErrorRepresentation

public ErrorRepresentation()
Constructor for a new ErrorRepresentation. Sets the MediaType of the representation to text/plain.


ErrorRepresentation

public ErrorRepresentation(java.util.Map<java.lang.String,java.lang.Throwable> map,
                           org.restlet.data.Status status)
Constructs a new ErrorRepresentation, given a set of Trowable-Explanation pairs, materialized by a Map and a Status characterization of the Representation, i.e. the status that fits this representation.

Parameters:
map - Map of Explanatory Messages to Error Causes (Throwables)
status - The corresponding status .

ErrorRepresentation

public ErrorRepresentation(java.lang.Throwable throwable,
                           java.lang.String message,
                           org.restlet.data.Status status)
Constructs a new ErrorRepresentation given a Throwable - the error or exception - a Status and an explanatory message that contains instructions to the client such as if it is recommended that the client repeats the same request etc.

Parameters:
throwable - The cause of the error/exception.
message - An explanatory message that the client shall receive along with the ErrorRepresentation.
status - The corresponding status that accompanies the ErrorRepresentation.
Method Detail

append

public ErrorRepresentation append(ErrorRepresentation other)
Concatenates two Error Representations by mixing together their explanatory messages and their lists of Throwables.

Parameters:
other - Some other error representation.
Returns:
The ErrorRepresentation that occurs from this concatenation.

append

public ErrorRepresentation append(java.lang.Throwable throwable,
                                  java.lang.String message,
                                  org.restlet.data.Status status)
Adds a Throwable and an explanatory message for it to the current ErrorRepresentation. The status of the new ErrorRepresentation comes up as a function of the current status and the new one accoriding to the method updateStatus(org.restlet.data.Status).

Parameters:
throwable - The new throwable to be added.
message - An explanatory message for the error.
status - The new status.
Returns:
The produced ErrorRepresentation.

getErrorLevel

public int getErrorLevel()
The Error Level is defined to be the number of Error or exception in this object.


getMessages

public java.util.Set<java.lang.String> getMessages()
The explanatory messages about the errors.

Returns:
set of explanatory messages.

updateStatus

public ErrorRepresentation updateStatus(org.restlet.data.Status newStatus)
Updates the (internal) status.The status can be updated only in the following cases:

Parameters:
newStatus - The new status.
Returns:
The new ErrorRepresentation
See Also:
getStatus()

getStatus

public org.restlet.data.Status getStatus()
Returns the status that accompanies the ErrorRepresentaiton.

Returns:
The status or the ErrorRepresentation.
See Also:
updateStatus(org.restlet.data.Status)

getText

public java.lang.String getText()
Returns the representation as plain text.

Overrides:
getText in class org.restlet.representation.Representation
Returns:
the ErrorRepresentation as String.

getStream

public java.io.InputStream getStream()
                              throws java.io.IOException
Returns a stream with the content of the representation.

Overrides:
getStream in class org.restlet.representation.OutputRepresentation
Returns:
A stream with the representation's content.
Throws:
java.io.IOException
See Also:
Representation.getStream()

write

public void write(java.io.OutputStream outputStream)
           throws java.io.IOException
Writes the representation to an output stream.

Specified by:
write in class org.restlet.representation.Representation
Parameters:
outputStream -
Throws:
java.io.IOException
See Also:
StreamRepresentation.write(java.nio.channels.WritableByteChannel), StreamRepresentation.write(java.io.Writer)