public class BeanAdapter
extends java.util.AbstractMap<java.lang.String,java.lang.Object>
Map
interface.
A call to Map.get(Object)
invokes the getter for the corresponding
property, and a call to Map.put(Object, Object)
invokes the
property's setter. Appending a "Property" suffix to the key returns the
corresponding property model.Modifier and Type | Class and Description |
---|---|
private static class |
BeanAdapter.MethodCache |
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
bean |
static java.lang.String |
GET_PREFIX |
private static java.util.HashMap<java.lang.Class<?>,BeanAdapter.MethodCache> |
globalMethodCache |
static java.lang.String |
IS_PREFIX |
private BeanAdapter.MethodCache |
localCache |
static java.lang.String |
PROPERTY_SUFFIX |
static java.lang.String |
SET_PREFIX |
static java.lang.String |
VALUE_OF_METHOD_NAME |
Constructor and Description |
---|
BeanAdapter(java.lang.Object bean)
Creates a new Bean adapter.
|
Modifier and Type | Method and Description |
---|---|
static <T> T |
coerce(java.lang.Object value,
java.lang.Class<? extends T> type)
Coerces a value to a given type.
|
boolean |
containsKey(java.lang.Object key)
Verifies the existence of a property.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet() |
boolean |
equals(java.lang.Object object) |
java.lang.Object |
get(java.lang.Object key)
Invokes the getter method for the given property.
|
static <T> T |
get(java.lang.Object target,
java.lang.Class<?> sourceType,
java.lang.String key)
Invokes the static getter method for the given property.
|
private java.lang.Object |
get(java.lang.String key) |
java.lang.Object |
getBean()
Returns the Bean object this adapter wraps.
|
private static BeanAdapter.MethodCache |
getClassMethodCache(java.lang.Class<?> type) |
static java.lang.Object |
getConstantValue(java.lang.Class<?> type,
java.lang.String name)
Returns the value of a named constant.
|
static java.lang.reflect.Type |
getGenericListItemType(java.lang.reflect.Type listType)
Determines the type of a list item.
|
static java.lang.reflect.Type |
getGenericMapValueType(java.lang.reflect.Type mapType)
Determines the type of a map value.
|
static java.lang.reflect.Type |
getGenericType(java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Class<?> targetType)
Returns the generic type of a static property.
|
java.lang.reflect.Type |
getGenericType(java.lang.String key)
Returns the generic type of a property.
|
private java.lang.reflect.Method |
getGetterMethod(java.lang.String key) |
static java.lang.Class<?> |
getListItemType(java.lang.reflect.Type listType)
Determines the type of a list item.
|
static java.lang.Class<?> |
getMapValueType(java.lang.reflect.Type mapType)
Determines the type of a map value.
|
private static java.lang.String |
getMethodName(java.lang.String prefix,
java.lang.String key) |
<T> ObservableValue<T> |
getPropertyModel(java.lang.String key)
Returns the property model for the given property.
|
private java.lang.reflect.Method |
getSetterMethod(java.lang.String key) |
private static java.lang.reflect.Method |
getStaticGetterMethod(java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Class<?> targetType) |
private static java.lang.reflect.Method |
getStaticSetterMethod(java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Class<?> valueType,
java.lang.Class<?> targetType) |
static java.lang.Class<?> |
getType(java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Class<?> targetType)
Returns the type of a static property.
|
java.lang.Class<?> |
getType(java.lang.String key)
Returns the type of a property.
|
int |
hashCode() |
static boolean |
isDefined(java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Class<?> targetType)
Tests the existence of a static property.
|
boolean |
isReadOnly(java.lang.String key)
Tests the mutability of a property.
|
static void |
put(java.lang.Object target,
java.lang.Class<?> sourceType,
java.lang.String key,
java.lang.Object value)
Invokes a static setter method for the given property.
|
java.lang.Object |
put(java.lang.String key,
java.lang.Object value)
Invokes a setter method for the given property.
|
private static java.lang.String |
toAllCaps(java.lang.String value) |
clear, clone, containsValue, isEmpty, keySet, putAll, remove, size, toString, values
private final java.lang.Object bean
private static final java.util.HashMap<java.lang.Class<?>,BeanAdapter.MethodCache> globalMethodCache
private final BeanAdapter.MethodCache localCache
public static final java.lang.String GET_PREFIX
public static final java.lang.String IS_PREFIX
public static final java.lang.String SET_PREFIX
public static final java.lang.String PROPERTY_SUFFIX
public static final java.lang.String VALUE_OF_METHOD_NAME
public BeanAdapter(java.lang.Object bean)
bean
- The Bean object to wrap.private static BeanAdapter.MethodCache getClassMethodCache(java.lang.Class<?> type)
public java.lang.Object getBean()
private java.lang.reflect.Method getGetterMethod(java.lang.String key)
private java.lang.reflect.Method getSetterMethod(java.lang.String key)
private static java.lang.String getMethodName(java.lang.String prefix, java.lang.String key)
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
get
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The property name.private java.lang.Object get(java.lang.String key)
public java.lang.Object put(java.lang.String key, java.lang.Object value)
coerce(Object, Class)
method is used as needed to attempt to
convert a given value to the property type, as defined by the return
value of the getter method.put
in interface java.util.Map<java.lang.String,java.lang.Object>
put
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The property name.value
- The new property value.PropertyNotFoundException
- If the given property does not exist or is read-only.public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
containsKey
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
key
- The property name.public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,java.lang.Object>
entrySet
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public boolean isReadOnly(java.lang.String key)
key
- The property name.public <T> ObservableValue<T> getPropertyModel(java.lang.String key)
key
- The property name.public java.lang.Class<?> getType(java.lang.String key)
key
- The property name.public java.lang.reflect.Type getGenericType(java.lang.String key)
key
- The property name.public boolean equals(java.lang.Object object)
equals
in interface java.util.Map<java.lang.String,java.lang.Object>
equals
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public int hashCode()
hashCode
in interface java.util.Map<java.lang.String,java.lang.Object>
hashCode
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public static <T> T coerce(java.lang.Object value, java.lang.Class<? extends T> type)
value
- type
- public static <T> T get(java.lang.Object target, java.lang.Class<?> sourceType, java.lang.String key)
target
- The object to which the property is attached.sourceType
- The class that defines the property.key
- The property name.public static void put(java.lang.Object target, java.lang.Class<?> sourceType, java.lang.String key, java.lang.Object value)
coerce(Object, Class)
method is used to attempt to convert the
value to the actual property type (defined by the return value of the
getter method).target
- The object to which the property is or will be attached.sourceType
- The class that defines the property.key
- The property name.value
- The new property value.PropertyNotFoundException
- If the given static property does not exist or is read-only.public static boolean isDefined(java.lang.Class<?> sourceType, java.lang.String key, java.lang.Class<?> targetType)
sourceType
- The class that defines the property.key
- The property name.targetType
- The type of the object to which the property applies.public static java.lang.Class<?> getType(java.lang.Class<?> sourceType, java.lang.String key, java.lang.Class<?> targetType)
sourceType
- The class that defines the property.key
- The property name.targetType
- The type of the object to which the property applies.public static java.lang.reflect.Type getGenericType(java.lang.Class<?> sourceType, java.lang.String key, java.lang.Class<?> targetType)
sourceType
- The class that defines the property.key
- The property name.targetType
- The type of the object to which the property applies.public static java.lang.Class<?> getListItemType(java.lang.reflect.Type listType)
listType
- public static java.lang.Class<?> getMapValueType(java.lang.reflect.Type mapType)
mapType
- public static java.lang.reflect.Type getGenericListItemType(java.lang.reflect.Type listType)
listType
- public static java.lang.reflect.Type getGenericMapValueType(java.lang.reflect.Type mapType)
mapType
- public static java.lang.Object getConstantValue(java.lang.Class<?> type, java.lang.String name)
type
- The type that defines the constant.name
- The name of the constant.private static java.lang.reflect.Method getStaticGetterMethod(java.lang.Class<?> sourceType, java.lang.String key, java.lang.Class<?> targetType)
private static java.lang.reflect.Method getStaticSetterMethod(java.lang.Class<?> sourceType, java.lang.String key, java.lang.Class<?> valueType, java.lang.Class<?> targetType)
private static java.lang.String toAllCaps(java.lang.String value)