Source Code Cross Referenced for ConnectionFactoryHelper.java in  » EJB-Server-JBoss-4.2.1 » server » org » jboss » jms » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » server » org.jboss.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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;
023:
024:        import javax.jms.JMSException;
025:        import javax.jms.Connection;
026:        import javax.jms.ConnectionFactory;
027:        import javax.jms.QueueConnection;
028:        import javax.jms.QueueConnectionFactory;
029:        import javax.jms.TopicConnection;
030:        import javax.jms.TopicConnectionFactory;
031:        import javax.jms.XAConnectionFactory;
032:        import javax.jms.XAQueueConnectionFactory;
033:        import javax.jms.XATopicConnectionFactory;
034:
035:        import org.jboss.logging.Logger;
036:
037:        /**
038:         * A helper for creating connections from jms connection factories.
039:         *      
040:         * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
041:         * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
042:         * @version $Revision: 57209 $
043:         */
044:        public class ConnectionFactoryHelper {
045:            /** Class logger. */
046:            private static Logger log = Logger
047:                    .getLogger(ConnectionFactoryHelper.class);
048:
049:            /**
050:             * Create a connection from the given factory.  An XA connection will
051:             * be created if possible.
052:             *
053:             * @param factory     An object that implements ConnectionFactory,
054:             *                    XAQConnectionFactory
055:             * @param username    The username to use or null for no user.
056:             * @param password    The password for the given username or null if no
057:             *                    username was specified.
058:             * @return            A queue connection.
059:             *                    
060:             * @throws JMSException                Failed to create connection.
061:             * @throws IllegalArgumentException    Factory is null or invalid.
062:             */
063:            public static Connection createConnection(final Object factory,
064:                    final String username, final String password)
065:                    throws JMSException {
066:                if (factory == null)
067:                    throw new IllegalArgumentException("factory is null");
068:
069:                log.debug("using connection factory: " + factory);
070:                log.debug("using username/password: "
071:                        + String.valueOf(username) + "/-- not shown --");
072:
073:                Connection connection;
074:
075:                if (factory instanceof  XAConnectionFactory) {
076:                    XAConnectionFactory qFactory = (XAConnectionFactory) factory;
077:                    if (username != null)
078:                        connection = qFactory.createXAConnection(username,
079:                                password);
080:                    else
081:                        connection = qFactory.createXAConnection();
082:
083:                    log.debug("created XAConnection: " + connection);
084:                } else if (factory instanceof  ConnectionFactory) {
085:                    ConnectionFactory qFactory = (ConnectionFactory) factory;
086:                    if (username != null)
087:                        connection = qFactory.createConnection(username,
088:                                password);
089:                    else
090:                        connection = qFactory.createConnection();
091:
092:                    log.debug("created Connection: " + connection);
093:                } else {
094:                    throw new IllegalArgumentException("factory is invalid");
095:                }
096:
097:                return connection;
098:            }
099:
100:            /**
101:             * Create a connection from the given factory.  An XA connection will
102:             * be created if possible.
103:             *
104:             * @param factory     An object that implements QueueConnectionFactory,
105:             *                    XAQueueConnectionFactory
106:             * @return            A queue connection.
107:             *
108:             * @throws JMSException                Failed to create connection.
109:             * @throws IllegalArgumentException    Factory is null or invalid.
110:             */
111:            public static Connection createConnection(final Object factory)
112:                    throws JMSException {
113:                return createConnection(factory, null, null);
114:            }
115:
116:            /**
117:             * Create a queue connection from the given factory.  An XA connection will
118:             * be created if possible.
119:             *
120:             * @param factory     An object that implements QueueConnectionFactory,
121:             *                    XAQueueConnectionFactory
122:             * @param username    The username to use or null for no user.
123:             * @param password    The password for the given username or null if no
124:             *                    username was specified.
125:             * @return            A queue connection.
126:             *                    
127:             * @throws JMSException                Failed to create connection.
128:             * @throws IllegalArgumentException    Factory is null or invalid.
129:             */
130:            public static QueueConnection createQueueConnection(
131:                    final Object factory, final String username,
132:                    final String password) throws JMSException {
133:                if (factory == null)
134:                    throw new IllegalArgumentException("factory is null");
135:
136:                log.debug("using connection factory: " + factory);
137:                log.debug("using username/password: "
138:                        + String.valueOf(username) + "/-- not shown --");
139:
140:                QueueConnection connection;
141:
142:                if (factory instanceof  XAQueueConnectionFactory) {
143:                    XAQueueConnectionFactory qFactory = (XAQueueConnectionFactory) factory;
144:                    if (username != null)
145:                        connection = qFactory.createXAQueueConnection(username,
146:                                password);
147:                    else
148:                        connection = qFactory.createXAQueueConnection();
149:
150:                    log.debug("created XAQueueConnection: " + connection);
151:                } else if (factory instanceof  QueueConnectionFactory) {
152:                    QueueConnectionFactory qFactory = (QueueConnectionFactory) factory;
153:                    if (username != null)
154:                        connection = qFactory.createQueueConnection(username,
155:                                password);
156:                    else
157:                        connection = qFactory.createQueueConnection();
158:
159:                    log.debug("created QueueConnection: " + connection);
160:                } else
161:                    throw new IllegalArgumentException("factory is invalid");
162:
163:                return connection;
164:            }
165:
166:            /**
167:             * Create a queue connection from the given factory.  An XA connection will
168:             * be created if possible.
169:             *
170:             * @param factory     An object that implements QueueConnectionFactory,
171:             *                    XAQueueConnectionFactory
172:             * @return            A queue connection.
173:             *
174:             * @throws JMSException                Failed to create connection.
175:             * @throws IllegalArgumentException    Factory is null or invalid.
176:             */
177:            public static QueueConnection createQueueConnection(
178:                    final Object factory) throws JMSException {
179:                return createQueueConnection(factory, null, null);
180:            }
181:
182:            /**
183:             * Create a topic connection from the given factory.  An XA connection will
184:             * be created if possible.
185:             *
186:             * @param factory     An object that implements TopicConnectionFactory,
187:             *                    XATopicConnectionFactory
188:             * @param username    The username to use or null for no user.
189:             * @param password    The password for the given username or null if no
190:             *                    username was specified.
191:             * @return            A topic connection.
192:             *                    
193:             * @throws JMSException                Failed to create connection.
194:             * @throws IllegalArgumentException    Factory is null or invalid.
195:             */
196:            public static TopicConnection createTopicConnection(
197:                    final Object factory, final String username,
198:                    final String password) throws JMSException {
199:                if (factory == null)
200:                    throw new IllegalArgumentException("factory is null");
201:
202:                log.debug("using connection factory: " + factory);
203:                log.debug("using username/password: "
204:                        + String.valueOf(username) + "/-- not shown --");
205:
206:                TopicConnection connection;
207:
208:                if (factory instanceof  XATopicConnectionFactory) {
209:                    XATopicConnectionFactory tFactory = (XATopicConnectionFactory) factory;
210:                    if (username != null)
211:                        connection = tFactory.createXATopicConnection(username,
212:                                password);
213:                    else
214:                        connection = tFactory.createXATopicConnection();
215:
216:                    log.debug("created XATopicConnection: " + connection);
217:                } else if (factory instanceof  TopicConnectionFactory) {
218:                    TopicConnectionFactory tFactory = (TopicConnectionFactory) factory;
219:                    if (username != null)
220:                        connection = tFactory.createTopicConnection(username,
221:                                password);
222:                    else
223:                        connection = tFactory.createTopicConnection();
224:
225:                    log.debug("created TopicConnection: " + connection);
226:                } else
227:                    throw new IllegalArgumentException("factory is invalid");
228:
229:                return connection;
230:            }
231:
232:            /**
233:             * Create a topic connection from the given factory.  An XA connection will
234:             * be created if possible.
235:             *
236:             * @param factory     An object that implements TopicConnectionFactory,
237:             *                    XATopicConnectionFactory
238:             * @return            A topic connection.
239:             *                    
240:             * @throws JMSException                Failed to create connection.
241:             * @throws IllegalArgumentException    Factory is null or invalid.
242:             */
243:            public static TopicConnection createTopicConnection(
244:                    final Object factory) throws JMSException {
245:                return createTopicConnection(factory, null, null);
246:            }
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.