org.apache.struts.util
Class BeanUtils

java.lang.Object
  |
  +--org.apache.struts.util.BeanUtils

Deprecated. At some point after Struts 1.0 final, will be replaced by an equivalent class in the Jakarta Commons Beanutils package.

public class BeanUtils
extends java.lang.Object

Utility methods for populating JavaBeans properties via reflection.

Version:
$Revision: 1.1 $ $Date$
Author:
Craig R. McClanahan, Ralph Schaer, Chris Audley

Field Summary
private static int debug
          Deprecated. The debugging detail level for this component.
 
Constructor Summary
BeanUtils()
          Deprecated.  
 
Method Summary
static java.lang.Object cloneBean(java.lang.Object bean)
          Deprecated. Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.
static java.util.Map describe(java.lang.Object bean)
          Deprecated. Return the entire set of properties for which the specified bean provides a read method.
static java.lang.String[] getArrayProperty(java.lang.Object bean, java.lang.String name)
          Deprecated. Return the value of the specified array property of the specified bean, as a String array.
static int getDebug()
          Deprecated.  
static java.lang.String getIndexedProperty(java.lang.Object bean, java.lang.String name)
          Deprecated. Return the value of the specified indexed property of the specified bean, as a String.
static java.lang.String getIndexedProperty(java.lang.Object bean, java.lang.String name, int index)
          Deprecated. Return the value of the specified indexed property of the specified bean, as a String.
static java.lang.String getNestedProperty(java.lang.Object bean, java.lang.String name)
          Deprecated. Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
static java.lang.String getProperty(java.lang.Object bean, java.lang.String name)
          Deprecated. Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
static java.lang.String getSimpleProperty(java.lang.Object bean, java.lang.String name)
          Deprecated. Return the value of the specified simple property of the specified bean, converted to a String.
static void populate(java.lang.Object bean, java.util.Map properties)
          Deprecated. Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.
static void setDebug(int newDebug)
          Deprecated.  
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

debug

private static int debug
Deprecated. 
The debugging detail level for this component.
Constructor Detail

BeanUtils

public BeanUtils()
Deprecated. 
Method Detail

getDebug

public static int getDebug()
Deprecated. 

setDebug

public static void setDebug(int newDebug)
Deprecated. 

cloneBean

public static java.lang.Object cloneBean(java.lang.Object bean)
                                  throws java.lang.IllegalAccessException,
                                         java.lang.InstantiationException,
                                         java.lang.reflect.InvocationTargetException,
                                         java.lang.NoSuchMethodException
Deprecated. 
Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.
Parameters:
bean - Bean to be cloned
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.InstantiationException - if a new instance of the bean's class cannot be instantiated
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

describe

public static java.util.Map describe(java.lang.Object bean)
                              throws java.lang.IllegalAccessException,
                                     java.lang.reflect.InvocationTargetException,
                                     java.lang.NoSuchMethodException
Deprecated. 
Return the entire set of properties for which the specified bean provides a read method. This map can be fed back to a call to BeanUtils.populate() to reconsitute the same set of properties, modulo differences for read-only and write-only properties.
Parameters:
bean - Bean whose properties are to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getArrayProperty

public static java.lang.String[] getArrayProperty(java.lang.Object bean,
                                                  java.lang.String name)
                                           throws java.lang.IllegalAccessException,
                                                  java.lang.reflect.InvocationTargetException,
                                                  java.lang.NoSuchMethodException
Deprecated. 
Return the value of the specified array property of the specified bean, as a String array.
Parameters:
bean - Bean whose property is to be extracted
name - Name of the property to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getIndexedProperty

public static java.lang.String getIndexedProperty(java.lang.Object bean,
                                                  java.lang.String name)
                                           throws java.lang.IllegalAccessException,
                                                  java.lang.reflect.InvocationTargetException,
                                                  java.lang.NoSuchMethodException
Deprecated. 
Return the value of the specified indexed property of the specified bean, as a String. The zero-relative index of the required value must be included (in square brackets) as a suffix to the property name, or IllegalArgumentException will be thrown.
Parameters:
bean - Bean whose property is to be extracted
name - propertyname[index] of the property value to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getIndexedProperty

public static java.lang.String getIndexedProperty(java.lang.Object bean,
                                                  java.lang.String name,
                                                  int index)
                                           throws java.lang.IllegalAccessException,
                                                  java.lang.reflect.InvocationTargetException,
                                                  java.lang.NoSuchMethodException
Deprecated. 
Return the value of the specified indexed property of the specified bean, as a String. The index is specified as a method parameter and must *not* be included in the property name expression
Parameters:
bean - Bean whose property is to be extracted
name - Simple property name of the property value to be extracted
index - Index of the property value to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getNestedProperty

public static java.lang.String getNestedProperty(java.lang.Object bean,
                                                 java.lang.String name)
                                          throws java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException,
                                                 java.lang.NoSuchMethodException
Deprecated. 
Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
Parameters:
bean - Bean whose property is to be extracted
name - Possibly nested name of the property to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.IllegalArgumentException - if a nested reference to a property returns null
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getProperty

public static java.lang.String getProperty(java.lang.Object bean,
                                           java.lang.String name)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException,
                                           java.lang.NoSuchMethodException
Deprecated. 
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

getSimpleProperty

public static java.lang.String getSimpleProperty(java.lang.Object bean,
                                                 java.lang.String name)
                                          throws java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException,
                                                 java.lang.NoSuchMethodException
Deprecated. 
Return the value of the specified simple property of the specified bean, converted to a String.
Parameters:
bean - Bean whose property is to be extracted
name - Name of the property to be extracted
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception
java.lang.NoSuchMethodException - if an accessor method for this propety cannot be found

populate

public static void populate(java.lang.Object bean,
                            java.util.Map properties)
                     throws java.lang.IllegalAccessException,
                            java.lang.reflect.InvocationTargetException
Deprecated. 
Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs. This method uses Java reflection APIs to identify corresponding "property setter" method names, and deals with setter arguments of type String, boolean, int, long, float, and double. In addition, array setters for these types (or the corresponding primitive types) can also be identified.

The particular setter method to be called for each property is determined using the usual JavaBeans introspection mechanisms. Thus, you may identify custom setter methods using a BeanInfo class that is associated with the class of the bean itself. If no such BeanInfo class is available, the standard method name conversion ("set" plus the capitalized name of the property in question) is used.

NOTE: It is contrary to the JavaBeans Specification to have more than one setter method (with different argument signatures) for the same property.

Parameters:
bean - JavaBean whose properties are being populated
properties - Map keyed by property name, with the corresponding (String or String[]) value(s) to be set
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception


Copyright © 2000-2001 - Apache Software Foundation