org.apache.commons.beanutils
クラス BeanUtils

java.lang.Object
  |
  +--org.apache.commons.beanutils.BeanUtils

public class BeanUtils
extends java.lang.Object

Utility methods for populating JavaBeans properties via reflection.

バージョン:
$Revision: 1.6 $ $Date: 2001/09/19 02:04:10 $
作成者:
Craig R. McClanahan, Ralph Schaer, Chris Audley, Rey Fran?is, Gregor Ra?an

フィールドの概要
private static int debug
          The debugging detail level for this component.
 
コンストラクタの概要
BeanUtils()
           
 
メソッドの概要
static java.lang.Object cloneBean(java.lang.Object bean)
          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)
          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)
          Return the value of the specified array property of the specified bean, as a String array.
static int getDebug()
           
static java.lang.String getIndexedProperty(java.lang.Object bean, java.lang.String name)
          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)
          Return the value of the specified indexed property of the specified bean, as a String.
static java.lang.String getMappedProperty(java.lang.Object bean, java.lang.String name)
          Return the value of the specified indexed property of the specified bean, as a String.
static java.lang.String getMappedProperty(java.lang.Object bean, java.lang.String name, java.lang.String key)
          Return the value of the specified mapped property of the specified bean, as a String.
static java.lang.String getNestedProperty(java.lang.Object bean, java.lang.String name)
          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)
          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)
          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)
          Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.
static void setDebug(int newDebug)
           
 
クラス java.lang.Object から継承したメソッド
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

フィールドの詳細

debug

private static int debug
The debugging detail level for this component.
コンストラクタの詳細

BeanUtils

public BeanUtils()
メソッドの詳細

getDebug

public static int getDebug()

setDebug

public static void setDebug(int newDebug)

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
Clone a bean based on the available property getters and setters, even if the bean class itself does not implement Cloneable.
パラメータ:
bean - Bean to be cloned
例外:
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
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.
パラメータ:
bean - Bean whose properties are to be extracted
例外:
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
Return the value of the specified array property of the specified bean, as a String array.
パラメータ:
bean - Bean whose property is to be extracted
name - Name of the property to be extracted
例外:
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
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.
パラメータ:
bean - Bean whose property is to be extracted
name - propertyname[index] of the property value to be extracted
例外:
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
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
パラメータ:
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
例外:
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

getMappedProperty

public static java.lang.String getMappedProperty(java.lang.Object bean,
                                                 java.lang.String name)
                                          throws java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException,
                                                 java.lang.NoSuchMethodException
Return the value of the specified indexed property of the specified bean, as a String. The String-valued key of the required value must be included (in parentheses) as a suffix to the property name, or IllegalArgumentException will be thrown.
パラメータ:
bean - Bean whose property is to be extracted
name - propertyname(index) of the property value to be extracted
例外:
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

getMappedProperty

public static java.lang.String getMappedProperty(java.lang.Object bean,
                                                 java.lang.String name,
                                                 java.lang.String key)
                                          throws java.lang.IllegalAccessException,
                                                 java.lang.reflect.InvocationTargetException,
                                                 java.lang.NoSuchMethodException
Return the value of the specified mapped property of the specified bean, as a String. The key is specified as a method parameter and must *not* be included in the property name expression
パラメータ:
bean - Bean whose property is to be extracted
name - Simple property name of the property value to be extracted
key - Lookup key of the property value to be extracted
例外:
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
Return the value of the (possibly nested) property of the specified name, for the specified bean, as a String.
パラメータ:
bean - Bean whose property is to be extracted
name - Possibly nested name of the property to be extracted
例外:
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
Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.
パラメータ:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
例外:
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
Return the value of the specified simple property of the specified bean, converted to a String.
パラメータ:
bean - Bean whose property is to be extracted
name - Name of the property to be extracted
例外:
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
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.

パラメータ:
bean - JavaBean whose properties are being populated
properties - Map keyed by property name, with the corresponding (String or String[]) value(s) to be set
例外:
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 (c) 2001 - Apache Software Foundation