Class ExceptionContext
- java.lang.Object
-
- org.apache.commons.math3.exception.util.ExceptionContext
-
- All Implemented Interfaces:
java.io.Serializable
public class ExceptionContext extends java.lang.Object implements java.io.Serializable
Class that contains the actual implementation of the functionality mandated by theExceptionContext
interface. All Commons Math exceptions delegate the interface's methods to this class.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Object>
context
Arbitrary context information.private java.util.List<java.lang.Object[]>
msgArguments
Various informations that enrich the informative message.private java.util.List<Localizable>
msgPatterns
Various informations that enrich the informative message.private static long
serialVersionUID
Serializable version Id.private java.lang.Throwable
throwable
The throwable to which this context refers to.
-
Constructor Summary
Constructors Constructor Description ExceptionContext(java.lang.Throwable throwable)
Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMessage(Localizable pattern, java.lang.Object... arguments)
Adds a message.private java.lang.String
buildMessage(java.util.Locale locale, java.lang.String separator)
Builds a message string.private void
deSerializeContext(java.io.ObjectInputStream in)
Deserializecontext
.private void
deSerializeMessages(java.io.ObjectInputStream in)
DeserializemsgPatterns
andmsgArguments
.java.util.Set<java.lang.String>
getKeys()
Gets all the keys stored in the exceptionjava.lang.String
getLocalizedMessage()
Gets the message in the default locale.java.lang.String
getMessage()
Gets the default message.java.lang.String
getMessage(java.util.Locale locale)
Gets the message in a specified locale.java.lang.String
getMessage(java.util.Locale locale, java.lang.String separator)
Gets the message in a specified locale.java.lang.Throwable
getThrowable()
Get a reference to the exception to which the context relates.java.lang.Object
getValue(java.lang.String key)
Gets the value associated to the given context key.private java.lang.String
nonSerializableReplacement(java.lang.Object obj)
Replaces a non-serializable object with an error message string.private void
readObject(java.io.ObjectInputStream in)
Deserialize this object from the given stream.private void
serializeContext(java.io.ObjectOutputStream out)
Serializecontext
.private void
serializeMessages(java.io.ObjectOutputStream out)
SerializemsgPatterns
andmsgArguments
.void
setValue(java.lang.String key, java.lang.Object value)
Sets the context (key, value) pair.private void
writeObject(java.io.ObjectOutputStream out)
Serialize this object to the given stream.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serializable version Id.- See Also:
- Constant Field Values
-
throwable
private java.lang.Throwable throwable
The throwable to which this context refers to.
-
msgPatterns
private java.util.List<Localizable> msgPatterns
Various informations that enrich the informative message.
-
msgArguments
private java.util.List<java.lang.Object[]> msgArguments
Various informations that enrich the informative message. The arguments will replace the corresponding place-holders inmsgPatterns
.
-
context
private java.util.Map<java.lang.String,java.lang.Object> context
Arbitrary context information.
-
-
Method Detail
-
getThrowable
public java.lang.Throwable getThrowable()
Get a reference to the exception to which the context relates.- Returns:
- a reference to the exception to which the context relates
-
addMessage
public void addMessage(Localizable pattern, java.lang.Object... arguments)
Adds a message.- Parameters:
pattern
- Message pattern.arguments
- Values for replacing the placeholders in the message pattern.
-
setValue
public void setValue(java.lang.String key, java.lang.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
- Context key (not null).value
- Context value.
-
getValue
public java.lang.Object getValue(java.lang.String key)
Gets the value associated to the given context key.- Parameters:
key
- Context key.- Returns:
- the context value or
null
if the key does not exist.
-
getKeys
public java.util.Set<java.lang.String> getKeys()
Gets all the keys stored in the exception- Returns:
- the set of keys.
-
getMessage
public java.lang.String getMessage()
Gets the default message.- Returns:
- the message.
-
getLocalizedMessage
public java.lang.String getLocalizedMessage()
Gets the message in the default locale.- Returns:
- the localized message.
-
getMessage
public java.lang.String getMessage(java.util.Locale locale)
Gets the message in a specified locale.- Parameters:
locale
- Locale in which the message should be translated.- Returns:
- the localized message.
-
getMessage
public java.lang.String getMessage(java.util.Locale locale, java.lang.String separator)
Gets the message in a specified locale.- Parameters:
locale
- Locale in which the message should be translated.separator
- Separator inserted between the message parts.- Returns:
- the localized message.
-
buildMessage
private java.lang.String buildMessage(java.util.Locale locale, java.lang.String separator)
Builds a message string.- Parameters:
locale
- Locale in which the message should be translated.separator
- Message separator.- Returns:
- a localized message string.
-
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
Serialize this object to the given stream.- Parameters:
out
- Stream.- Throws:
java.io.IOException
- This should never happen.
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
Deserialize this object from the given stream.- Parameters:
in
- Stream.- Throws:
java.io.IOException
- This should never happen.java.lang.ClassNotFoundException
- This should never happen.
-
serializeMessages
private void serializeMessages(java.io.ObjectOutputStream out) throws java.io.IOException
SerializemsgPatterns
andmsgArguments
.- Parameters:
out
- Stream.- Throws:
java.io.IOException
- This should never happen.
-
deSerializeMessages
private void deSerializeMessages(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
DeserializemsgPatterns
andmsgArguments
.- Parameters:
in
- Stream.- Throws:
java.io.IOException
- This should never happen.java.lang.ClassNotFoundException
- This should never happen.
-
serializeContext
private void serializeContext(java.io.ObjectOutputStream out) throws java.io.IOException
Serializecontext
.- Parameters:
out
- Stream.- Throws:
java.io.IOException
- This should never happen.
-
deSerializeContext
private void deSerializeContext(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
Deserializecontext
.- Parameters:
in
- Stream.- Throws:
java.io.IOException
- This should never happen.java.lang.ClassNotFoundException
- This should never happen.
-
nonSerializableReplacement
private java.lang.String nonSerializableReplacement(java.lang.Object obj)
Replaces a non-serializable object with an error message string.- Parameters:
obj
- Object that does not implement theSerializable
interface.- Returns:
- a string that mentions which class could not be serialized.
-
-