Class DefaultExceptionContext
- java.lang.Object
-
- org.apache.commons.lang3.exception.DefaultExceptionContext
-
- All Implemented Interfaces:
java.io.Serializable,ExceptionContext
public class DefaultExceptionContext extends java.lang.Object implements ExceptionContext, java.io.Serializable
Default implementation of the context storing the label-value pairs for contexted exceptions.This implementation is serializable, however this is dependent on the values that are added also being serializable.
- Since:
- 3.0
- See Also:
ContextedException,ContextedRuntimeException, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultExceptionContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DefaultExceptionContextaddContextValue(java.lang.String label, java.lang.Object value)Adds a contextual label-value pair into this context.java.util.List<Pair<java.lang.String,java.lang.Object>>getContextEntries()Retrieves the full list of label-value pairs defined in the contextual data.java.util.Set<java.lang.String>getContextLabels()Retrieves the full set of labels defined in the contextual data.java.util.List<java.lang.Object>getContextValues(java.lang.String label)Retrieves all the contextual data values associated with the label.java.lang.ObjectgetFirstContextValue(java.lang.String label)Retrieves the first available contextual data value associated with the label.java.lang.StringgetFormattedExceptionMessage(java.lang.String baseMessage)Builds the message containing the contextual information.DefaultExceptionContextsetContextValue(java.lang.String label, java.lang.Object value)Sets a contextual label-value pair into this context.
-
-
-
Method Detail
-
addContextValue
public DefaultExceptionContext addContextValue(java.lang.String label, java.lang.Object value)
Adds a contextual label-value pair into this context.The pair will be added to the context, independently of an already existing pair with the same label.
- Specified by:
addContextValuein interfaceExceptionContext- Parameters:
label- the label of the item to add,nullnot recommendedvalue- the value of item to add, may benull- Returns:
this, for method chaining, notnull
-
getContextEntries
public java.util.List<Pair<java.lang.String,java.lang.Object>> getContextEntries()
Retrieves the full list of label-value pairs defined in the contextual data.- Specified by:
getContextEntriesin interfaceExceptionContext- Returns:
- the list of pairs, not
null
-
getContextLabels
public java.util.Set<java.lang.String> getContextLabels()
Retrieves the full set of labels defined in the contextual data.- Specified by:
getContextLabelsin interfaceExceptionContext- Returns:
- the set of labels, not
null
-
getContextValues
public java.util.List<java.lang.Object> getContextValues(java.lang.String label)
Retrieves all the contextual data values associated with the label.- Specified by:
getContextValuesin interfaceExceptionContext- Parameters:
label- the label to get the contextual values for, may benull- Returns:
- the contextual values associated with the label, never
null
-
getFirstContextValue
public java.lang.Object getFirstContextValue(java.lang.String label)
Retrieves the first available contextual data value associated with the label.- Specified by:
getFirstContextValuein interfaceExceptionContext- Parameters:
label- the label to get the contextual value for, may benull- Returns:
- the first contextual value associated with the label, may be
null
-
getFormattedExceptionMessage
public java.lang.String getFormattedExceptionMessage(java.lang.String baseMessage)
Builds the message containing the contextual information.- Specified by:
getFormattedExceptionMessagein interfaceExceptionContext- Parameters:
baseMessage- the base exception message without context information appended- Returns:
- the exception message with context information appended, never null
-
setContextValue
public DefaultExceptionContext setContextValue(java.lang.String label, java.lang.Object value)
Sets a contextual label-value pair into this context.The pair will be added normally, but any existing label-value pair with the same label is removed from the context.
- Specified by:
setContextValuein interfaceExceptionContext- Parameters:
label- the label of the item to add,nullnot recommendedvalue- the value of item to add, may benull- Returns:
this, for method chaining, notnull
-
-