org.yajul.util
Class BeanProperties

java.lang.Object
  extended by org.yajul.util.BeanProperties

public class BeanProperties
extends java.lang.Object

Represents the property accessor methods for a given class, and provides methods for accessing the properties at run-time.

Author:
josh Apr 4, 2004 9:11:19 AM

Constructor Summary
BeanProperties(java.lang.Class c)
          Constructs a set of property accessors from the class.
 
Method Summary
 java.util.Iterator accessorMethods()
          Returns an iterator that returns all AccessorMethods for all properties in the class.
 void copy(java.lang.Object bean, java.lang.Object copy)
          Copies all of the properties from one bean into another.
 PropertyAccessors getAccessorMethods(java.lang.String propertyName)
          Returns the pair of accessor methods for the given property name.
 java.lang.String getClassName()
          Returns the name of the class.
 double getDoubleProperty(java.lang.Object bean, java.lang.String propertyName)
          Returns a double property value.
 int getIntProperty(java.lang.Object bean, java.lang.String propertyName)
          Returns an int property value.
 java.lang.Object getProperty(java.lang.Object bean, java.lang.String propertyName)
          Returns the value of the specified property.
 java.util.Set getPropertyNames()
          Returns the set of all the property name Strings in the class.
 java.util.Iterator propertyNames()
          Returns an iterator that returns the String names of all properties in the class.
 java.lang.Object setProperty(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value)
          Sets the property in the bean to the specified value.
 int size()
          Returns the number of properties in the class.
 java.util.Collection<java.lang.Object> values(java.lang.Object bean)
          Returns a collection of all of the property values in the specified bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanProperties

public BeanProperties(java.lang.Class c)
Constructs a set of property accessors from the class.

Parameters:
c - the class
Method Detail

getClassName

public java.lang.String getClassName()
Returns the name of the class.

Returns:
the name of the class.

size

public int size()
Returns the number of properties in the class.

Returns:
the number of properties in the class.

getProperty

public java.lang.Object getProperty(java.lang.Object bean,
                                    java.lang.String propertyName)
Returns the value of the specified property.

Parameters:
bean - the object
propertyName - the name of the property to get
Returns:
the value of the property in the specified bean

setProperty

public java.lang.Object setProperty(java.lang.Object bean,
                                    java.lang.String propertyName,
                                    java.lang.Object value)
Sets the property in the bean to the specified value.

Parameters:
bean - the object to set the property in
propertyName - the name of the property
value - the new property value
Returns:
the new property value

propertyNames

public java.util.Iterator propertyNames()
Returns an iterator that returns the String names of all properties in the class.

Returns:
an iterator that returns the String names of all properties in the class.

getPropertyNames

public java.util.Set getPropertyNames()
Returns the set of all the property name Strings in the class.

Returns:
the set of all the property name Strings in the class.

getAccessorMethods

public PropertyAccessors getAccessorMethods(java.lang.String propertyName)
Returns the pair of accessor methods for the given property name.

Parameters:
propertyName - the property name.
Returns:
the accessor methods for the property

accessorMethods

public java.util.Iterator accessorMethods()
Returns an iterator that returns all AccessorMethods for all properties in the class.

Returns:
an iterator that returns all AccessorMethods for all properties in the class.

getDoubleProperty

public double getDoubleProperty(java.lang.Object bean,
                                java.lang.String propertyName)
Returns a double property value.

Parameters:
bean - the bean
propertyName - the property name
Returns:
the property value as a double

getIntProperty

public int getIntProperty(java.lang.Object bean,
                          java.lang.String propertyName)
Returns an int property value.

Parameters:
bean - the bean
propertyName - the property name
Returns:
the int property value

values

public java.util.Collection<java.lang.Object> values(java.lang.Object bean)
                                              throws java.lang.Exception
Returns a collection of all of the property values in the specified bean.

Parameters:
bean - the bean
Returns:
a collection of all of the property values in the specified bean
Throws:
java.lang.Exception - if a property cannot be accessed.

copy

public void copy(java.lang.Object bean,
                 java.lang.Object copy)
          throws java.lang.Exception
Copies all of the properties from one bean into another. The two beans must be of the same class.

Parameters:
bean - the source bean.
copy - the target bean.
Throws:
java.lang.Exception - if a property could not be accessed.


Copyright © 2008. All Rights Reserved.