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.serviceexporters;
18:
19: import javax.jms.Connection;
20: import javax.jms.ConnectionFactory;
21: import javax.jms.Destination;
22: import javax.jms.Queue;
23: import javax.jms.Session;
24:
25: import org.kuali.rice.exceptions.RiceRuntimeException;
26: import org.logicblaze.lingo.jms.JmsServiceExporter;
27:
28: import edu.iu.uis.eden.messaging.JmsServiceDefinition;
29: import edu.iu.uis.eden.messaging.ServerSideRemotedServiceHolder;
30: import edu.iu.uis.eden.messaging.ServiceInfo;
31: import edu.iu.uis.eden.messaging.bam.BAMServerProxy;
32:
33: /**
34: *
35: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
36: */
37: public class JmsExporter implements ServiceExporter {
38:
39: private ServiceInfo serviceInfo;
40:
41: public JmsExporter(ServiceInfo serviceInfo) {
42: this .setServiceInfo(serviceInfo);
43: }
44:
45: public ServerSideRemotedServiceHolder getServiceExporter(
46: Object serviceImpl) {
47: try {
48: ConnectionFactory connectionFactory = ((JmsServiceDefinition) this .serviceInfo
49: .getServiceDefinition()).getConnectionFactory();
50: String interfaceName = ((JmsServiceDefinition) this .serviceInfo
51: .getServiceDefinition()).getServiceInterface();
52: JmsServiceExporter jmsExporter = new JmsServiceExporter();
53: jmsExporter.setService(wrapServiceInBamProxy(serviceImpl));
54: jmsExporter.setServiceInterface(Class
55: .forName(interfaceName));
56: jmsExporter.setConnectionFactory(connectionFactory);
57: jmsExporter.setDestination(getDestination(
58: connectionFactory, interfaceName));
59: jmsExporter.afterPropertiesSet();
60: return new ServerSideRemotedServiceHolder(null,
61: serviceImpl, this .serviceInfo);
62: } catch (Exception e) {
63: throw new RiceRuntimeException(
64: "Unable to configure service "
65: + this .getServiceInfo(), e);
66: }
67: }
68:
69: public ServiceInfo getServiceInfo() {
70: return this .serviceInfo;
71: }
72:
73: public void setServiceInfo(ServiceInfo serviceInfo) {
74: this .serviceInfo = serviceInfo;
75: }
76:
77: protected Destination getDestination(
78: ConnectionFactory connectionFactory, String queueName)
79: throws Exception {
80: Connection connection = connectionFactory.createConnection();
81: Session session = connection.createSession(true,
82: Session.AUTO_ACKNOWLEDGE);
83: Queue queue = session.createQueue(queueName);
84: return queue;
85: }
86:
87: protected Object wrapServiceInBamProxy(Object service) {
88: return BAMServerProxy.wrap(service, this.getServiceInfo());
89: }
90: }
|