Coverage Report - org.acegisecurity.intercept.method.AbstractMethodDefinitionSource
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractMethodDefinitionSource
62% 
67% 
4.333
 
 1  
 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 2  
  *
 3  
  * Licensed under the Apache License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  *     http://www.apache.org/licenses/LICENSE-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software
 10  
  * distributed under the License is distributed on an "AS IS" BASIS,
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
  * See the License for the specific language governing permissions and
 13  
  * limitations under the License.
 14  
  */
 15  
 
 16  
 package org.acegisecurity.intercept.method;
 17  
 
 18  
 import org.acegisecurity.ConfigAttributeDefinition;
 19  
 
 20  
 import org.aopalliance.intercept.MethodInvocation;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 import org.aspectj.lang.JoinPoint;
 26  
 import org.aspectj.lang.reflect.CodeSignature;
 27  
 
 28  
 import org.springframework.util.Assert;
 29  
 
 30  
 import java.lang.reflect.Method;
 31  
 
 32  
 
 33  
 /**
 34  
  * Abstract implementation of <Code>MethodDefinitionSource</code>.
 35  
  *
 36  
  * @author Ben Alex
 37  
  * @version $Id: AbstractMethodDefinitionSource.java 1496 2006-05-23 13:38:33Z benalex $
 38  
  */
 39  55
 public abstract class AbstractMethodDefinitionSource implements MethodDefinitionSource {
 40  
     //~ Static fields/initializers =====================================================================================
 41  
 
 42  4
     private static final Log logger = LogFactory.getLog(AbstractMethodDefinitionSource.class);
 43  
 
 44  
     //~ Methods ========================================================================================================
 45  
 
 46  
     public ConfigAttributeDefinition getAttributes(Object object)
 47  
         throws IllegalArgumentException {
 48  59
         Assert.notNull(object, "Object cannot be null");
 49  
 
 50  59
         if (object instanceof MethodInvocation) {
 51  56
             return this.lookupAttributes(((MethodInvocation) object).getMethod());
 52  
         }
 53  
 
 54  3
         if (object instanceof JoinPoint) {
 55  3
             JoinPoint jp = (JoinPoint) object;
 56  3
             Class targetClazz = jp.getTarget().getClass();
 57  3
             String targetMethodName = jp.getStaticPart().getSignature().getName();
 58  3
             Class[] types = ((CodeSignature) jp.getStaticPart().getSignature()).getParameterTypes();
 59  
 
 60  3
             if (logger.isDebugEnabled()) {
 61  0
                 logger.debug("Target Class: " + targetClazz);
 62  0
                 logger.debug("Target Method Name: " + targetMethodName);
 63  
 
 64  0
                 for (int i = 0; i < types.length; i++) {
 65  0
                     if (logger.isDebugEnabled()) {
 66  0
                         logger.debug("Target Method Arg #" + i + ": " + types[i]);
 67  
                     }
 68  
                 }
 69  
             }
 70  
 
 71  
             try {
 72  3
                 return this.lookupAttributes(targetClazz.getMethod(targetMethodName, types));
 73  0
             } catch (NoSuchMethodException nsme) {
 74  0
                 throw new IllegalArgumentException("Could not obtain target method from JoinPoint: " + jp);
 75  
             }
 76  
         }
 77  
 
 78  0
         throw new IllegalArgumentException("Object must be a MethodInvocation or JoinPoint");
 79  
     }
 80  
 
 81  
     /**
 82  
      * Performs the actual lookup of the relevant <code>ConfigAttributeDefinition</code> for the specified
 83  
      * <code>Method</code> which is subject of the method invocation.<P>Provided so subclasses need only to
 84  
      * provide one basic method to properly interface with the <code>MethodDefinitionSource</code>.</p>
 85  
      *  <p>Returns <code>null</code> if there are no matching attributes for the method.</p>
 86  
      *
 87  
      * @param method the method being invoked for which configuration attributes should be looked up
 88  
      *
 89  
      * @return the <code>ConfigAttributeDefinition</code> that applies to the specified <code>Method</code>
 90  
      */
 91  
     protected abstract ConfigAttributeDefinition lookupAttributes(Method method);
 92  
 
 93  
     public boolean supports(Class clazz) {
 94  24
         return (MethodInvocation.class.isAssignableFrom(clazz) || JoinPoint.class.isAssignableFrom(clazz));
 95  
     }
 96  
 }