webwork.util
Class BeanUtil

java.lang.Object
  extended bywebwork.util.BeanUtil

public final class BeanUtil
extends java.lang.Object

JavaBean utility methods

Version:
$Revision: 1.39 $
Author:
Rickard Öberg (rickard@middleware-company.com), Matt Baldree (matt@smallleap.com)

Constructor Summary
BeanUtil()
           
 
Method Summary
protected static java.util.Map buildFieldMap(java.lang.Class objClass)
          Build field map for a class.
static void copy(java.lang.Object from, java.lang.Object to)
          Copy JavaBean property values from one object to another.
static void copy(java.lang.Object from, java.lang.Object to, boolean includeNull)
          Copy JavaBean property values from one object to another.
static java.lang.Object getAsValue(java.beans.PropertyEditor pe, java.lang.String txt)
          Helper method that gets the value using a PropertyEditor If the editor is a FastPropertyEditor then getAsValue is called otherwise normal setAsText, getValue calls are made
protected static java.util.Map getFieldMapForClass(java.lang.Class objClass)
          Get the field map for a class.
protected static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String property, java.lang.Object obj)
          Get a property descriptor for a given field on an object
protected static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class objClass)
          Get property descriptors for a class.
static java.beans.PropertyEditor getPropertyEditor(java.lang.Class clazz)
          Helper method to retrieve a property editor out of cache.
protected static java.beans.PropertyEditor getPropertyEditor(java.beans.PropertyDescriptor descriptor)
          get The property Editor for the propertyDescriptor.
protected static boolean setIndexedStringValueDirectly(java.lang.Object obj, java.beans.IndexedPropertyDescriptor descriptor, java.lang.String[] values, java.lang.Integer index)
          Set a indexed field with a String value directly.
protected static void setIndexedStringValueWithPropertyEditor(java.lang.Object obj, java.beans.IndexedPropertyDescriptor descriptor, java.lang.String[] values, java.lang.Integer index)
          Set a indexed field with a String value directly using the Property Editor.
protected static boolean setIndexedValue(java.lang.Object obj, java.beans.IndexedPropertyDescriptor descriptor, java.lang.Object val, java.lang.Integer index)
          Set an indexed field.
static void setProperties(java.util.Map from, java.lang.Object to)
          Set JavaBean property values on an object with values taken from a map.
static void setProperty(java.lang.String propertyName, java.lang.Object val, java.lang.Object obj)
          Set a single JavaBean property value on an object.
protected static void setProperty(java.lang.String propertyName, java.lang.Object val, java.lang.Object obj, java.util.Map fieldMap)
          Set a single JavaBean property value on an object.
protected static boolean setStringValueDirectly(java.lang.Object obj, java.beans.PropertyDescriptor descriptor, java.lang.String[] values)
          Set a non-indexed field with a String value directly.
protected static void setStringValueWithPropertyEditor(java.lang.Object obj, java.beans.PropertyDescriptor descriptor, java.lang.String[] values, java.lang.Class paramClass)
          Set a non-indexed field with a String value directly using the Property Editor.
protected static boolean setValue(java.lang.Object obj, java.beans.PropertyDescriptor descriptor, java.lang.Object val)
          Set a non-indexed field.
static java.lang.String toStringValue(java.lang.Object obj)
          Call toString on object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtil

public BeanUtil()
Method Detail

copy

public static void copy(java.lang.Object from,
                        java.lang.Object to)
                 throws java.lang.IllegalArgumentException
Copy JavaBean property values from one object to another.

Parameters:
from - the source object
to - the destination object
Throws:
java.lang.IllegalArgumentException - thrown if the copy fails for some reason

copy

public static void copy(java.lang.Object from,
                        java.lang.Object to,
                        boolean includeNull)
                 throws java.lang.IllegalArgumentException
Copy JavaBean property values from one object to another.

Parameters:
from - the source object
to - the destination object
includeNull - whether null values are copied or not
Throws:
java.lang.IllegalArgumentException - thrown if the copy fails for some reason

setProperties

public static void setProperties(java.util.Map from,
                                 java.lang.Object to)
                          throws java.lang.IllegalArgumentException
Set JavaBean property values on an object with values taken from a map. If the values in the map are of type String or String[] they may be converted to the actual property type by the use of property editors.

Parameters:
from - map of values
to - the destination object
Throws:
java.lang.IllegalArgumentException

setProperty

public static void setProperty(java.lang.String propertyName,
                               java.lang.Object val,
                               java.lang.Object obj)
                        throws java.lang.IllegalArgumentException
Set a single JavaBean property value on an object. If the values in the map are of type String or String[] they may be converted to the actual property type by the use of property editors.

Parameters:
propertyName - String representing the property or subproperty
val - the value to set
obj - the object to set the property on.
Throws:
java.lang.IllegalArgumentException

setProperty

protected static void setProperty(java.lang.String propertyName,
                                  java.lang.Object val,
                                  java.lang.Object obj,
                                  java.util.Map fieldMap)
                           throws java.lang.IllegalArgumentException
Set a single JavaBean property value on an object. If the values in the map are of type String or String[] they may be converted to the actual property type by the use of property editors.

Parameters:
propertyName - String representing the property or subproperty
val - the value to set
obj - the object to set the property on.
fieldMap - Map with the PropertyDescriptors of the obj
Throws:
java.lang.IllegalArgumentException

getPropertyEditor

public static java.beans.PropertyEditor getPropertyEditor(java.lang.Class clazz)
Helper method to retrieve a property editor out of cache.


getAsValue

public static java.lang.Object getAsValue(java.beans.PropertyEditor pe,
                                          java.lang.String txt)
Helper method that gets the value using a PropertyEditor If the editor is a FastPropertyEditor then getAsValue is called otherwise normal setAsText, getValue calls are made


toStringValue

public static java.lang.String toStringValue(java.lang.Object obj)
Call toString on object. If object has an associated ValidationEditorSupport property editor then its getAsText will be called. This allows you to associate a common toString algorithm to call types. Objects of class String are however only returned


setValue

protected static boolean setValue(java.lang.Object obj,
                                  java.beans.PropertyDescriptor descriptor,
                                  java.lang.Object val)
                           throws java.lang.IllegalArgumentException
Set a non-indexed field. Will delegate the actuall setting of the field to one of three methods. Sections were taken from BeanUtil.setProprty (rev.1.4)

Parameters:
obj - the object to set the property on.
descriptor - the PropertyDescriptor representing the property to set
val - the value to set
Throws:
java.lang.IllegalArgumentException

setIndexedValue

protected static boolean setIndexedValue(java.lang.Object obj,
                                         java.beans.IndexedPropertyDescriptor descriptor,
                                         java.lang.Object val,
                                         java.lang.Integer index)
Set an indexed field. Will delegate the actual setting of the field to one of three methods. Sections were taken from BeanUtil.setProprty (rev.1.4)

Parameters:
obj - the object to set the property on.
descriptor - the PropertyDescriptor representing the property to set
val - the value to set
index - the index to set it at
Throws:
java.lang.IllegalArgumentException

setStringValueDirectly

protected static boolean setStringValueDirectly(java.lang.Object obj,
                                                java.beans.PropertyDescriptor descriptor,
                                                java.lang.String[] values)
                                         throws java.lang.IllegalArgumentException
Set a non-indexed field with a String value directly.

Parameters:
obj - the object we are trying to set it on
descriptor - PropertyDescriptor representing the firled we want to set
values - the String array we are setting
Throws:
java.lang.IllegalArgumentException

setStringValueWithPropertyEditor

protected static void setStringValueWithPropertyEditor(java.lang.Object obj,
                                                       java.beans.PropertyDescriptor descriptor,
                                                       java.lang.String[] values,
                                                       java.lang.Class paramClass)
                                                throws java.lang.IllegalArgumentException
Set a non-indexed field with a String value directly using the Property Editor.

Parameters:
obj - the object we are trying to set it on
descriptor - PropertyDescriptor representing the firled we want to set
values - the String array we are setting
paramClass - The parameter class used in the write method. Passed in for efficiency.
Throws:
java.lang.IllegalArgumentException

setIndexedStringValueWithPropertyEditor

protected static void setIndexedStringValueWithPropertyEditor(java.lang.Object obj,
                                                              java.beans.IndexedPropertyDescriptor descriptor,
                                                              java.lang.String[] values,
                                                              java.lang.Integer index)
                                                       throws java.lang.IllegalArgumentException
Set a indexed field with a String value directly using the Property Editor.

Parameters:
obj - the object we are trying to set it on
descriptor - PropertyDescriptor representing the firled we want to set
values - the String array we are setting
index - the index that we want to set
Throws:
java.lang.IllegalArgumentException

setIndexedStringValueDirectly

protected static boolean setIndexedStringValueDirectly(java.lang.Object obj,
                                                       java.beans.IndexedPropertyDescriptor descriptor,
                                                       java.lang.String[] values,
                                                       java.lang.Integer index)
                                                throws java.lang.IllegalArgumentException
Set a indexed field with a String value directly.

Parameters:
obj - the object we are trying to set it on
descriptor - PropertyDescriptor representing the firled we want to set
values - the String array we are setting
index - the index that we want to set
Throws:
java.lang.IllegalArgumentException

getPropertyDescriptor

protected static java.beans.PropertyDescriptor getPropertyDescriptor(java.lang.String property,
                                                                     java.lang.Object obj)
Get a property descriptor for a given field on an object

Parameters:
property - the property that we are interested in
obj - the object we want the property descriptor for

getFieldMapForClass

protected static java.util.Map getFieldMapForClass(java.lang.Class objClass)
Get the field map for a class. The map is used by getPropertyDescriptor. If it does not exist for the class it will call buildFieldMap

Parameters:
objClass - the object we want to build the field map for

buildFieldMap

protected static java.util.Map buildFieldMap(java.lang.Class objClass)
Build field map for a class.

Parameters:
objClass - the object we want to build the field map for
Returns:
a Map with the keys being property names and values being PropertyDescriptors

getPropertyEditor

protected static java.beans.PropertyEditor getPropertyEditor(java.beans.PropertyDescriptor descriptor)
get The property Editor for the propertyDescriptor. Handles both Indexed and non_indexed properties

Parameters:
descriptor - PropertyDescriptor
Returns:
the PropertyEditor

getPropertyDescriptors

protected static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Class objClass)
Get property descriptors for a class. Only return descriptors for properties that are not a property of java.lang.Object based on webwork (0.95) Dispatcher Code

Parameters:
objClass -
Returns:
array of property descriptors


Copyright © 2001-2003 WebWork All Rights Reserved.