KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > jms > JmsInUsingJCABinding


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
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 org.apache.servicemix.components.jms;
18
19 import javax.jbi.JBIException;
20 import javax.resource.spi.ActivationSpec JavaDoc;
21 import javax.transaction.TransactionManager JavaDoc;
22
23 import org.jencks.JCAConnector;
24 import org.jencks.JCAContainer;
25 import org.jencks.SingletonEndpointFactory;
26
27 /**
28  * Uses the JCA Container for better inbound subscription.
29  *
30  * @version $Revision: 441058 $
31  */

32 public class JmsInUsingJCABinding extends JmsInBinding {
33
34     private JCAContainer jcaContainer;
35     private ActivationSpec JavaDoc activationSpec;
36     private TransactionManager JavaDoc transactionManager;
37     private JCAConnector jcaConnector;
38
39     protected void init() throws JBIException {
40         if (jcaContainer == null) {
41             throw new IllegalArgumentException JavaDoc("Must specify a jcaContainer property");
42         }
43         if (activationSpec == null) {
44             throw new IllegalArgumentException JavaDoc("Must specify an activationSpec property");
45         }
46         jcaConnector = jcaContainer.addConnector();
47         jcaConnector.setActivationSpec(activationSpec);
48         if (transactionManager == null) {
49             transactionManager = (TransactionManager JavaDoc) getContext().getTransactionManager();
50         }
51         if (transactionManager != null) {
52             jcaConnector.setTransactionManager(transactionManager);
53         }
54         jcaConnector.setEndpointFactory(new SingletonEndpointFactory(this, transactionManager));
55         try {
56             jcaConnector.afterPropertiesSet();
57         } catch (Exception JavaDoc e) {
58             throw new JBIException("Unable to initialize jca connector", e);
59         }
60         super.init();
61     }
62     
63     public void start() throws JBIException {
64         try {
65             jcaConnector.start();
66         } catch (Exception JavaDoc e) {
67             throw new JBIException("Unable to start jca connector", e);
68         }
69         super.start();
70     }
71     
72     public void stop() throws JBIException {
73         super.stop();
74         try {
75             jcaConnector.destroy();
76         } catch (Exception JavaDoc e) {
77             throw new JBIException("Unable to stop jca connector", e);
78         }
79     }
80
81     public JCAContainer getJcaContainer() {
82         return jcaContainer;
83     }
84
85     public void setJcaContainer(JCAContainer jcaContainer) {
86         this.jcaContainer = jcaContainer;
87     }
88
89     public ActivationSpec JavaDoc getActivationSpec() {
90         return activationSpec;
91     }
92
93     public void setActivationSpec(ActivationSpec JavaDoc activationSpec) {
94         this.activationSpec = activationSpec;
95     }
96
97     public TransactionManager JavaDoc getTransactionManager() {
98         return transactionManager;
99     }
100
101     public void setTransactionManager(TransactionManager JavaDoc transactionManager) {
102         this.transactionManager = transactionManager;
103     }
104
105     public JCAConnector getJcaConnector() {
106         return jcaConnector;
107     }
108 }
109
Popular Tags