Coverage Report - org.kuali.rice.kns.util.spring.ClassOrMethodAnnotationFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassOrMethodAnnotationFilter
0%
0/10
0%
0/6
2.5
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.util.spring;
 17  
 
 18  
 import java.lang.annotation.Annotation;
 19  
 import java.lang.reflect.Method;
 20  
 
 21  
 import org.springframework.aop.ClassFilter;
 22  
 import org.springframework.transaction.annotation.Transactional;
 23  
 
 24  
 /**
 25  
  * Matches if the annotation specified during construction is present on the class or any of methods returned by class.getMethods().
 26  
  */
 27  
 public class ClassOrMethodAnnotationFilter implements ClassFilter {
 28  
     private final Class<? extends Annotation> annotationType;
 29  
 
 30  0
     public ClassOrMethodAnnotationFilter(Class<? extends Annotation> annotationType) {
 31  0
         this.annotationType = annotationType;
 32  0
     }
 33  
 
 34  
     public boolean matches(Class clazz) {
 35  0
         boolean isAnnotationPresent = clazz.isAnnotationPresent(this.annotationType);
 36  0
         if (!isAnnotationPresent) {
 37  0
             for (Method method : clazz.getMethods()) {
 38  0
                 if (method.isAnnotationPresent(annotationType)) {
 39  0
                     isAnnotationPresent = true;
 40  
 //                    if (Transactional.class.equals(this.annotationType)) {
 41  
 //                        throw new RuntimeException("The @Transactional annotation should be specified at the class level and overriden at the method level, if need be.");
 42  
 //                    }
 43  0
                     break;
 44  
                 }
 45  
             }
 46  
         }
 47  0
         return isAnnotationPresent;
 48  
     }
 49  
 }