Coverage report

  %line %branch
mnemosyne.core.MethodInterceptor
93% 
100% 

 1  
 /*
 2  
  * Copyright 2004 Charles Blaxland
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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 mnemosyne.core;
 17  
 
 18  
 import mnemosyne.aop.MethodCall;
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 import java.lang.reflect.Method;
 23  
 
 24  
 
 25  
 /**
 26  
  * @version $Id: MethodInterceptor.java,v 1.1.1.1 2004/08/07 06:41:03 charlesblaxland Exp $
 27  
  */
 28  7
 public class MethodInterceptor
 29  
 {
 30  14
     private static final Log log = LogFactory.getLog(MethodInterceptor.class);
 31  
 
 32  
     public Object intercept(final MethodCall methodCall) throws Throwable
 33  
     {
 34  572
         Object originalTarget = methodCall.getTarget();
 35  572
         Persistable persistable = (Persistable) originalTarget;
 36  
 
 37  572
         if (persistable.isPersistent())
 38  
         {
 39  341
             if (log.isTraceEnabled())
 40  
             {
 41  0
                 log.trace("Intercepted method call on persistent object: " + originalTarget.getClass().getName() + "." + methodCall.getMethodName());
 42  
             }
 43  
 
 44  341
             Method method = methodCall.getMethod();
 45  341
             PersistentObject persistentObject = persistable.getPersistentObject();
 46  341
             boolean isMutating = isMutatingMethod(method);
 47  
 
 48  341
             Object target = isMutating ? persistentObject.findWritableTargetObject() : persistentObject.findTargetObject();
 49  
 
 50  341
             if (target != originalTarget)
 51  
             {
 52  90
                 methodCall.setTarget(target);
 53  
             }
 54  
         }
 55  
 
 56  572
         return methodCall.invoke();
 57  
     }
 58  
 
 59  
     protected static boolean isMutatingMethod(Method method)
 60  
     {
 61  
         // TODO
 62  341
         return true;
 63  
     }
 64  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.