01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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 edu.iu.uis.eden.messaging.objectremoting;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.apache.log4j.Logger;
21: import org.kuali.bus.services.KSBServiceLocator;
22: import org.kuali.rice.core.Core;
23: import org.kuali.rice.definition.ObjectDefinition;
24: import org.kuali.rice.lifecycle.BaseLifecycle;
25: import org.kuali.rice.resourceloader.GlobalResourceLoader;
26:
27: import edu.iu.uis.eden.messaging.JavaServiceDefinition;
28: import edu.iu.uis.eden.messaging.ServiceInfo;
29: import edu.iu.uis.eden.messaging.config.ServiceBasedServiceDefinitionRegisterer;
30:
31: public class ObjectRemoterServiceImpl extends BaseLifecycle implements
32: ObjectRemoterService {
33:
34: private static final Logger LOG = Logger
35: .getLogger(ObjectRemoterServiceImpl.class);
36:
37: private ServiceBasedServiceDefinitionRegisterer defRegisterer;
38: private static long counter = 0;
39:
40: public ServiceInfo getRemotedClassURL(
41: ObjectDefinition objectDefinition) {
42: LOG.debug("Looking for object "
43: + objectDefinition.getClassName());
44: objectDefinition.setAtRemotingLayer(true);
45: Object target = GlobalResourceLoader.getResourceLoader()
46: .getObject(objectDefinition);
47: //make sure that we have the class
48: if (target == null) {
49: LOG.debug("Didn't find object " + objectDefinition);
50: return null;
51: }
52:
53: LOG.debug("Found object " + objectDefinition);
54: JavaServiceDefinition serviceDefinition = new JavaServiceDefinition();
55: serviceDefinition.setLocalServiceName(objectDefinition
56: .getClassName()
57: + counter++);
58: serviceDefinition.setService(target);
59: serviceDefinition.validate();
60:
61: KSBServiceLocator.getServiceDeployer().registerTempService(
62: serviceDefinition, target);
63: serviceDefinition.setService(null);
64: return new ServiceInfo(serviceDefinition);
65: }
66:
67: public void removeService(QName serviceName) {
68: LOG.debug("Removing service " + serviceName
69: + " from message entity"
70: + Core.getCurrentContextConfig().getMessageEntity());
71: KSBServiceLocator.getServiceDeployer()
72: .removeRemoteServiceFromRegistry(serviceName);
73: }
74:
75: public void start() throws Exception {
76: this .defRegisterer = new ServiceBasedServiceDefinitionRegisterer(
77: "ksb.objectRemoterServiceDefinition");
78: this .defRegisterer.registerServiceDefinition(false);
79: setStarted(true);
80: }
81:
82: public void stop() throws Exception {
83: this .defRegisterer.unregisterServiceDefinition();
84: setStarted(false);
85: }
86: }
|