You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2010/07/13 01:45:05 UTC
svn commit: r963534 -
/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Author: djencks
Date: Mon Jul 12 23:45:05 2010
New Revision: 963534
URL: http://svn.apache.org/viewvc?rev=963534&view=rev
Log:
inferring the type of an injection needs to look at possible setters as well as fields
Modified:
geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?rev=963534&r1=963533&r2=963534&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java (original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java Mon Jul 12 23:45:05 2010
@@ -17,7 +17,9 @@
package org.apache.geronimo.naming.deployment;
+import java.beans.Introspector;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -342,8 +344,8 @@ public abstract class AbstractNamingBuil
try {
Class<?> clazz = bundle.loadClass(className);
String fieldName = getStringValue(injectionTarget.getInjectionTargetName());
- Field field = getField(clazz, fieldName);
- Class<?> fieldType = deprimitivize(field.getType());
+ Class<?> fieldType = getField(clazz, fieldName);
+ fieldType = deprimitivize(fieldType);
if (type == null) {
type = fieldType;
} else if (!fieldType.equals(type)) {
@@ -385,13 +387,24 @@ public abstract class AbstractNamingBuil
primitives.put(short.class, Short.class);
}
- private Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
+ private Class<?> getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
do {
try {
- return clazz.getDeclaredField(fieldName);
+ return clazz.getDeclaredField(fieldName).getType();
} catch (NoSuchFieldException e) {
//look at superclass
}
+ for (Method method: clazz.getDeclaredMethods()) {
+ if (method.getReturnType() == void.class && method.getParameterTypes().length == 1) {
+ String methodName = method.getName();
+ if (methodName.startsWith("set")) {
+ String type = Introspector.decapitalize(methodName.substring(3));
+ if (fieldName.equals(type)) {
+ return method.getParameterTypes()[0];
+ }
+ }
+ }
+ }
clazz = clazz.getSuperclass();
} while (clazz != null);
throw new NoSuchFieldException(fieldName);