01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.serviceconnectors;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.ByteArrayOutputStream;
21: import java.io.ObjectInputStream;
22: import java.io.ObjectOutput;
23: import java.io.ObjectOutputStream;
24:
25: import org.kuali.bus.services.KSBServiceLocator;
26:
27: import edu.iu.uis.eden.messaging.RemotedServiceHolder;
28: import edu.iu.uis.eden.messaging.RemotedServiceRegistry;
29: import edu.iu.uis.eden.messaging.ServiceInfo;
30: import edu.iu.uis.eden.messaging.bam.BAMClientProxy;
31:
32: /**
33: *
34: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
35: */
36: public class BusLocalConnector extends AbstractServiceConnector {
37:
38: public BusLocalConnector(final ServiceInfo serviceInfo) {
39: super (serviceInfo);
40: }
41:
42: public RemotedServiceHolder getServiceHolder() throws Exception {
43: final Object service = getServiceProxy(KSBServiceLocator
44: .getServiceDeployer().getLocalService(
45: getServiceInfo().getQname()));
46: return new RemotedServiceHolder(service,
47: cloneServiceInfo(getServiceInfo()));
48: }
49:
50: private Object getServiceProxy(Object service) {
51: return BAMClientProxy.wrap(service, getServiceInfo());
52: }
53:
54: /**
55: * this is a hack so we don't mess with the {@link ServiceInfo} on the deployment
56: * side of things from the {@link RemotedServiceRegistry}. We need the service in the {@link ServiceInfo}
57: * used on the client to be null but it can't be for the server side stuff - solution serialize the
58: * object just like it was put in a datastore.
59: *
60: * @param serviceInfo
61: * @return
62: * @throws Exception
63: */
64: private ServiceInfo cloneServiceInfo(final ServiceInfo serviceInfo)
65: throws Exception {
66:
67: ObjectInputStream in = null;
68: ObjectOutput out = null;
69: Object tempService = serviceInfo.getServiceDefinition()
70: .getService();
71:
72: try {
73: serviceInfo.getServiceDefinition().setService(null);
74: ByteArrayOutputStream bos = new ByteArrayOutputStream();
75: out = new ObjectOutputStream(bos);
76: out.writeObject(serviceInfo);
77:
78: in = new ObjectInputStream(new ByteArrayInputStream(bos
79: .toByteArray()));
80: return (ServiceInfo) in.readObject();
81: } finally {
82: serviceInfo.getServiceDefinition().setService(tempService);
83: in.close();
84: out.close();
85: }
86: }
87: }
|