KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jms > JmsConnectionFactoryImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.adapter.jms;
23
24 import javax.jms.Connection JavaDoc;
25 import javax.jms.JMSException JavaDoc;
26 import javax.jms.QueueConnection JavaDoc;
27 import javax.jms.TopicConnection JavaDoc;
28 import javax.naming.Reference JavaDoc;
29 import javax.resource.Referenceable JavaDoc;
30 import javax.resource.spi.ConnectionManager JavaDoc;
31 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
32
33 import org.jboss.logging.Logger;
34
35 /**
36  * The the connection factory implementation for the JMS RA.
37  *
38  * <p>
39  * This object will be the QueueConnectionFactory or TopicConnectionFactory
40  * which clients will use to create connections.
41  *
42  * @author <a HREF="mailto:peter.antman@tim.se">Peter Antman</a>.
43  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
44  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
45  * @version <tt>$Revision: 38315 $</tt>
46  */

47 public class JmsConnectionFactoryImpl
48    implements JmsConnectionFactory, Referenceable JavaDoc
49 {
50    private static final long serialVersionUID = -5135366013101194277L;
51
52    private static final Logger log = Logger.getLogger(JmsConnectionFactoryImpl.class);
53
54    private ManagedConnectionFactory JavaDoc mcf;
55
56    private ConnectionManager JavaDoc cm;
57
58    private Reference JavaDoc reference;
59
60    public JmsConnectionFactoryImpl(final ManagedConnectionFactory JavaDoc mcf,
61                                    final ConnectionManager JavaDoc cm)
62    {
63       this.mcf = mcf;
64
65       boolean trace = log.isTraceEnabled();
66       if (cm == null)
67       {
68          // This is standalone usage, no appserver
69
this.cm = new JmsConnectionManager();
70          if (trace)
71             log.trace("Created new connection manager");
72       }
73       else
74          this.cm = cm;
75
76       if (trace)
77          log.trace("Using ManagedConnectionFactory=" + mcf + ", ConnectionManager=" + cm);
78    }
79
80    public void setReference(final Reference JavaDoc reference)
81    {
82       this.reference = reference;
83
84       if (log.isTraceEnabled())
85          log.trace("Using Reference=" + reference);
86    }
87     
88    public Reference JavaDoc getReference()
89    {
90       return reference;
91    }
92    
93    // --- QueueConnectionFactory
94

95    public QueueConnection JavaDoc createQueueConnection() throws JMSException JavaDoc
96    {
97       QueueConnection JavaDoc qc = new JmsSessionFactoryImpl(mcf, cm, QUEUE);
98
99       if (log.isTraceEnabled())
100          log.trace("Created queue connection: " + qc);
101       
102       return qc;
103    }
104    
105    public QueueConnection JavaDoc createQueueConnection(String JavaDoc userName, String JavaDoc password)
106       throws JMSException JavaDoc
107    {
108       JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, QUEUE);
109       s.setUserName(userName);
110       s.setPassword(password);
111
112       if (log.isTraceEnabled())
113          log.trace("Created queue connection: " + s);
114       
115       return s;
116    }
117
118    // --- TopicConnectionFactory
119

120    public TopicConnection JavaDoc createTopicConnection() throws JMSException JavaDoc
121    {
122       TopicConnection JavaDoc tc = new JmsSessionFactoryImpl(mcf, cm, TOPIC);
123
124       if (log.isTraceEnabled())
125          log.trace("Created topic connection: " + tc);
126
127       return tc;
128    }
129    
130    public TopicConnection JavaDoc createTopicConnection(String JavaDoc userName, String JavaDoc password)
131       throws JMSException JavaDoc
132    {
133       JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, TOPIC);
134       s.setUserName(userName);
135       s.setPassword(password);
136       
137       if (log.isTraceEnabled())
138          log.trace("Created topic connection: " + s);
139
140       return s;
141    }
142
143    // --- JMS 1.1
144

145    public Connection JavaDoc createConnection()
146       throws JMSException JavaDoc
147    {
148       Connection JavaDoc c = new JmsSessionFactoryImpl(mcf, cm, BOTH);
149
150       if (log.isTraceEnabled())
151          log.trace("Created connection: " + c);
152
153       return c;
154    }
155
156    public Connection JavaDoc createConnection(String JavaDoc userName, String JavaDoc password)
157       throws JMSException JavaDoc
158    {
159       JmsSessionFactoryImpl s = new JmsSessionFactoryImpl(mcf, cm, BOTH);
160       s.setUserName(userName);
161       s.setPassword(password);
162       
163       if (log.isTraceEnabled())
164          log.trace("Created connection: " + s);
165
166       return s;
167    }
168 }
169
Popular Tags