Class ContextBase
- All Implemented Interfaces:
Serializable, Cloneable, Map, Context
- Direct Known Subclasses:
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: 499247 $ $Date: 2007-01-24 04:09:44 +0000 (Wed, 24 Jan 2007) $
- Author:
- Craig R. McClanahan
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classPrivate implementation ofSetthat implements the semantics required for the value returned byentrySet().private classPrivate implementation ofIteratorfor theSetreturned byentrySet().private classPrivate implementation ofMap.Entryfor each item inEntrySetImpl.private classPrivate implementation ofCollectionthat implements the semantics required for the value returned byvalues().private classPrivate implementation ofIteratorfor theCollectionreturned byvalues().Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MapThePropertyDescriptors for all JavaBeans properties of thisContextimplementation class, keyed by property name.private PropertyDescriptor[]The samePropertyDescriptors as an array.private static ObjectDistinguished singleton value that is stored in the map for each key that is actually a property.private static Object[]Zero-length array of parameter values for calling property getters. -
Constructor Summary
ConstructorsConstructorDescriptionDefault, no argument constructor.ContextBase(Map map) Initialize the contents of thisContextby copying the values from the specifiedMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Override the defaultMapbehavior to clear all keys and values except those corresponding to JavaBeans properties.booleancontainsValue(Object value) Override the defaultMapbehavior to returntrueif the specified value is present in either the underlyingMapor one of the local property values.private IteratorReturn anIteratorover the set ofMap.Entryobjects representing our key-value pairs.private Map.EntryReturn aMap.Entryfor the specified key value, if it is present; otherwise, returnnull.entrySet()Override the defaultMapbehavior to return aSetthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException.Override the defaultMapbehavior to return the value of a local property if the specified key matches a local property name.private voidCustomize the contents of our underlyingMapso that it contains keys corresponding to all of the JavaBeans properties of theContextimplementation class.booleanisEmpty()Override the defaultMapbehavior to returntrueif the underlyingMaponly contains key-value pairs for local properties (if any).keySet()Override the defaultMapbehavior to return aSetthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException.Override the defaultMapbehavior to set the value of a local property if the specified key matches a local property name.voidOverride the defaultMapbehavior to call theput()method individually for each key-value pair in the specifiedMap.private ObjectreadProperty(PropertyDescriptor descriptor) Get and return the value for the specified property.Override the defaultMapbehavior to throwUnsupportedOperationExceptionon any attempt to remove a key that is the name of a local property.private booleanRemove the specified key-value pair, if it exists, and returntrue.values()Override the defaultMapbehavior to return aCollectionthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException.private IteratorReturn anIteratorover the set of values in thisMap.private voidwriteProperty(PropertyDescriptor descriptor, Object value) Set the value for the specified property.Methods inherited from class HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, forEach, getOrDefault, merge, newHashMap, putIfAbsent, remove, replace, replace, replaceAll, sizeMethods inherited from class AbstractMap
equals, hashCode, toStringMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Field Details
-
descriptors
-
pd
The same
PropertyDescriptors as an array. -
singleton
Distinguished singleton value that is stored in the map for each key that is actually a property. This value is used to ensure that
equals()comparisons will always fail. -
zeroParams
Zero-length array of parameter values for calling property getters.
-
-
Constructor Details
-
ContextBase
public ContextBase()Default, no argument constructor. -
ContextBase
Initialize the contents of this
Contextby copying the values from the specifiedMap. Any keys inmapthat 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 valueUnsupportedOperationException- if a local property does not have a write method.
-
-
Method Details
-
clear
-
containsValue
Override the default
Mapbehavior to returntrueif the specified value is present in either the underlyingMapor one of the local property values.- Specified by:
containsValuein interfaceMap- Overrides:
containsValuein classHashMap- Parameters:
value- the value look for in the context.- Returns:
trueif found in this context otherwisefalse.- Throws:
IllegalArgumentException- if a property getter throws an exception
-
entrySet
Override the default
Mapbehavior to return aSetthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException. -
get
Override the default
Mapbehavior to return the value of a local property if the specified key matches a local property name.IMPLEMENTATION NOTE - If the specified
keyidentifies a write-only property,nullwill arbitrarily be returned, in order to avoid difficulties implementing the contracts of theMapinterface.- Specified by:
getin interfaceMap- Overrides:
getin classHashMap- 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 valueUnsupportedOperationException- if this local property does not have a read method.
-
isEmpty
-
keySet
Override the default
Mapbehavior to return aSetthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException. -
put
Override the default
Mapbehavior to set the value of a local property if the specified key matches a local property name.- Specified by:
putin interfaceMap- Overrides:
putin classHashMap- 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 wrting this local property valueUnsupportedOperationException- if this local property does not have both a read method and a write method
-
putAll
Override the default
Mapbehavior to call theput()method individually for each key-value pair in the specifiedMap.- Specified by:
putAllin interfaceMap- Overrides:
putAllin classHashMap- Parameters:
map-Mapcontaining key-value pairs to store (or replace)- Throws:
IllegalArgumentException- if an exception is thrown reading or wrting a local property valueUnsupportedOperationException- if a local property does not have both a read method and a write method
-
remove
Override the default
Mapbehavior to throwUnsupportedOperationExceptionon any attempt to remove a key that is the name of a local property.- Specified by:
removein interfaceMap- Overrides:
removein classHashMap- Parameters:
key- Key to be removed- Returns:
- The value removed from the Context.
- Throws:
UnsupportedOperationException- if the specifiedkeymatches the name of a local property
-
values
Override the default
Mapbehavior to return aCollectionthat meets the specified default behavior except for attempts to remove the key for a property of theContextimplementation class, which will throwUnsupportedOperationException. -
entriesIterator
Return an
Iteratorover the set ofMap.Entryobjects representing our key-value pairs. -
entry
-
initialize
private void initialize()Customize the contents of our underlying
Mapso that it contains keys corresponding to all of the JavaBeans properties of theContextimplementation class.- Throws:
IllegalArgumentException- if an exception is thrown writing this local property valueUnsupportedOperationException- if this local property does not have a write method.
-
readProperty
Get and return the value for the specified property.
- Parameters:
descriptor-PropertyDescriptorfor the specified property- Throws:
IllegalArgumentException- if an exception is thrown reading this local property valueUnsupportedOperationException- if this local property does not have a read method.
-
remove
Remove the specified key-value pair, if it exists, and return
true. If this pair does not exist, returnfalse.- Parameters:
entry- Key-value pair to be removed- Throws:
UnsupportedOperationException- if the specified key identifies a property instead of an attribute
-
valuesIterator
Return an
Iteratorover the set of values in thisMap. -
writeProperty
Set the value for the specified property.
- Parameters:
descriptor-PropertyDescriptorfor the specified propertyvalue- The new value for this property (must be of the correct type)- Throws:
IllegalArgumentException- if an exception is thrown writing this local property valueUnsupportedOperationException- if this local property does not have a write method.
-