r01f.reflection.fluent
Class PropertyInvoker<T>
java.lang.Object
r01f.reflection.fluent.PropertyInvoker<T>
- Type Parameters:
T - the declared type for the property to access.
Usage example:
// Retrieves the value of the property "name"
String name = Reflection.property("name").ofType(String.class).in(person).get();
// Sets the value of the property "name" to "Yoda"
Reflection.property("name").ofType(String.class).in(person).set("Yoda");
// Retrieves the value of the static property "count"
int count = Reflection.staticField("count").ofType(int.class).in(Person.class).get();
// Sets the value of the static property "count" to 3
Reflection.property("count").ofType(int.class).in(Person.class).set(3);
public final class PropertyInvoker<T>
- extends java.lang.Object
Reflection to access a property from a JavaBean.
|
Constructor Summary |
private |
PropertyInvoker(java.lang.String propertyName,
java.lang.Object target,
java.beans.PropertyDescriptor descriptor)
|
|
Method Summary |
private static
|
_createInvoker(java.lang.String name,
java.lang.Class<?> expectedType,
java.lang.Object target)
|
private static java.beans.PropertyDescriptor |
_descriptorForProperty(java.lang.String propertyName,
java.lang.Object target)
|
private static ReflectionException |
_incorrectPropertyType(java.lang.String name,
java.lang.Object target,
java.lang.Class<?> actual,
java.lang.Class<?> expected)
|
private static void |
_verifyCorrectType(java.lang.String propertyName,
java.lang.Object target,
java.lang.Class<?> expectedType,
java.beans.PropertyDescriptor descriptor)
|
T |
get()
Returns the value of the property managed by this class. |
java.beans.PropertyDescriptor |
info()
Returns the "real" property managed by this class. |
(package private) static
|
newInvoker(java.lang.String propertyName,
java.lang.Class<T> expectedType,
java.lang.Object target)
|
(package private) static
|
newInvoker(java.lang.String propertyName,
TypeRef<T> expectedType,
java.lang.Object target)
|
void |
set(T value)
Sets a value in the property managed by this class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_propertyName
private final java.lang.String _propertyName
_targetObj
private final java.lang.Object _targetObj
_propertyDescriptor
private final java.beans.PropertyDescriptor _propertyDescriptor
PropertyInvoker
private PropertyInvoker(java.lang.String propertyName,
java.lang.Object target,
java.beans.PropertyDescriptor descriptor)
newInvoker
static <T> PropertyInvoker<T> newInvoker(java.lang.String propertyName,
TypeRef<T> expectedType,
java.lang.Object target)
newInvoker
static <T> PropertyInvoker<T> newInvoker(java.lang.String propertyName,
java.lang.Class<T> expectedType,
java.lang.Object target)
set
public void set(T value)
- Sets a value in the property managed by this class.
- Parameters:
value - the value to set.
- Throws:
ReflectionError - if the given value cannot be set.
get
public T get()
- Returns the value of the property managed by this class.
- Returns:
- the value of the property managed by this class.
- Throws:
ReflectionError - if the value of the property cannot be retrieved.
info
public java.beans.PropertyDescriptor info()
- Returns the "real" property managed by this class.
- Returns:
- the "real" property managed by this class.
_createInvoker
private static <T> PropertyInvoker<T> _createInvoker(java.lang.String name,
java.lang.Class<?> expectedType,
java.lang.Object target)
_verifyCorrectType
private static void _verifyCorrectType(java.lang.String propertyName,
java.lang.Object target,
java.lang.Class<?> expectedType,
java.beans.PropertyDescriptor descriptor)
_descriptorForProperty
private static java.beans.PropertyDescriptor _descriptorForProperty(java.lang.String propertyName,
java.lang.Object target)
_incorrectPropertyType
private static ReflectionException _incorrectPropertyType(java.lang.String name,
java.lang.Object target,
java.lang.Class<?> actual,
java.lang.Class<?> expected)