com.ibatis.common.beans
Class BeanProbe

java.lang.Object
  extended bycom.ibatis.common.beans.BeanProbe

public class BeanProbe
extends java.lang.Object

BeanProbe is an instantiatable wrapper for any JavaBeans compliant object that allows simple reflective access to bean properties. All methods forward to equivalent methods in StaticBeanProbe. In some cases it may be easier to use this wrapper class instead of having to constantly pass the object references to the property accessor methods of StaticBeanProbe.

Examples:

BeanProbe probe = new BeanProbe(object);

probe.setObject(propertyName, value);

Object value = probe.getObject(propertyName);

Author:
clinton_begin

Field Summary
private  java.lang.Object object
           
 
Constructor Summary
BeanProbe(java.lang.Object obj)
          Creates new BeanProbe to wrap a bean
 
Method Summary
 boolean beanEquals(java.lang.Object object2)
          Compares a bean to the wrapped bean to see if it is equal - all properties are equal.
 boolean beanEquals(java.lang.Object object2, java.lang.String[] properties)
          Compares a bean to the wrapped bean to see if it is equal enough - the list of named properties are equal.
 int beanHashCode()
          Calculates a hash code for all readable properties of the bean
 int beanHashCode(java.lang.String[] properties)
          Calculates a hash code for a subset of the readable properties of a bean
 boolean equals(java.lang.Object obj)
          Compares the beans to another
 boolean getBoolean(java.lang.String name)
          Gets a boolean property
 byte getByte(java.lang.String name)
          Gets a byte property
 char getCharacter(java.lang.String name)
          Gets a char property
 java.util.Date getDate(java.lang.String name)
          Gets a Date property
 double getDouble(java.lang.String name)
          Gets a double property
 java.lang.Object getField(java.lang.String name)
          Get an Object value from a field (property)
 float getFloat(java.lang.String name)
          Gets a float property
 int getInteger(java.lang.String name)
          Gets an Integer property
 long getLong(java.lang.String name)
          Gets a long property
 java.lang.Object getObject(java.lang.String name)
          Gets an Object property
 java.lang.Class getPropertyTypeForGetter(java.lang.String name)
          Gets the type of a property based on the getter
 java.lang.Class getPropertyTypeForSetter(java.lang.String name)
          Gets the type of a property based on the setter
 java.lang.String[] getReadablePropertyNames()
          Returns an array of the names of the readable properties for the bean
 short getShort(java.lang.String name)
          Gets a short property
 java.lang.String getString(java.lang.String name)
          Gets a String property
 java.lang.String[] getWriteablePropertyNames()
          Returns an array of the names of the writeable properties for the bean
 int hashCode()
          Generates a hashcode for the bean
 boolean hasReadableProperty(java.lang.String propertyName)
          Checks to see if a bean has a readable property by name
 boolean hasWritableProperty(java.lang.String propertyName)
          Checks to see if a bean has a writeable property by name
 void setBoolean(java.lang.String name, boolean value)
          Sets a boolean property
 void setByte(java.lang.String name, byte value)
          Sets a byte property
 void setCharacter(java.lang.String name, char value)
          Sets a char property
 void setDate(java.lang.String name, java.util.Date value)
          Sets a Date property
 void setDouble(java.lang.String name, double value)
          Sets a double property
 void setField(java.lang.String name, java.lang.Object value)
          Set a field (property) to an Object value
 void setFloat(java.lang.String name, float value)
          Sets a float property
 void setInteger(java.lang.String name, int value)
          Sets an Integer property
 void setLong(java.lang.String name, long value)
          Sets a long property
 void setObject(java.lang.String name, java.lang.Object value)
          Sets an Object property
 void setShort(java.lang.String name, short value)
          Sets a short property
 void setString(java.lang.String name, java.lang.String value)
          Sets a String property
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

object

private java.lang.Object object
Constructor Detail

BeanProbe

public BeanProbe(java.lang.Object obj)
Creates new BeanProbe to wrap a bean

Parameters:
obj - The bean to wrap
Method Detail

setField

public void setField(java.lang.String name,
                     java.lang.Object value)
Set a field (property) to an Object value

Parameters:
name - Property name
value - New value

getField

public java.lang.Object getField(java.lang.String name)
Get an Object value from a field (property)

Parameters:
name - Property name
Returns:
The value of the property

getReadablePropertyNames

public java.lang.String[] getReadablePropertyNames()
Returns an array of the names of the readable properties for the bean

Returns:
The names

getWriteablePropertyNames

public java.lang.String[] getWriteablePropertyNames()
Returns an array of the names of the writeable properties for the bean

Returns:
The names

beanEquals

public boolean beanEquals(java.lang.Object object2)
Compares a bean to the wrapped bean to see if it is equal - all properties are equal.

Parameters:
object2 - The bean to compare
Returns:
True if the beans are the same

beanEquals

public boolean beanEquals(java.lang.Object object2,
                          java.lang.String[] properties)
Compares a bean to the wrapped bean to see if it is equal enough - the list of named properties are equal.

Parameters:
object2 - The bean to compare
properties - The properties to test
Returns:
True if the properties listed are all equal

beanHashCode

public int beanHashCode()
Calculates a hash code for all readable properties of the bean

Returns:
The hashcode

beanHashCode

public int beanHashCode(java.lang.String[] properties)
Calculates a hash code for a subset of the readable properties of a bean

Parameters:
properties - A list of the properties to hash
Returns:
The hashcode

getPropertyTypeForSetter

public java.lang.Class getPropertyTypeForSetter(java.lang.String name)
Gets the type of a property based on the setter

Parameters:
name - Property name
Returns:
The property type

getPropertyTypeForGetter

public java.lang.Class getPropertyTypeForGetter(java.lang.String name)
Gets the type of a property based on the getter

Parameters:
name - Property name
Returns:
The property type

getObject

public java.lang.Object getObject(java.lang.String name)
Gets an Object property

Parameters:
name - Property name
Returns:
The value of the property

setObject

public void setObject(java.lang.String name,
                      java.lang.Object value)
Sets an Object property

Parameters:
name - Property name
value - New value

getString

public java.lang.String getString(java.lang.String name)
Gets a String property

Parameters:
name - Property name
Returns:
The value of the property

setString

public void setString(java.lang.String name,
                      java.lang.String value)
Sets a String property

Parameters:
name - Property name
value - New value

getInteger

public int getInteger(java.lang.String name)
Gets an Integer property

Parameters:
name - Property name
Returns:
The value of the property

setInteger

public void setInteger(java.lang.String name,
                       int value)
Sets an Integer property

Parameters:
name - Property name
value - New value

getLong

public long getLong(java.lang.String name)
Gets a long property

Parameters:
name - Property name
Returns:
The value of the property

setLong

public void setLong(java.lang.String name,
                    long value)
Sets a long property

Parameters:
name - Property name
value - New value

getShort

public short getShort(java.lang.String name)
Gets a short property

Parameters:
name - Property name
Returns:
The value of the property

setShort

public void setShort(java.lang.String name,
                     short value)
Sets a short property

Parameters:
name - Property name
value - New value

getByte

public byte getByte(java.lang.String name)
Gets a byte property

Parameters:
name - Property name
Returns:
The value of the property

setByte

public void setByte(java.lang.String name,
                    byte value)
Sets a byte property

Parameters:
name - Property name
value - New value

getCharacter

public char getCharacter(java.lang.String name)
Gets a char property

Parameters:
name - Property name
Returns:
The value of the property

setCharacter

public void setCharacter(java.lang.String name,
                         char value)
Sets a char property

Parameters:
name - Property name
value - New value

getDouble

public double getDouble(java.lang.String name)
Gets a double property

Parameters:
name - Property name
Returns:
The value of the property

setDouble

public void setDouble(java.lang.String name,
                      double value)
Sets a double property

Parameters:
name - Property name
value - New value

getFloat

public float getFloat(java.lang.String name)
Gets a float property

Parameters:
name - Property name
Returns:
The value of the property

setFloat

public void setFloat(java.lang.String name,
                     float value)
Sets a float property

Parameters:
name - Property name
value - New value

getBoolean

public boolean getBoolean(java.lang.String name)
Gets a boolean property

Parameters:
name - Property name
Returns:
The value of the property

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
Sets a boolean property

Parameters:
name - Property name
value - New value

getDate

public java.util.Date getDate(java.lang.String name)
Gets a Date property

Parameters:
name - Property name
Returns:
The value of the property

setDate

public void setDate(java.lang.String name,
                    java.util.Date value)
Sets a Date property

Parameters:
name - Property name
value - New value

hasWritableProperty

public boolean hasWritableProperty(java.lang.String propertyName)
Checks to see if a bean has a writeable property by name

Parameters:
propertyName - The property to look for
Returns:
True if the bean has a writeable property with the name in propertyName

hasReadableProperty

public boolean hasReadableProperty(java.lang.String propertyName)
Checks to see if a bean has a readable property by name

Parameters:
propertyName - The property to look for
Returns:
True if the bean has a readable property with the name in propertyName

hashCode

public int hashCode()
Generates a hashcode for the bean

Returns:
The hash code

equals

public boolean equals(java.lang.Object obj)
Compares the beans to another

Parameters:
obj - The bean to compare
Returns:
True if the beans are the same