|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pivot.beans.BeanAdapter
public class BeanAdapter
Exposes Java bean properties of an object via the Map
interface. A call to Dictionary.get(Object)
invokes the getter for
the corresponding property, and a call to
Map.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.
Getter methods must be named "getProperty" where "property" is the property name. If there is no "get" method, then an "isProperty" method can also be used. Setter methods (if present) must be named "setProperty".
Getter and setter methods are checked before straight fields
named "property" in order to support proper data encapsulation.
And only public
and non-static
methods
and fields can be accessed.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Map |
---|
Map.MapListenerList<K,V> |
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary |
---|
Dictionary.Pair<K,V> |
Field Summary | |
---|---|
static String |
GET_PREFIX
|
static String |
IS_PREFIX
|
static String |
SET_PREFIX
|
Constructor Summary | |
---|---|
BeanAdapter(Object bean)
Creates a new bean dictionary. |
|
BeanAdapter(Object bean,
boolean ignoreReadOnlyProperties)
Creates a new bean dictionary which can ignore readonly fields (that is, straight fields marked as final or bean
properties where there is a "get" method but no corresponding
"set" method). |
Method Summary | ||
---|---|---|
void |
clear()
Removes all entries in the map. |
|
static
|
coerce(Object value,
Class<? extends T> type)
Coerces a value to a given 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. |
|
Comparator<String> |
getComparator()
Returns the collection's sort order. |
|
int |
getCount()
Returns the number of entries in the map. |
|
static Field |
getField(Class<?> beanClass,
String key)
Returns the public, non-static fields for a property. |
|
static Type |
getGenericType(Class<?> beanClass,
String key)
Returns the generic type of a property. |
|
Type |
getGenericType(String key)
Returns the generic type of a property. |
|
static Method |
getGetterMethod(Class<?> beanClass,
String key)
Returns the getter method for a property. |
|
ListenerList<MapListener<String,Object>> |
getMapListeners()
Returns the map listener collection. |
|
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 |
isEmpty()
Tests the emptiness of the collection. |
|
static boolean |
isReadOnly(Class<?> beanClass,
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 setter method for the given property. |
|
void |
putAll(Map<String,?> valueMap)
Invokes the setter methods for all the given properties that are present in the map. |
|
boolean |
putAll(Map<String,?> valueMap,
boolean ignoreErrors)
Invokes the setter methods for all the given properties that are present in the map. |
|
Object |
remove(String key)
Removes a key/value pair from the map. |
|
void |
setComparator(Comparator<String> comparator)
Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order. |
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
Constructor Detail |
---|
public BeanAdapter(Object bean)
bean
- The bean object to wrap.public BeanAdapter(Object bean, boolean ignoreReadOnlyProperties)
final
or bean
properties where there is a "get" method but no corresponding
"set" method).
bean
- The bean object to wrap.Method Detail |
---|
public Object getBean()
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>
put
in interface Map<String,Object>
key
- The property name.value
- The new property value.
PropertyNotFoundException
- If the given property does not exist or is read-only.MapListener.valueAdded(Map, Object)
,
MapListener.valueUpdated(Map, Object, Object)
public void putAll(Map<String,?> valueMap)
valueMap
- The map of keys and values to be set.
PropertyNotFoundException
- If any of the given properties do not exist or are read-only.public boolean putAll(Map<String,?> valueMap, boolean ignoreErrors)
valueMap
- The map of keys and values to be set.ignoreErrors
- If true
then any PropertyNotFoundException
thrown by the put()
method will be caught and ignored.
true
if any exceptions were caught, false
if not.public Object remove(String key)
Dictionary
remove
in interface Dictionary<String,Object>
remove
in interface Map<String,Object>
key
- The key whose mapping is to be removed.
UnsupportedOperationException
- This method is not supported.MapListener.valueRemoved(Map, Object, Object)
public void clear()
Map
clear
in interface Collection<String>
clear
in interface Map<String,Object>
UnsupportedOperationException
- This method is not supported.MapListener.mapCleared(Map)
public boolean containsKey(String key)
containsKey
in interface Dictionary<String,Object>
key
- The property name.
public boolean isEmpty()
Collection
isEmpty
in interface Collection<String>
UnsupportedOperationException
- This method is not supported.public int getCount()
Map
getCount
in interface Map<String,Object>
UnsupportedOperationException
- This method is not supported.public Comparator<String> getComparator()
Collection
getComparator
in interface Collection<String>
Collection.setComparator(Comparator)
public void setComparator(Comparator<String> comparator)
Collection
Calling this method more than once with the same comparator will re-sort the collection.
setComparator
in interface Collection<String>
setComparator
in interface Map<String,Object>
comparator
- The comparator used to order elements in the collection, or null if the
collection is unsorted.
UnsupportedOperationException
- This method is not supported.MapListener.comparatorChanged(Map, Comparator)
public boolean isReadOnly(String key)
key
- The property name.
public Class<?> getType(String key)
key
- The property name.getType(Class, String)
public Type getGenericType(String key)
key
- The property name.getGenericType(Class, String)
public Iterator<String> iterator()
iterator
in interface Iterable<String>
public ListenerList<MapListener<String,Object>> getMapListeners()
Map
getMapListeners
in interface Map<String,Object>
public static boolean isReadOnly(Class<?> beanClass, String key)
beanClass
- 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 Type getGenericType(Class<?> beanClass, String key)
beanClass
- The bean class.key
- The property name.
ParameterizedType
will be returned. Otherwise,
an instance of Class
will be returned.public static Field getField(Class<?> beanClass, String key)
beanClass
- The bean class.key
- 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 <T> T coerce(Object value, Class<? extends T> type)
value
- type
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |