felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1520079 - /felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
Date Wed, 04 Sep 2013 17:32:16 GMT
Author: clement
Date: Wed Sep  4 17:32:15 2013
New Revision: 1520079

URL: http://svn.apache.org/r1520079
Log:
FELIX-4216 Allow @Property without name in constructors

Use the parameter's name to infer the property's name.

Modified:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=1520079&r1=1520078&r2=1520079&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
Wed Sep  4 17:32:15 2013
@@ -127,7 +127,25 @@ public class ConfigurationHandler extend
                 if (fieldName == null && methodName != null) {
                     name = methodName;
                 } else if (fieldName == null && paramIndex != null) {
-                    name = paramIndex;
+                    try {
+                    // Extract the name from the arguments.
+                    MethodMetadata[] constructors = getFactory().getPojoMetadata().getConstructors();
+                    if (constructors.length != 1) {
+                        throw new ConfigurationException("Cannot infer the property name
injected in the constructor " +
+                                "parameter #" + paramIndex + " - add the `name` attribute");
+                    } else {
+                        int idx = Integer.valueOf(paramIndex);
+                        if (constructors[0].getMethodArgumentNames().length > idx) {
+                            name = constructors[0].getMethodArgumentNames()[idx];
+                        } else {
+                            throw new ConfigurationException("Cannot infer the property name
injected in the constructor " +
+                                    "parameter #" + paramIndex + " - not enough argument
in the constructor :" +
+                                    constructors[0].getArguments());
+                        }
+                    }
+                    } catch(Throwable e) {
+                        e.printStackTrace();
+                    }
                 } else {
                     name = fieldName;
                 }



Mime
View raw message