Author: oheger
Date: Sun Dec 22 20:38:04 2013
New Revision: 1553027
URL: http://svn.apache.org/r1553027
Log:
BeanHelper now provides a method for copying properties.
This method uses the internal PropertiesUtilsBean instance, so that enhanced
introspection is enabled. This is needed to deal with parameters objects
which have a fluent API.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java?rev=1553027&r1=1553026&r2=1553027&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/beanutils/BeanHelper.java
Sun Dec 22 20:38:04 2013
@@ -296,6 +296,29 @@ public final class BeanHelper
}
/**
+ * Copies matching properties from the source bean to the destination bean
+ * using a specially configured {@code PropertyUtilsBean} instance. This
+ * method ensures that enhanced introspection is enabled when doing the
copy
+ * operation.
+ *
+ * @param dest the destination bean
+ * @param orig the source bean
+ * @throws NoSuchMethodException exception thrown by
+ * {@code PropertyUtilsBean}
+ * @throws InvocationTargetException exception thrown by
+ * {@code PropertyUtilsBean}
+ * @throws IllegalAccessException exception thrown by
+ * {@code PropertyUtilsBean}
+ * @since 2.0
+ */
+ public static void copyProperties(Object dest, Object orig)
+ throws IllegalAccessException, InvocationTargetException,
+ NoSuchMethodException
+ {
+ beanUtilsBean.getPropertyUtils().copyProperties(dest, orig);
+ }
+
+ /**
* Return the Class of the property if it can be determined.
* @param bean The bean containing the property.
* @param propName The name of the property.
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java?rev=1553027&r1=1553026&r2=1553027&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/beanutils/TestBeanHelper.java
Sun Dec 22 20:38:04 2013
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.LazyDynaBean;
import org.apache.commons.configuration.ConfigurationRuntimeException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.easymock.EasyMock;
@@ -390,6 +391,21 @@ public class TestBeanHelper
}
/**
+ * Tests whether properties from one bean to another can be copied.
+ */
+ @Test
+ public void testCopyProperties() throws Exception
+ {
+ PropertiesConfiguration src = new PropertiesConfiguration();
+ src.setHeader("TestHeader");
+ src.setFooter("TestFooter");
+ LazyDynaBean dest = new LazyDynaBean();
+ BeanHelper.copyProperties(dest, src);
+ assertEquals("Wrong footer property", "TestFooter",
dest.get("footer"));
+ assertEquals("Wrong header property", "TestHeader",
dest.get("header"));
+ }
+
+ /**
* Returns an initialized bean declaration.
*
* @return the bean declaration