fedora.server.errors
Class ServerException

java.lang.Object
  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended byfedora.server.errors.ServerException
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DisallowedHostException, DisseminationException, FailedAuthzException, GeneralException, InconsistentTableSpecException, InitializationException, InvalidContextException, InvalidIPSpecException, InvalidOperatorException, InvalidStateException, MalformedPidException, ObjectValidityException, QueryParseException, ReplicationException, RepositoryConfigurationException, ResourceIndexException, ShutdownException, StorageException, StreamIOException, UnknownSessionTokenException, UnrecognizedFieldException, UnsupportedTranslationException

public abstract class ServerException
extends java.lang.Exception

Title: ServerException.java

Description: 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.

-----------------------------------------------------------------------------

License and Copyright: The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/.

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The entire file consists of original code. Copyright © 2002-2005 by The Rector and Visitors of the University of Virginia and Cornell University. All rights reserved.

-----------------------------------------------------------------------------

Version:
$Id: ServerException.java,v 1.11 2005/01/11 20:06:06 cwilper Exp $
Author:
cwilper@cs.cornell.edu
See Also:
Serialized Form

Constructor Summary
ServerException(java.lang.String bundleName, java.lang.String code, java.lang.String[] values, java.lang.String[] details, java.lang.Throwable cause)
          Constructs a new ServerException.
 
Method Summary
 java.lang.String getCode()
          Gets the identifier for the message.
 java.lang.String[] getDetails()
          Gets any detail messages, preferring the Server locale.
 java.lang.String[] getDetails(java.util.Locale locale)
          Gets any detail messages, preferring the provided locale.
 java.lang.String getMessage()
          Gets the message, preferring the Server locale.
 java.lang.String getMessage(java.util.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(java.lang.String bundleName,
                       java.lang.String code,
                       java.lang.String[] values,
                       java.lang.String[] details,
                       java.lang.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 java.lang.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 java.lang.String getMessage()
Gets the message, preferring the Server locale.

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

getMessage

public java.lang.String getMessage(java.util.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 java.lang.String[] getDetails()
Gets any detail messages, preferring the Server locale.

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

getDetails

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

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