jfun.util.beans
Class BeanType

java.lang.Object
  extended by jfun.util.beans.BeanType
All Implemented Interfaces:
java.io.Serializable

public final class BeanType
extends java.lang.Object
implements java.io.Serializable

Represents all the meta-information of a Java bean.

Zephyr Business Solutions Corp.

Author:
Ben Yu
See Also:
Serialized Form

Method Summary
 boolean equals(java.lang.Object obj)
           
 java.lang.Class getIndexedPropertyType(java.lang.String name)
          Get the type of an indexed property.
 java.lang.reflect.Method getIndexedReader(java.lang.String name)
          Get the reader method for an indexed property.
 java.lang.reflect.Method getIndexedWriter(java.lang.String name)
          Get the writer method for an indexed property.
 java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String name)
          Get the PropertyDescriptor for a given property.
 java.util.Set getPropertyNames()
          Get the property names of this bean type.
 java.lang.reflect.Method getPropertySetter(java.lang.String name)
          Get the setter method for a property.
static java.lang.Class getPropertySetterType(java.beans.PropertyDescriptor desc)
          Get the type of a property.
 java.lang.Class getPropertySetterType(java.lang.String name)
          Get the type of the property.
 java.lang.Class getPropertyType(java.lang.String name)
          Get the type of a property.
 java.lang.reflect.Method getReader(java.lang.String name)
          Get the reader method of a property.
 java.lang.Class getType()
          Get the type of this java bean.
 java.lang.reflect.Method getWriter(java.lang.String name)
          Get the writer method of a property.
 int hashCode()
           
static BeanType instance(java.lang.Class type)
          Get a BeanType object.
 void setProperty(java.lang.Object bean, java.lang.String name, java.lang.Object val)
          Set value for a property of a bean of this type.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getType

public java.lang.Class getType()
Get the type of this java bean.

Returns:
the Class object representing the type.

getPropertyNames

public java.util.Set getPropertyNames()
Get the property names of this bean type.

Returns:
the set of all the property names.

instance

public static BeanType instance(java.lang.Class type)
                         throws java.beans.IntrospectionException
Get a BeanType object.

Parameters:
type - the type of the java bean.
Returns:
the BeanType instance.
Throws:
java.Beans.IntrospectionException
java.beans.IntrospectionException

getPropertyDescriptor

public java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String name)
Get the PropertyDescriptor for a given property.

Parameters:
name - the property name.
Returns:
The PropertyDescriptor object, null if the property is not found.

getPropertyType

public java.lang.Class getPropertyType(java.lang.String name)
                                throws NoSuchPropertyException
Get the type of a property.

Parameters:
name - the name of the property.
Returns:
the type of the property.
Throws:
NoSuchPropertyException - when the property cannot be found.

getPropertySetterType

public java.lang.Class getPropertySetterType(java.lang.String name)
Get the type of the property. If the property is indexed, the array type of the property type is returned.

Parameters:
name - the property name.
Returns:
the type.

getPropertySetter

public java.lang.reflect.Method getPropertySetter(java.lang.String name)
Get the setter method for a property. If a non-indexed version is not available, return the indexed version.

Parameters:
name - the property name.
Returns:
the Method object.

getPropertySetterType

public static java.lang.Class getPropertySetterType(java.beans.PropertyDescriptor desc)
Get the type of a property. If the property is indexed, the array type of the property type is returned.

Parameters:
desc - the descriptor for the property.
Returns:
the type.

getIndexedPropertyType

public java.lang.Class getIndexedPropertyType(java.lang.String name)
                                       throws NoSuchPropertyException
Get the type of an indexed property.

Parameters:
name - the name of the property.
Returns:
the type of the property.
Throws:
NoSuchPropertyException - when the property cannot be found.

getWriter

public java.lang.reflect.Method getWriter(java.lang.String name)
                                   throws NoSuchPropertyException
Get the writer method of a property.

Parameters:
name - the property name.
Returns:
the writer method. null if the method is not writable.
Throws:
NoSuchPropertyException - when the property cannot be found.

getReader

public java.lang.reflect.Method getReader(java.lang.String name)
                                   throws NoSuchPropertyException
Get the reader method of a property.

Parameters:
name - the property name.
Returns:
the reader method. null if the method is not readable.
Throws:
NoSuchPropertyException - when the property cannot be found.

getIndexedWriter

public java.lang.reflect.Method getIndexedWriter(java.lang.String name)
                                          throws NoSuchPropertyException
Get the writer method for an indexed property.

Parameters:
name - the property name.
Returns:
the writer method. null if the method is not writable or not indexed.
Throws:
NoSuchPropertyException - when the property cannot be found.

getIndexedReader

public java.lang.reflect.Method getIndexedReader(java.lang.String name)
                                          throws NoSuchPropertyException
Get the reader method for an indexed property.

Parameters:
name - the property name.
Returns:
the reader method. null if the method is not readable or not indexed.
Throws:
NoSuchPropertyException - when the property cannot be found.

setProperty

public void setProperty(java.lang.Object bean,
                        java.lang.String name,
                        java.lang.Object val)
                 throws NoSuchPropertyException,
                        PropertyNotWritableException,
                        java.lang.reflect.InvocationTargetException,
                        java.lang.IllegalAccessException
Set value for a property of a bean of this type.

This method also handles properties accessed by index. When the property requires an index, the value has to be an array or null, where null is equivalent to an empty array. *

The array elements are then set to the property by index from 0 up.

Parameters:
bean - the bean object.
name - the property name.
val - the new value of the property.
Throws:
NoSuchPropertyException - when the property cannot be found.
PropertyNotWritableException - when the property is not writable.
java.lang.reflect.InvocationTargetException - any exception caused by the setter method.
java.lang.IllegalAccessException - if access to the setter method failed.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object