org.apache.commons.math3.exception.util

## Class ExceptionContext

- java.lang.Object
- - org.apache.commons.math3.exception.util.ExceptionContext

- All Implemented Interfaces:
    Serializable

      public class ExceptionContext
      extends Object
      implements Serializable

  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
  Version:
    $Id: ExceptionContext.java 1364388 2012-07-22 18:16:43Z tn $
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field 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 long` | `serialVersionUID` Serializable version Id.
    `private Throwable` | `throwable` The throwable to which this context refers to.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExceptionContext(Throwable throwable)` Simple constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMessage(Localizable pattern, Object... arguments)` Adds a message.
    `private String` | `buildMessage(Locale locale, String separator)` Builds a message string.
    `private void` | `deSerializeContext(ObjectInputStream in)` Deserialize `context`.
    `private void` | `deSerializeMessages(ObjectInputStream in)` Deserialize `msgPatterns` and `msgArguments`.
    `Set<String>` | `getKeys()` Gets all the keys stored in the exception
    `String` | `getLocalizedMessage()` Gets the message in the default locale.
    `String` | `getMessage()` Gets the default message.
    `String` | `getMessage(Locale locale)` Gets the message in a specified locale.
    `String` | `getMessage(Locale locale, String separator)` Gets the message in a specified locale.
    `Throwable` | `getThrowable()` Get a reference to the exception to which the context relates.
    `Object` | `getValue(String key)` Gets the value associated to the given context key.
    `private String` | `nonSerializableReplacement(Object obj)` Replaces a non-serializable object with an error message string.
    `private void` | `readObject(ObjectInputStream in)` Deserialize this object from the given stream.
    `private void` | `serializeContext(ObjectOutputStream out)` Serialize `context`.
    `private void` | `serializeMessages(ObjectOutputStream out)` Serialize `msgPatterns` and `msgArguments`.
    `void` | `setValue(String key, Object value)` Sets the context (key, value) pair.
    `private void` | `writeObject(ObjectOutputStream out)` Serialize this object to the given stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          private static final long serialVersionUID

      Serializable version Id.
      See Also:
        Constant Field Values

    - #### throwable

          private Throwable throwable

      The throwable to which this context refers to.

    - #### msgPatterns

          private List<Localizable> msgPatterns

      Various informations that enrich the informative message.

    - #### msgArguments

          private List<Object[]> msgArguments

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

    - #### context

          private Map<String,Object> context

      Arbitrary context information.

  - ### Constructor Detail

    - #### ExceptionContext

          public ExceptionContext(Throwable throwable)

      Simple constructor.
      Parameters:
        `throwable` - the exception this context refers too

  - ### Method Detail

    - #### getThrowable

          public 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,
                        Object... arguments)

      Adds a message.
      Parameters:
        `pattern` - Message pattern.
        `arguments` - Values for replacing the placeholders in the message pattern.

    - #### setValue

          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` - Context key (not null).
        `value` - Context value.

    - #### getValue

          public Object getValue(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 Set<String> getKeys()

      Gets all the keys stored in the exception
      Returns:
        the set of keys.

    - #### getMessage

          public String getMessage()

      Gets the default message.
      Returns:
        the message.

    - #### getLocalizedMessage

          public String getLocalizedMessage()

      Gets the message in the default locale.
      Returns:
        the localized message.

    - #### getMessage

          public String getMessage(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 String getMessage(Locale locale,
                          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 String buildMessage(Locale locale,
                            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(ObjectOutputStream out)
                            throws IOException

      Serialize this object to the given stream.
      Parameters:
        `out` - Stream.
      Throws:
        `IOException` - This should never happen.

    - #### readObject

          private void readObject(ObjectInputStream in)
                           throws IOException,
                                  ClassNotFoundException

      Deserialize this object from the given stream.
      Parameters:
        `in` - Stream.
      Throws:
        `IOException` - This should never happen.
        `ClassNotFoundException` - This should never happen.

    - #### serializeMessages

          private void serializeMessages(ObjectOutputStream out)
                                  throws IOException

      Serialize `msgPatterns` and `msgArguments`.
      Parameters:
        `out` - Stream.
      Throws:
        `IOException` - This should never happen.

    - #### deSerializeMessages

          private void deSerializeMessages(ObjectInputStream in)
                                    throws IOException,
                                           ClassNotFoundException

      Deserialize `msgPatterns` and `msgArguments`.
      Parameters:
        `in` - Stream.
      Throws:
        `IOException` - This should never happen.
        `ClassNotFoundException` - This should never happen.

    - #### serializeContext

          private void serializeContext(ObjectOutputStream out)
                                 throws IOException

      Serialize `context`.
      Parameters:
        `out` - Stream.
      Throws:
        `IOException` - This should never happen.

    - #### deSerializeContext

          private void deSerializeContext(ObjectInputStream in)
                                   throws IOException,
                                          ClassNotFoundException

      Deserialize `context`.
      Parameters:
        `in` - Stream.
      Throws:
        `IOException` - This should never happen.
        `ClassNotFoundException` - This should never happen.

    - #### nonSerializableReplacement

          private String nonSerializableReplacement(Object obj)

      Replaces a non-serializable object with an error message string.
      Parameters:
        `obj` - Object that does not implement the `Serializable` interface.
      Returns:
        a string that mentions which class could not be serialized.

Copyright (c) 2003-2013 Apache Software Foundation