You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2014/03/18 16:07:44 UTC
svn commit: r1578946 -
/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
Author: justin
Date: Tue Mar 18 15:07:43 2014
New Revision: 1578946
URL: http://svn.apache.org/r1578946
Log:
SLING-3460 - internal refactoring to ease meta-annotation support
Modified:
sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
Modified: sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java?rev=1578946&r1=1578945&r2=1578946&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java (original)
+++ sling/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java Tue Mar 18 15:07:43 2014
@@ -289,14 +289,31 @@ public class ModelAdapterFactory impleme
}
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;
}
}
}