From aa211dbaa1abcf906a2a49469f96330997eedf1e Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 10 Jul 2008 18:34:22 +0000 Subject: [PATCH] Go back to the original patch. The better one didn't pan out. Sorry for the noise. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@675667 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalina/core/DefaultInstanceManager.java | 111 +++++++++++---------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/java/org/apache/catalina/core/DefaultInstanceManager.java b/java/org/apache/catalina/core/DefaultInstanceManager.java index 0d3e265a7..b1bbb1a89 100644 --- a/java/org/apache/catalina/core/DefaultInstanceManager.java +++ b/java/org/apache/catalina/core/DefaultInstanceManager.java @@ -245,62 +245,67 @@ public class DefaultInstanceManager implements InstanceManager { return; } - // Initialize fields annotations - Field[] fields = instance.getClass().getDeclaredFields(); - for (Field field : fields) { - if (injections != null && injections.containsKey(field.getName())) { - lookupFieldResource(context, instance, field, injections.get(field.getName())); - } else if (field.isAnnotationPresent(Resource.class)) { - Resource annotation = field.getAnnotation(Resource.class); - lookupFieldResource(context, instance, field, annotation.name()); - } else if (field.isAnnotationPresent(EJB.class)) { - EJB annotation = field.getAnnotation(EJB.class); - lookupFieldResource(context, instance, field, annotation.name()); - } else if (field.isAnnotationPresent(WebServiceRef.class)) { - WebServiceRef annotation = - field.getAnnotation(WebServiceRef.class); - lookupFieldResource(context, instance, field, annotation.name()); - } else if (field.isAnnotationPresent(PersistenceContext.class)) { - PersistenceContext annotation = - field.getAnnotation(PersistenceContext.class); - lookupFieldResource(context, instance, field, annotation.name()); - } else if (field.isAnnotationPresent(PersistenceUnit.class)) { - PersistenceUnit annotation = - field.getAnnotation(PersistenceUnit.class); - lookupFieldResource(context, instance, field, annotation.name()); - } - } - - // Initialize methods annotations - Method[] methods = instance.getClass().getDeclaredMethods(); - for (Method method : methods) { - String methodName = method.getName(); - if (injections != null && methodName.startsWith("set") && methodName.length() > 3) { - String fieldName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); - if (injections.containsKey(fieldName)) { - lookupMethodResource(context, instance, method, injections.get(fieldName)); - break; + Class clazz = instance.getClass(); + + while (clazz != null) { + // Initialize fields annotations + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + if (injections != null && injections.containsKey(field.getName())) { + lookupFieldResource(context, instance, field, injections.get(field.getName())); + } else if (field.isAnnotationPresent(Resource.class)) { + Resource annotation = field.getAnnotation(Resource.class); + lookupFieldResource(context, instance, field, annotation.name()); + } else if (field.isAnnotationPresent(EJB.class)) { + EJB annotation = field.getAnnotation(EJB.class); + lookupFieldResource(context, instance, field, annotation.name()); + } else if (field.isAnnotationPresent(WebServiceRef.class)) { + WebServiceRef annotation = + field.getAnnotation(WebServiceRef.class); + lookupFieldResource(context, instance, field, annotation.name()); + } else if (field.isAnnotationPresent(PersistenceContext.class)) { + PersistenceContext annotation = + field.getAnnotation(PersistenceContext.class); + lookupFieldResource(context, instance, field, annotation.name()); + } else if (field.isAnnotationPresent(PersistenceUnit.class)) { + PersistenceUnit annotation = + field.getAnnotation(PersistenceUnit.class); + lookupFieldResource(context, instance, field, annotation.name()); } } - if (method.isAnnotationPresent(Resource.class)) { - Resource annotation = method.getAnnotation(Resource.class); - lookupMethodResource(context, instance, method, annotation.name()); - } else if (method.isAnnotationPresent(EJB.class)) { - EJB annotation = method.getAnnotation(EJB.class); - lookupMethodResource(context, instance, method, annotation.name()); - } else if (method.isAnnotationPresent(WebServiceRef.class)) { - WebServiceRef annotation = - method.getAnnotation(WebServiceRef.class); - lookupMethodResource(context, instance, method, annotation.name()); - } else if (method.isAnnotationPresent(PersistenceContext.class)) { - PersistenceContext annotation = - method.getAnnotation(PersistenceContext.class); - lookupMethodResource(context, instance, method, annotation.name()); - } else if (method.isAnnotationPresent(PersistenceUnit.class)) { - PersistenceUnit annotation = - method.getAnnotation(PersistenceUnit.class); - lookupMethodResource(context, instance, method, annotation.name()); + + // Initialize methods annotations + Method[] methods = clazz.getDeclaredMethods(); + for (Method method : methods) { + String methodName = method.getName(); + if (injections != null && methodName.startsWith("set") && methodName.length() > 3) { + String fieldName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); + if (injections.containsKey(fieldName)) { + lookupMethodResource(context, instance, method, injections.get(fieldName)); + break; + } + } + if (method.isAnnotationPresent(Resource.class)) { + Resource annotation = method.getAnnotation(Resource.class); + lookupMethodResource(context, instance, method, annotation.name()); + } else if (method.isAnnotationPresent(EJB.class)) { + EJB annotation = method.getAnnotation(EJB.class); + lookupMethodResource(context, instance, method, annotation.name()); + } else if (method.isAnnotationPresent(WebServiceRef.class)) { + WebServiceRef annotation = + method.getAnnotation(WebServiceRef.class); + lookupMethodResource(context, instance, method, annotation.name()); + } else if (method.isAnnotationPresent(PersistenceContext.class)) { + PersistenceContext annotation = + method.getAnnotation(PersistenceContext.class); + lookupMethodResource(context, instance, method, annotation.name()); + } else if (method.isAnnotationPresent(PersistenceUnit.class)) { + PersistenceUnit annotation = + method.getAnnotation(PersistenceUnit.class); + lookupMethodResource(context, instance, method, annotation.name()); + } } + clazz = clazz.getSuperclass(); } } -- 2.11.0