org.fcrepo.server.errors
Class ServerException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by org.fcrepo.server.errors.ServerException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AuthzException, BackendSecurityParserException, DisallowedHostException, DisseminationException, GeneralException, InconsistentTableSpecException, InitializationException, InvalidContextException, InvalidIPSpecException, InvalidOperatorException, InvalidStateException, InvalidXMLNameException, MalformedPidException, MessagingException, ObjectValidityException, PasswordComparisonException, QueryParseException, ReplicationException, RepositoryConfigurationException, ResourceIndexException, ShutdownException, StorageException, StreamIOException, UnknownSessionTokenException, UnrecognizedFieldException, UnsupportedTranslationException

public abstract class ServerException
extends Exception

The superclass for all Fedora server exceptions.

This class encourages the use of resource bundles as message (and detail text) sources so that localization may easily be implemented.

Methods that return text will attempt to find the message by code in the ResourceBundle, but will fall back to simply returning the code if no such message can be found in the ResourceBundle, or no such ResourceBundle exists or the bundleName given in the constructor is null.

This enables developers to temporarily construct exceptions with something like:

     throw new MyException(null, "myMessageId", null, null, null);
 

Exceptions of this type have the benefit that they can be easily converted to informative, localized SOAP Fault envelopes.

Author:
Chris Wilper
See Also:
Serialized Form

Constructor Summary
ServerException(String bundleName, String code, String[] values, String[] details, Throwable cause)
          Constructs a new ServerException.
 
Method Summary
 String getCode()
          Gets the identifier for the message.
 String[] getDetails()
          Gets any detail messages, preferring the Server locale.
 String[] getDetails(Locale locale)
          Gets any detail messages, preferring the provided locale.
 String getMessage()
          Gets the message, preferring the Server locale.
 String getMessage(Locale locale)
          Gets the message, preferring the provided locale.
 void setWasServer()
          Sets the value for the "wasServer" flag for this exception.
 boolean wasServer()
          Tells whether the error occurred because of an unexpected error in the server, likely requiring action on the part of the server administrator.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerException

public ServerException(String bundleName,
                       String code,
                       String[] values,
                       String[] details,
                       Throwable cause)
Constructs a new ServerException.

Parameters:
bundleName - The bundle in which the message resides.
code - The identifier for the message in the bundle, aka the key.
values - Replacements for placeholders in the message, where placeholders are of the form {num} where num starts at 0, indicating the 0th (1st) item in this array.
details - Identifiers for messages which provide detail on the error. This may empty or null.
cause - The underlying exception if known, null meaning unknown or none.
Method Detail

getCode

public String getCode()
Gets the identifier for the message.

Returns:
The code, which is also the key in the MessageBundle for this exception.

wasServer

public boolean wasServer()
Tells whether the error occurred because of an unexpected error in the server, likely requiring action on the part of the server administrator.

If it's not an error in the server, it means that the client made a mistake, which is the more likely case.


setWasServer

public void setWasServer()
Sets the value for the "wasServer" flag for this exception.


getMessage

public String getMessage()
Gets the message, preferring the Server locale.

Overrides:
getMessage in class Throwable
Returns:
The message, with {num}-indexed placeholders populated, if needed.

getMessage

public String getMessage(Locale locale)
Gets the message, preferring the provided locale.

When a message in the desired locale is not found, the locale selection logic described by the java.util.ResourceBundle class javadoc is used.

Parameters:
locale - The preferred locale.
Returns:
The message, with {num}-indexed placeholders populated, if needed.

getDetails

public String[] getDetails()
Gets any detail messages, preferring the Server locale.

Returns:
The detail messages, with {num}-indexed placeholders populated, if needed.

getDetails

public String[] getDetails(Locale locale)
Gets any detail messages, preferring the provided locale.

Returns:
The detail messages, with {num}-indexed placeholders populated, if needed.


Copyright © 2012 DuraSpace. All Rights Reserved.