net.sf.japaki.beans
Class ReflectionProperty<B,V>

java.lang.Object
  extended by net.sf.japaki.beans.ReflectionProperty<B,V>
All Implemented Interfaces:
Property<B,V>

public class ReflectionProperty<B,V>
extends Object
implements Property<B,V>

Property based on methods.


Constructor Summary
ReflectionProperty(Method getter, Method setter, String name)
          Constructs a new reflection property.
 
Method Summary
 Class<V> getType()
          Returns the parameter type of this property.
 V getValue(B bean)
          Retrieves the value of this property from the specified bean.
static
<B,V> ReflectionProperty<B,V>
newInstance(Class<B> beanType, String name)
          Creates a reflection property from a class and a property name.
 void setValue(B bean, V value)
          Stores the value in the property specified by this object in the specified bean.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReflectionProperty

public ReflectionProperty(Method getter,
                          Method setter,
                          String name)
Constructs a new reflection property.

Parameters:
getter - method that retrieves the value from the bean
setter - method that stores the value in the bean
name - name of the property. It is used for the string representation in toString().
Method Detail

newInstance

public static <B,V> ReflectionProperty<B,V> newInstance(Class<B> beanType,
                                                        String name)
Creates a reflection property from a class and a property name. The method names are expected as "get" + Name and "set" + Name, respectively.

Parameters:
beanType - the class of the property's bean
name - property name
Returns:
the created property

getValue

public V getValue(B bean)
Description copied from interface: Property
Retrieves the value of this property from the specified bean.

Specified by:
getValue in interface Property<B,V>
Parameters:
bean - the bean from which to read the value
Returns:
the found value
Throws:
IllegalArgumentException - if the class of the bean does not match with the underlying getter method.
RuntimeException - if an IllegalAccessException or an InvocationTargetException occurs.

setValue

public void setValue(B bean,
                     V value)
Description copied from interface: Property
Stores the value in the property specified by this object in the specified bean.

Specified by:
setValue in interface Property<B,V>
Parameters:
bean - the bean in which to store the value
value - the new value of the property
Throws:
IllegalArgumentException - depending on the bean
UnsupportedOperationException - if setter is not defined.
NullPointerException - if bean is null and the setter method is an instance method.
RuntimeException - if an IllegalAccessException or an InvocationTargetException occurs.

getType

public Class<V> getType()
Returns the parameter type of this property.

Specified by:
getType in interface Property<B,V>
Returns:
the parameter type of this property.

toString

public String toString()
Overrides:
toString in class Object