?? propertyutils.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.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import org.apache.commons.collections.FastHashMap;
/**
* <p>Utility methods for using Java Reflection APIs to facilitate generic
* property getter and setter operations on Java objects.</p>
*
* <p>The implementations for these methods are provided by <code>PropertyUtilsBean</code>.
* For more details see {@link PropertyUtilsBean}.</p>
*
* @author Craig R. McClanahan
* @author Ralph Schaer
* @author Chris Audley
* @author Rey Francois
* @author Gregor Rayman
* @author Jan Sorensen
* @author Scott Sanders
* @version $Revision: 644137 $ $Date: 2008-04-03 03:30:23 +0100 (Thu, 03 Apr 2008) $
* @see PropertyUtilsBean
* @see org.apache.commons.beanutils.expression.Resolver
*/
public class PropertyUtils {
// ----------------------------------------------------- Manifest Constants
/**
* The delimiter that preceeds the zero-relative subscript for an
* indexed reference.
*
* @deprecated The notation used for property name expressions is now
* dependant on the {@link org.apache.commons.beanutils.expression.Resolver}
* implementation being used.
*/
public static final char INDEXED_DELIM = '[';
/**
* The delimiter that follows the zero-relative subscript for an
* indexed reference.
*
* @deprecated The notation used for property name expressions is now
* dependant on the {@link org.apache.commons.beanutils.expression.Resolver}
* implementation being used.
*/
public static final char INDEXED_DELIM2 = ']';
/**
* The delimiter that preceeds the key of a mapped property.
*
* @deprecated The notation used for property name expressions is now
* dependant on the {@link org.apache.commons.beanutils.expression.Resolver}
* implementation being used.
*/
public static final char MAPPED_DELIM = '(';
/**
* The delimiter that follows the key of a mapped property.
*
* @deprecated The notation used for property name expressions is now
* dependant on the {@link org.apache.commons.beanutils.expression.Resolver}
* implementation being used.
*/
public static final char MAPPED_DELIM2 = ')';
/**
* The delimiter that separates the components of a nested reference.
*
* @deprecated The notation used for property name expressions is now
* dependant on the {@link org.apache.commons.beanutils.expression.Resolver}
* implementation being used.
*/
public static final char NESTED_DELIM = '.';
// ------------------------------------------------------- Static 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 The <code>debug</code> static property is no longer used
*/
private static int debug = 0;
/**
* The <code>debug</code> static property is no longer used
* @return debug property
* @deprecated The <code>debug</code> static property is no longer used
*/
public static int getDebug() {
return (debug);
}
/**
* The <code>debug</code> static property is no longer used
* @param newDebug debug property
* @deprecated The <code>debug</code> static property is no longer used
*/
public static void setDebug(int newDebug) {
debug = newDebug;
}
// --------------------------------------------------------- Public Methods
/**
* Clear any cached property descriptors information for all classes
* loaded by any class loaders. This is useful in cases where class
* loaders are thrown away to implement class reloading.
*
* <p>For more details see <code>PropertyUtilsBean</code>.</p>
*
* @see PropertyUtilsBean#clearDescriptors
*/
public static void clearDescriptors() {
PropertyUtilsBean.getInstance().clearDescriptors();
}
/**
* <p>Copy property values from the "origin" bean to the "destination" bean
* for all cases where the property names are the same (even though the
* actual getter and setter methods might have been customized via
* <code>BeanInfo</code> classes).</p>
*
* <p>For more details see <code>PropertyUtilsBean</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
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* propety cannot be found
* @see PropertyUtilsBean#copyProperties
*/
public static void copyProperties(Object dest, Object orig)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
PropertyUtilsBean.getInstance().copyProperties(dest, orig);
}
/**
* <p>Return the entire set of properties for which the specified bean
* provides a read method.</p>
*
* <p>For more details see <code>PropertyUtilsBean</code>.</p>
*
* @param bean Bean whose properties are to be extracted
* @return The set of properties for the bean
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception IllegalArgumentException if <code>bean</code> is null
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* propety cannot be found
* @see PropertyUtilsBean#describe
*/
public static Map describe(Object bean)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return (PropertyUtilsBean.getInstance().describe(bean));
}
/**
* <p>Return the value of the specified indexed property of the specified
* bean, with no type conversions.</p>
*
* <p>For more details see <code>PropertyUtilsBean</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 value
*
* @exception IndexOutOfBoundsException if the specified index
* is outside the valid range for the underlying property
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception IllegalArgumentException if <code>bean</code> or
* <code>name</code> is null
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* propety cannot be found
* @see PropertyUtilsBean#getIndexedProperty(Object,String)
*/
public static Object getIndexedProperty(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return (PropertyUtilsBean.getInstance().getIndexedProperty(bean, name));
}
/**
* <p>Return the value of the specified indexed property of the specified
* bean, with no type conversions.</p>
*
* <p>For more details see <code>PropertyUtilsBean</code>.</p>
*
* @param bean Bean whose property is to be extracted
* @param name Simple property name of the property value to be extracted
* @param index Index of the property value to be extracted
* @return the indexed property value
*
* @exception IndexOutOfBoundsException if the specified index
* is outside the valid range for the underlying property
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method
* @exception IllegalArgumentException if <code>bean</code> or
* <code>name</code> is null
* @exception InvocationTargetException if the property accessor method
* throws an exception
* @exception NoSuchMethodException if an accessor method for this
* propety cannot be found
* @see PropertyUtilsBean#getIndexedProperty(Object,String, int)
*/
public static Object getIndexedProperty(Object bean,
String name, int index)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
return (PropertyUtilsBean.getInstance().getIndexedProperty(bean, name, index));
}
/**
* <p>Return the value of the specified mapped property of the
* specified bean, with no type conversions.</p>
*
* <p>For more details see <code>PropertyUtilsBean</code>.</p>
*
* @param bean Bean whose property is to be extracted
* @param name <code>propertyname(key)</code> of the property value
* to be extracted
* @return the mapped 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
* propety cannot be found
* @see PropertyUtilsBean#getMappedProperty(Object,String)
*/
public static Object getMappedProperty(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -