Author: hadrian
Date: Wed Oct 22 22:41:04 2008
New Revision: 707277

URL: http://svn.apache.org/viewvc?rev=707277&view=rev
Log:
CAMEL-990.  Patch applied with many thanks.

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=707277&r1=707276&r2=707277&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
 Wed Oct 22 22:41:04 2008
@@ -20,6 +20,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
 import java.net.URL;
@@ -138,8 +139,27 @@
             CachingInjector injector = null;
 
             for (Method method : methods) {
-                Converter annotation = method.getAnnotation(Converter.class);
-                if (annotation != null) {
+                // this may be prone to ClassLoader or packaging problems when 
the same class is defined
+                // in two different jars (as is the case sometimes with specs).
+                boolean found = method.getAnnotation(Converter.class) != null;
+                if (!found) {
+                    // try to find meta annotation
+                    Annotation[] annotations = method.getAnnotations();
+                    for (Annotation a : annotations) {
+                        Annotation[] metaAnnotations = 
a.annotationType().getAnnotations();
+                        for (Annotation meta : metaAnnotations) {
+                            if 
(meta.annotationType().getName().equals(Converter.class.getName())) {
+                                found = true;
+                                break;
+                            }
+                        }
+                        if (found) {
+                            break;
+                        }
+                    }
+                }
+
+                if (found) {
                     if (isValidConverterMethod(method)) {
                         int modifiers = method.getModifiers();
                         if (isAbstract(modifiers) || !isPublic(modifiers)) {

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?rev=707277&r1=707276&r2=707277&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
 Wed Oct 22 22:41:04 2008
@@ -141,13 +141,28 @@
          * constructor.
          */
         public boolean matches(Class type) {
-            return type != null && type.isAnnotationPresent(annotation);
+            return type != null && hasAnnotation(type, annotation);
         }
 
         @Override
         public String toString() {
             return "annotated with @" + annotation.getSimpleName();
         }
+        
+        private boolean hasAnnotation(Class<?> clazz, Class<? extends 
Annotation> annotationType) {
+            if (clazz.isAnnotationPresent(annotationType)) {
+                return true;
+            }
+            // check for meta annotations
+            for (Annotation a : clazz.getAnnotations()) {
+                for (Annotation meta : a.annotationType().getAnnotations()) {
+                    if 
(meta.annotationType().getName().equals(annotationType.getName())) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
     }
 
     /**


Reply via email to