KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > ra > ConnectionFactoryImpl


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Coridan.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.ra;
48
49
50 //import org.activemq.ra.jms.ConnectionProxy;
51
import java.io.Serializable JavaDoc;
52
53 import javax.jms.Connection JavaDoc;
54 import javax.jms.ConnectionFactory JavaDoc;
55 import javax.jms.QueueConnection JavaDoc;
56 import javax.jms.QueueConnectionFactory JavaDoc;
57 import javax.jms.TopicConnection JavaDoc;
58 import javax.jms.TopicConnectionFactory JavaDoc;
59 import javax.jms.JMSException JavaDoc;
60
61 import javax.naming.Reference JavaDoc;
62 import javax.resource.Referenceable JavaDoc;
63 import javax.resource.ResourceException JavaDoc;
64 import javax.resource.spi.ConnectionManager JavaDoc;
65
66 import org.apache.commons.logging.Log;
67 import org.apache.commons.logging.LogFactory;
68
69
70 /**
71  * @version $Revision: 1.1.1.1 $
72  */

73 public class ConnectionFactoryImpl implements ConnectionFactory JavaDoc, QueueConnectionFactory JavaDoc,
74                                               TopicConnectionFactory JavaDoc, Referenceable JavaDoc, Serializable JavaDoc
75 {
76     private static final long serialVersionUID = 3616445704952820529L;
77     private static final Log log = LogFactory.getLog(ConnectionFactoryImpl.class);
78     
79     transient private ConnectionManager JavaDoc manager;
80     transient private ManagedConnectionFactoryImpl factory;
81     private final ConnectionRequestInfoImpl info;
82     private Reference JavaDoc reference = null;
83
84
85     /**
86      * The constructor is called by the ManagedConnection.createConnection()
87      * @param factory
88      * @param manager
89      * @param info
90      */

91     public ConnectionFactoryImpl(ManagedConnectionFactoryImpl factory,
92                                  ConnectionManager JavaDoc manager,
93                                  ConnectionRequestInfoImpl info) {
94         this.factory = factory;
95         this.manager = manager;
96         this.info = info;
97     }
98     
99     
100     /**
101      * @param info
102      * @return
103      * @throws JMSException
104      */

105     private Connection JavaDoc createConnection(ConnectionRequestInfoImpl info) throws JMSException JavaDoc {
106         try {
107 // if( info.isUseInboundSessionEnabled() ) {
108
// return new ConnectionProxy();
109
// }
110

111             // Delegate the connection request to the ConnectionManager
112
// according to JCA 1.5 spec.
113
return (Connection JavaDoc) manager.allocateConnection(factory, info);
114         }
115         catch (ResourceException JavaDoc e) {
116             log.debug("Connection could not be created:", e);
117             // we want to throw JMSException here
118
if (e.getCause() instanceof JMSException JavaDoc) {
119                 // Throw the root cause if it was a JMSException
120
throw (JMSException JavaDoc) e.getCause();
121             }
122             throw new JMSException JavaDoc(e.getMessage());
123         }
124     }
125     
126     
127     ///////////////////////////////////////////////////////
128
//
129
// Implement the javax.jms.ConnectionFactory interface
130
//
131
///////////////////////////////////////////////////////
132

133     /**
134      * @see javax.jms.ConnectionFactory#createConnection()
135      */

136     public Connection JavaDoc createConnection() throws JMSException JavaDoc {
137         return createConnection(info.copy());
138     }
139
140     /**
141      * @see javax.jms.ConnectionFactory#createConnection(java.lang.String, java.lang.String)
142      */

143     public Connection JavaDoc createConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
144         ConnectionRequestInfoImpl i = info.copy();
145         i.setUserName(userName);
146         i.setPassword(password);
147         return createConnection(i);
148     }
149
150   
151     ////////////////////////////////////////////////////////////
152
//
153
// Implement the javax.jms.QueueConnectionFactory interface
154
//
155
////////////////////////////////////////////////////////////
156

157     /**
158      * @see javax.jms.QueueConnectionFactory#createQueueConnection(java.lang.String, java.lang.String)
159      */

160     public QueueConnection JavaDoc createQueueConnection() throws JMSException JavaDoc {
161         return (QueueConnection JavaDoc) createConnection();
162     }
163
164     /**
165      * @see javax.jms.QueueConnectionFactory#createQueueConnection(java.lang.String, java.lang.String)
166      */

167     public QueueConnection JavaDoc createQueueConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
168         return (QueueConnection JavaDoc) createConnection(userName, password);
169     }
170     
171     
172     ////////////////////////////////////////////////////////////
173
//
174
// Implement the javax.jms.TopicConnectionFactory interface
175
//
176
////////////////////////////////////////////////////////////
177

178     /**
179      * @see javax.jms.TopicConnectionFactory#createTopicConnection(java.lang.String, java.lang.String)
180      */

181     public TopicConnection JavaDoc createTopicConnection() throws JMSException JavaDoc {
182         return (TopicConnection JavaDoc) createConnection();
183     }
184     
185     /**
186      * @see javax.jms.TopicConnectionFactory#createTopicConnection(java.lang.String, java.lang.String)
187      */

188     public TopicConnection JavaDoc createTopicConnection(String JavaDoc userName, String JavaDoc password) throws JMSException JavaDoc {
189         return (TopicConnection JavaDoc) createConnection(userName, password);
190     }
191     
192     
193     ////////////////////////////////////////////////////////
194
//
195
// Implement the javax.resource.Referenceable interface
196
//
197
////////////////////////////////////////////////////////
198

199     /**
200      * @see javax.naming.Referenceable#getReference()
201      */

202     public Reference JavaDoc getReference() {
203         return reference;
204     }
205
206     /**
207      * @see javax.resource.Referenceable#setReference(javax.naming.Reference)
208      */

209     public void setReference(Reference JavaDoc reference) {
210         this.reference = reference;
211     }
212 }
213
Popular Tags