com.lonniepryor.blues.util
Class BeanHelper

java.lang.Object
  |
  +--com.lonniepryor.blues.util.BeanHelper
Direct Known Subclasses:
XmlBeanHelper

public class BeanHelper
extends java.lang.Object

Helper class that introspects and provides access to information about a JavaBean.

Version:
$Revision: 1.1 $
Author:
Lonnie Pryor

Constructor Summary
protected BeanHelper(java.lang.Class beanType)
          Creates a new BeanHelper object.
 
Method Summary
static void activateCache()
          Activates the thread-local helper cache (must always be followed by a call to deactivateCache()).
 boolean canWriteStringsTo(java.lang.String propertyName)
          Returns true if the bean helper can write strings to the specified property.
 boolean clearProperty(java.lang.Object instance, java.lang.String propertyName)
          Clears the value of the named property on the specified instance.
static void deactivateCache()
          Deactivates the thread-local helper cache (must always be preceeded by a call to activateCache()).
 boolean equals(java.lang.Object obj)
           
 java.lang.Class getBeanType()
          Returns the type of the bean.
 java.lang.Object getProperty(java.lang.Object instance, java.lang.String propertyName)
          Returns the value of the named property on the specified instance, or null if it is not found.
 java.lang.reflect.Method getPropertyAccessor(java.lang.String propertyName)
          Returns the accessor method for the named property, or null if one is not found.
 java.lang.reflect.Method getPropertyMutator(java.lang.String propertyName)
          Returns the mutator method for the named property, or null if one is not found.
 java.util.Set getPropertyNames()
          Returns the names of all of the properties the bean type exposes.
 java.lang.Class getPropertyType(java.lang.String propertyName)
          Returns the type of the named property, or null if one is not found.
 int hashCode()
           
static BeanHelper introspect(java.lang.Class beanType)
          Introspects the specified bean class, using the local cache if one is active.
static java.lang.Object invoke(java.lang.Object target, java.lang.reflect.Method method, java.lang.Object[] parameters)
          Invokes the specified method on the supplied object.
 java.lang.Object newBeanInstance()
          Creates a new instance of this helper's JavaBean class.
 boolean setProperty(java.lang.Object instance, java.lang.String propertyName, java.lang.Object propertyValue)
          Sets the value of the named property on the specified instance.
 boolean setPropertyAsString(java.lang.Object instance, java.lang.String propertyName, java.lang.String propertyValue)
          Sets the value of the named property on the specified instance as a string.
static java.lang.Object stringToValue(java.lang.Class valueType, java.lang.String string)
          Converts a string into a basic value type.
static java.lang.String toPropertyName(java.lang.reflect.Method method)
          Determines the name of the property implied by the supplied method.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeanHelper

protected BeanHelper(java.lang.Class beanType)
Creates a new BeanHelper object.

Parameters:
beanType - The class of the bean.
Method Detail

toPropertyName

public static java.lang.String toPropertyName(java.lang.reflect.Method method)
Determines the name of the property implied by the supplied method.

Parameters:
method - The method to determine a property name for.
Returns:
The name of the property implied by the supplied method.

introspect

public static BeanHelper introspect(java.lang.Class beanType)
Introspects the specified bean class, using the local cache if one is active.

Parameters:
beanType - The class of the bean.
Returns:
The helper instance for the specified class.

activateCache

public static void activateCache()
Activates the thread-local helper cache (must always be followed by a call to deactivateCache()).


deactivateCache

public static void deactivateCache()
Deactivates the thread-local helper cache (must always be preceeded by a call to activateCache()).


invoke

public static java.lang.Object invoke(java.lang.Object target,
                                      java.lang.reflect.Method method,
                                      java.lang.Object[] parameters)
Invokes the specified method on the supplied object.

Parameters:
target - The target to invoke on.
method - The method to invoke.
parameters - The parameters to pass.
Returns:
The return value of the method.

stringToValue

public static java.lang.Object stringToValue(java.lang.Class valueType,
                                             java.lang.String string)
Converts a string into a basic value type.

Parameters:
valueType - The value type to convert to.
string - The string to convert.
Returns:
The resulting instance of the value type representing the supplied string.

getBeanType

public java.lang.Class getBeanType()
Returns the type of the bean.

Returns:
The type of the bean.

getPropertyNames

public java.util.Set getPropertyNames()
Returns the names of all of the properties the bean type exposes.

Returns:
The names of all of the properties the bean type exposes.

getPropertyAccessor

public java.lang.reflect.Method getPropertyAccessor(java.lang.String propertyName)
Returns the accessor method for the named property, or null if one is not found.

Parameters:
propertyName - The name of the property.
Returns:
The accessor method for the named property, or null if one is not found.

getPropertyMutator

public java.lang.reflect.Method getPropertyMutator(java.lang.String propertyName)
Returns the mutator method for the named property, or null if one is not found.

Parameters:
propertyName - The name of the property.
Returns:
The mutator method for the named property, or null if one is not found.

getPropertyType

public java.lang.Class getPropertyType(java.lang.String propertyName)
Returns the type of the named property, or null if one is not found.

Parameters:
propertyName - The name of the property.
Returns:
The type of the named property, or null if one is not found.

canWriteStringsTo

public boolean canWriteStringsTo(java.lang.String propertyName)
Returns true if the bean helper can write strings to the specified property.

Parameters:
propertyName - The name of the property.
Returns:
True if the bean helper can write strings to the specified property.

newBeanInstance

public java.lang.Object newBeanInstance()
Creates a new instance of this helper's JavaBean class.

Returns:
A new bean instance.

getProperty

public java.lang.Object getProperty(java.lang.Object instance,
                                    java.lang.String propertyName)
Returns the value of the named property on the specified instance, or null if it is not found.

Parameters:
instance - The instance to return the property value from.
propertyName - The name of the property to return.
Returns:
The value of the property or null if it is not found.

setProperty

public boolean setProperty(java.lang.Object instance,
                           java.lang.String propertyName,
                           java.lang.Object propertyValue)
Sets the value of the named property on the specified instance.

Parameters:
instance - The instance to set the property value on.
propertyName - The name of the property to set.
propertyValue - The value to set the property to.
Returns:
True if the property was successfully set.

setPropertyAsString

public boolean setPropertyAsString(java.lang.Object instance,
                                   java.lang.String propertyName,
                                   java.lang.String propertyValue)
Sets the value of the named property on the specified instance as a string.

Parameters:
instance - The instance to set the property value on.
propertyName - The name of the property to set.
propertyValue - The string value to set the property to.
Returns:
True if the property was successfully set.

clearProperty

public boolean clearProperty(java.lang.Object instance,
                             java.lang.String propertyName)
Clears the value of the named property on the specified instance.

Parameters:
instance - The instance to clear the property value on.
propertyName - The name of the property to clear.
Returns:
True if the property was successfully cleared.

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


Copyright © 2003 Blues Framework. All Rights Reserved.