public abstract class ServerException extends Exception
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.
| Constructor and Description |
|---|
ServerException(String bundleName,
String code,
String[] values,
String[] details,
Throwable cause)
Constructs a new ServerException.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringpublic ServerException(String bundleName, String code, String[] values, String[] details, Throwable cause)
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.public String getCode()
MessageBundle
for this exception.public boolean wasServer()
If it's not an error in the server, it means that the client made a mistake, which is the more likely case.
public void setWasServer()
public String getMessage()
Server locale.getMessage in class Throwablepublic String getMessage(Locale 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.
locale - The preferred locale.public String[] getDetails()
Server locale.Copyright © 2013 DuraSpace. All Rights Reserved.