org.jbeans
Class BeanProperty

java.lang.Object
  |
  +--org.jbeans.BaseBeanProperty
        |
        +--org.jbeans.BeanProperty
Direct Known Subclasses:
IndexedBeanProperty, SynchronizedBeanProperty

public class BeanProperty
extends BaseBeanProperty

This class is used to describe, and manipulate JavaBean properties. The properties that this class handles are normal properties and NOT nested properties (see NestedBeanProperty for more information on nested bean properties).

Author:
Brian Pontarelli

Field Summary
protected  Method read
           
protected  Method write
           
 
Fields inherited from class org.jbeans.BaseBeanProperty
BAD_CONVERT, beanClass, conversionListeners, GET, POST_CONVERT, PRE_CONVERT, propertyListeners, propertyName, propertyType, SET
 
Constructor Summary
protected BeanProperty()
          Default constructor that can be used by sub-classes that want to delay the initialization of the propertyName and beanClass or that do not use these members.
  BeanProperty(String propertyName, Class beanClass)
          Constructs a new bean property using the property name and the bean class given.
  BeanProperty(String propertyName, String beanClass)
          Constructs a new bean property using the property name and the fully qualified name of the bean class given.
 
Method Summary
 Class getBeanClass()
          Returns the bean class that the property is defined in
 Object getPropertyValue(Object bean)
          Returns the value of the Java bean property for the given bean instance.
 Method getReadMethod()
          Returns the read method of the bean property
 Method getWriteMethod()
          Returns the write method name of the bean property
protected  void initialize()
          Initializes the bean property by finding the read and write methods and setting up the propertyType for this BeanProperty.
 void setPropertyValue(Object bean, Object value, boolean convert)
          Sets the value of the Java bean property to the given value
 
Methods inherited from class org.jbeans.BaseBeanProperty
addConversionListener, addPropertyListener, convertParameter, fireConversionEvent, firePropertyEvent, getConversionListeners, getFullName, getPropertyListeners, getPropertyName, getPropertyType, hasConversionListeners, hasPropertyListeners, instantiate, removeConversionListener, removePropertyListener, setPropertyValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

read

protected Method read

write

protected Method write
Constructor Detail

BeanProperty

protected BeanProperty()
Default constructor that can be used by sub-classes that want to delay the initialization of the propertyName and beanClass or that do not use these members. This constructor also calls the default constructor from the BaseBeanProperty super-class. This means that using this constructor will not make a template method call to #initialize().

BeanProperty

public BeanProperty(String propertyName,
                    Class beanClass)
             throws BeanException
Constructs a new bean property using the property name and the bean class given.

If the bean class does not have a write method (set method) than the property is considered read-only. The bean class MUST have a read method (get method) or this method will throw and exception. This method calls the super-class constructor with the same signature.

Parameters:
propertyName - The name of the JavaBean property
beanClass - The Class object used to find the read and write methods for the JavaBean property
Throws:
BeanException - If the property is invalid or does not exist in the bean class given

BeanProperty

public BeanProperty(String propertyName,
                    String beanClass)
             throws BeanException
Constructs a new bean property using the property name and the fully qualified name of the bean class given.

If the bean class does not have a write method (set method) than the property is considered read-only. The bean class MUST have a read method (get method) or this method will throw and exception. This method calls the super-class constructor with the same signature.

Parameters:
propertyName - The name of the JavaBean property
beanClass - The fuly qualified name of the bean class object used to find the read and write methods for the Java bean property
Throws:
BeanException - If the property is invalid or does not exist in the bean class given
Method Detail

initialize

protected void initialize()
                   throws BeanException
Initializes the bean property by finding the read and write methods and setting up the propertyType for this BeanProperty.
Overrides:
initialize in class BaseBeanProperty
Throws:
BeanException - If the bean class does not contain the property

getBeanClass

public Class getBeanClass()
Returns the bean class that the property is defined in
Overrides:
getBeanClass in class BaseBeanProperty

getReadMethod

public Method getReadMethod()
Returns the read method of the bean property

getWriteMethod

public Method getWriteMethod()
Returns the write method name of the bean property

getPropertyValue

public Object getPropertyValue(Object bean)
                        throws BeanException
Returns the value of the Java bean property for the given bean instance.
Overrides:
getPropertyValue in class BaseBeanProperty
Parameters:
bean - The instance of the Java bean to retrieve the property from
Throws:
BeanException - If there was an error getting the Java bean property or the getter/is method threw a checked Exception

setPropertyValue

public void setPropertyValue(Object bean,
                             Object value,
                             boolean convert)
                      throws BeanException,
                             TypeConversionException
Sets the value of the Java bean property to the given value
Overrides:
setPropertyValue in class BaseBeanProperty
Parameters:
bean - The instance of the Java bean to set the property on
value - The value to set the property to
convert - Determines whether or not value should be converted to the type that the setter requires or not
Throws:
BeanException - If there was an error setting the Java bean property or the setter method threw a checked Exception
TypeConversionException - If there was a problem auto-converting the property value