You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/20 22:19:06 UTC
[commons-beanutils] 02/02: Remove trailing white spaces.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit 2856228955862883a4bf962ddfe4b5f9d20ebd9c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Oct 20 18:18:51 2019 -0400
Remove trailing white spaces.
---
.../apache/commons/beanutils2/BeanPredicate.java | 6 +-
.../org/apache/commons/beanutils2/BeanUtils.java | 882 +++++------
.../apache/commons/beanutils2/ConvertUtils.java | 424 ++---
.../apache/commons/beanutils2/PropertyUtils.java | 1648 ++++++++++----------
.../apache/commons/beanutils2/WrapDynaClass.java | 822 +++++-----
.../beanutils2/converters/BooleanConverter.java | 452 +++---
.../commons/beanutils2/bugs/Jira157TestCase.java | 396 ++---
.../commons/beanutils2/bugs/Jira520TestCase.java | 110 +-
8 files changed, 2370 insertions(+), 2370 deletions(-)
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java b/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java
index c729d23..6be8d12 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java
@@ -27,7 +27,7 @@ import org.apache.commons.logging.LogFactory;
* <p>Predicate implementation that applies the given <code>Predicate</code>
* to the result of calling the given property getter.
* </p>
- *
+ *
* @param <T> the type of the input to the predicate
*/
public class BeanPredicate<T> implements Predicate<T> {
@@ -51,7 +51,7 @@ public class BeanPredicate<T> implements Predicate<T> {
this.propertyName = propertyName;
this.predicate = predicate;
}
-
+
/**
* Evaluates the given object by applying the {@link #getPredicate()}
* to a property value named by {@link #getPropertyName()}.
@@ -87,7 +87,7 @@ public class BeanPredicate<T> implements Predicate<T> {
return evaluation;
}
-
+
/**
* Gets the name of the property whose value is to be predicated.
* in the evaluation.
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanUtils.java b/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
index 0a1698e..94a6e25 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanUtils.java
@@ -1,441 +1,441 @@
-/*
- * 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.beanutils2;
-
-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>
- *
- * @see BeanUtilsBean
- */
-
-public class BeanUtils {
-
-
- // ------------------------------------------------------ Private Variables
-
-
-
-
- // --------------------------------------------------------- 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InstantiationException if a new instance of the bean's
- * class cannot be instantiated
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#cloneBean
- */
- public static Object cloneBean(final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws 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.
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @see BeanUtilsBean#copyProperties
- */
- public static void copyProperties(final Object dest, final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @see BeanUtilsBean#copyProperty
- */
- public static void copyProperty(final Object bean, final String name, final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#describe
- */
- public static Map<String, String> describe(final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getArrayProperty
- */
- public static String[] getArrayProperty(final Object bean, final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getIndexedProperty(Object, String)
- */
- public static String getIndexedProperty(final Object bean, final 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
- * @param index Index of the property value to be extracted
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getIndexedProperty(Object, String, int)
- */
- public static String getIndexedProperty(final Object bean,
- final String name, final int index)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getIndexedProperty(bean, name, index);
-
- }
-
-
- /**
- * <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 mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getMappedProperty(Object, String)
- */
- public static String getMappedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getMappedProperty(bean, name);
-
- }
-
-
- /**
- * <p>Return the value of the specified mapped 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 Simple property name of the property value to be extracted
- * @param key Lookup key of the property value to be extracted
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getMappedProperty(Object, String, String)
- */
- public static String getMappedProperty(final Object bean,
- final String name, final String key)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getMappedProperty(bean, name, key);
-
- }
-
-
- /**
- * <p>Return the value of the (possibly nested) property of the specified
- * name, for 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 Possibly nested name of the property to be extracted
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getNestedProperty
- */
- public static String getNestedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getNestedProperty(bean, name);
-
- }
-
-
- /**
- * <p>Return the value of the specified property of the specified bean,
- * no matter which property reference format is used, as a String.</p>
- *
- * <p>For more details see <code>BeanUtilsBean</code>.</p>
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getProperty
- */
- public static String getProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getProperty(bean, name);
-
- }
-
-
- /**
- * <p>Return the value of the specified simple property of the specified
- * bean, converted to a String.</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 property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see BeanUtilsBean#getSimpleProperty
- */
- public static String getSimpleProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return BeanUtilsBean.getInstance().getSimpleProperty(bean, name);
-
- }
-
-
- /**
- * <p>Populate the JavaBeans properties of the specified bean, based on
- * the specified name/value pairs.</p>
- *
- * <p>For more details see <code>BeanUtilsBean</code>.</p>
- *
- * @param bean JavaBean whose properties are being populated
- * @param properties Map keyed by property name, with the
- * corresponding (String or String[]) value(s) to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @see BeanUtilsBean#populate
- */
- public static void populate(final Object bean, final Map<String, ? extends Object> properties)
- throws IllegalAccessException, InvocationTargetException {
-
- BeanUtilsBean.getInstance().populate(bean, properties);
- }
-
-
- /**
- * <p>Set the specified property value, performing type conversions as
- * required to conform to the type of the destination property.</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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @see BeanUtilsBean#setProperty
- */
- public static void setProperty(final Object bean, final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException {
-
- BeanUtilsBean.getInstance().setProperty(bean, name, value);
- }
-
- /**
- * If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
- *
- * @param throwable The throwable.
- * @param cause The cause of the throwable.
- * @return true if the cause was initialized, otherwise false.
- * @since 1.8.0
- */
- public static boolean initCause(final Throwable throwable, final Throwable cause) {
- return BeanUtilsBean.getInstance().initCause(throwable, cause);
- }
-
- /**
- * Create a cache.
- * @param <K> the key type of the cache
- * @param <V> the value type of the cache
- * @return a new cache
- * @since 1.8.0
- */
- public static <K, V> Map<K, V> createCache() {
- return new WeakFastHashMap<>();
- }
-}
+/*
+ * 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.beanutils2;
+
+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>
+ *
+ * @see BeanUtilsBean
+ */
+
+public class BeanUtils {
+
+
+ // ------------------------------------------------------ Private Variables
+
+
+
+
+ // --------------------------------------------------------- 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InstantiationException if a new instance of the bean's
+ * class cannot be instantiated
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#cloneBean
+ */
+ public static Object cloneBean(final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws 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.
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @see BeanUtilsBean#copyProperties
+ */
+ public static void copyProperties(final Object dest, final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @see BeanUtilsBean#copyProperty
+ */
+ public static void copyProperty(final Object bean, final String name, final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#describe
+ */
+ public static Map<String, String> describe(final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getArrayProperty
+ */
+ public static String[] getArrayProperty(final Object bean, final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getIndexedProperty(Object, String)
+ */
+ public static String getIndexedProperty(final Object bean, final 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
+ * @param index Index of the property value to be extracted
+ * @return The indexed property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getIndexedProperty(Object, String, int)
+ */
+ public static String getIndexedProperty(final Object bean,
+ final String name, final int index)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getIndexedProperty(bean, name, index);
+
+ }
+
+
+ /**
+ * <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 mapped property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getMappedProperty(Object, String)
+ */
+ public static String getMappedProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getMappedProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return the value of the specified mapped 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 Simple property name of the property value to be extracted
+ * @param key Lookup key of the property value to be extracted
+ * @return The mapped property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getMappedProperty(Object, String, String)
+ */
+ public static String getMappedProperty(final Object bean,
+ final String name, final String key)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getMappedProperty(bean, name, key);
+
+ }
+
+
+ /**
+ * <p>Return the value of the (possibly nested) property of the specified
+ * name, for 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 Possibly nested name of the property to be extracted
+ * @return The nested property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getNestedProperty
+ */
+ public static String getNestedProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getNestedProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return the value of the specified property of the specified bean,
+ * no matter which property reference format is used, as a String.</p>
+ *
+ * <p>For more details see <code>BeanUtilsBean</code>.</p>
+ *
+ * @param bean Bean whose property is to be extracted
+ * @param name Possibly indexed and/or nested name of the property
+ * to be extracted
+ * @return The property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getProperty
+ */
+ public static String getProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return the value of the specified simple property of the specified
+ * bean, converted to a String.</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 property's value, converted to a String
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * property cannot be found
+ * @see BeanUtilsBean#getSimpleProperty
+ */
+ public static String getSimpleProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return BeanUtilsBean.getInstance().getSimpleProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Populate the JavaBeans properties of the specified bean, based on
+ * the specified name/value pairs.</p>
+ *
+ * <p>For more details see <code>BeanUtilsBean</code>.</p>
+ *
+ * @param bean JavaBean whose properties are being populated
+ * @param properties Map keyed by property name, with the
+ * corresponding (String or String[]) value(s) to be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @see BeanUtilsBean#populate
+ */
+ public static void populate(final Object bean, final Map<String, ? extends Object> properties)
+ throws IllegalAccessException, InvocationTargetException {
+
+ BeanUtilsBean.getInstance().populate(bean, properties);
+ }
+
+
+ /**
+ * <p>Set the specified property value, performing type conversions as
+ * required to conform to the type of the destination property.</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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @see BeanUtilsBean#setProperty
+ */
+ public static void setProperty(final Object bean, final String name, final Object value)
+ throws IllegalAccessException, InvocationTargetException {
+
+ BeanUtilsBean.getInstance().setProperty(bean, name, value);
+ }
+
+ /**
+ * If we're running on JDK 1.4 or later, initialize the cause for the given throwable.
+ *
+ * @param throwable The throwable.
+ * @param cause The cause of the throwable.
+ * @return true if the cause was initialized, otherwise false.
+ * @since 1.8.0
+ */
+ public static boolean initCause(final Throwable throwable, final Throwable cause) {
+ return BeanUtilsBean.getInstance().initCause(throwable, cause);
+ }
+
+ /**
+ * Create a cache.
+ * @param <K> the key type of the cache
+ * @param <V> the value type of the cache
+ * @return a new cache
+ * @since 1.8.0
+ */
+ public static <K, V> Map<K, V> createCache() {
+ return new WeakFastHashMap<>();
+ }
+}
diff --git a/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java b/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
index 927f2f2..ec3587e 100644
--- a/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
@@ -1,212 +1,212 @@
-/*
- * 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.beanutils2;
-
-/**
- * <p>Utility methods for converting String scalar values to objects of the
- * specified Class, String arrays to arrays of the specified Class.</p>
- *
- * <p>For more details, see <code>ConvertUtilsBean</code> which provides the
- * implementations for these methods.</p>
- *
- * @see ConvertUtilsBean
- */
-
-public class ConvertUtils {
-
-
- // ------------------------------------------------------ Static Properties
-
-
-
- // --------------------------------------------------------- Public Classes
-
-
- /**
- * <p>Convert the specified value into a String.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param value Value to be converted (may be null)
- * @return The converted String value or null if value is null
- *
- * @see ConvertUtilsBean#convert(Object)
- */
- public static String convert(final Object value) {
- return ConvertUtilsBean.getInstance().convert(value);
- }
-
-
- /**
- * <p>Convert the specified value to an object of the specified class (if
- * possible). Otherwise, return a String representation of the value.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param value Value to be converted (may be null)
- * @param clazz Java class to be converted to (must not be null)
- * @return The converted value
- *
- * @see ConvertUtilsBean#convert(String, Class)
- */
- public static Object convert(final String value, final Class<?> clazz) {
- return ConvertUtilsBean.getInstance().convert(value, clazz);
- }
-
-
- /**
- * <p>Convert an array of specified values to an array of objects of the
- * specified class (if possible).</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param values Array of values to be converted
- * @param clazz Java array or element class to be converted to (must not be null)
- * @return The converted value
- *
- * @see ConvertUtilsBean#convert(String[], Class)
- */
- public static Object convert(final String[] values, final Class<?> clazz) {
- return ConvertUtilsBean.getInstance().convert(values, clazz);
- }
-
- /**
- * <p>Convert the value to an object of the specified class (if
- * possible).</p>
- *
- * @param value Value to be converted (may be null)
- * @param targetType Class of the value to be converted to (must not be null)
- * @return The converted value
- *
- * @throws ConversionException if thrown by an underlying Converter
- */
- public static Object convert(final Object value, final Class<?> targetType) {
- return ConvertUtilsBean.getInstance().convert(value, targetType);
- }
-
- /**
- * <p>Remove all registered {@link Converter}s, and re-establish the
- * standard Converters.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @see ConvertUtilsBean#deregister()
- */
- public static void deregister() {
- ConvertUtilsBean.getInstance().deregister();
- }
-
-
- /**
- * <p>Remove any registered {@link Converter} for the specified destination
- * <code>Class</code>.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param clazz Class for which to remove a registered Converter
- * @see ConvertUtilsBean#deregister(Class)
- */
- public static void deregister(final Class<?> clazz) {
- ConvertUtilsBean.getInstance().deregister(clazz);
- }
-
-
- /**
- * <p>Look up and return any registered {@link Converter} for the specified
- * destination class; if there is no registered Converter, return
- * <code>null</code>.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param clazz Class for which to return a registered Converter
- * @return The registered {@link Converter} or <code>null</code> if not found
- * @see ConvertUtilsBean#lookup(Class)
- */
- public static Converter lookup(final Class<?> clazz) {
- return ConvertUtilsBean.getInstance().lookup(clazz);
- }
-
- /**
- * Look up and return any registered {@link Converter} for the specified
- * source and destination class; if there is no registered Converter,
- * return <code>null</code>.
- *
- * @param sourceType Class of the value being converted
- * @param targetType Class of the value to be converted to
- * @return The registered {@link Converter} or <code>null</code> if not found
- */
- public static Converter lookup(final Class<?> sourceType, final Class<?> targetType) {
- return ConvertUtilsBean.getInstance().lookup(sourceType, targetType);
- }
-
- /**
- * <p>Register a custom {@link Converter} for the specified destination
- * <code>Class</code>, replacing any previously registered Converter.</p>
- *
- * <p>For more details see <code>ConvertUtilsBean</code>.</p>
- *
- * @param converter Converter to be registered
- * @param clazz Destination class for conversions performed by this
- * Converter
- * @see ConvertUtilsBean#register(Converter, Class)
- */
- public static void register(final Converter converter, final Class<?> clazz) {
- ConvertUtilsBean.getInstance().register(converter, clazz);
- }
-
-
- /**
- * Change primitive Class types to the associated wrapper class. This is
- * useful for concrete converter implementations which typically treat
- * primitive types like their corresponding wrapper types.
- *
- * @param <T> The type to be checked.
- * @param type The class type to check.
- * @return The converted type.
- * @since 1.9
- */
- // All type casts are safe because the TYPE members of the wrapper types
- // return their own class.
- @SuppressWarnings("unchecked")
- public static <T> Class<T> primitiveToWrapper(final Class<T> type) {
- if (type == null || !type.isPrimitive()) {
- return type;
- }
-
- if (type == Integer.TYPE) {
- return (Class<T>) Integer.class;
- } else if (type == Double.TYPE) {
- return (Class<T>) Double.class;
- } else if (type == Long.TYPE) {
- return (Class<T>) Long.class;
- } else if (type == Boolean.TYPE) {
- return (Class<T>) Boolean.class;
- } else if (type == Float.TYPE) {
- return (Class<T>) Float.class;
- } else if (type == Short.TYPE) {
- return (Class<T>) Short.class;
- } else if (type == Byte.TYPE) {
- return (Class<T>) Byte.class;
- } else if (type == Character.TYPE) {
- return (Class<T>) Character.class;
- } else {
- return type;
- }
- }
-}
+/*
+ * 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.beanutils2;
+
+/**
+ * <p>Utility methods for converting String scalar values to objects of the
+ * specified Class, String arrays to arrays of the specified Class.</p>
+ *
+ * <p>For more details, see <code>ConvertUtilsBean</code> which provides the
+ * implementations for these methods.</p>
+ *
+ * @see ConvertUtilsBean
+ */
+
+public class ConvertUtils {
+
+
+ // ------------------------------------------------------ Static Properties
+
+
+
+ // --------------------------------------------------------- Public Classes
+
+
+ /**
+ * <p>Convert the specified value into a String.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param value Value to be converted (may be null)
+ * @return The converted String value or null if value is null
+ *
+ * @see ConvertUtilsBean#convert(Object)
+ */
+ public static String convert(final Object value) {
+ return ConvertUtilsBean.getInstance().convert(value);
+ }
+
+
+ /**
+ * <p>Convert the specified value to an object of the specified class (if
+ * possible). Otherwise, return a String representation of the value.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param value Value to be converted (may be null)
+ * @param clazz Java class to be converted to (must not be null)
+ * @return The converted value
+ *
+ * @see ConvertUtilsBean#convert(String, Class)
+ */
+ public static Object convert(final String value, final Class<?> clazz) {
+ return ConvertUtilsBean.getInstance().convert(value, clazz);
+ }
+
+
+ /**
+ * <p>Convert an array of specified values to an array of objects of the
+ * specified class (if possible).</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param values Array of values to be converted
+ * @param clazz Java array or element class to be converted to (must not be null)
+ * @return The converted value
+ *
+ * @see ConvertUtilsBean#convert(String[], Class)
+ */
+ public static Object convert(final String[] values, final Class<?> clazz) {
+ return ConvertUtilsBean.getInstance().convert(values, clazz);
+ }
+
+ /**
+ * <p>Convert the value to an object of the specified class (if
+ * possible).</p>
+ *
+ * @param value Value to be converted (may be null)
+ * @param targetType Class of the value to be converted to (must not be null)
+ * @return The converted value
+ *
+ * @throws ConversionException if thrown by an underlying Converter
+ */
+ public static Object convert(final Object value, final Class<?> targetType) {
+ return ConvertUtilsBean.getInstance().convert(value, targetType);
+ }
+
+ /**
+ * <p>Remove all registered {@link Converter}s, and re-establish the
+ * standard Converters.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @see ConvertUtilsBean#deregister()
+ */
+ public static void deregister() {
+ ConvertUtilsBean.getInstance().deregister();
+ }
+
+
+ /**
+ * <p>Remove any registered {@link Converter} for the specified destination
+ * <code>Class</code>.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param clazz Class for which to remove a registered Converter
+ * @see ConvertUtilsBean#deregister(Class)
+ */
+ public static void deregister(final Class<?> clazz) {
+ ConvertUtilsBean.getInstance().deregister(clazz);
+ }
+
+
+ /**
+ * <p>Look up and return any registered {@link Converter} for the specified
+ * destination class; if there is no registered Converter, return
+ * <code>null</code>.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param clazz Class for which to return a registered Converter
+ * @return The registered {@link Converter} or <code>null</code> if not found
+ * @see ConvertUtilsBean#lookup(Class)
+ */
+ public static Converter lookup(final Class<?> clazz) {
+ return ConvertUtilsBean.getInstance().lookup(clazz);
+ }
+
+ /**
+ * Look up and return any registered {@link Converter} for the specified
+ * source and destination class; if there is no registered Converter,
+ * return <code>null</code>.
+ *
+ * @param sourceType Class of the value being converted
+ * @param targetType Class of the value to be converted to
+ * @return The registered {@link Converter} or <code>null</code> if not found
+ */
+ public static Converter lookup(final Class<?> sourceType, final Class<?> targetType) {
+ return ConvertUtilsBean.getInstance().lookup(sourceType, targetType);
+ }
+
+ /**
+ * <p>Register a custom {@link Converter} for the specified destination
+ * <code>Class</code>, replacing any previously registered Converter.</p>
+ *
+ * <p>For more details see <code>ConvertUtilsBean</code>.</p>
+ *
+ * @param converter Converter to be registered
+ * @param clazz Destination class for conversions performed by this
+ * Converter
+ * @see ConvertUtilsBean#register(Converter, Class)
+ */
+ public static void register(final Converter converter, final Class<?> clazz) {
+ ConvertUtilsBean.getInstance().register(converter, clazz);
+ }
+
+
+ /**
+ * Change primitive Class types to the associated wrapper class. This is
+ * useful for concrete converter implementations which typically treat
+ * primitive types like their corresponding wrapper types.
+ *
+ * @param <T> The type to be checked.
+ * @param type The class type to check.
+ * @return The converted type.
+ * @since 1.9
+ */
+ // All type casts are safe because the TYPE members of the wrapper types
+ // return their own class.
+ @SuppressWarnings("unchecked")
+ public static <T> Class<T> primitiveToWrapper(final Class<T> type) {
+ if (type == null || !type.isPrimitive()) {
+ return type;
+ }
+
+ if (type == Integer.TYPE) {
+ return (Class<T>) Integer.class;
+ } else if (type == Double.TYPE) {
+ return (Class<T>) Double.class;
+ } else if (type == Long.TYPE) {
+ return (Class<T>) Long.class;
+ } else if (type == Boolean.TYPE) {
+ return (Class<T>) Boolean.class;
+ } else if (type == Float.TYPE) {
+ return (Class<T>) Float.class;
+ } else if (type == Short.TYPE) {
+ return (Class<T>) Short.class;
+ } else if (type == Byte.TYPE) {
+ return (Class<T>) Byte.class;
+ } else if (type == Character.TYPE) {
+ return (Class<T>) Character.class;
+ } else {
+ return type;
+ }
+ }
+}
diff --git a/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java b/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java
index 1df9d8d..828c12c 100644
--- a/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java
@@ -1,824 +1,824 @@
-/*
- * 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.beanutils2;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-
-/**
- * <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>
- *
- * @see PropertyUtilsBean
- * @see org.apache.commons.beanutils2.expression.Resolver
- */
-
-public class PropertyUtils {
-
-
- // ----------------------------------------------------- Manifest Constants
-
-
-
-
-
- // ------------------------------------------------------- Static Variables
-
-
-
-
- // --------------------------------------------------------- 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();
-
- }
-
- /**
- * Resets the registered {@link BeanIntrospector} objects to the initial default
- * state.
- *
- * @since 1.9
- */
- public static void resetBeanIntrospectors() {
- PropertyUtilsBean.getInstance().resetBeanIntrospectors();
- }
-
- /**
- * Adds a <code>BeanIntrospector</code>. This object is invoked when the
- * property descriptors of a class need to be obtained.
- *
- * @param introspector the <code>BeanIntrospector</code> to be added (must
- * not be <b>null</b>
- * @throws IllegalArgumentException if the argument is <b>null</b>
- * @since 1.9
- */
- public static void addBeanIntrospector(final BeanIntrospector introspector) {
- PropertyUtilsBean.getInstance().addBeanIntrospector(introspector);
- }
-
- /**
- * Removes the specified <code>BeanIntrospector</code>.
- *
- * @param introspector the <code>BeanIntrospector</code> to be removed
- * @return <b>true</b> if the <code>BeanIntrospector</code> existed and
- * could be removed, <b>false</b> otherwise
- * @since 1.9
- */
- public static boolean removeBeanIntrospector(final BeanIntrospector introspector) {
- return PropertyUtilsBean.getInstance().removeBeanIntrospector(
- introspector);
- }
-
- /**
- * <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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if the <code>dest</code> or
- * <code>orig</code> argument is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#copyProperties
- */
- public static void copyProperties(final Object dest, final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#describe
- */
- public static Map<String, Object> describe(final 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
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getIndexedProperty(Object,String)
- */
- public static Object getIndexedProperty(final Object bean, final 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
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getIndexedProperty(Object,String, int)
- */
- public static Object getIndexedProperty(final Object bean,
- final String name, final 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
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getMappedProperty(Object,String)
- */
- public static Object getMappedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getMappedProperty(bean, name);
-
- }
-
-
- /**
- * <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 Mapped property name of the property value to be extracted
- * @param key Key of the property value to be extracted
- * @return the mapped property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getMappedProperty(Object,String, String)
- */
- public static Object getMappedProperty(final Object bean,
- final String name, final String key)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getMappedProperty(bean, name, key);
-
- }
-
-
- /**
- * <p>Return the mapped property descriptors for this bean class.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param beanClass Bean class to be introspected
- * @return the mapped property descriptors
- * @see PropertyUtilsBean#getMappedPropertyDescriptors(Class)
- */
- static Map<Class<?>, Map> getMappedPropertyDescriptors(final Class<?> beanClass) {
-
- return PropertyUtilsBean.getInstance().getMappedPropertyDescriptors(beanClass);
-
- }
-
-
- /**
- * <p>Return the value of the (possibly nested) property of the specified
- * name, for 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 Possibly nested name of the property to be extracted
- * @return the nested property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws NestedNullException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException
- * if the property accessor method throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getNestedProperty
- */
- public static Object getNestedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getNestedProperty(bean, name);
-
- }
-
-
- /**
- * <p>Return the value of the specified property of the specified bean,
- * no matter which property reference format is used, 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 Possibly indexed and/or nested name of the property
- * to be extracted
- * @return the property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getProperty
- */
- public static Object getProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getProperty(bean, name);
-
- }
-
-
- /**
- * <p>Retrieve the property descriptor for the specified property of the
- * specified bean, or return <code>null</code> if there is no such
- * descriptor.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property descriptor
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getPropertyDescriptor
- */
- public static PropertyDescriptor getPropertyDescriptor(final Object bean,
- final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptor(bean, name);
-
- }
-
-
- /**
- * <p>Retrieve the property descriptors for the specified class,
- * introspecting and caching them the first time a particular bean class
- * is encountered.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param beanClass Bean class for which property descriptors are requested
- * @return the property descriptors
- * @throws IllegalArgumentException if <code>beanClass</code> is null
- * @see PropertyUtilsBean#getPropertyDescriptors(Class)
- */
- public static PropertyDescriptor[]
- getPropertyDescriptors(final Class<?> beanClass) {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass);
-
- }
-
-
- /**
- * <p>Retrieve the property descriptors for the specified bean,
- * introspecting and caching them the first time a particular bean class
- * is encountered.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean for which property descriptors are requested
- * @return the property descriptors
- * @throws IllegalArgumentException if <code>bean</code> is null
- * @see PropertyUtilsBean#getPropertyDescriptors(Object)
- */
- public static PropertyDescriptor[] getPropertyDescriptors(final Object bean) {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean);
-
- }
-
-
- /**
- * <p>Return the Java Class repesenting the property editor class that has
- * been registered for this property (if any).</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property editor class
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getPropertyEditorClass(Object,String)
- */
- public static Class<?> getPropertyEditorClass(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyEditorClass(bean, name);
-
- }
-
-
- /**
- * <p>Return the Java Class representing the property type of the specified
- * property, or <code>null</code> if there is no such property for the
- * specified bean.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return The property type
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getPropertyType(Object, String)
- */
- public static Class<?> getPropertyType(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyType(bean, name);
- }
-
-
- /**
- * <p>Return an accessible property getter method for this property,
- * if there is one; otherwise return <code>null</code>.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param descriptor Property descriptor to return a getter for
- * @return The read method
- * @see PropertyUtilsBean#getReadMethod(PropertyDescriptor)
- */
- public static Method getReadMethod(final PropertyDescriptor descriptor) {
-
- return PropertyUtilsBean.getInstance().getReadMethod(descriptor);
-
- }
-
-
- /**
- * <p>Return the value of the specified simple 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 Name of the property to be extracted
- * @return The property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if the property name
- * is nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#getSimpleProperty
- */
- public static Object getSimpleProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getSimpleProperty(bean, name);
-
- }
-
-
- /**
- * <p>Return an accessible property setter method for this property,
- * if there is one; otherwise return <code>null</code>.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param descriptor Property descriptor to return a setter for
- * @return The write method
- * @see PropertyUtilsBean#getWriteMethod(PropertyDescriptor)
- */
- public static Method getWriteMethod(final PropertyDescriptor descriptor) {
-
- return PropertyUtilsBean.getInstance().getWriteMethod(descriptor);
-
- }
-
-
- /**
- * <p>Return <code>true</code> if the specified property name identifies
- * a readable property on the specified bean; otherwise, return
- * <code>false</code>.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return <code>true</code> if the property is readable,
- * otherwise <code>false</code>
- *
- * @throws IllegalArgumentException if <code>bean</code>
- * or <code>name</code> is <code>null</code>
- * @see PropertyUtilsBean#isReadable
- * @since BeanUtils 1.6
- */
- public static boolean isReadable(final Object bean, final String name) {
-
- return PropertyUtilsBean.getInstance().isReadable(bean, name);
- }
-
-
- /**
- * <p>Return <code>true</code> if the specified property name identifies
- * a writeable property on the specified bean; otherwise, return
- * <code>false</code>.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return <code>true</code> if the property is writeable,
- * otherwise <code>false</code>
- *
- * @throws IllegalArgumentException if <code>bean</code>
- * or <code>name</code> is <code>null</code>
- * @see PropertyUtilsBean#isWriteable
- * @since BeanUtils 1.6
- */
- public static boolean isWriteable(final Object bean, final String name) {
-
- return PropertyUtilsBean.getInstance().isWriteable(bean, name);
- }
-
-
- /**
- * <p>Sets 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 modified
- * @param name <code>propertyname[index]</code> of the property value
- * to be modified
- * @param value Value to which the specified property element
- * should be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
- */
- public static void setIndexedProperty(final Object bean, final String name,
- final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, value);
-
- }
-
-
- /**
- * <p>Sets 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 set
- * @param name Simple property name of the property value to be set
- * @param index Index of the property value to be set
- * @param value Value to which the indexed property element is to be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
- */
- public static void setIndexedProperty(final Object bean, final String name,
- final int index, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, index, value);
- }
-
-
- /**
- * <p>Sets 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 set
- * @param name <code>propertyname(key)</code> of the property value
- * to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setMappedProperty(Object, String, Object)
- */
- public static void setMappedProperty(final Object bean, final String name,
- final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setMappedProperty(bean, name, value);
- }
-
-
- /**
- * <p>Sets 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 set
- * @param name Mapped property name of the property value to be set
- * @param key Key of the property value to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setMappedProperty(Object, String, String, Object)
- */
- public static void setMappedProperty(final Object bean, final String name,
- final String key, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setMappedProperty(bean, name, key, value);
- }
-
-
- /**
- * <p>Sets the value of the (possibly nested) property of the specified
- * name, for 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 modified
- * @param name Possibly nested name of the property to be modified
- * @param value Value to which the property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setNestedProperty
- */
- public static void setNestedProperty(final Object bean,
- final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setNestedProperty(bean, name, value);
- }
-
-
- /**
- * <p>Set the value of the specified property of the specified bean,
- * no matter which property reference format is used, with no
- * type conversions.</p>
- *
- * <p>For more details see <code>PropertyUtilsBean</code>.</p>
- *
- * @param bean Bean whose property is to be modified
- * @param name Possibly indexed and/or nested name of the property
- * to be modified
- * @param value Value to which this property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setProperty
- */
- public static void setProperty(final Object bean, final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setProperty(bean, name, value);
-
- }
-
-
- /**
- * <p>Set the value of the specified simple 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 modified
- * @param name Name of the property to be modified
- * @param value Value to which the property should be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if <code>bean</code> or
- * <code>name</code> is null
- * @throws IllegalArgumentException if the property name is
- * nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * propety cannot be found
- * @see PropertyUtilsBean#setSimpleProperty
- */
- public static void setSimpleProperty(final Object bean,
- final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setSimpleProperty(bean, name, value);
- }
-
-
-}
+/*
+ * 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.beanutils2;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+
+/**
+ * <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>
+ *
+ * @see PropertyUtilsBean
+ * @see org.apache.commons.beanutils2.expression.Resolver
+ */
+
+public class PropertyUtils {
+
+
+ // ----------------------------------------------------- Manifest Constants
+
+
+
+
+
+ // ------------------------------------------------------- Static Variables
+
+
+
+
+ // --------------------------------------------------------- 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();
+
+ }
+
+ /**
+ * Resets the registered {@link BeanIntrospector} objects to the initial default
+ * state.
+ *
+ * @since 1.9
+ */
+ public static void resetBeanIntrospectors() {
+ PropertyUtilsBean.getInstance().resetBeanIntrospectors();
+ }
+
+ /**
+ * Adds a <code>BeanIntrospector</code>. This object is invoked when the
+ * property descriptors of a class need to be obtained.
+ *
+ * @param introspector the <code>BeanIntrospector</code> to be added (must
+ * not be <b>null</b>
+ * @throws IllegalArgumentException if the argument is <b>null</b>
+ * @since 1.9
+ */
+ public static void addBeanIntrospector(final BeanIntrospector introspector) {
+ PropertyUtilsBean.getInstance().addBeanIntrospector(introspector);
+ }
+
+ /**
+ * Removes the specified <code>BeanIntrospector</code>.
+ *
+ * @param introspector the <code>BeanIntrospector</code> to be removed
+ * @return <b>true</b> if the <code>BeanIntrospector</code> existed and
+ * could be removed, <b>false</b> otherwise
+ * @since 1.9
+ */
+ public static boolean removeBeanIntrospector(final BeanIntrospector introspector) {
+ return PropertyUtilsBean.getInstance().removeBeanIntrospector(
+ introspector);
+ }
+
+ /**
+ * <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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if the <code>dest</code> or
+ * <code>orig</code> argument is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#copyProperties
+ */
+ public static void copyProperties(final Object dest, final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#describe
+ */
+ public static Map<String, Object> describe(final 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
+ *
+ * @throws IndexOutOfBoundsException if the specified index
+ * is outside the valid range for the underlying property
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getIndexedProperty(Object,String)
+ */
+ public static Object getIndexedProperty(final Object bean, final 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
+ *
+ * @throws IndexOutOfBoundsException if the specified index
+ * is outside the valid range for the underlying property
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getIndexedProperty(Object,String, int)
+ */
+ public static Object getIndexedProperty(final Object bean,
+ final String name, final 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
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getMappedProperty(Object,String)
+ */
+ public static Object getMappedProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getMappedProperty(bean, name);
+
+ }
+
+
+ /**
+ * <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 Mapped property name of the property value to be extracted
+ * @param key Key of the property value to be extracted
+ * @return the mapped property value
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getMappedProperty(Object,String, String)
+ */
+ public static Object getMappedProperty(final Object bean,
+ final String name, final String key)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getMappedProperty(bean, name, key);
+
+ }
+
+
+ /**
+ * <p>Return the mapped property descriptors for this bean class.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param beanClass Bean class to be introspected
+ * @return the mapped property descriptors
+ * @see PropertyUtilsBean#getMappedPropertyDescriptors(Class)
+ */
+ static Map<Class<?>, Map> getMappedPropertyDescriptors(final Class<?> beanClass) {
+
+ return PropertyUtilsBean.getInstance().getMappedPropertyDescriptors(beanClass);
+
+ }
+
+
+ /**
+ * <p>Return the value of the (possibly nested) property of the specified
+ * name, for 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 Possibly nested name of the property to be extracted
+ * @return the nested property value
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws NestedNullException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException
+ * if the property accessor method throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getNestedProperty
+ */
+ public static Object getNestedProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getNestedProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return the value of the specified property of the specified bean,
+ * no matter which property reference format is used, 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 Possibly indexed and/or nested name of the property
+ * to be extracted
+ * @return the property value
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getProperty
+ */
+ public static Object getProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Retrieve the property descriptor for the specified property of the
+ * specified bean, or return <code>null</code> if there is no such
+ * descriptor.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean for which a property descriptor is requested
+ * @param name Possibly indexed and/or nested name of the property for
+ * which a property descriptor is requested
+ * @return the property descriptor
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getPropertyDescriptor
+ */
+ public static PropertyDescriptor getPropertyDescriptor(final Object bean,
+ final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getPropertyDescriptor(bean, name);
+
+ }
+
+
+ /**
+ * <p>Retrieve the property descriptors for the specified class,
+ * introspecting and caching them the first time a particular bean class
+ * is encountered.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param beanClass Bean class for which property descriptors are requested
+ * @return the property descriptors
+ * @throws IllegalArgumentException if <code>beanClass</code> is null
+ * @see PropertyUtilsBean#getPropertyDescriptors(Class)
+ */
+ public static PropertyDescriptor[]
+ getPropertyDescriptors(final Class<?> beanClass) {
+
+ return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass);
+
+ }
+
+
+ /**
+ * <p>Retrieve the property descriptors for the specified bean,
+ * introspecting and caching them the first time a particular bean class
+ * is encountered.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean for which property descriptors are requested
+ * @return the property descriptors
+ * @throws IllegalArgumentException if <code>bean</code> is null
+ * @see PropertyUtilsBean#getPropertyDescriptors(Object)
+ */
+ public static PropertyDescriptor[] getPropertyDescriptors(final Object bean) {
+
+ return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean);
+
+ }
+
+
+ /**
+ * <p>Return the Java Class repesenting the property editor class that has
+ * been registered for this property (if any).</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean for which a property descriptor is requested
+ * @param name Possibly indexed and/or nested name of the property for
+ * which a property descriptor is requested
+ * @return the property editor class
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getPropertyEditorClass(Object,String)
+ */
+ public static Class<?> getPropertyEditorClass(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getPropertyEditorClass(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return the Java Class representing the property type of the specified
+ * property, or <code>null</code> if there is no such property for the
+ * specified bean.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean for which a property descriptor is requested
+ * @param name Possibly indexed and/or nested name of the property for
+ * which a property descriptor is requested
+ * @return The property type
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getPropertyType(Object, String)
+ */
+ public static Class<?> getPropertyType(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getPropertyType(bean, name);
+ }
+
+
+ /**
+ * <p>Return an accessible property getter method for this property,
+ * if there is one; otherwise return <code>null</code>.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param descriptor Property descriptor to return a getter for
+ * @return The read method
+ * @see PropertyUtilsBean#getReadMethod(PropertyDescriptor)
+ */
+ public static Method getReadMethod(final PropertyDescriptor descriptor) {
+
+ return PropertyUtilsBean.getInstance().getReadMethod(descriptor);
+
+ }
+
+
+ /**
+ * <p>Return the value of the specified simple 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 Name of the property to be extracted
+ * @return The property value
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if the property name
+ * is nested or indexed
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#getSimpleProperty
+ */
+ public static Object getSimpleProperty(final Object bean, final String name)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ return PropertyUtilsBean.getInstance().getSimpleProperty(bean, name);
+
+ }
+
+
+ /**
+ * <p>Return an accessible property setter method for this property,
+ * if there is one; otherwise return <code>null</code>.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param descriptor Property descriptor to return a setter for
+ * @return The write method
+ * @see PropertyUtilsBean#getWriteMethod(PropertyDescriptor)
+ */
+ public static Method getWriteMethod(final PropertyDescriptor descriptor) {
+
+ return PropertyUtilsBean.getInstance().getWriteMethod(descriptor);
+
+ }
+
+
+ /**
+ * <p>Return <code>true</code> if the specified property name identifies
+ * a readable property on the specified bean; otherwise, return
+ * <code>false</code>.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean to be examined (may be a {@link DynaBean}
+ * @param name Property name to be evaluated
+ * @return <code>true</code> if the property is readable,
+ * otherwise <code>false</code>
+ *
+ * @throws IllegalArgumentException if <code>bean</code>
+ * or <code>name</code> is <code>null</code>
+ * @see PropertyUtilsBean#isReadable
+ * @since BeanUtils 1.6
+ */
+ public static boolean isReadable(final Object bean, final String name) {
+
+ return PropertyUtilsBean.getInstance().isReadable(bean, name);
+ }
+
+
+ /**
+ * <p>Return <code>true</code> if the specified property name identifies
+ * a writeable property on the specified bean; otherwise, return
+ * <code>false</code>.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean to be examined (may be a {@link DynaBean}
+ * @param name Property name to be evaluated
+ * @return <code>true</code> if the property is writeable,
+ * otherwise <code>false</code>
+ *
+ * @throws IllegalArgumentException if <code>bean</code>
+ * or <code>name</code> is <code>null</code>
+ * @see PropertyUtilsBean#isWriteable
+ * @since BeanUtils 1.6
+ */
+ public static boolean isWriteable(final Object bean, final String name) {
+
+ return PropertyUtilsBean.getInstance().isWriteable(bean, name);
+ }
+
+
+ /**
+ * <p>Sets 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 modified
+ * @param name <code>propertyname[index]</code> of the property value
+ * to be modified
+ * @param value Value to which the specified property element
+ * should be set
+ *
+ * @throws IndexOutOfBoundsException if the specified index
+ * is outside the valid range for the underlying property
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
+ */
+ public static void setIndexedProperty(final Object bean, final String name,
+ final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, value);
+
+ }
+
+
+ /**
+ * <p>Sets 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 set
+ * @param name Simple property name of the property value to be set
+ * @param index Index of the property value to be set
+ * @param value Value to which the indexed property element is to be set
+ *
+ * @throws IndexOutOfBoundsException if the specified index
+ * is outside the valid range for the underlying property
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
+ */
+ public static void setIndexedProperty(final Object bean, final String name,
+ final int index, final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, index, value);
+ }
+
+
+ /**
+ * <p>Sets 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 set
+ * @param name <code>propertyname(key)</code> of the property value
+ * to be set
+ * @param value The property value to be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setMappedProperty(Object, String, Object)
+ */
+ public static void setMappedProperty(final Object bean, final String name,
+ final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setMappedProperty(bean, name, value);
+ }
+
+
+ /**
+ * <p>Sets 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 set
+ * @param name Mapped property name of the property value to be set
+ * @param key Key of the property value to be set
+ * @param value The property value to be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setMappedProperty(Object, String, String, Object)
+ */
+ public static void setMappedProperty(final Object bean, final String name,
+ final String key, final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setMappedProperty(bean, name, key, value);
+ }
+
+
+ /**
+ * <p>Sets the value of the (possibly nested) property of the specified
+ * name, for 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 modified
+ * @param name Possibly nested name of the property to be modified
+ * @param value Value to which the property is to be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if a nested reference to a
+ * property returns null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setNestedProperty
+ */
+ public static void setNestedProperty(final Object bean,
+ final String name, final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setNestedProperty(bean, name, value);
+ }
+
+
+ /**
+ * <p>Set the value of the specified property of the specified bean,
+ * no matter which property reference format is used, with no
+ * type conversions.</p>
+ *
+ * <p>For more details see <code>PropertyUtilsBean</code>.</p>
+ *
+ * @param bean Bean whose property is to be modified
+ * @param name Possibly indexed and/or nested name of the property
+ * to be modified
+ * @param value Value to which this property is to be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setProperty
+ */
+ public static void setProperty(final Object bean, final String name, final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setProperty(bean, name, value);
+
+ }
+
+
+ /**
+ * <p>Set the value of the specified simple 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 modified
+ * @param name Name of the property to be modified
+ * @param value Value to which the property should be set
+ *
+ * @throws IllegalAccessException if the caller does not have
+ * access to the property accessor method
+ * @throws IllegalArgumentException if <code>bean</code> or
+ * <code>name</code> is null
+ * @throws IllegalArgumentException if the property name is
+ * nested or indexed
+ * @throws InvocationTargetException if the property accessor method
+ * throws an exception
+ * @throws NoSuchMethodException if an accessor method for this
+ * propety cannot be found
+ * @see PropertyUtilsBean#setSimpleProperty
+ */
+ public static void setSimpleProperty(final Object bean,
+ final String name, final Object value)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException {
+
+ PropertyUtilsBean.getInstance().setSimpleProperty(bean, name, value);
+ }
+
+
+}
diff --git a/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java b/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java
index e81e213..00f1008 100644
--- a/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java
+++ b/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java
@@ -1,411 +1,411 @@
-/*
- * 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.beanutils2;
-
-
-import java.beans.PropertyDescriptor;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-
-/**
- * Implementation of {@link DynaClass} that wrap
- * standard JavaBean instances.
- * <p>
- * This class should not usually need to be used directly
- * to create new {@link WrapDynaBean} instances -
- * it's usually better to call the {@link WrapDynaBean} constructor.
- * For example:
- * </p>
- * <pre>
- * Object javaBean = ...;
- * DynaBean wrapper = new WrapDynaBean(javaBean);
- * </pre>
- *
- */
-
-public class WrapDynaClass implements DynaClass {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a new WrapDynaClass for the specified JavaBean class. This
- * constructor is private; WrapDynaClass instances will be created as
- * needed via calls to the <code>createDynaClass(Class)</code> method.
- *
- * @param beanClass JavaBean class to be introspected around
- * @param propUtils the {@code PropertyUtilsBean} associated with this class
- */
- private WrapDynaClass(final Class<?> beanClass, final PropertyUtilsBean propUtils) {
-
- this.beanClassRef = new SoftReference<Class<?>>(beanClass);
- this.beanClassName = beanClass.getName();
- propertyUtilsBean = propUtils;
- introspect();
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * Name of the JavaBean class represented by this WrapDynaClass.
- */
- private String beanClassName = null;
-
- /**
- * Reference to the JavaBean class represented by this WrapDynaClass.
- */
- private Reference<Class<?>> beanClassRef = null;
-
- /** Stores the associated {@code PropertyUtilsBean} instance. */
- private final PropertyUtilsBean propertyUtilsBean;
-
- /**
- * The set of PropertyDescriptors for this bean class.
- */
- protected PropertyDescriptor[] descriptors = null;
-
-
- /**
- * The set of PropertyDescriptors for this bean class, keyed by the
- * property name. Individual descriptor instances will be the same
- * instances as those in the <code>descriptors</code> list.
- */
- protected HashMap<String, PropertyDescriptor> descriptorsMap = new HashMap<>();
-
-
- /**
- * The set of dynamic properties that are part of this DynaClass.
- */
- protected DynaProperty[] properties = null;
-
-
- /**
- * The set of dynamic properties that are part of this DynaClass,
- * keyed by the property name. Individual descriptor instances will
- * be the same instances as those in the <code>properties</code> list.
- */
- protected HashMap<String, DynaProperty> propertiesMap = new HashMap<>();
-
-
- // ------------------------------------------------------- Static Variables
-
-
- private static final ContextClassLoaderLocal<Map<CacheKey, WrapDynaClass>> CLASSLOADER_CACHE =
- new ContextClassLoaderLocal<Map<CacheKey, WrapDynaClass>>() {
- @Override
- protected Map<CacheKey, WrapDynaClass> initialValue() {
- return new WeakHashMap<>();
- }
- };
-
- /**
- * Returns the cache for the already created class instances. For each
- * combination of bean class and {@code PropertyUtilsBean} instance an
- * entry is created in the cache.
- * @return the cache for already created {@code WrapDynaClass} instances
- */
- private static Map<CacheKey, WrapDynaClass> getClassesCache() {
- return CLASSLOADER_CACHE.get();
- }
-
-
-
-
- // ------------------------------------------------------ DynaClass Methods
-
- /**
- * Return the class of the underlying wrapped bean.
- *
- * @return the class of the underlying wrapped bean
- * @since 1.8.0
- */
- protected Class<?> getBeanClass() {
- return beanClassRef.get();
- }
-
- /**
- * Return the name of this DynaClass (analogous to the
- * {@code getName()} method of {@code java.lang.Class}, which
- * allows the same {@code DynaClass} implementation class to support
- * different dynamic classes, with different sets of properties.
- *
- * @return the name of the DynaClass
- */
- @Override
- public String getName() {
-
- return beanClassName;
-
- }
-
-
- /**
- * Return a property descriptor for the specified property, if it exists;
- * otherwise, return <code>null</code>.
- *
- * @param name Name of the dynamic property for which a descriptor
- * is requested
- * @return The descriptor for the specified property
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public DynaProperty getDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException
- ("No property name specified");
- }
- return propertiesMap.get(name);
-
- }
-
-
- /**
- * <p>Return an array of <code>ProperyDescriptors</code> for the properties
- * currently defined in this DynaClass. If no properties are defined, a
- * zero-length array will be returned.</p>
- *
- * <p><strong>FIXME</strong> - Should we really be implementing
- * <code>getBeanInfo()</code> instead, which returns property descriptors
- * and a bunch of other stuff?</p>
- *
- * @return the set of properties for this DynaClass
- */
- @Override
- public DynaProperty[] getDynaProperties() {
-
- return properties;
-
- }
-
-
- /**
- * <p>Instantiates a new standard JavaBean instance associated with
- * this DynaClass and return it wrapped in a new WrapDynaBean
- * instance. <strong>NOTE</strong> the JavaBean should have a
- * no argument constructor.</p>
- *
- * <p><strong>NOTE</strong> - Most common use cases should not need to use
- * this method. It is usually better to create new
- * <code>WrapDynaBean</code> instances by calling its constructor.
- * For example:</p>
- * <pre><code>
- * Object javaBean = ...;
- * DynaBean wrapper = new WrapDynaBean(javaBean);
- * </code></pre>
- * <p>
- * (This method is needed for some kinds of <code>DynaBean</code> framework.)
- * </p>
- *
- * @return A new <code>DynaBean</code> instance
- * @throws IllegalAccessException if the Class or the appropriate
- * constructor is not accessible
- * @throws InstantiationException if this Class represents an abstract
- * class, an array class, a primitive type, or void; or if instantiation
- * fails for some other reason
- */
- @Override
- public DynaBean newInstance()
- throws IllegalAccessException, InstantiationException {
-
- return new WrapDynaBean(getBeanClass().newInstance());
-
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Return the PropertyDescriptor for the specified property name, if any;
- * otherwise return <code>null</code>.
- *
- * @param name Name of the property to be retrieved
- * @return The descriptor for the specified property
- */
- public PropertyDescriptor getPropertyDescriptor(final String name) {
-
- return descriptorsMap.get(name);
-
- }
-
-
- // --------------------------------------------------------- Static Methods
-
-
- /**
- * Clear our cache of WrapDynaClass instances.
- */
- public static void clear() {
-
- getClassesCache().clear();
-
- }
-
-
- /**
- * Create (if necessary) and return a new <code>WrapDynaClass</code>
- * instance for the specified bean class.
- *
- * @param beanClass Bean class for which a WrapDynaClass is requested
- * @return A new <i>Wrap</i> {@link DynaClass}
- */
- public static WrapDynaClass createDynaClass(final Class<?> beanClass) {
-
- return createDynaClass(beanClass, null);
-
- }
-
-
- /**
- * Create (if necessary) and return a new {@code WrapDynaClass} instance
- * for the specified bean class using the given {@code PropertyUtilsBean}
- * instance for introspection. Using this method a specially configured
- * {@code PropertyUtilsBean} instance can be hooked into the introspection
- * mechanism of the managed bean. The argument is optional; if no
- * {@code PropertyUtilsBean} object is provided, the default instance is used.
- * @param beanClass Bean class for which a WrapDynaClass is requested
- * @param pu the optional {@code PropertyUtilsBean} to be used for introspection
- * @return A new <i>Wrap</i> {@link DynaClass}
- * @since 1.9
- */
- public static WrapDynaClass createDynaClass(final Class<?> beanClass, final PropertyUtilsBean pu) {
-
- final PropertyUtilsBean propUtils = pu != null ? pu : PropertyUtilsBean.getInstance();
- final CacheKey key = new CacheKey(beanClass, propUtils);
- WrapDynaClass dynaClass = getClassesCache().get(key);
- if (dynaClass == null) {
- dynaClass = new WrapDynaClass(beanClass, propUtils);
- getClassesCache().put(key, dynaClass);
- }
- return dynaClass;
-
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Returns the {@code PropertyUtilsBean} instance associated with this class. This
- * bean is used for introspection.
- *
- * @return the associated {@code PropertyUtilsBean} instance
- * @since 1.9
- */
- protected PropertyUtilsBean getPropertyUtilsBean() {
- return propertyUtilsBean;
- }
-
- /**
- * Introspect our bean class to identify the supported properties.
- */
- protected void introspect() {
-
- // Look up the property descriptors for this bean class
- final Class<?> beanClass = getBeanClass();
- PropertyDescriptor[] regulars =
- getPropertyUtilsBean().getPropertyDescriptors(beanClass);
- if (regulars == null) {
- regulars = new PropertyDescriptor[0];
- }
- Map<?, ?> mappeds =
- PropertyUtils.getMappedPropertyDescriptors(beanClass);
- if (mappeds == null) {
- mappeds = new HashMap<>();
- }
-
- // Construct corresponding DynaProperty information
- properties = new DynaProperty[regulars.length + mappeds.size()];
- for (int i = 0; i < regulars.length; i++) {
- descriptorsMap.put(regulars[i].getName(),
- regulars[i]);
- properties[i] =
- new DynaProperty(regulars[i].getName(),
- regulars[i].getPropertyType());
- propertiesMap.put(properties[i].getName(),
- properties[i]);
- }
- int j = regulars.length;
- for (final Map.Entry<?, ?> entry : mappeds.entrySet()) {
- final String name = (String) entry.getKey();
- final PropertyDescriptor descriptor =
- (PropertyDescriptor) entry.getValue();
- properties[j] =
- new DynaProperty(descriptor.getName(),
- Map.class);
- propertiesMap.put(properties[j].getName(),
- properties[j]);
- j++;
- }
-
- }
-
- /**
- * A class representing the combined key for the cache of {@code WrapDynaClass}
- * instances. A single key consists of a bean class and an instance of
- * {@code PropertyUtilsBean}. Instances are immutable.
- */
- private static class CacheKey {
- /** The bean class. */
- private final Class<?> beanClass;
-
- /** The instance of PropertyUtilsBean. */
- private final PropertyUtilsBean propUtils;
-
- /**
- * Creates a new instance of {@code CacheKey}.
- *
- * @param beanCls the bean class
- * @param pu the instance of {@code PropertyUtilsBean}
- */
- public CacheKey(final Class<?> beanCls, final PropertyUtilsBean pu) {
- beanClass = beanCls;
- propUtils = pu;
- }
-
- @Override
- public int hashCode() {
- final int factor = 31;
- int result = 17;
- result = factor * beanClass.hashCode() + result;
- result = factor * propUtils.hashCode() + result;
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof CacheKey)) {
- return false;
- }
-
- final CacheKey c = (CacheKey) obj;
- return beanClass.equals(c.beanClass) && propUtils.equals(c.propUtils);
- }
- }
-}
+/*
+ * 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.beanutils2;
+
+
+import java.beans.PropertyDescriptor;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+
+/**
+ * Implementation of {@link DynaClass} that wrap
+ * standard JavaBean instances.
+ * <p>
+ * This class should not usually need to be used directly
+ * to create new {@link WrapDynaBean} instances -
+ * it's usually better to call the {@link WrapDynaBean} constructor.
+ * For example:
+ * </p>
+ * <pre>
+ * Object javaBean = ...;
+ * DynaBean wrapper = new WrapDynaBean(javaBean);
+ * </pre>
+ *
+ */
+
+public class WrapDynaClass implements DynaClass {
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Construct a new WrapDynaClass for the specified JavaBean class. This
+ * constructor is private; WrapDynaClass instances will be created as
+ * needed via calls to the <code>createDynaClass(Class)</code> method.
+ *
+ * @param beanClass JavaBean class to be introspected around
+ * @param propUtils the {@code PropertyUtilsBean} associated with this class
+ */
+ private WrapDynaClass(final Class<?> beanClass, final PropertyUtilsBean propUtils) {
+
+ this.beanClassRef = new SoftReference<Class<?>>(beanClass);
+ this.beanClassName = beanClass.getName();
+ propertyUtilsBean = propUtils;
+ introspect();
+
+ }
+
+
+ // ----------------------------------------------------- Instance Variables
+
+ /**
+ * Name of the JavaBean class represented by this WrapDynaClass.
+ */
+ private String beanClassName = null;
+
+ /**
+ * Reference to the JavaBean class represented by this WrapDynaClass.
+ */
+ private Reference<Class<?>> beanClassRef = null;
+
+ /** Stores the associated {@code PropertyUtilsBean} instance. */
+ private final PropertyUtilsBean propertyUtilsBean;
+
+ /**
+ * The set of PropertyDescriptors for this bean class.
+ */
+ protected PropertyDescriptor[] descriptors = null;
+
+
+ /**
+ * The set of PropertyDescriptors for this bean class, keyed by the
+ * property name. Individual descriptor instances will be the same
+ * instances as those in the <code>descriptors</code> list.
+ */
+ protected HashMap<String, PropertyDescriptor> descriptorsMap = new HashMap<>();
+
+
+ /**
+ * The set of dynamic properties that are part of this DynaClass.
+ */
+ protected DynaProperty[] properties = null;
+
+
+ /**
+ * The set of dynamic properties that are part of this DynaClass,
+ * keyed by the property name. Individual descriptor instances will
+ * be the same instances as those in the <code>properties</code> list.
+ */
+ protected HashMap<String, DynaProperty> propertiesMap = new HashMap<>();
+
+
+ // ------------------------------------------------------- Static Variables
+
+
+ private static final ContextClassLoaderLocal<Map<CacheKey, WrapDynaClass>> CLASSLOADER_CACHE =
+ new ContextClassLoaderLocal<Map<CacheKey, WrapDynaClass>>() {
+ @Override
+ protected Map<CacheKey, WrapDynaClass> initialValue() {
+ return new WeakHashMap<>();
+ }
+ };
+
+ /**
+ * Returns the cache for the already created class instances. For each
+ * combination of bean class and {@code PropertyUtilsBean} instance an
+ * entry is created in the cache.
+ * @return the cache for already created {@code WrapDynaClass} instances
+ */
+ private static Map<CacheKey, WrapDynaClass> getClassesCache() {
+ return CLASSLOADER_CACHE.get();
+ }
+
+
+
+
+ // ------------------------------------------------------ DynaClass Methods
+
+ /**
+ * Return the class of the underlying wrapped bean.
+ *
+ * @return the class of the underlying wrapped bean
+ * @since 1.8.0
+ */
+ protected Class<?> getBeanClass() {
+ return beanClassRef.get();
+ }
+
+ /**
+ * Return the name of this DynaClass (analogous to the
+ * {@code getName()} method of {@code java.lang.Class}, which
+ * allows the same {@code DynaClass} implementation class to support
+ * different dynamic classes, with different sets of properties.
+ *
+ * @return the name of the DynaClass
+ */
+ @Override
+ public String getName() {
+
+ return beanClassName;
+
+ }
+
+
+ /**
+ * Return a property descriptor for the specified property, if it exists;
+ * otherwise, return <code>null</code>.
+ *
+ * @param name Name of the dynamic property for which a descriptor
+ * is requested
+ * @return The descriptor for the specified property
+ *
+ * @throws IllegalArgumentException if no property name is specified
+ */
+ @Override
+ public DynaProperty getDynaProperty(final String name) {
+
+ if (name == null) {
+ throw new IllegalArgumentException
+ ("No property name specified");
+ }
+ return propertiesMap.get(name);
+
+ }
+
+
+ /**
+ * <p>Return an array of <code>ProperyDescriptors</code> for the properties
+ * currently defined in this DynaClass. If no properties are defined, a
+ * zero-length array will be returned.</p>
+ *
+ * <p><strong>FIXME</strong> - Should we really be implementing
+ * <code>getBeanInfo()</code> instead, which returns property descriptors
+ * and a bunch of other stuff?</p>
+ *
+ * @return the set of properties for this DynaClass
+ */
+ @Override
+ public DynaProperty[] getDynaProperties() {
+
+ return properties;
+
+ }
+
+
+ /**
+ * <p>Instantiates a new standard JavaBean instance associated with
+ * this DynaClass and return it wrapped in a new WrapDynaBean
+ * instance. <strong>NOTE</strong> the JavaBean should have a
+ * no argument constructor.</p>
+ *
+ * <p><strong>NOTE</strong> - Most common use cases should not need to use
+ * this method. It is usually better to create new
+ * <code>WrapDynaBean</code> instances by calling its constructor.
+ * For example:</p>
+ * <pre><code>
+ * Object javaBean = ...;
+ * DynaBean wrapper = new WrapDynaBean(javaBean);
+ * </code></pre>
+ * <p>
+ * (This method is needed for some kinds of <code>DynaBean</code> framework.)
+ * </p>
+ *
+ * @return A new <code>DynaBean</code> instance
+ * @throws IllegalAccessException if the Class or the appropriate
+ * constructor is not accessible
+ * @throws InstantiationException if this Class represents an abstract
+ * class, an array class, a primitive type, or void; or if instantiation
+ * fails for some other reason
+ */
+ @Override
+ public DynaBean newInstance()
+ throws IllegalAccessException, InstantiationException {
+
+ return new WrapDynaBean(getBeanClass().newInstance());
+
+ }
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Return the PropertyDescriptor for the specified property name, if any;
+ * otherwise return <code>null</code>.
+ *
+ * @param name Name of the property to be retrieved
+ * @return The descriptor for the specified property
+ */
+ public PropertyDescriptor getPropertyDescriptor(final String name) {
+
+ return descriptorsMap.get(name);
+
+ }
+
+
+ // --------------------------------------------------------- Static Methods
+
+
+ /**
+ * Clear our cache of WrapDynaClass instances.
+ */
+ public static void clear() {
+
+ getClassesCache().clear();
+
+ }
+
+
+ /**
+ * Create (if necessary) and return a new <code>WrapDynaClass</code>
+ * instance for the specified bean class.
+ *
+ * @param beanClass Bean class for which a WrapDynaClass is requested
+ * @return A new <i>Wrap</i> {@link DynaClass}
+ */
+ public static WrapDynaClass createDynaClass(final Class<?> beanClass) {
+
+ return createDynaClass(beanClass, null);
+
+ }
+
+
+ /**
+ * Create (if necessary) and return a new {@code WrapDynaClass} instance
+ * for the specified bean class using the given {@code PropertyUtilsBean}
+ * instance for introspection. Using this method a specially configured
+ * {@code PropertyUtilsBean} instance can be hooked into the introspection
+ * mechanism of the managed bean. The argument is optional; if no
+ * {@code PropertyUtilsBean} object is provided, the default instance is used.
+ * @param beanClass Bean class for which a WrapDynaClass is requested
+ * @param pu the optional {@code PropertyUtilsBean} to be used for introspection
+ * @return A new <i>Wrap</i> {@link DynaClass}
+ * @since 1.9
+ */
+ public static WrapDynaClass createDynaClass(final Class<?> beanClass, final PropertyUtilsBean pu) {
+
+ final PropertyUtilsBean propUtils = pu != null ? pu : PropertyUtilsBean.getInstance();
+ final CacheKey key = new CacheKey(beanClass, propUtils);
+ WrapDynaClass dynaClass = getClassesCache().get(key);
+ if (dynaClass == null) {
+ dynaClass = new WrapDynaClass(beanClass, propUtils);
+ getClassesCache().put(key, dynaClass);
+ }
+ return dynaClass;
+
+ }
+
+
+ // ------------------------------------------------------ Protected Methods
+
+ /**
+ * Returns the {@code PropertyUtilsBean} instance associated with this class. This
+ * bean is used for introspection.
+ *
+ * @return the associated {@code PropertyUtilsBean} instance
+ * @since 1.9
+ */
+ protected PropertyUtilsBean getPropertyUtilsBean() {
+ return propertyUtilsBean;
+ }
+
+ /**
+ * Introspect our bean class to identify the supported properties.
+ */
+ protected void introspect() {
+
+ // Look up the property descriptors for this bean class
+ final Class<?> beanClass = getBeanClass();
+ PropertyDescriptor[] regulars =
+ getPropertyUtilsBean().getPropertyDescriptors(beanClass);
+ if (regulars == null) {
+ regulars = new PropertyDescriptor[0];
+ }
+ Map<?, ?> mappeds =
+ PropertyUtils.getMappedPropertyDescriptors(beanClass);
+ if (mappeds == null) {
+ mappeds = new HashMap<>();
+ }
+
+ // Construct corresponding DynaProperty information
+ properties = new DynaProperty[regulars.length + mappeds.size()];
+ for (int i = 0; i < regulars.length; i++) {
+ descriptorsMap.put(regulars[i].getName(),
+ regulars[i]);
+ properties[i] =
+ new DynaProperty(regulars[i].getName(),
+ regulars[i].getPropertyType());
+ propertiesMap.put(properties[i].getName(),
+ properties[i]);
+ }
+ int j = regulars.length;
+ for (final Map.Entry<?, ?> entry : mappeds.entrySet()) {
+ final String name = (String) entry.getKey();
+ final PropertyDescriptor descriptor =
+ (PropertyDescriptor) entry.getValue();
+ properties[j] =
+ new DynaProperty(descriptor.getName(),
+ Map.class);
+ propertiesMap.put(properties[j].getName(),
+ properties[j]);
+ j++;
+ }
+
+ }
+
+ /**
+ * A class representing the combined key for the cache of {@code WrapDynaClass}
+ * instances. A single key consists of a bean class and an instance of
+ * {@code PropertyUtilsBean}. Instances are immutable.
+ */
+ private static class CacheKey {
+ /** The bean class. */
+ private final Class<?> beanClass;
+
+ /** The instance of PropertyUtilsBean. */
+ private final PropertyUtilsBean propUtils;
+
+ /**
+ * Creates a new instance of {@code CacheKey}.
+ *
+ * @param beanCls the bean class
+ * @param pu the instance of {@code PropertyUtilsBean}
+ */
+ public CacheKey(final Class<?> beanCls, final PropertyUtilsBean pu) {
+ beanClass = beanCls;
+ propUtils = pu;
+ }
+
+ @Override
+ public int hashCode() {
+ final int factor = 31;
+ int result = 17;
+ result = factor * beanClass.hashCode() + result;
+ result = factor * propUtils.hashCode() + result;
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CacheKey)) {
+ return false;
+ }
+
+ final CacheKey c = (CacheKey) obj;
+ return beanClass.equals(c.beanClass) && propUtils.equals(c.propUtils);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java
index 4b76da2..ce28ca4 100644
--- a/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java
+++ b/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java
@@ -1,226 +1,226 @@
-/*
- * 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.beanutils2.converters;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from <b>Boolean</b> objects.
- * {@link org.apache.commons.beanutils2.Converter} implementation that
- * handles conversion to and from <b>java.lang.Boolean</b> objects.
- * <p>
- * Can be configured to either return a <i>default value</i> or throw a
- * <code>ConversionException</code> if a conversion error occurs.
- * </p>
- * <p>
- * By default any object whose string representation is one of the values
- * {"yes", "y", "true", "on", "1"} is converted to Boolean.TRUE, and
- * string representations {"no", "n", "false", "off", "0"} are converted
- * to Boolean.FALSE. The recognized true/false strings can be changed by:
- * </p>
- * <pre>
- * String[] trueStrings = {"oui", "o", "1"};
- * String[] falseStrings = {"non", "n", "0"};
- * Converter bc = new BooleanConverter(trueStrings, falseStrings);
- * ConvertUtils.register(bc, Boolean.class);
- * ConvertUtils.register(bc, Boolean.TYPE);
- * </pre>
- *
- * <p>Case is ignored when converting values to true or false.</p>
- *
- * @since 1.3
- */
-public final class BooleanConverter extends AbstractConverter {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Create a {@link org.apache.commons.beanutils2.Converter} that will throw a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs, ie the string value being converted is
- * not one of the known true strings, nor one of the known false strings.
- */
- public BooleanConverter() {
- super();
- }
-
-
- /**
- * Create a {@link org.apache.commons.beanutils2.Converter} that will return the specified default value
- * if a conversion error occurs, ie the string value being converted is
- * not one of the known true strings, nor one of the known false strings.
- *
- * @param defaultValue The default value to be returned if the value
- * being converted is not recognized. This value may be null, in which
- * case null will be returned on conversion failure. When non-null, it is
- * expected that this value will be either Boolean.TRUE or Boolean.FALSE.
- * The special value BooleanConverter.NO_DEFAULT can also be passed here,
- * in which case this constructor acts like the no-argument one.
- */
- public BooleanConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.Converter} that will throw a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs, ie the string value being converted is
- * not one of the known true strings, nor one of the known false strings.
- * <p>
- * The provided string arrays are copied, so that changes to the elements
- * of the array after this call is made do not affect this object.
- *
- * @param trueStrings is the set of strings which should convert to the
- * value Boolean.TRUE. The value null must not be present. Case is
- * ignored.
- *
- * @param falseStrings is the set of strings which should convert to the
- * value Boolean.TRUE. The value null must not be present. Case is
- * ignored.
- * @since 1.8.0
- */
- public BooleanConverter(final String[] trueStrings, final String[] falseStrings) {
- super();
- this.trueStrings = copyStrings(trueStrings);
- this.falseStrings = copyStrings(falseStrings);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.Converter} that will return
- * the specified default value if a conversion error occurs.
- * <p>
- * The provided string arrays are copied, so that changes to the elements
- * of the array after this call is made do not affect this object.
- *
- * @param trueStrings is the set of strings which should convert to the
- * value Boolean.TRUE. The value null must not be present. Case is
- * ignored.
- *
- * @param falseStrings is the set of strings which should convert to the
- * value Boolean.TRUE. The value null must not be present. Case is
- * ignored.
- *
- * @param defaultValue The default value to be returned if the value
- * being converted is not recognized. This value may be null, in which
- * case null will be returned on conversion failure. When non-null, it is
- * expected that this value will be either Boolean.TRUE or Boolean.FALSE.
- * The special value BooleanConverter.NO_DEFAULT can also be passed here,
- * in which case an exception will be thrown on conversion failure.
- * @since 1.8.0
- */
- public BooleanConverter(final String[] trueStrings, final String[] falseStrings,
- final Object defaultValue) {
- super(defaultValue);
- this.trueStrings = copyStrings(trueStrings);
- this.falseStrings = copyStrings(falseStrings);
- }
-
-
- // ----------------------------------------------------- Static Variables
-
-
-
-
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * The set of strings that are known to map to Boolean.TRUE.
- */
- private String[] trueStrings = {"true", "yes", "y", "on", "1"};
-
- /**
- * The set of strings that are known to map to Boolean.FALSE.
- */
- private String[] falseStrings = {"false", "no", "n", "off", "0"};
-
- // --------------------------------------------------------- Protected Methods
-
- /**
- * Return the default type this <code>Converter</code> handles.
- *
- * @return The default type this <code>Converter</code> handles.
- * @since 1.8.0
- */
- @Override
- protected Class<Boolean> getDefaultType() {
- return Boolean.class;
- }
-
- /**
- * Convert the specified input object into an output object of the
- * specified type.
- *
- * @param <T> Target type of the conversion.
- * @param type is the type to which this value should be converted. In the
- * case of this BooleanConverter class, this value is ignored.
- *
- * @param value is the input value to be converted. The toString method
- * shall be invoked on this object, and the result compared (ignoring
- * case) against the known "true" and "false" string values.
- *
- * @return Boolean.TRUE if the value was a recognized "true" value,
- * Boolean.FALSE if the value was a recognized "false" value, or
- * the default value if the value was not recognized and the constructor
- * was provided with a default value.
- *
- * @throws Throwable if an error occurs converting to the specified type
- * @since 1.8.0
- */
- @Override
- protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
-
- if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) {
- // All the values in the trueStrings and falseStrings arrays are
- // guaranteed to be lower-case. By converting the input value
- // to lowercase too, we can use the efficient String.equals method
- // instead of the less-efficient String.equalsIgnoreCase method.
- final String stringValue = value.toString().toLowerCase();
-
- for (final String trueString : trueStrings) {
- if (trueString.equals(stringValue)) {
- return type.cast(Boolean.TRUE);
- }
- }
-
- for (final String falseString : falseStrings) {
- if (falseString.equals(stringValue)) {
- return type.cast(Boolean.FALSE);
- }
- }
- }
-
- throw conversionException(type, value);
- }
-
- /**
- * This method creates a copy of the provided array, and ensures that
- * all the strings in the newly created array contain only lower-case
- * letters.
- * <p>
- * Using this method to copy string arrays means that changes to the
- * src array do not modify the dst array.
- */
- private static String[] copyStrings(final String[] src) {
- final String[] dst = new String[src.length];
- for(int i=0; i<src.length; ++i) {
- dst[i] = src[i].toLowerCase();
- }
- return dst;
- }
-}
+/*
+ * 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.beanutils2.converters;
+
+/**
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
+ * to and from <b>Boolean</b> objects.
+ * {@link org.apache.commons.beanutils2.Converter} implementation that
+ * handles conversion to and from <b>java.lang.Boolean</b> objects.
+ * <p>
+ * Can be configured to either return a <i>default value</i> or throw a
+ * <code>ConversionException</code> if a conversion error occurs.
+ * </p>
+ * <p>
+ * By default any object whose string representation is one of the values
+ * {"yes", "y", "true", "on", "1"} is converted to Boolean.TRUE, and
+ * string representations {"no", "n", "false", "off", "0"} are converted
+ * to Boolean.FALSE. The recognized true/false strings can be changed by:
+ * </p>
+ * <pre>
+ * String[] trueStrings = {"oui", "o", "1"};
+ * String[] falseStrings = {"non", "n", "0"};
+ * Converter bc = new BooleanConverter(trueStrings, falseStrings);
+ * ConvertUtils.register(bc, Boolean.class);
+ * ConvertUtils.register(bc, Boolean.TYPE);
+ * </pre>
+ *
+ * <p>Case is ignored when converting values to true or false.</p>
+ *
+ * @since 1.3
+ */
+public final class BooleanConverter extends AbstractConverter {
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Create a {@link org.apache.commons.beanutils2.Converter} that will throw a
+ * {@link org.apache.commons.beanutils2.ConversionException}
+ * if a conversion error occurs, ie the string value being converted is
+ * not one of the known true strings, nor one of the known false strings.
+ */
+ public BooleanConverter() {
+ super();
+ }
+
+
+ /**
+ * Create a {@link org.apache.commons.beanutils2.Converter} that will return the specified default value
+ * if a conversion error occurs, ie the string value being converted is
+ * not one of the known true strings, nor one of the known false strings.
+ *
+ * @param defaultValue The default value to be returned if the value
+ * being converted is not recognized. This value may be null, in which
+ * case null will be returned on conversion failure. When non-null, it is
+ * expected that this value will be either Boolean.TRUE or Boolean.FALSE.
+ * The special value BooleanConverter.NO_DEFAULT can also be passed here,
+ * in which case this constructor acts like the no-argument one.
+ */
+ public BooleanConverter(final Object defaultValue) {
+ super(defaultValue);
+ }
+
+ /**
+ * Create a {@link org.apache.commons.beanutils2.Converter} that will throw a
+ * {@link org.apache.commons.beanutils2.ConversionException}
+ * if a conversion error occurs, ie the string value being converted is
+ * not one of the known true strings, nor one of the known false strings.
+ * <p>
+ * The provided string arrays are copied, so that changes to the elements
+ * of the array after this call is made do not affect this object.
+ *
+ * @param trueStrings is the set of strings which should convert to the
+ * value Boolean.TRUE. The value null must not be present. Case is
+ * ignored.
+ *
+ * @param falseStrings is the set of strings which should convert to the
+ * value Boolean.TRUE. The value null must not be present. Case is
+ * ignored.
+ * @since 1.8.0
+ */
+ public BooleanConverter(final String[] trueStrings, final String[] falseStrings) {
+ super();
+ this.trueStrings = copyStrings(trueStrings);
+ this.falseStrings = copyStrings(falseStrings);
+ }
+
+ /**
+ * Create a {@link org.apache.commons.beanutils2.Converter} that will return
+ * the specified default value if a conversion error occurs.
+ * <p>
+ * The provided string arrays are copied, so that changes to the elements
+ * of the array after this call is made do not affect this object.
+ *
+ * @param trueStrings is the set of strings which should convert to the
+ * value Boolean.TRUE. The value null must not be present. Case is
+ * ignored.
+ *
+ * @param falseStrings is the set of strings which should convert to the
+ * value Boolean.TRUE. The value null must not be present. Case is
+ * ignored.
+ *
+ * @param defaultValue The default value to be returned if the value
+ * being converted is not recognized. This value may be null, in which
+ * case null will be returned on conversion failure. When non-null, it is
+ * expected that this value will be either Boolean.TRUE or Boolean.FALSE.
+ * The special value BooleanConverter.NO_DEFAULT can also be passed here,
+ * in which case an exception will be thrown on conversion failure.
+ * @since 1.8.0
+ */
+ public BooleanConverter(final String[] trueStrings, final String[] falseStrings,
+ final Object defaultValue) {
+ super(defaultValue);
+ this.trueStrings = copyStrings(trueStrings);
+ this.falseStrings = copyStrings(falseStrings);
+ }
+
+
+ // ----------------------------------------------------- Static Variables
+
+
+
+
+
+ // ----------------------------------------------------- Instance Variables
+
+ /**
+ * The set of strings that are known to map to Boolean.TRUE.
+ */
+ private String[] trueStrings = {"true", "yes", "y", "on", "1"};
+
+ /**
+ * The set of strings that are known to map to Boolean.FALSE.
+ */
+ private String[] falseStrings = {"false", "no", "n", "off", "0"};
+
+ // --------------------------------------------------------- Protected Methods
+
+ /**
+ * Return the default type this <code>Converter</code> handles.
+ *
+ * @return The default type this <code>Converter</code> handles.
+ * @since 1.8.0
+ */
+ @Override
+ protected Class<Boolean> getDefaultType() {
+ return Boolean.class;
+ }
+
+ /**
+ * Convert the specified input object into an output object of the
+ * specified type.
+ *
+ * @param <T> Target type of the conversion.
+ * @param type is the type to which this value should be converted. In the
+ * case of this BooleanConverter class, this value is ignored.
+ *
+ * @param value is the input value to be converted. The toString method
+ * shall be invoked on this object, and the result compared (ignoring
+ * case) against the known "true" and "false" string values.
+ *
+ * @return Boolean.TRUE if the value was a recognized "true" value,
+ * Boolean.FALSE if the value was a recognized "false" value, or
+ * the default value if the value was not recognized and the constructor
+ * was provided with a default value.
+ *
+ * @throws Throwable if an error occurs converting to the specified type
+ * @since 1.8.0
+ */
+ @Override
+ protected <T> T convertToType(final Class<T> type, final Object value) throws Throwable {
+
+ if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) {
+ // All the values in the trueStrings and falseStrings arrays are
+ // guaranteed to be lower-case. By converting the input value
+ // to lowercase too, we can use the efficient String.equals method
+ // instead of the less-efficient String.equalsIgnoreCase method.
+ final String stringValue = value.toString().toLowerCase();
+
+ for (final String trueString : trueStrings) {
+ if (trueString.equals(stringValue)) {
+ return type.cast(Boolean.TRUE);
+ }
+ }
+
+ for (final String falseString : falseStrings) {
+ if (falseString.equals(stringValue)) {
+ return type.cast(Boolean.FALSE);
+ }
+ }
+ }
+
+ throw conversionException(type, value);
+ }
+
+ /**
+ * This method creates a copy of the provided array, and ensures that
+ * all the strings in the newly created array contain only lower-case
+ * letters.
+ * <p>
+ * Using this method to copy string arrays means that changes to the
+ * src array do not modify the dst array.
+ */
+ private static String[] copyStrings(final String[] src) {
+ final String[] dst = new String[src.length];
+ for(int i=0; i<src.length; ++i) {
+ dst[i] = src[i].toLowerCase();
+ }
+ return dst;
+ }
+}
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira157TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira157TestCase.java
index 3d9ce1f..81875e5 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira157TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira157TestCase.java
@@ -1,198 +1,198 @@
-/*
- * 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.beanutils2.bugs;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import org.apache.commons.beanutils2.BeanUtils;
-import org.apache.commons.beanutils2.BeanUtilsBean;
-import org.apache.commons.beanutils2.PropertyUtilsBean;
-import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Beanutils's describe() method cannot determine reader methods for anonymous
- * class - see Jira issue# BEANUTILS-157.
- *
- * @see <a
- * href="https://issues.apache.org/jira/browse/BEANUTILS-157">https://issues.apache.org/jira/browse/BEANUTILS-157<a/>
- */
-public class Jira157TestCase extends TestCase {
-
- private final Log log = LogFactory.getLog(Jira157TestCase.class);
-
- /**
- * Create a test case with the specified name.
- *
- * @param name The name of the test
- */
- public Jira157TestCase(final String name) {
- super(name);
- }
-
- /**
- * Run the Test.
- *
- * @param args Arguments
- */
- public static void main(final String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- /**
- * Create a test suite for this test.
- *
- * @return a test suite
- */
- public static Test suite() {
- return new TestSuite(Jira157TestCase.class);
- }
-
- /**
- * Set up.
- *
- * @throws java.lang.Exception
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- BeanUtilsBean custom = new BeanUtilsBean();
- custom.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
- BeanUtilsBean.setInstance(custom);
- }
-
- /**
- * Tear Down.
- *
- * @throws java.lang.Exception
- */
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Test with an private class that overrides a public method
- * of a "grand parent" public class.
- * <p />
- * See Jira issue# BEANUTILS-157.
- */
- public void testIssue_BEANUTILS_157_BeanUtils_Describe_Serializable() {
- final Object bean = new Serializable() {
- private static final long serialVersionUID = 1L;
-
- @SuppressWarnings("unused")
- public String getX() {
- return "x-value";
- }
- @SuppressWarnings("unused")
- public String getY() {
- return "y-value";
- }
- };
- Map<String, String> result = null;
- try {
- result = BeanUtils.describe(bean);
- } catch (final Throwable t) {
- log.error("Describe Serializable: " + t.getMessage(), t);
- fail("Describe Serializable Threw exception: " + t);
- }
- assertEquals("Check Size", 1, result.size());
- assertTrue("Class", result.containsKey("class"));
- }
-
- /**
- * Test with an private class that overrides a public method
- * of a "grand parent" public class.
- * <p />
- * See Jira issue# BEANUTILS-157.
- */
- public void testIssue_BEANUTILS_157_BeanUtils_Describe_Interface() {
- final Object bean = new XY() {
- @Override
- public String getX() {
- return "x-value";
- }
- @Override
- public String getY() {
- return "y-value";
- }
- };
- Map<String, String> result = null;
- try {
- result = BeanUtils.describe(bean);
- } catch (final Throwable t) {
- log.error("Describe Interface: " + t.getMessage(), t);
- fail("Describe Interface Threw exception: " + t);
- }
- assertEquals("Check Size", 3, result.size());
- assertTrue("Class", result.containsKey("class"));
- assertTrue("X Key", result.containsKey("x"));
- assertTrue("Y Key", result.containsKey("y"));
- assertEquals("X Value", "x-value", result.get("x"));
- assertEquals("Y Value", "y-value", result.get("y"));
- }
-
- /**
- * Test with an private class that overrides a public method
- * of a "grand parent" public class.
- * <p />
- * See Jira issue# BEANUTILS-157.
- */
- public void testIssue_BEANUTILS_157_BeanUtils_Describe_Bean() {
- final Object bean = new FooBar();
- Map<String, String> result = null;
- try {
- result = BeanUtils.describe(bean);
- } catch (final Throwable t) {
- log.error("Describe Bean: " + t.getMessage(), t);
- fail("Describe Bean Threw exception: " + t);
- }
- assertEquals("Check Size", 2, result.size());
- assertTrue("Class", result.containsKey("class"));
- assertTrue("publicFoo Key", result.containsKey("publicFoo"));
- assertEquals("publicFoo Value", "PublicFoo Value", result.get("publicFoo"));
- }
-
- public static interface XY {
- String getX();
- String getY();
- }
-
- public static class FooBar {
- String getPackageFoo() {
- return "Package Value";
- }
- @SuppressWarnings("unused")
- private String getPrivateFoo() {
- return "PrivateFoo Value";
- }
- protected String getProtectedFoo() {
- return "ProtectedFoo Value";
- }
- public String getPublicFoo() {
- return "PublicFoo Value";
- }
- }
-}
+/*
+ * 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.beanutils2.bugs;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.apache.commons.beanutils2.BeanUtils;
+import org.apache.commons.beanutils2.BeanUtilsBean;
+import org.apache.commons.beanutils2.PropertyUtilsBean;
+import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Beanutils's describe() method cannot determine reader methods for anonymous
+ * class - see Jira issue# BEANUTILS-157.
+ *
+ * @see <a
+ * href="https://issues.apache.org/jira/browse/BEANUTILS-157">https://issues.apache.org/jira/browse/BEANUTILS-157<a/>
+ */
+public class Jira157TestCase extends TestCase {
+
+ private final Log log = LogFactory.getLog(Jira157TestCase.class);
+
+ /**
+ * Create a test case with the specified name.
+ *
+ * @param name The name of the test
+ */
+ public Jira157TestCase(final String name) {
+ super(name);
+ }
+
+ /**
+ * Run the Test.
+ *
+ * @param args Arguments
+ */
+ public static void main(final String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ /**
+ * Create a test suite for this test.
+ *
+ * @return a test suite
+ */
+ public static Test suite() {
+ return new TestSuite(Jira157TestCase.class);
+ }
+
+ /**
+ * Set up.
+ *
+ * @throws java.lang.Exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ BeanUtilsBean custom = new BeanUtilsBean();
+ custom.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
+ BeanUtilsBean.setInstance(custom);
+ }
+
+ /**
+ * Tear Down.
+ *
+ * @throws java.lang.Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test with an private class that overrides a public method
+ * of a "grand parent" public class.
+ * <p />
+ * See Jira issue# BEANUTILS-157.
+ */
+ public void testIssue_BEANUTILS_157_BeanUtils_Describe_Serializable() {
+ final Object bean = new Serializable() {
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unused")
+ public String getX() {
+ return "x-value";
+ }
+ @SuppressWarnings("unused")
+ public String getY() {
+ return "y-value";
+ }
+ };
+ Map<String, String> result = null;
+ try {
+ result = BeanUtils.describe(bean);
+ } catch (final Throwable t) {
+ log.error("Describe Serializable: " + t.getMessage(), t);
+ fail("Describe Serializable Threw exception: " + t);
+ }
+ assertEquals("Check Size", 1, result.size());
+ assertTrue("Class", result.containsKey("class"));
+ }
+
+ /**
+ * Test with an private class that overrides a public method
+ * of a "grand parent" public class.
+ * <p />
+ * See Jira issue# BEANUTILS-157.
+ */
+ public void testIssue_BEANUTILS_157_BeanUtils_Describe_Interface() {
+ final Object bean = new XY() {
+ @Override
+ public String getX() {
+ return "x-value";
+ }
+ @Override
+ public String getY() {
+ return "y-value";
+ }
+ };
+ Map<String, String> result = null;
+ try {
+ result = BeanUtils.describe(bean);
+ } catch (final Throwable t) {
+ log.error("Describe Interface: " + t.getMessage(), t);
+ fail("Describe Interface Threw exception: " + t);
+ }
+ assertEquals("Check Size", 3, result.size());
+ assertTrue("Class", result.containsKey("class"));
+ assertTrue("X Key", result.containsKey("x"));
+ assertTrue("Y Key", result.containsKey("y"));
+ assertEquals("X Value", "x-value", result.get("x"));
+ assertEquals("Y Value", "y-value", result.get("y"));
+ }
+
+ /**
+ * Test with an private class that overrides a public method
+ * of a "grand parent" public class.
+ * <p />
+ * See Jira issue# BEANUTILS-157.
+ */
+ public void testIssue_BEANUTILS_157_BeanUtils_Describe_Bean() {
+ final Object bean = new FooBar();
+ Map<String, String> result = null;
+ try {
+ result = BeanUtils.describe(bean);
+ } catch (final Throwable t) {
+ log.error("Describe Bean: " + t.getMessage(), t);
+ fail("Describe Bean Threw exception: " + t);
+ }
+ assertEquals("Check Size", 2, result.size());
+ assertTrue("Class", result.containsKey("class"));
+ assertTrue("publicFoo Key", result.containsKey("publicFoo"));
+ assertEquals("publicFoo Value", "PublicFoo Value", result.get("publicFoo"));
+ }
+
+ public static interface XY {
+ String getX();
+ String getY();
+ }
+
+ public static class FooBar {
+ String getPackageFoo() {
+ return "Package Value";
+ }
+ @SuppressWarnings("unused")
+ private String getPrivateFoo() {
+ return "PrivateFoo Value";
+ }
+ protected String getProtectedFoo() {
+ return "ProtectedFoo Value";
+ }
+ public String getPublicFoo() {
+ return "PublicFoo Value";
+ }
+ }
+}
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java
index c9dd2a0..a440912 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira520TestCase.java
@@ -1,55 +1,55 @@
-/*
- * 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.beanutils2.bugs;
-
-import org.apache.commons.beanutils2.AlphaBean;
-import org.apache.commons.beanutils2.BeanUtilsBean;
-import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector;
-
-import junit.framework.TestCase;
-
-/**
- * Fix CVE: https://nvd.nist.gov/vuln/detail/CVE-2014-0114
- *
- * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-520">https://issues.apache.org/jira/browse/BEANUTILS-520</a>
- */
-public class Jira520TestCase extends TestCase {
- /**
- * By default opt-in to security that does not allow access to "class".
- */
- public void testSuppressClassPropertyByDefault() throws Exception {
- final BeanUtilsBean bub = new BeanUtilsBean();
- final AlphaBean bean = new AlphaBean();
- try {
- bub.getProperty(bean, "class");
- fail("Could access class property!");
- } catch (final NoSuchMethodException ex) {
- // ok
- }
- }
-
- /**
- * Allow opt-out to make your app less secure but allow access to "class".
- */
- public void testAllowAccessToClassProperty() throws Exception {
- final BeanUtilsBean bub = new BeanUtilsBean();
- bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
- final AlphaBean bean = new AlphaBean();
- String result = bub.getProperty(bean, "class");
- assertEquals("Class property should have been accessed", "class org.apache.commons.beanutils2.AlphaBean", result);
- }
-}
+/*
+ * 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.beanutils2.bugs;
+
+import org.apache.commons.beanutils2.AlphaBean;
+import org.apache.commons.beanutils2.BeanUtilsBean;
+import org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector;
+
+import junit.framework.TestCase;
+
+/**
+ * Fix CVE: https://nvd.nist.gov/vuln/detail/CVE-2014-0114
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-520">https://issues.apache.org/jira/browse/BEANUTILS-520</a>
+ */
+public class Jira520TestCase extends TestCase {
+ /**
+ * By default opt-in to security that does not allow access to "class".
+ */
+ public void testSuppressClassPropertyByDefault() throws Exception {
+ final BeanUtilsBean bub = new BeanUtilsBean();
+ final AlphaBean bean = new AlphaBean();
+ try {
+ bub.getProperty(bean, "class");
+ fail("Could access class property!");
+ } catch (final NoSuchMethodException ex) {
+ // ok
+ }
+ }
+
+ /**
+ * Allow opt-out to make your app less secure but allow access to "class".
+ */
+ public void testAllowAccessToClassProperty() throws Exception {
+ final BeanUtilsBean bub = new BeanUtilsBean();
+ bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
+ final AlphaBean bean = new AlphaBean();
+ String result = bub.getProperty(bean, "class");
+ assertEquals("Class property should have been accessed", "class org.apache.commons.beanutils2.AlphaBean", result);
+ }
+}