KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > client > JBossConnection


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.client;
8
9 import java.util.Enumeration JavaDoc;
10
11 import javax.jms.Connection JavaDoc;
12 import javax.jms.ConnectionConsumer JavaDoc;
13 import javax.jms.ConnectionMetaData JavaDoc;
14 import javax.jms.Destination JavaDoc;
15 import javax.jms.ExceptionListener JavaDoc;
16 import javax.jms.JMSException JavaDoc;
17 import javax.jms.Queue JavaDoc;
18 import javax.jms.QueueConnection JavaDoc;
19 import javax.jms.QueueSession JavaDoc;
20 import javax.jms.ServerSessionPool JavaDoc;
21 import javax.jms.Session JavaDoc;
22 import javax.jms.Topic JavaDoc;
23 import javax.jms.TopicConnection JavaDoc;
24 import javax.jms.TopicSession JavaDoc;
25 import javax.jms.XAConnection JavaDoc;
26 import javax.jms.XAQueueConnection JavaDoc;
27 import javax.jms.XAQueueSession JavaDoc;
28 import javax.jms.XASession JavaDoc;
29 import javax.jms.XATopicConnection JavaDoc;
30 import javax.jms.XATopicSession JavaDoc;
31
32 /**
33  * A connection
34  *
35  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
36  * @version $Revision: 1.3 $
37  */

38 public class JBossConnection
39    implements Connection JavaDoc, QueueConnection JavaDoc, TopicConnection JavaDoc,
40               XAConnection JavaDoc, XAQueueConnection JavaDoc, XATopicConnection JavaDoc
41 {
42    // Constants -----------------------------------------------------
43

44    // Attributes ----------------------------------------------------
45

46    /** The connection delegate */
47    private ConnectionDelegate delegate;
48
49    /** The exception listener */
50    private ExceptionListener JavaDoc listener;
51
52    /** Are we an XAConnection */
53    private boolean isXAConnection;
54
55    // Static --------------------------------------------------------
56

57    // Constructors --------------------------------------------------
58

59    public JBossConnection(ConnectionDelegate delegate, boolean isXAConnection)
60       throws JMSException JavaDoc
61    {
62       this.delegate = delegate;
63       this.isXAConnection = isXAConnection;
64    }
65
66    // Public --------------------------------------------------------
67

68    /**
69     * Retrieve the extension property names
70     */

71    public Enumeration JavaDoc getJMSXPropertyNames()
72       throws JMSException JavaDoc
73    {
74       return delegate.getJMSXPropertyNames();
75    }
76
77    // Connection implementation -------------------------------------
78

79     public void close() throws JMSException JavaDoc
80     {
81       delegate.closing();
82       delegate.close();
83     }
84
85     public ConnectionConsumer JavaDoc createConnectionConsumer(
86         Destination JavaDoc destination,
87         String JavaDoc messageSelector,
88         ServerSessionPool JavaDoc sessionPool,
89         int maxMessages)
90         throws JMSException JavaDoc
91     {
92         // TODO createConnectionConsumer
93
return null;
94     }
95
96     public ConnectionConsumer JavaDoc createDurableConnectionConsumer(
97         Topic JavaDoc topic,
98         String JavaDoc subscriptionName,
99         String JavaDoc messageSelector,
100         ServerSessionPool JavaDoc sessionPool,
101         int maxMessages)
102         throws JMSException JavaDoc
103     {
104         // TODO createDurableConnectionConsumer
105
return null;
106     }
107
108     public Session JavaDoc createSession(boolean transacted, int acknowledgeMode) throws JMSException JavaDoc
109     {
110       if (transacted)
111          acknowledgeMode = Session.SESSION_TRANSACTED;
112       return new JBossSession(delegate.createSession(false, transacted, acknowledgeMode), false, transacted, acknowledgeMode);
113     }
114
115     public String JavaDoc getClientID() throws JMSException JavaDoc
116     {
117       return delegate.getClientID();
118     }
119
120     public ExceptionListener JavaDoc getExceptionListener() throws JMSException JavaDoc
121     {
122       return listener;
123     }
124
125     public ConnectionMetaData JavaDoc getMetaData() throws JMSException JavaDoc
126     {
127       return new JBossConnectionMetaData(delegate);
128     }
129
130     public void setClientID(String JavaDoc clientID) throws JMSException JavaDoc
131     {
132       delegate.setClientID(clientID);
133     }
134
135     public void setExceptionListener(ExceptionListener JavaDoc listener) throws JMSException JavaDoc
136     {
137       delegate.setExceptionListener(listener);
138       this.listener = listener;
139     }
140
141     public void start() throws JMSException JavaDoc
142     {
143       delegate.start();
144     }
145
146     public void stop() throws JMSException JavaDoc
147     {
148       delegate.stop();
149     }
150
151    // QueueConnection implementation --------------------------------
152

153     public ConnectionConsumer JavaDoc createConnectionConsumer(
154         Queue JavaDoc queue,
155         String JavaDoc messageSelector,
156         ServerSessionPool JavaDoc sessionPool,
157         int maxMessages)
158         throws JMSException JavaDoc
159     {
160       return createConnectionConsumer((Destination JavaDoc) queue, messageSelector, sessionPool, maxMessages);
161     }
162
163     public QueueSession JavaDoc createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException JavaDoc
164     {
165       return (QueueSession JavaDoc) createSession(transacted, acknowledgeMode);
166     }
167
168    // TopicConnection implementation --------------------------------
169

170     public ConnectionConsumer JavaDoc createConnectionConsumer(
171         Topic JavaDoc topic,
172         String JavaDoc messageSelector,
173         ServerSessionPool JavaDoc sessionPool,
174         int maxMessages)
175         throws JMSException JavaDoc
176     {
177       return createConnectionConsumer((Destination JavaDoc) topic, messageSelector, sessionPool, maxMessages);
178     }
179
180     public TopicSession JavaDoc createTopicSession(boolean transacted, int acknowledgeMode)
181       throws JMSException JavaDoc
182     {
183       return (TopicSession JavaDoc) createSession(transacted, acknowledgeMode);
184     }
185
186    // XAConnection implementation -----------------------------------
187

188    public XASession JavaDoc createXASession() throws JMSException JavaDoc
189    {
190       if (isXAConnection == false)
191          throw new JMSException JavaDoc("Not an xa connection");
192       return new JBossSession(delegate.createSession(true, true, Session.SESSION_TRANSACTED), true, true, Session.SESSION_TRANSACTED);
193    }
194
195    // XAQueueConnection implementation ------------------------------
196

197    public XAQueueSession JavaDoc createXAQueueSession() throws JMSException JavaDoc
198    {
199       return (XAQueueSession JavaDoc) createXASession();
200    }
201
202    // XATopicConnection implementation ------------------------------
203

204    public XATopicSession JavaDoc createXATopicSession() throws JMSException JavaDoc
205    {
206       return (XATopicSession JavaDoc) createXASession();
207    }
208
209    // Protected ------------------------------------------------------
210

211    // Package Private ------------------------------------------------
212

213    // Private --------------------------------------------------------
214

215    // Inner Classes --------------------------------------------------
216
}
217
Popular Tags