This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.models.impl-1.0.4
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git

commit 53b4d54b2cf081f3c763b0a4b527090e6c2656c5
Author: Justin Edelson <jus...@apache.org>
AuthorDate: Tue Mar 18 15:07:43 2014 +0000

    SLING-3460 - internal refactoring to ease meta-annotation support
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/models/impl@1578946
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/models/impl/ModelAdapterFactory.java     | 25 ++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java 
b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
index 6fe7868..aed43f2 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
@@ -289,14 +289,31 @@ public class ModelAdapterFactory implements 
AdapterFactory, Runnable {
     }
 
     private String getSource(AnnotatedElement element) {
-        Source source = element.getAnnotation(Source.class);
+        Source source = getAnnotation(element, Source.class);
         if (source != null) {
             return source.value();
         } else {
+            return null;
+        }
+    }
+
+    /**
+     * Get an annotation from either the element itself or on any of the
+     * element's annotations (meta-annotations).
+     * 
+     * @param element the element
+     * @param annotationClass the annotation class
+     * @return the found annotation or null
+     */
+    private <T extends Annotation> T getAnnotation(AnnotatedElement element, 
Class<T> annotationClass) {
+        T annotation = element.getAnnotation(annotationClass);
+        if (annotation != null) {
+            return annotation;
+        } else {
             for (Annotation ann : element.getAnnotations()) {
-                source = ann.annotationType().getAnnotation(Source.class);
-                if (source != null) {
-                    return source.value();
+                annotation = 
ann.annotationType().getAnnotation(annotationClass);
+                if (annotation != null) {
+                    return annotation;
                 }
             }
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Reply via email to