sk.baka.tools
Class JavaUtils.BeanProperty

java.lang.Object
  extended by sk.baka.tools.JavaUtils.BeanProperty
Enclosing class:
JavaUtils

@Immutable
public static final class JavaUtils.BeanProperty
extends Object

Contains accessors to a bean property.


Field Summary
 Field field
          The field itself.
 Method getter
          A field's getter, null if not public or non-existant.
 Method setter
          A field's setter, null if not public or non-existant.
 
Method Summary
static JavaUtils.BeanProperty from(Class<?> clazz, String name)
          Creates a bean property accessor for given property.
static JavaUtils.BeanProperty from(Field field)
          Creates a bean property accessor for given field.
 String getName()
          Returns the property name.
 Class<?> getType()
          Returns the type of the property.
 Object getValue(Object bean)
          Retrieves a property value.
 void setValue(Object bean, Object value)
          Sets a property value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

field

public final Field field
The field itself. Must be public if there are no accompanying getters nor setters.


getter

public final Method getter
A field's getter, null if not public or non-existant.


setter

public final Method setter
A field's setter, null if not public or non-existant.

Method Detail

getType

public Class<?> getType()
Returns the type of the property.

Returns:
the property type (not the type of the property's actual value), never null.

from

public static JavaUtils.BeanProperty from(Field field)
Creates a bean property accessor for given field.

Parameters:
field - the field to access.
Returns:
a bean property accessor instance or null if given field is not public and it does not have public getter nor setter.

from

public static JavaUtils.BeanProperty from(Class<?> clazz,
                                          String name)
Creates a bean property accessor for given property.

Parameters:
name - the property name
clazz - the bean class
Returns:
a bean property accessor instance or null if given field is not public and it does not have public getter nor setter.

getName

public String getName()
Returns the property name.

Returns:
the property name, never null.

getValue

public Object getValue(Object bean)
Retrieves a property value. Uses getter if available, uses direct field access otherwise. In such case, the method will fail if the field is not accessible (e.g. it is private).

Parameters:
bean - the bean instance.
Returns:
retrieved value
Throws:
RuntimeException - if the retrieval fails

setValue

public void setValue(Object bean,
                     Object value)
Sets a property value. Uses setter if available, uses direct field access otherwise.

Parameters:
bean - the bean instance.
value - the value to set
Throws:
RuntimeException - if the setting fails


Copyright © 2009-2010. All Rights Reserved.