Coverage Report - org.apache.shiro.aop.AnnotationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AnnotationHandler
70%
7/10
50%
1/2
1.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.shiro.aop;
 20  
 
 21  
 import java.lang.annotation.Annotation;
 22  
 
 23  
 import org.apache.shiro.SecurityUtils;
 24  
 import org.apache.shiro.subject.Subject;
 25  
 
 26  
 
 27  
 /**
 28  
  * Base support class for implementations that reads and processes JSR-175 annotations.
 29  
  *
 30  
  * @since 0.9.0
 31  
  */
 32  
 public abstract class AnnotationHandler {
 33  
 
 34  
     /**
 35  
      * The type of annotation this handler will process.
 36  
      */
 37  
     protected Class<? extends Annotation> annotationClass;
 38  
 
 39  
     /**
 40  
      * Constructs an <code>AnnotationHandler</code> who processes annotations of the
 41  
      * specified type.  Immediately calls {@link #setAnnotationClass(Class)}.
 42  
      *
 43  
      * @param annotationClass the type of annotation this handler will process.
 44  
      */
 45  5
     public AnnotationHandler(Class<? extends Annotation> annotationClass) {
 46  5
         setAnnotationClass(annotationClass);
 47  5
     }
 48  
 
 49  
     /**
 50  
      * Returns the {@link org.apache.shiro.subject.Subject Subject} associated with the currently-executing code.
 51  
      * <p/>
 52  
      * This default implementation merely calls <code>{@link org.apache.shiro.SecurityUtils#getSubject SecurityUtils.getSubject()}</code>.
 53  
      *
 54  
      * @return the {@link org.apache.shiro.subject.Subject Subject} associated with the currently-executing code.
 55  
      */
 56  
     protected Subject getSubject() {
 57  5
         return SecurityUtils.getSubject();
 58  
     }
 59  
 
 60  
     /**
 61  
      * Sets the type of annotation this handler will inspect and process.
 62  
      *
 63  
      * @param annotationClass the type of annotation this handler will process.
 64  
      * @throws IllegalArgumentException if the argument is <code>null</code>.
 65  
      */
 66  
     protected void setAnnotationClass(Class<? extends Annotation> annotationClass)
 67  
             throws IllegalArgumentException {
 68  5
         if (annotationClass == null) {
 69  0
             String msg = "annotationClass argument cannot be null";
 70  0
             throw new IllegalArgumentException(msg);
 71  
         }
 72  5
         this.annotationClass = annotationClass;
 73  5
     }
 74  
 
 75  
     /**
 76  
      * Returns the type of annotation this handler inspects and processes.
 77  
      *
 78  
      * @return the type of annotation this handler inspects and processes.
 79  
      */
 80  
     public Class<? extends Annotation> getAnnotationClass() {
 81  0
         return this.annotationClass;
 82  
     }
 83  
 
 84  
 }