Top Description Fields Constructors Methods
org.apache.commons.math3.exception.util

public Class ExceptionContext

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.util.List, .ArrayList, .Set, .Map, .HashMap, .Locale, java.io.IOException, .Serializable, .ObjectOutputStream, .ObjectInputStream, java.text.MessageFormat

Class that contains the actual implementation of the functionality mandated by the ExceptionContext interface. All Commons Math exceptions delegate the interface's methods to this class.
Since
3.0

Field Summary

Modifier and TypeField and Description
private Map<String, Object>
context

Arbitrary context information.

private List<Object[]>
msgArguments

Various informations that enrich the informative message.

private List<Localizable>
msgPatterns

Various informations that enrich the informative message.

private static final long
serialVersionUID

Serializable version Id.

private Throwable
throwable

The throwable to which this context refers to.

Constructor Summary

AccessConstructor and Description
public
ExceptionContext(final Throwable
the exception this context refers too
throwable
)

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addMessage(Localizable
Message pattern.
pattern
,
Object...
Values for replacing the placeholders in the message pattern.
arguments
)

Adds a message.

private String

Returns:

a localized message string.
buildMessage
(Locale
Locale in which the message should be translated.
locale
,
String
Message separator.
separator
)

Builds a message string.

private void
private void
public Set<String>

Returns:

the set of keys.
getKeys
()

Gets all the keys stored in the exception

public String

Returns:

the localized message.
getLocalizedMessage
()

Gets the message in the default locale.

public String

Returns:

the message.
getMessage
()

Gets the default message.

public String

Returns:

the localized message.
getMessage
(final Locale
Locale in which the message should be translated.
locale
)

Gets the message in a specified locale.

public String

Returns:

the localized message.
getMessage
(final Locale
Locale in which the message should be translated.
locale
,
final String
Separator inserted between the message parts.
separator
)

Gets the message in a specified locale.

public Throwable

Returns:

a reference to the exception to which the context relates
getThrowable
()

Get a reference to the exception to which the context relates.

public Object

Returns:

the context value or null if the key does not exist.
getValue
(String
Context key.
key
)

Gets the value associated to the given context key.

private String

Returns:

a string that mentions which class could not be serialized.
nonSerializableReplacement
(Object
Object that does not implement the Serializable interface.
obj
)

Replaces a non-serializable object with an error message string.

private void
readObject(ObjectInputStream
Stream.
in
)

Deserialize this object from the given stream.

private void
private void
public void
setValue(String
Context key (not null).
key
,
Object
Context value.
value
)

Sets the context (key, value) pair.

private void
writeObject(ObjectOutputStream
Stream.
out
)

Serialize this object to the given stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private Map<String, Object> context

Arbitrary context information.

msgArgumentsback to summary
private List<Object[]> msgArguments

Various informations that enrich the informative message. The arguments will replace the corresponding place-holders in msgPatterns.

msgPatternsback to summary
private List<Localizable> msgPatterns

Various informations that enrich the informative message.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version Id.

throwableback to summary
private Throwable throwable

The throwable to which this context refers to.

Constructor Detail

ExceptionContextback to summary
public ExceptionContext(final Throwable throwable)

Simple constructor.

Parameters
throwable:Throwable

the exception this context refers too

Method Detail

addMessageback to summary
public void addMessage(Localizable pattern, Object... arguments)

Adds a message.

Parameters
pattern:Localizable

Message pattern.

arguments:Object[]

Values for replacing the placeholders in the message pattern.

buildMessageback to summary
private String buildMessage(Locale locale, String separator)

Builds a message string.

Parameters
locale:Locale

Locale in which the message should be translated.

separator:String

Message separator.

Returns:String

a localized message string.

deSerializeContextback to summary
private void deSerializeContext(ObjectInputStream in) throws IOException, ClassNotFoundException

Deserialize context.

Parameters
in:ObjectInputStream

Stream.

Exceptions
IOException:
This should never happen.
ClassNotFoundException:
This should never happen.
deSerializeMessagesback to summary
private void deSerializeMessages(ObjectInputStream in) throws IOException, ClassNotFoundException

Deserialize msgPatterns and msgArguments.

Parameters
in:ObjectInputStream

Stream.

Exceptions
IOException:
This should never happen.
ClassNotFoundException:
This should never happen.
getKeysback to summary
public Set<String> getKeys()

Gets all the keys stored in the exception

Returns:Set<String>

the set of keys.

getLocalizedMessageback to summary
public String getLocalizedMessage()

Gets the message in the default locale.

Returns:String

the localized message.

getMessageback to summary
public String getMessage()

Gets the default message.

Returns:String

the message.

getMessageback to summary
public String getMessage(final Locale locale)

Gets the message in a specified locale.

Parameters
locale:Locale

Locale in which the message should be translated.

Returns:String

the localized message.

getMessageback to summary
public String getMessage(final Locale locale, final String separator)

Gets the message in a specified locale.

Parameters
locale:Locale

Locale in which the message should be translated.

separator:String

Separator inserted between the message parts.

Returns:String

the localized message.

getThrowableback to summary
public Throwable getThrowable()

Get a reference to the exception to which the context relates.

Returns:Throwable

a reference to the exception to which the context relates

getValueback to summary
public Object getValue(String key)

Gets the value associated to the given context key.

Parameters
key:String

Context key.

Returns:Object

the context value or null if the key does not exist.

nonSerializableReplacementback to summary
private String nonSerializableReplacement(Object obj)

Replaces a non-serializable object with an error message string.

Parameters
obj:Object

Object that does not implement the Serializable interface.

Returns:String

a string that mentions which class could not be serialized.

readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException

Deserialize this object from the given stream.

Parameters
in:ObjectInputStream

Stream.

Exceptions
IOException:
This should never happen.
ClassNotFoundException:
This should never happen.
serializeContextback to summary
private void serializeContext(ObjectOutputStream out) throws IOException

Serialize context.

Parameters
out:ObjectOutputStream

Stream.

Exceptions
IOException:
This should never happen.
serializeMessagesback to summary
private void serializeMessages(ObjectOutputStream out) throws IOException

Serialize msgPatterns and msgArguments.

Parameters
out:ObjectOutputStream

Stream.

Exceptions
IOException:
This should never happen.
setValueback to summary
public void setValue(String key, Object value)

Sets the context (key, value) pair. Keys are assumed to be unique within an instance. If the same key is assigned a new value, the previous one will be lost.

Parameters
key:String

Context key (not null).

value:Object

Context value.

writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException

Serialize this object to the given stream.

Parameters
out:ObjectOutputStream

Stream.

Exceptions
IOException:
This should never happen.