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.resource.adapter.jms;
023:
024: import javax.jms.Connection;
025: import javax.jms.JMSException;
026: import javax.jms.QueueConnection;
027: import javax.jms.TopicConnection;
028: import javax.naming.Reference;
029: import javax.resource.Referenceable;
030: import javax.resource.spi.ConnectionManager;
031: import javax.resource.spi.ManagedConnectionFactory;
032:
033: import org.jboss.logging.Logger;
034:
035: /**
036: * The the connection factory implementation for the JMS RA.
037: *
038: * <p>
039: * This object will be the QueueConnectionFactory or TopicConnectionFactory
040: * which clients will use to create connections.
041: *
042: * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>.
043: * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
044: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
045: * @version <tt>$Revision: 57189 $</tt>
046: */
047: public class JmsConnectionFactoryImpl implements JmsConnectionFactory,
048: Referenceable {
049: private static final long serialVersionUID = -5135366013101194277L;
050:
051: private static final Logger log = Logger
052: .getLogger(JmsConnectionFactoryImpl.class);
053:
054: private ManagedConnectionFactory mcf;
055:
056: private ConnectionManager cm;
057:
058: private Reference reference;
059:
060: public JmsConnectionFactoryImpl(final ManagedConnectionFactory mcf,
061: final ConnectionManager cm) {
062: this .mcf = mcf;
063:
064: boolean trace = log.isTraceEnabled();
065: if (cm == null) {
066: // This is standalone usage, no appserver
067: this .cm = new JmsConnectionManager();
068: if (trace)
069: log.trace("Created new connection manager");
070: } else
071: this .cm = cm;
072:
073: if (trace)
074: log.trace("Using ManagedConnectionFactory=" + mcf
075: + ", ConnectionManager=" + cm);
076: }
077:
078: public void setReference(final Reference reference) {
079: this .reference = reference;
080:
081: if (log.isTraceEnabled())
082: log.trace("Using Reference=" + reference);
083: }
084:
085: public Reference getReference() {
086: return reference;
087: }
088:
089: // --- QueueConnectionFactory
090:
091: public QueueConnection createQueueConnection() throws JMSException {
092: QueueConnection qc = new JmsSessionFactoryImpl(mcf, cm, QUEUE);
093:
094: if (log.isTraceEnabled())
095: log.trace("Created queue connection: " + qc);
096:
097: return qc;
098: }
099:
100: public QueueConnection createQueueConnection(String userName,
101: String password) throws JMSException {
102: JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm,
103: QUEUE);
104: s.setUserName(userName);
105: s.setPassword(password);
106:
107: if (log.isTraceEnabled())
108: log.trace("Created queue connection: " + s);
109:
110: return s;
111: }
112:
113: // --- TopicConnectionFactory
114:
115: public TopicConnection createTopicConnection() throws JMSException {
116: TopicConnection tc = new JmsSessionFactoryImpl(mcf, cm, TOPIC);
117:
118: if (log.isTraceEnabled())
119: log.trace("Created topic connection: " + tc);
120:
121: return tc;
122: }
123:
124: public TopicConnection createTopicConnection(String userName,
125: String password) throws JMSException {
126: JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm,
127: TOPIC);
128: s.setUserName(userName);
129: s.setPassword(password);
130:
131: if (log.isTraceEnabled())
132: log.trace("Created topic connection: " + s);
133:
134: return s;
135: }
136:
137: // --- JMS 1.1
138:
139: public Connection createConnection() throws JMSException {
140: Connection c = new JmsSessionFactoryImpl(mcf, cm, BOTH);
141:
142: if (log.isTraceEnabled())
143: log.trace("Created connection: " + c);
144:
145: return c;
146: }
147:
148: public Connection createConnection(String userName, String password)
149: throws JMSException {
150: JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm,
151: BOTH);
152: s.setUserName(userName);
153: s.setPassword(password);
154:
155: if (log.isTraceEnabled())
156: log.trace("Created connection: " + s);
157:
158: return s;
159: }
160: }
|