You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2008/07/09 22:50:18 UTC
svn commit: r675340 -
/tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Author: markt
Date: Wed Jul 9 13:50:18 2008
New Revision: 675340
URL: http://svn.apache.org/viewvc?rev=675340&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45285
Should look for annotations all the way up the class hierarchy
Modified:
tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Modified: tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java?rev=675340&r1=675339&r2=675340&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java Wed Jul 9 13:50:18 2008
@@ -245,62 +245,67 @@
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();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r675340 - /tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Posted by Mark Thomas <ma...@apache.org>.
Mark Thomas wrote:
> Remy Maucherat wrote:
>> On Wed, 2008-07-09 at 20:50 +0000, markt@apache.org wrote:
>>> Author: markt
>>> Date: Wed Jul 9 13:50:18 2008
>>> New Revision: 675340
>>>
>>> URL: http://svn.apache.org/viewvc?rev=675340&view=rev
>>> Log:
>>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45285
>>> Should look for annotations all the way up the class hierarchy
>>
>> preDestroy and postConstruct apparently include a recursive trick to do
>> that. Probably all 3 should be similar.
>
> The patch does the same thing but in a different way. I'll make them
> consistent.
I couldn't make them consistent without changing the API so I have left it
alone.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r675340 - /tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Posted by Mark Thomas <ma...@apache.org>.
Remy Maucherat wrote:
> On Wed, 2008-07-09 at 20:50 +0000, markt@apache.org wrote:
>> Author: markt
>> Date: Wed Jul 9 13:50:18 2008
>> New Revision: 675340
>>
>> URL: http://svn.apache.org/viewvc?rev=675340&view=rev
>> Log:
>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45285
>> Should look for annotations all the way up the class hierarchy
>
> preDestroy and postConstruct apparently include a recursive trick to do
> that. Probably all 3 should be similar.
The patch does the same thing but in a different way. I'll make them
consistent.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r675340 -
/tomcat/trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Posted by Remy Maucherat <re...@apache.org>.
On Wed, 2008-07-09 at 20:50 +0000, markt@apache.org wrote:
> Author: markt
> Date: Wed Jul 9 13:50:18 2008
> New Revision: 675340
>
> URL: http://svn.apache.org/viewvc?rev=675340&view=rev
> Log:
> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45285
> Should look for annotations all the way up the class hierarchy
preDestroy and postConstruct apparently include a recursive trick to do
that. Probably all 3 should be similar.
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org