Coverage Report - org.kuali.rice.ksb.messaging.bam.BAMClientProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
BAMClientProxy
0%
0/14
0%
0/8
2.75
 
 1  
 /*
 2  
  * Copyright 2006-2011 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.ksb.messaging.bam;
 17  
 
 18  
 import java.lang.reflect.InvocationTargetException;
 19  
 import java.lang.reflect.Method;
 20  
 import java.lang.reflect.Proxy;
 21  
 
 22  
 import org.kuali.rice.core.api.config.property.Config;
 23  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 24  
 import org.kuali.rice.core.impl.resourceloader.ContextClassLoaderProxy;
 25  
 import org.kuali.rice.core.util.ClassLoaderUtils;
 26  
 import org.kuali.rice.core.util.reflect.BaseTargetedInvocationHandler;
 27  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 28  
 import org.kuali.rice.ksb.impl.registry.ServiceInfoBo;
 29  
 import org.kuali.rice.ksb.messaging.bam.service.BAMService;
 30  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 31  
 
 32  
 
 33  
 /**
 34  
  * A client-side proxy for that records an entry in the BAM for invocations
 35  
  * on the proxied service.
 36  
  *
 37  
  * @see BAMService
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  */
 41  
 public class BAMClientProxy extends BaseTargetedInvocationHandler {
 42  
 
 43  
         private ServiceConfiguration serviceConfiguration;
 44  
         
 45  
         private BAMClientProxy(Object target, ServiceConfiguration serviceConfiguration) {
 46  0
                 super(target);
 47  0
                 this.serviceConfiguration = serviceConfiguration;
 48  0
         }
 49  
         
 50  
         public static boolean isBamSupported() {
 51  0
                 return KSBServiceLocator.getBAMService() != null && Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(Config.BAM_ENABLED));
 52  
         }
 53  
         
 54  
         public static Object wrap(Object target, ServiceConfiguration serviceConfiguration) {
 55  0
                 if (!isBamSupported()) {
 56  0
                         return target;
 57  
                 }
 58  0
                 return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(), ContextClassLoaderProxy.getInterfacesToProxy(target), new BAMClientProxy(target, serviceConfiguration));
 59  
         }
 60  
         
 61  
         protected Object invokeInternal(Object proxyObject, Method method, Object[] arguments) throws Throwable {
 62  0
                 BAMTargetEntry bamTargetEntry = KSBServiceLocator.getBAMService().recordClientInvocation(this.serviceConfiguration, getTarget(), method, arguments);
 63  
                 try {
 64  0
                         return method.invoke(getTarget(), arguments);        
 65  0
                 } catch (Throwable throwable) {
 66  0
                         if (throwable instanceof InvocationTargetException) {
 67  0
                                 throwable = throwable.getCause();
 68  
                         }
 69  0
                         KSBServiceLocator.getBAMService().recordClientInvocationError(throwable, bamTargetEntry);
 70  0
                         throw throwable;
 71  
                 }
 72  
         }
 73  
 }