|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pivot.beans.BeanDictionary
public class BeanDictionary
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary |
---|
Dictionary.Pair<K,V> |
Field Summary | |
---|---|
static String |
FIELD_PREFIX
|
static String |
GET_PREFIX
|
static String |
IS_PREFIX
|
static String |
LISTENERS_SUFFIX
|
static String |
PROPERTY_CHANGE_SUFFIX
|
static String |
SET_PREFIX
|
Constructor Summary | |
---|---|
BeanDictionary()
Creates a new bean dictionary that is not associated with a bean. |
|
BeanDictionary(Object bean)
Creates a new bean dictionary. |
|
BeanDictionary(Object bean,
boolean ignoreReadOnlyProperties)
Creates a new bean dictionary. |
Method Summary | |
---|---|
static Object |
coerce(String value,
Class<?> type)
Coerces a string value to a primitive type. |
boolean |
containsKey(String key)
Verifies the existence of a property. |
Object |
get(String key)
Invokes the getter method for the given property. |
Object |
getBean()
Returns the bean object this dictionary wraps. |
ListenerList<BeanDictionaryListener> |
getBeanDictionaryListeners()
|
static Field |
getField(Class<?> type,
String fieldName)
Returns the public, non-static field for a property. |
static Method |
getGetterMethod(Class<?> beanClass,
String key)
Returns the getter method for a property. |
static Method |
getSetterMethod(Class<?> beanClass,
String key,
Class<?> valueType)
Returns the setter method for a property. |
static Class<?> |
getType(Class<?> beanClass,
String key)
Returns the type of a property. |
Class<?> |
getType(String key)
Returns the type of a property. |
boolean |
isNotifying(String key)
Tells whether or not the specified property fires change events. |
static boolean |
isReadOnly(Class<?> type,
String key)
Tests the read-only state of a property. |
boolean |
isReadOnly(String key)
Tests the read-only state of a property. |
Iterator<String> |
iterator()
Returns an iterator over the bean's properties. |
Object |
put(String key,
Object value)
Invokes the a setter method for the given property. |
Object |
remove(String key)
Removes a key/value pair from the map. |
void |
setBean(Object bean)
Sets the bean object that this dictionary will wrap. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String GET_PREFIX
public static final String IS_PREFIX
public static final String SET_PREFIX
public static final String FIELD_PREFIX
public static final String LISTENERS_SUFFIX
public static final String PROPERTY_CHANGE_SUFFIX
Constructor Detail |
---|
public BeanDictionary()
public BeanDictionary(Object bean)
bean
- The bean object to wrap.public BeanDictionary(Object bean, boolean ignoreReadOnlyProperties)
bean
- The bean object to wrap.Method Detail |
---|
public Object getBean()
public void setBean(Object bean)
NOTE: failing to clear the bean of a bean dictionary may result in memory leaks, as the bean object may maintain references to the bean dictionary as long as it is set.
bean
- The bean object, or null to clear the bean.public Object get(String key)
get
in interface Dictionary<String,Object>
key
- The property name.
public Object put(String key, Object value)
put
in interface Dictionary<String,Object>
key
- The property name.value
- The new property value.
PropertyNotFoundException
- If the given property does not exist or is read-only.public Object remove(String key)
Dictionary
remove
in interface Dictionary<String,Object>
key
- The key whose mapping is to be removed.
UnsupportedOperationException
- This method is not supported.public boolean containsKey(String key)
containsKey
in interface Dictionary<String,Object>
key
- The property name.
public boolean isReadOnly(String key)
key
- The property name.
public boolean isNotifying(String key)
key
- The property name.
public Class<?> getType(String key)
key
- The property name.
public Iterator<String> iterator()
iterator
in interface Iterable<String>
public static boolean isReadOnly(Class<?> type, String key)
type
- The bean class.key
- The property name.
public static Class<?> getType(Class<?> beanClass, String key)
beanClass
- The bean class.key
- The property name.
public static Field getField(Class<?> type, String fieldName)
type
- The bean classfieldName
- The property name
public static Method getGetterMethod(Class<?> beanClass, String key)
beanClass
- The bean class.key
- The property name.
public static Method getSetterMethod(Class<?> beanClass, String key, Class<?> valueType)
beanClass
- The bean class.key
- The property name.
public static Object coerce(String value, Class<?> type)
value
- type
-
public ListenerList<BeanDictionaryListener> getBeanDictionaryListeners()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |