jfun.util.beans
Class Bean

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

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

A wrapper class for Java Bean object.

Zephyr Business Solutions Corp.

Author:
Ben Yu
See Also:
Serialized Form

Method Summary
 boolean equals(java.lang.Object obj)
           
 BeanType getBeanType()
          Get the BeanType object for this object.
 java.lang.Object getObject()
          Get the Java bean object.
 java.lang.Object getProperty(java.lang.String name)
          Get value for a property.
 java.lang.Object getProperty(java.lang.String name, int ind)
          Get value for an indexed property.
 int hashCode()
           
static Bean instance(BeanType btype, java.lang.Object obj)
          Create a Bean object for a Java object.
static Bean instance(java.lang.Class type, java.lang.Object obj)
          Create a Bean object for a Java object.
static Bean instance(java.lang.Object obj)
          Create a Bean object for a Java object.
 Bean setProperty(java.lang.String name, int ind, java.lang.Object val)
          Set value for an indexed property.
 Bean setProperty(java.lang.String name, java.lang.Object val)
          Set value for a property.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getObject

public java.lang.Object getObject()
Get the Java bean object.

Returns:
the object.

getBeanType

public BeanType getBeanType()
Get the BeanType object for this object.

Returns:
the BeanType object.

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws NoSuchPropertyException,
                                    PropertyNotReadableException,
                                    java.lang.reflect.InvocationTargetException,
                                    java.lang.IllegalAccessException
Get value for a property.

Parameters:
name - the property name.
Returns:
the property value.
Throws:
NoSuchPropertyException - when the property is not found.
PropertyNotReadableException - when the property cannot be read.
java.lang.reflect.InvocationTargetException - any exception caused by the getter method.
java.lang.IllegalAccessException - if access to the getter method failed.

setProperty

public Bean setProperty(java.lang.String name,
                        java.lang.Object val)
                 throws NoSuchPropertyException,
                        PropertyNotWritableException,
                        java.lang.reflect.InvocationTargetException,
                        java.lang.IllegalAccessException
Set value for a property.

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:
name - the property name.
val - the new value of the property.
Returns:
this Bean object.
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.

getProperty

public java.lang.Object getProperty(java.lang.String name,
                                    int ind)
                             throws NoSuchPropertyException,
                                    PropertyNotReadableException,
                                    java.lang.reflect.InvocationTargetException
Get value for an indexed property.

Parameters:
name - the property name.
ind - the index.
Returns:
the property value.
Throws:
NoSuchPropertyException - when the property is not found.
PropertyNotReadableException - when the property cannot be read.
java.lang.Throwable - any exception caused by the getter method.
java.lang.reflect.InvocationTargetException

setProperty

public Bean setProperty(java.lang.String name,
                        int ind,
                        java.lang.Object val)
                 throws NoSuchPropertyException,
                        PropertyNotWritableException,
                        java.lang.reflect.InvocationTargetException
Set value for an indexed property.

Parameters:
name - the property name.
ind - the index.
val - the new value of the property.
Returns:
this Bean object.
Throws:
NoSuchPropertyException - when the property cannot be found.
PropertyNotWritableException - when the property is not writable.
java.lang.Throwable - any exception caused by the setter method.
java.lang.reflect.InvocationTargetException

instance

public static Bean instance(java.lang.Object obj)
                     throws java.beans.IntrospectionException
Create a Bean object for a Java object.

Parameters:
obj - the object.
Returns:
the Bean object.
Throws:
java.Beans.IntrospectionException
java.beans.IntrospectionException

instance

public static Bean instance(java.lang.Class type,
                            java.lang.Object obj)
                     throws java.beans.IntrospectionException
Create a Bean object for a Java object.

Parameters:
type - the type used to introspect properties.
obj - the object.
Returns:
the Bean object.
Throws:
java.Beans.IntrospectionException
java.beans.IntrospectionException

instance

public static Bean instance(BeanType btype,
                            java.lang.Object obj)
Create a Bean object for a Java object.

Parameters:
btype - the bean type containing the meta information for all properties.
obj - the object.
Returns:
the Bean object.

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