2525 * Handles Spring's {@link Order} annotation as well as {@link javax.annotation.Priority}. 
2626 * 
2727 * @author Stephane Nicoll 
28+  * @author Juergen Hoeller 
2829 * @since 4.1 
2930 * @see Order 
3031 * @see javax.annotation.Priority 
3132 */ 
33+ @ SuppressWarnings ("unchecked" )
3234public  abstract  class  OrderUtils  {
3335
34- 	private  static  final   String   PRIORITY_ANNOTATION_CLASS_NAME  =  "javax.annotation.Priority" ;
36+ 	private  static  Class <?  extends   Annotation >  priorityAnnotationType  =  null ;
3537
36- 	private  static  final  boolean  priorityPresent  =
37- 			ClassUtils .isPresent (PRIORITY_ANNOTATION_CLASS_NAME , OrderUtils .class .getClassLoader ());
38+ 	static  {
39+ 		try  {
40+ 			priorityAnnotationType  = (Class <? extends  Annotation >)
41+ 					ClassUtils .forName ("javax.annotation.Priority" , OrderUtils .class .getClassLoader ());
42+ 		}
43+ 		catch  (ClassNotFoundException  ex ) {
44+ 			// javax.annotation.Priority not available 
45+ 		}
46+ 	}
3847
3948
4049	/** 
@@ -52,7 +61,7 @@ public static Integer getOrder(Class<?> type) {
5261	 * default value if none can be found. 
5362	 * <p>Take care of {@link Order @Order} and {@code @javax.annotation.Priority}. 
5463	 * @param type the type to handle 
55- 	 * @return the priority value of  the default if none can be found 
64+ 	 * @return the priority value, or  the specified  default order  if none can be found 
5665	 */ 
5766	public  static  Integer  getOrder (Class <?> type , Integer  defaultOrder ) {
5867		Order  order  = AnnotationUtils .findAnnotation (type , Order .class );
@@ -67,17 +76,16 @@ public static Integer getOrder(Class<?> type, Integer defaultOrder) {
6776	}
6877
6978	/** 
70- 	 * Return the value of the {@code javax.annotation.Priority} annotation set  
71- 	 * on the specified type or {@code null} if none is set . 
79+ 	 * Return the value of the {@code javax.annotation.Priority} annotation 
80+ 	 * declared  on the specified type,  or {@code null} if none. 
7281	 * @param type the type to handle 
73- 	 * @return the priority value if the annotation is set,  {@code null} otherwise  
82+ 	 * @return the priority value if the annotation is declared, or  {@code null} if none  
7483	 */ 
7584	public  static  Integer  getPriority (Class <?> type ) {
76- 		if  (priorityPresent ) {
77- 			for  (Annotation  annotation  : type .getAnnotations ()) {
78- 				if  (PRIORITY_ANNOTATION_CLASS_NAME .equals (annotation .annotationType ().getName ())) {
79- 					return  (Integer ) AnnotationUtils .getValue (annotation );
80- 				}
85+ 		if  (priorityAnnotationType  != null ) {
86+ 			Annotation  priority  = AnnotationUtils .findAnnotation (type , priorityAnnotationType );
87+ 			if  (priority  != null ) {
88+ 				return  (Integer ) AnnotationUtils .getValue (priority );
8189			}
8290		}
8391		return  null ;
0 commit comments