pivot.beans
Class BeanDictionary

java.lang.Object
  extended by pivot.beans.BeanDictionary
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>, Dictionary<java.lang.String,java.lang.Object>
Direct Known Subclasses:
Component.StyleDictionary

public class BeanDictionary
extends java.lang.Object
implements Dictionary<java.lang.String,java.lang.Object>, java.lang.Iterable<java.lang.String>

Exposes Java bean properties of an object via the Dictionary interface. A call to Dictionary.get(Object) invokes the getter for the corresponding property, and a call to Dictionary.put(Object, Object) invokes the property's setter.

Properties may provide multiple setters; the appropriate setter to invoke is determined by the type of the value being set. If the value is null, the return type of the getter method is used.

Author:
gbrown

Field Summary
static java.lang.String GET_PREFIX
           
static java.lang.String IS_PREFIX
           
static java.lang.String LISTENERS_SUFFIX
           
static java.lang.String SET_PREFIX
           
 
Constructor Summary
BeanDictionary(java.lang.Object bean)
          Creates a new bean dictionary.
BeanDictionary(java.lang.Object bean, boolean ignoreReadOnlyProperties)
          Creates a new bean dictionary.
 
Method Summary
 boolean containsKey(java.lang.String key)
          Verifies the existence of a property.
 java.lang.Object get(java.lang.String key)
          Invokes the getter method for the given property.
 java.lang.Object getBean()
          Returns the bean object this dictionary wraps.
 java.lang.Class<?> getType(java.lang.String key)
          Returns the type of a property.
 boolean isEmpty()
          Verifies that the bean contains at least one property.
 boolean isReadOnly(java.lang.String key)
          Tests the read-only state of a property.
 java.util.Iterator<java.lang.String> iterator()
          Returns an iterator over the bean's properties.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
          Invokes the a setter method for the given property.
 java.lang.Object remove(java.lang.String key)
          Removes a key/value pair from the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_PREFIX

public static final java.lang.String GET_PREFIX
See Also:
Constant Field Values

IS_PREFIX

public static final java.lang.String IS_PREFIX
See Also:
Constant Field Values

SET_PREFIX

public static final java.lang.String SET_PREFIX
See Also:
Constant Field Values

LISTENERS_SUFFIX

public static final java.lang.String LISTENERS_SUFFIX
See Also:
Constant Field Values
Constructor Detail

BeanDictionary

public BeanDictionary(java.lang.Object bean)
Creates a new bean dictionary.

Parameters:
bean - The bean object to wrap.

BeanDictionary

public BeanDictionary(java.lang.Object bean,
                      boolean ignoreReadOnlyProperties)
Creates a new bean dictionary.

Parameters:
bean - The bean object to wrap.
Method Detail

getBean

public java.lang.Object getBean()
Returns the bean object this dictionary wraps.


get

public java.lang.Object get(java.lang.String key)
Invokes the getter method for the given property.

Specified by:
get in interface Dictionary<java.lang.String,java.lang.Object>
Parameters:
key - The property name.
Returns:
The value returned by the method, or null if no such method exists.

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)
Invokes the a setter method for the given property. The method signature is determined by the type of the value. If the value is null, the return type of the getter method is used.

Specified by:
put in interface Dictionary<java.lang.String,java.lang.Object>
Parameters:
key - The property name.
value - The new property value.
Returns:
Returns null, since returning the previous value would require a call to the getter method, which may not be an efficient operation.
Throws:
PropertyNotFoundException - If the given property does not exist or is read-only.

remove

public java.lang.Object remove(java.lang.String key)
Description copied from interface: Dictionary
Removes a key/value pair from the map.

Specified by:
remove in interface Dictionary<java.lang.String,java.lang.Object>
Parameters:
key - The key whose mapping is to be removed.
Returns:
The value that was removed.
Throws:
java.lang.UnsupportedOperationException - This method is not supported.

containsKey

public boolean containsKey(java.lang.String key)
Verifies the existence of a property. The property must have a getter method; write-only properties are not supported.

Specified by:
containsKey in interface Dictionary<java.lang.String,java.lang.Object>
Parameters:
key - The property name.
Returns:
true if the property exists; false, otherwise.

isEmpty

public boolean isEmpty()
Verifies that the bean contains at least one property.

Specified by:
isEmpty in interface Dictionary<java.lang.String,java.lang.Object>
Returns:
true if the dictionary contains no keys; false, otherwise.

isReadOnly

public boolean isReadOnly(java.lang.String key)
Tests the read-only state of a property.

Parameters:
key - The property name.
Returns:
true if the property is read-only; false, otherwise.

getType

public java.lang.Class<?> getType(java.lang.String key)
Returns the type of a property.

Parameters:
key - The property name.
Returns:
The type of the property.

iterator

public java.util.Iterator<java.lang.String> iterator()
Returns an iterator over the bean's properties.

Specified by:
iterator in interface java.lang.Iterable<java.lang.String>
Returns:
A property iterator for this bean.