Package org.apache.commons.chain.impl
Class ContextBase
- Direct Known Subclasses:
WebContext
,WebContext
Convenience base class for
Context
implementations.
In addition to the minimal functionality required by the Context
interface, this class implements the recommended support for
Attribute-Property Transparency. This is implemented by
analyzing the available JavaBeans properties of this class (or its
subclass), exposes them as key-value pairs in the Map
,
with the key being the name of the property itself.
IMPLEMENTATION NOTE - Because empty
is a
read-only property defined by the Map
interface, it may not
be utilized as an attribute key or property name.
- Version:
- $Revision$ $Date$
- Author:
- Craig R. McClanahan
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorDescriptionDefault, no argument constructor.ContextBase
(Map<String, Object> map) Initialize the contents of thisContext
by copying the values from the specifiedMap
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Override the defaultMap
behavior to clear all keys and values except those corresponding to JavaBeans properties.boolean
containsValue
(Object value) Override the defaultMap
behavior to returntrue
if the specified value is present in either the underlyingMap
or one of the local property values.entrySet()
Override the defaultMap
behavior to return aSet
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
.Override the defaultMap
behavior to return the value of a local property if the specified key matches a local property name.boolean
isEmpty()
Override the defaultMap
behavior to returntrue
if the underlyingMap
only contains key-value pairs for local properties (if any).keySet()
Override the defaultMap
behavior to return aSet
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
.Override the defaultMap
behavior to set the value of a local property if the specified key matches a local property name.void
Override the defaultMap
behavior to call theput()
method individually for each key-value pair in the specifiedMap
.Override the defaultMap
behavior to throwUnsupportedOperationException
on any attempt to remove a key that is the name of a local property.values()
Override the defaultMap
behavior to return aCollection
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
.Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll, size
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Constructor Details
-
ContextBase
public ContextBase()Default, no argument constructor. -
ContextBase
Initialize the contents of thisContext
by copying the values from the specifiedMap
. Any keys inmap
that correspond to local properties will cause the setter method for that property to be called.- Parameters:
map
- Map whose key-value pairs are added- Throws:
IllegalArgumentException
- if an exception is thrown writing a local property value.UnsupportedOperationException
- if a local property does not have a write method.
-
-
Method Details
-
clear
Override the defaultMap
behavior to clear all keys and values except those corresponding to JavaBeans properties. -
containsValue
Override the defaultMap
behavior to returntrue
if the specified value is present in either the underlyingMap
or one of the local property values.- Specified by:
containsValue
in interfaceMap<String,
Object> - Overrides:
containsValue
in classHashMap<String,
Object> - Parameters:
value
- the value look for in the context.- Returns:
true
if found in this context otherwisefalse
.- Throws:
IllegalArgumentException
- if a property getter throws an exception
-
entrySet
Override the defaultMap
behavior to return aSet
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
. -
get
Override the defaultMap
behavior to return the value of a local property if the specified key matches a local property name.IMPLEMENTATION NOTE - If the specified
key
identifies a write-only property,null
will arbitrarily be returned, in order to avoid difficulties implementing the contracts of theMap
interface.- Specified by:
get
in interfaceMap<String,
Object> - Overrides:
get
in classHashMap<String,
Object> - Parameters:
key
- Key of the value to be returned- Returns:
- The value for the specified key.
- Throws:
IllegalArgumentException
- if an exception is thrown reading this local property value.UnsupportedOperationException
- if this local property does not have a read method.
-
isEmpty
Override the defaultMap
behavior to returntrue
if the underlyingMap
only contains key-value pairs for local properties (if any). -
keySet
Override the defaultMap
behavior to return aSet
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
. -
put
Override the defaultMap
behavior to set the value of a local property if the specified key matches a local property name.- Specified by:
put
in interfaceMap<String,
Object> - Overrides:
put
in classHashMap<String,
Object> - Parameters:
key
- Key of the value to be stored or replacedvalue
- New value to be stored- Returns:
- The value added to the Context.
- Throws:
IllegalArgumentException
- if an exception is thrown reading or writing this local property value.UnsupportedOperationException
- if this local property does not have both a read method and a write method
-
putAll
Override the defaultMap
behavior to call theput()
method individually for each key-value pair in the specifiedMap
.- Specified by:
putAll
in interfaceMap<String,
Object> - Overrides:
putAll
in classHashMap<String,
Object> - Parameters:
map
-Map
containing key-value pairs to store (or replace)- Throws:
IllegalArgumentException
- if an exception is thrown reading or writing a local property value.UnsupportedOperationException
- if a local property does not have both a read method and a write method
-
remove
Override the defaultMap
behavior to throwUnsupportedOperationException
on any attempt to remove a key that is the name of a local property. -
values
Override the defaultMap
behavior to return aCollection
that meets the specified default behavior except for attempts to remove the key for a property of theContext
implementation class, which will throwUnsupportedOperationException
.
-