?? beanutils.java
字號:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.beanutils;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
/**
* <p>Utility methods for populating JavaBeans properties via reflection.</p>
*
* <p>The implementations are provided by {@link BeanUtilsBean}.
* These static utility methods use the default instance.
* More sophisticated behaviour can be provided by using a <code>BeanUtilsBean</code> instance.</p>
*
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
* @author Rey Francois
* @author Gregor Rayman
* @version $Revision: 687089 $ $Date: 2008-08-19 17:33:30 +0100 (Tue, 19 Aug 2008) $
* @see BeanUtilsBean
*/
public class BeanUtils {
// ------------------------------------------------------ Private Variables
/**
* The debugging detail level for this component.
*
* Note that this static variable will have unexpected side-effects if
* this class is deployed in a shared classloader within a container.
* However as it is actually completely ignored by this class due to its
* deprecated status, it doesn't do any actual harm.
*
* @deprecated BeanUtils now uses commons-logging for all log messages.
* Use your favorite logging tool to configure logging for
* this class.
*/
private static int debug = 0;
/**
* The <code>debug</code> static property is no longer used
* @return debug property
* @deprecated BeanUtils now uses commons-logging for all log messages.
* Use your favorite logging tool to configure logging for
* this class.
*/
public static int getDebug() {
return (debug);
}
/**
* The <code>debug</code> static property is no longer used
* @param newDebug debug property
* @deprecated BeanUtils now uses commons-logging for all log messages.
* Use your favorite logging tool to configure logging for
* this class.
*/
public static void setDebug(int newDebug) {
debug = newDebug;
}
// --------------------------------------------------------- Class Methods
/**
* <p>Clone a bean based on the available property getters and setters,
* even if the bean class itself does not implement Cloneable.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean to be cloned
* @return the cloned bean
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception InstantiationException if a new instance of the bean's
* class cannot be instantiated
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* property cannot be found
* @see BeanUtilsBean#cloneBean
*/
public static Object cloneBean(Object bean)
throws IllegalAccessException, InstantiationException,
InvocationTargetException, NoSuchMethodException {
return BeanUtilsBean.getInstance().cloneBean(bean);
}
/**
* <p>Copy property values from the origin bean to the destination bean
* for all cases where the property names are the same.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param dest Destination bean whose properties are modified
* @param orig Origin bean whose properties are retrieved
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception IllegalArgumentException if the <code>dest</code> or
* <code>orig</code> argument is null or if the <code>dest</code>
* property type is different from the source type and the relevant
* converter has not been registered.
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @see BeanUtilsBean#copyProperties
*/
public static void copyProperties(Object dest, Object orig)
throws IllegalAccessException, InvocationTargetException {
BeanUtilsBean.getInstance().copyProperties(dest, orig);
}
/**
* <p>Copy the specified property value to the specified destination bean,
* performing any type conversion that is required.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean on which setting is to be performed
* @param name Property name (can be nested/indexed/mapped/combo)
* @param value Value to be set
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @see BeanUtilsBean#copyProperty
*/
public static void copyProperty(Object bean, String name, Object value)
throws IllegalAccessException, InvocationTargetException {
BeanUtilsBean.getInstance().copyProperty(bean, name, value);
}
/**
* <p>Return the entire set of properties for which the specified bean
* provides a read method.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean whose properties are to be extracted
* @return Map of property descriptors
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* property cannot be found
* @see BeanUtilsBean#describe
*/
public static Map describe(Object bean)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return BeanUtilsBean.getInstance().describe(bean);
}
/**
* <p>Return the value of the specified array property of the specified
* bean, as a String array.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean whose property is to be extracted
* @param name Name of the property to be extracted
* @return The array property value
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* property cannot be found
* @see BeanUtilsBean#getArrayProperty
*/
public static String[] getArrayProperty(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return BeanUtilsBean.getInstance().getArrayProperty(bean, name);
}
/**
* <p>Return the value of the specified indexed property of the specified
* bean, as a String.</p>
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean whose property is to be extracted
* @param name <code>propertyname[index]</code> of the property value
* to be extracted
* @return The indexed property's value, converted to a String
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* property cannot be found
* @see BeanUtilsBean#getIndexedProperty(Object, String)
*/
public static String getIndexedProperty(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return BeanUtilsBean.getInstance().getIndexedProperty(bean, name);
}
/**
* 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
*
* <p>For more details see <code>BeanUtilsBean</code>.</p>
*
* @param bean Bean whose property is to be extracted
* @param name Simple property name of the property value to be extracted
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -