|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap
org.apache.commons.chain.impl.ContextBase
public class ContextBase
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
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.
Nested Class Summary | |
---|---|
private class |
ContextBase.EntrySetImpl
Private implementation of Set that implements the
semantics required for the value returned by entrySet() . |
private class |
ContextBase.EntrySetIterator
Private implementation of Iterator for the
Set returned by entrySet() . |
private class |
ContextBase.MapEntryImpl
Private implementation of Map.Entry for each item in
EntrySetImpl . |
private class |
ContextBase.ValuesImpl
Private implementation of Collection that implements the
semantics required for the value returned by values() . |
private class |
ContextBase.ValuesIterator
Private implementation of Iterator for the
Collection returned by values() . |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
private java.util.Map |
descriptors
The PropertyDescriptor s for all JavaBeans properties
of this Context implementation class, keyed by property name. |
private java.beans.PropertyDescriptor[] |
pd
The same PropertyDescriptor s as an array. |
private static java.lang.Object |
singleton
Distinguished singleton value that is stored in the map for each key that is actually a property. |
private static java.lang.Object[] |
zeroParams
Zero-length array of parameter values for calling property getters. |
Constructor Summary | |
---|---|
ContextBase()
Default, no argument constructor. |
|
ContextBase(java.util.Map map)
Initialize the contents of this Context by copying the
values from the specified Map . |
Method Summary | |
---|---|
void |
clear()
Override the default Map behavior to clear all keys and
values except those corresponding to JavaBeans properties. |
boolean |
containsValue(java.lang.Object value)
Override the default Map behavior to return
true if the specified value is present in either the
underlying Map or one of the local property values. |
private void |
eliminate(java.lang.String name)
Eliminate the specified property descriptor from the list of property descriptors in pd . |
private java.util.Iterator |
entriesIterator()
Return an Iterator over the set of Map.Entry
objects representing our key-value pairs. |
private java.util.Map.Entry |
entry(java.lang.Object key)
Return a Map.Entry for the specified key value, if it
is present; otherwise, return null . |
java.util.Set |
entrySet()
Override the default Map behavior to return a
Set that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException . |
java.lang.Object |
get(java.lang.Object key)
Override the default Map behavior to return the value
of a local property if the specified key matches a local property name. |
private void |
initialize()
Customize the contents of our underlying Map so that
it contains keys corresponding to all of the JavaBeans properties of
the Context implementation class. |
boolean |
isEmpty()
Override the default Map behavior to return
true if the underlying Map only contains
key-value pairs for local properties (if any). |
java.util.Set |
keySet()
Override the default Map behavior to return a
Set that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException . |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Override the default Map behavior to set the value
of a local property if the specified key matches a local property name. |
void |
putAll(java.util.Map map)
Override the default Map behavior to call the
put() method individually for each key-value pair
in the specified Map . |
private java.lang.Object |
readProperty(java.beans.PropertyDescriptor descriptor)
Get and return the value for the specified property. |
private boolean |
remove(java.util.Map.Entry entry)
Remove the specified key-value pair, if it exists, and return true . |
java.lang.Object |
remove(java.lang.Object key)
Override the default Map behavior to throw
UnsupportedOperationException on any attempt to
remove a key that is the name of a local property. |
java.util.Collection |
values()
Override the default Map behavior to return a
Collection that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException . |
private java.util.Iterator |
valuesIterator()
Return an Iterator over the set of values in this
Map . |
private void |
writeProperty(java.beans.PropertyDescriptor descriptor,
java.lang.Object value)
Set the value for the specified property. |
Methods inherited from class java.util.HashMap |
---|
clone, containsKey, 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 |
---|
containsKey, equals, hashCode, size |
Field Detail |
---|
private java.util.Map descriptors
The PropertyDescriptor
s for all JavaBeans properties
of this Context
implementation class, keyed by property name.
This collection is allocated only if there are any JavaBeans
properties.
private java.beans.PropertyDescriptor[] pd
The same PropertyDescriptor
s as an array.
private static java.lang.Object 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.
private static java.lang.Object[] zeroParams
Zero-length array of parameter values for calling property getters.
Constructor Detail |
---|
public ContextBase()
public ContextBase(java.util.Map map)
Initialize the contents of this Context
by copying the
values from the specified Map
. Any keys in map
that correspond to local properties will cause the setter method for
that property to be called.
map
- Map whose key-value pairs are added
java.lang.IllegalArgumentException
- if an exception is thrown
writing a local property value
java.lang.UnsupportedOperationException
- if a local property does not
have a write method.Method Detail |
---|
public void clear()
Override the default Map
behavior to clear all keys and
values except those corresponding to JavaBeans properties.
clear
in interface java.util.Map
clear
in class java.util.HashMap
public boolean containsValue(java.lang.Object value)
Override the default Map
behavior to return
true
if the specified value is present in either the
underlying Map
or one of the local property values.
containsValue
in interface java.util.Map
containsValue
in class java.util.HashMap
java.lang.IllegalArgumentException
- if a property getter
throws an exceptionpublic java.util.Set entrySet()
Override the default Map
behavior to return a
Set
that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException
.
entrySet
in interface java.util.Map
entrySet
in class java.util.HashMap
public java.lang.Object get(java.lang.Object key)
Override the default Map
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 the Map
interface.
get
in interface java.util.Map
get
in class java.util.HashMap
key
- Key of the value to be returned
java.lang.IllegalArgumentException
- if an exception is thrown
reading this local property value
java.lang.UnsupportedOperationException
- if this local property does not
have a read method.public boolean isEmpty()
Override the default Map
behavior to return
true
if the underlying Map
only contains
key-value pairs for local properties (if any).
isEmpty
in interface java.util.Map
isEmpty
in class java.util.HashMap
public java.util.Set keySet()
Override the default Map
behavior to return a
Set
that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException
.
keySet
in interface java.util.Map
keySet
in class java.util.HashMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Override the default Map
behavior to set the value
of a local property if the specified key matches a local property name.
put
in interface java.util.Map
put
in class java.util.HashMap
key
- Key of the value to be stored or replacedvalue
- New value to be stored
java.lang.IllegalArgumentException
- if an exception is thrown
reading or wrting this local property value
java.lang.UnsupportedOperationException
- if this local property does not
have both a read method and a write methodpublic void putAll(java.util.Map map)
Override the default Map
behavior to call the
put()
method individually for each key-value pair
in the specified Map
.
putAll
in interface java.util.Map
putAll
in class java.util.HashMap
map
- Map
containing key-value pairs to store
(or replace)
java.lang.IllegalArgumentException
- if an exception is thrown
reading or wrting a local property value
java.lang.UnsupportedOperationException
- if a local property does not
have both a read method and a write methodpublic java.lang.Object remove(java.lang.Object key)
Override the default Map
behavior to throw
UnsupportedOperationException
on any attempt to
remove a key that is the name of a local property.
remove
in interface java.util.Map
remove
in class java.util.HashMap
key
- Key to be removed
java.lang.UnsupportedOperationException
- if the specified
key
matches the name of a local propertypublic java.util.Collection values()
Override the default Map
behavior to return a
Collection
that meets the specified default behavior except
for attempts to remove the key for a property of the Context
implementation class, which will throw
UnsupportedOperationException
.
values
in interface java.util.Map
values
in class java.util.HashMap
private void eliminate(java.lang.String name)
Eliminate the specified property descriptor from the list of
property descriptors in pd
.
name
- Name of the property to eliminate
java.lang.IllegalArgumentException
- if the specified property name
is not presentprivate java.util.Iterator entriesIterator()
Return an Iterator
over the set of Map.Entry
objects representing our key-value pairs.
private java.util.Map.Entry entry(java.lang.Object key)
Return a Map.Entry
for the specified key value, if it
is present; otherwise, return null
.
key
- Attribute key or property nameprivate void initialize()
Customize the contents of our underlying Map
so that
it contains keys corresponding to all of the JavaBeans properties of
the Context
implementation class.
java.lang.IllegalArgumentException
- if an exception is thrown
writing this local property value
java.lang.UnsupportedOperationException
- if this local property does not
have a write method.private java.lang.Object readProperty(java.beans.PropertyDescriptor descriptor)
Get and return the value for the specified property.
descriptor
- PropertyDescriptor
for the
specified property
java.lang.IllegalArgumentException
- if an exception is thrown
reading this local property value
java.lang.UnsupportedOperationException
- if this local property does not
have a read method.private boolean remove(java.util.Map.Entry entry)
Remove the specified key-value pair, if it exists, and return
true
. If this pair does not exist, return
false
.
entry
- Key-value pair to be removed
java.lang.UnsupportedOperationException
- if the specified key
identifies a property instead of an attributeprivate java.util.Iterator valuesIterator()
Return an Iterator
over the set of values in this
Map
.
private void writeProperty(java.beans.PropertyDescriptor descriptor, java.lang.Object value)
Set the value for the specified property.
descriptor
- PropertyDescriptor
for the
specified propertyvalue
- The new value for this property (must be of the
correct type)
java.lang.IllegalArgumentException
- if an exception is thrown
writing this local property value
java.lang.UnsupportedOperationException
- if this local property does not
have a write method.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |