Coverage Report - org.kuali.rice.ksb.messaging.KSBClientProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
KSBClientProxy
0%
0/12
0%
0/2
2.333
 
 1  
 /*
 2  
  * Copyright 2009 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;
 17  
 
 18  
 import java.lang.reflect.InvocationHandler;
 19  
 import java.lang.reflect.InvocationTargetException;
 20  
 import java.lang.reflect.Method;
 21  
 import java.lang.reflect.Proxy;
 22  
 
 23  
 import javax.xml.namespace.QName;
 24  
 
 25  
 import org.apache.log4j.Logger;
 26  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 27  
 
 28  
 /**
 29  
  * This class creates a proxy for services deployed on KSB. A 
 30  
  * reference to the service is obtained only upon the first method
 31  
  * invocation.
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  
 public class KSBClientProxy implements InvocationHandler {
 37  
 
 38  0
 private static final Logger LOG = Logger.getLogger(KSBClientProxy.class);
 39  
     
 40  
     QName serviceName;
 41  
     Object service;
 42  
 
 43  
     @SuppressWarnings("unchecked")
 44  
     public static <T> T newInstance(String serviceQName, Class<T> interfaceClass) throws InstantiationException, IllegalAccessException {
 45  0
         return (T)Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, new KSBClientProxy(serviceQName));
 46  
     }
 47  
 
 48  0
     public KSBClientProxy(String serviceQName){
 49  0
         this.serviceName = QName.valueOf(serviceQName);
 50  0
     }
 51  
     
 52  
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
 53  0
         if (this.service == null){
 54  0
             LOG.info("Getting service using GRL for: " + serviceName);
 55  0
             service = GlobalResourceLoader.getService(serviceName);
 56  0
             LOG.info("Obtained service using GRL for: " + serviceName);
 57  
         }
 58  
         try {
 59  0
                 return method.invoke(service, args);
 60  0
             } catch (InvocationTargetException e) {
 61  0
                 throw e.getCause();
 62  
             }
 63  
     }
 64  
 
 65  
 }