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