public class ContextBase extends HashMap implements Context
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.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
ContextBase()
Default, no argument constructor.
|
ContextBase(Map map)
Initialize the contents of this
Context by copying the
values from the specified Map . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Override the default
Map behavior to clear all keys and
values except those corresponding to JavaBeans properties. |
boolean |
containsValue(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. |
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 . |
Object |
get(Object key)
Override the default
Map behavior to return the value
of a local property if the specified key matches a local property name. |
boolean |
isEmpty()
Override the default
Map behavior to return
true if the underlying Map only contains
key-value pairs for local properties (if any). |
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 . |
Object |
put(Object key,
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(Map map)
Override the default
Map behavior to call the
put() method individually for each key-value pair
in the specified Map . |
Object |
remove(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. |
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 . |
clone, compute, computeIfAbsent, computeIfPresent, containsKey, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll, size
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll, size
public ContextBase()
public ContextBase(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 addedIllegalArgumentException
- if an exception is thrown
writing a local property valueUnsupportedOperationException
- if a local property does not
have a write method.public void clear()
Override the default Map
behavior to clear all keys and
values except those corresponding to JavaBeans properties.
public boolean containsValue(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 Map
containsValue
in class HashMap
value
- the value look for in the context.true
if found in this context otherwise
false
.IllegalArgumentException
- if a property getter
throws an exceptionpublic 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
.
public Object get(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 Map
get
in class HashMap
key
- Key of the value to be returnedIllegalArgumentException
- if an exception is thrown
reading this local property valueUnsupportedOperationException
- 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).
public 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
.
public Object put(Object key, 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 Map
put
in class HashMap
key
- Key of the value to be stored or replacedvalue
- New value to be storedIllegalArgumentException
- 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 methodpublic void putAll(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 Map
putAll
in class HashMap
map
- Map
containing key-value pairs to store
(or replace)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 methodpublic Object remove(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 Map
remove
in class HashMap
key
- Key to be removedUnsupportedOperationException
- if the specified
key
matches the name of a local propertypublic 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
.
Copyright © 2003–2021 The Apache Software Foundation. All rights reserved.