001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.jms.client;
023:
024: import java.util.Enumeration;
025:
026: import javax.jms.Connection;
027: import javax.jms.ConnectionConsumer;
028: import javax.jms.ConnectionMetaData;
029: import javax.jms.Destination;
030: import javax.jms.ExceptionListener;
031: import javax.jms.JMSException;
032: import javax.jms.Queue;
033: import javax.jms.QueueConnection;
034: import javax.jms.QueueSession;
035: import javax.jms.ServerSessionPool;
036: import javax.jms.Session;
037: import javax.jms.Topic;
038: import javax.jms.TopicConnection;
039: import javax.jms.TopicSession;
040: import javax.jms.XAConnection;
041: import javax.jms.XAQueueConnection;
042: import javax.jms.XAQueueSession;
043: import javax.jms.XASession;
044: import javax.jms.XATopicConnection;
045: import javax.jms.XATopicSession;
046:
047: /**
048: * A connection
049: *
050: * @author <a href="mailto:adrian@jboss.org>Adrian Brock</a>
051: * @version $Revision: 57195 $
052: */
053: public class JBossConnection implements Connection, QueueConnection,
054: TopicConnection, XAConnection, XAQueueConnection,
055: XATopicConnection {
056: // Constants -----------------------------------------------------
057:
058: // Attributes ----------------------------------------------------
059:
060: /** The connection delegate */
061: private ConnectionDelegate delegate;
062:
063: /** The exception listener */
064: private ExceptionListener listener;
065:
066: /** Are we an XAConnection */
067: private boolean isXAConnection;
068:
069: // Static --------------------------------------------------------
070:
071: // Constructors --------------------------------------------------
072:
073: public JBossConnection(ConnectionDelegate delegate,
074: boolean isXAConnection) throws JMSException {
075: this .delegate = delegate;
076: this .isXAConnection = isXAConnection;
077: }
078:
079: // Public --------------------------------------------------------
080:
081: /**
082: * Retrieve the extension property names
083: */
084: public Enumeration getJMSXPropertyNames() throws JMSException {
085: return delegate.getJMSXPropertyNames();
086: }
087:
088: // Connection implementation -------------------------------------
089:
090: public void close() throws JMSException {
091: delegate.closing();
092: delegate.close();
093: }
094:
095: public ConnectionConsumer createConnectionConsumer(
096: Destination destination, String messageSelector,
097: ServerSessionPool sessionPool, int maxMessages)
098: throws JMSException {
099: // TODO createConnectionConsumer
100: return null;
101: }
102:
103: public ConnectionConsumer createDurableConnectionConsumer(
104: Topic topic, String subscriptionName,
105: String messageSelector, ServerSessionPool sessionPool,
106: int maxMessages) throws JMSException {
107: // TODO createDurableConnectionConsumer
108: return null;
109: }
110:
111: public Session createSession(boolean transacted, int acknowledgeMode)
112: throws JMSException {
113: if (transacted)
114: acknowledgeMode = Session.SESSION_TRANSACTED;
115: return new JBossSession(delegate.createSession(false,
116: transacted, acknowledgeMode), false, transacted,
117: acknowledgeMode);
118: }
119:
120: public String getClientID() throws JMSException {
121: return delegate.getClientID();
122: }
123:
124: public ExceptionListener getExceptionListener() throws JMSException {
125: return listener;
126: }
127:
128: public ConnectionMetaData getMetaData() throws JMSException {
129: return new JBossConnectionMetaData(delegate);
130: }
131:
132: public void setClientID(String clientID) throws JMSException {
133: delegate.setClientID(clientID);
134: }
135:
136: public void setExceptionListener(ExceptionListener listener)
137: throws JMSException {
138: delegate.setExceptionListener(listener);
139: this .listener = listener;
140: }
141:
142: public void start() throws JMSException {
143: delegate.start();
144: }
145:
146: public void stop() throws JMSException {
147: delegate.stop();
148: }
149:
150: // QueueConnection implementation --------------------------------
151:
152: public ConnectionConsumer createConnectionConsumer(Queue queue,
153: String messageSelector, ServerSessionPool sessionPool,
154: int maxMessages) throws JMSException {
155: return createConnectionConsumer((Destination) queue,
156: messageSelector, sessionPool, maxMessages);
157: }
158:
159: public QueueSession createQueueSession(boolean transacted,
160: int acknowledgeMode) throws JMSException {
161: return (QueueSession) createSession(transacted, acknowledgeMode);
162: }
163:
164: // TopicConnection implementation --------------------------------
165:
166: public ConnectionConsumer createConnectionConsumer(Topic topic,
167: String messageSelector, ServerSessionPool sessionPool,
168: int maxMessages) throws JMSException {
169: return createConnectionConsumer((Destination) topic,
170: messageSelector, sessionPool, maxMessages);
171: }
172:
173: public TopicSession createTopicSession(boolean transacted,
174: int acknowledgeMode) throws JMSException {
175: return (TopicSession) createSession(transacted, acknowledgeMode);
176: }
177:
178: // XAConnection implementation -----------------------------------
179:
180: public XASession createXASession() throws JMSException {
181: if (isXAConnection == false)
182: throw new JMSException("Not an xa connection");
183: return new JBossSession(delegate.createSession(true, true,
184: Session.SESSION_TRANSACTED), true, true,
185: Session.SESSION_TRANSACTED);
186: }
187:
188: // XAQueueConnection implementation ------------------------------
189:
190: public XAQueueSession createXAQueueSession() throws JMSException {
191: return (XAQueueSession) createXASession();
192: }
193:
194: // XATopicConnection implementation ------------------------------
195:
196: public XATopicSession createXATopicSession() throws JMSException {
197: return (XATopicSession) createXASession();
198: }
199:
200: // Protected ------------------------------------------------------
201:
202: // Package Private ------------------------------------------------
203:
204: // Private --------------------------------------------------------
205:
206: // Inner Classes --------------------------------------------------
207: }
|