Coverage Report - org.kuali.rice.ksb.messaging.objectremoting.ObjectRemoterServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectRemoterServiceImpl
0%
0/27
0%
0/2
1.5
 
 1  
 /*
 2  
  * Copyright 2007 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.objectremoting;
 17  
 
 18  
 import javax.xml.namespace.QName;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.core.config.ConfigContext;
 22  
 import org.kuali.rice.core.lifecycle.BaseLifecycle;
 23  
 import org.kuali.rice.core.reflect.ObjectDefinition;
 24  
 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
 25  
 import org.kuali.rice.ksb.messaging.JavaServiceDefinition;
 26  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 27  
 import org.kuali.rice.ksb.messaging.config.ServiceBasedServiceDefinitionRegisterer;
 28  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 29  
 
 30  
 
 31  0
 public class ObjectRemoterServiceImpl extends BaseLifecycle implements ObjectRemoterService {
 32  
 
 33  0
         private static final Logger LOG = Logger.getLogger(ObjectRemoterServiceImpl.class);
 34  
 
 35  
         private ServiceBasedServiceDefinitionRegisterer defRegisterer;
 36  0
         private static long counter = 0;
 37  
 
 38  
         public ServiceInfo getRemotedClassURL(ObjectDefinition objectDefinition) {
 39  0
                 LOG.debug("Looking for object " + objectDefinition.getClassName());
 40  0
                 objectDefinition.setAtRemotingLayer(true);
 41  0
                 Object target = GlobalResourceLoader.getResourceLoader().getObject(objectDefinition);
 42  
                 //make sure that we have the class
 43  0
                 if (target == null) {
 44  0
                         LOG.debug("Didn't find object " + objectDefinition);
 45  0
                         return null;
 46  
                 }
 47  
 
 48  0
                 LOG.debug("Found object " + objectDefinition);
 49  0
                 JavaServiceDefinition serviceDefinition = new JavaServiceDefinition();
 50  0
                 serviceDefinition.setLocalServiceName(objectDefinition.getClassName() + counter++);
 51  0
                 serviceDefinition.setService(target);
 52  0
                 serviceDefinition.validate();
 53  
                 
 54  0
                 KSBServiceLocator.getServiceDeployer().registerTempService(serviceDefinition, target);
 55  0
         serviceDefinition.setService(null);
 56  0
                 return new ServiceInfo(serviceDefinition);
 57  
         }
 58  
         
 59  
         public void removeService(QName serviceName) {
 60  0
                 LOG.debug("Removing service " + serviceName + " from service namespace" + ConfigContext.getCurrentContextConfig().getServiceNamespace());
 61  0
                 KSBServiceLocator.getServiceDeployer().removeRemoteServiceFromRegistry(serviceName);
 62  0
         }
 63  
 
 64  
         public void start() throws Exception {
 65  0
             this.defRegisterer = new ServiceBasedServiceDefinitionRegisterer("ksb.objectRemoterServiceDefinition");
 66  0
             this.defRegisterer.registerServiceDefinition(false);
 67  0
                 setStarted(true);
 68  0
         }
 69  
 
 70  
         public void stop() throws Exception {
 71  0
             this.defRegisterer.unregisterServiceDefinition();
 72  0
                 setStarted(false);
 73  0
         }
 74  
 }