introduced AnnotationUtils.getAnnotation(AnnotatedElement, annotationType)
This commit is contained in:
parent
abdae3d26b
commit
df3761e3f6
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.core.annotation;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.AnnotatedElement;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -60,6 +61,26 @@ public abstract class AnnotationUtils {
|
||||||
private static final Map<Class<?>, Boolean> annotatedInterfaceCache = new WeakHashMap<Class<?>, Boolean>();
|
private static final Map<Class<?>, Boolean> annotatedInterfaceCache = new WeakHashMap<Class<?>, Boolean>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a single {@link Annotation} of <code>annotationType</code> from the supplied
|
||||||
|
* Method, Constructor or Field.
|
||||||
|
* @param ae the Method, Constructor or Field to look for annotations on
|
||||||
|
* @param annotationType the annotation class to look for
|
||||||
|
* @return the annotations found
|
||||||
|
*/
|
||||||
|
public static <T extends Annotation> T getAnnotation(AnnotatedElement ae, Class<T> annotationType) {
|
||||||
|
T ann = ae.getAnnotation(annotationType);
|
||||||
|
if (ann == null) {
|
||||||
|
for (Annotation metaAnn : ae.getAnnotations()) {
|
||||||
|
ann = metaAnn.annotationType().getAnnotation(annotationType);
|
||||||
|
if (ann != null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ann;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all {@link Annotation Annotations} from the supplied {@link Method}.
|
* Get all {@link Annotation Annotations} from the supplied {@link Method}.
|
||||||
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
* <p>Correctly handles bridge {@link Method Methods} generated by the compiler.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,10 +17,10 @@
|
||||||
package org.springframework.transaction.annotation;
|
package org.springframework.transaction.annotation;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.transaction.interceptor.NoRollbackRuleAttribute;
|
import org.springframework.transaction.interceptor.NoRollbackRuleAttribute;
|
||||||
import org.springframework.transaction.interceptor.RollbackRuleAttribute;
|
import org.springframework.transaction.interceptor.RollbackRuleAttribute;
|
||||||
import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute;
|
import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute;
|
||||||
|
@ -35,15 +35,7 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||||
public class SpringTransactionAnnotationParser implements TransactionAnnotationParser, Serializable {
|
public class SpringTransactionAnnotationParser implements TransactionAnnotationParser, Serializable {
|
||||||
|
|
||||||
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
|
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
|
||||||
Transactional ann = ae.getAnnotation(Transactional.class);
|
Transactional ann = AnnotationUtils.getAnnotation(ae, Transactional.class);
|
||||||
if (ann == null) {
|
|
||||||
for (Annotation metaAnn : ae.getAnnotations()) {
|
|
||||||
ann = metaAnn.annotationType().getAnnotation(Transactional.class);
|
|
||||||
if (ann != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ann != null) {
|
if (ann != null) {
|
||||||
return parseTransactionAnnotation(ann);
|
return parseTransactionAnnotation(ann);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue