You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/12/09 19:58:20 UTC
svn commit: r1419092 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/
test/java/org/apache/commons/configuration/builder/
Author: oheger
Date: Sun Dec 9 18:58:19 2012
New Revision: 1419092
URL: http://svn.apache.org/viewvc?rev=1419092&view=rev
Log:
Improved introspection for properties with a fluent API return type.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderParametersBeanInfo.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderParametersBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderParametersBeanInfo.java?rev=1419092&r1=1419091&r2=1419092&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderParametersBeanInfo.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BuilderParametersBeanInfo.java Sun Dec 9 18:58:19 2012
@@ -23,10 +23,10 @@ import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.reflect.Method;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
-import java.util.Set;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -136,7 +136,8 @@ public abstract class BuilderParametersB
private static PropertyDescriptor[] extractPropertyDescriptors(
Class<?> beanClass, BeanInfo stdBeanInfo)
{
- Set<String> propertyNames = fetchPropertyNames(stdBeanInfo);
+ Map<String, PropertyDescriptor> propertyDescs =
+ fetchPropertyDescriptors(stdBeanInfo);
Collection<PropertyDescriptor> descriptors =
new LinkedList<PropertyDescriptor>();
@@ -145,19 +146,24 @@ public abstract class BuilderParametersB
if (m.getName().startsWith(PREFIX_SET_METHOD))
{
String propertyName = propertyName(m);
- if (!propertyNames.contains(propertyName))
+ PropertyDescriptor pd = propertyDescs.get(propertyName);
+ try
{
- try
+ if (pd == null)
{
descriptors.add(createFluentPropertyDescritor(m,
propertyName));
}
- catch (IntrospectionException e)
+ else if (pd.getWriteMethod() == null)
{
- LOG.warn("Error when creating PropertyDescriptor for "
- + m + "! Ignoring this property.", e);
+ pd.setWriteMethod(m);
}
}
+ catch (IntrospectionException e)
+ {
+ LOG.warn("Error when creating PropertyDescriptor for " + m
+ + "! Ignoring this property.", e);
+ }
}
}
@@ -165,15 +171,16 @@ public abstract class BuilderParametersB
}
/**
- * Obtains the names of all properties from the given {@code BeanInfo}
- * object.
+ * Obtains a map of all properties from the given {@code BeanInfo} object.
*
* @param info the {@code BeanInfo} (may be <b>null</b>)
- * @return a set with all property names
+ * @return a map allowing direct access to property descriptors by name
*/
- private static Set<String> fetchPropertyNames(BeanInfo info)
+ private static Map<String, PropertyDescriptor> fetchPropertyDescriptors(
+ BeanInfo info)
{
- Set<String> propertyNames = new HashSet<String>();
+ Map<String, PropertyDescriptor> propDescs =
+ new HashMap<String, PropertyDescriptor>();
if (info != null)
{
PropertyDescriptor[] descs = info.getPropertyDescriptors();
@@ -181,12 +188,12 @@ public abstract class BuilderParametersB
{
for (PropertyDescriptor pd : descs)
{
- propertyNames.add(pd.getName());
+ propDescs.put(pd.getName(), pd);
}
}
}
- return propertyNames;
+ return propDescs;
}
/**
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java?rev=1419092&r1=1419091&r2=1419092&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/ParametersBeanTestImpl.java Sun Dec 9 18:58:19 2012
@@ -27,6 +27,8 @@ public class ParametersBeanTestImpl exte
private String stringProperty;
+ private String fluentGetProperty;
+
public int getIntProperty()
{
return intProperty;
@@ -52,4 +54,15 @@ public class ParametersBeanTestImpl exte
setStringProperty(value);
return this;
}
+
+ public String getFluentPropertyWithGet()
+ {
+ return fluentGetProperty;
+ }
+
+ public ParametersBeanTestImpl setFluentPropertyWithGet(String s)
+ {
+ fluentGetProperty = s;
+ return this;
+ }
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java?rev=1419092&r1=1419091&r2=1419092&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBuilderParametersBeanInfo.java Sun Dec 9 18:58:19 2012
@@ -56,6 +56,9 @@ public class TestBuilderParametersBeanIn
fetchDescriptor(properties, "throwExceptionOnMissing");
pd = fetchDescriptor(properties, "fluentProperty");
assertNull("Got a read method for fluentProperty", pd.getReadMethod());
+ pd = fetchDescriptor(properties, "fluentPropertyWithGet");
+ assertNotNull("No read method for fluent property", pd.getReadMethod());
+ assertNotNull("No write method for fluent property", pd.getWriteMethod());
}
/**