KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > OutboundTopicConnectionFactory


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Frederic Maistre (Bull SA)
21  * Contributor(s): Nicolas Tachker (Bull SA)
22  */

23 package org.objectweb.joram.client.connector;
24
25 import javax.jms.IllegalStateException JavaDoc;
26 import javax.jms.JMSException JavaDoc;
27 import javax.jms.JMSSecurityException JavaDoc;
28 import javax.resource.spi.ConnectionManager JavaDoc;
29 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
30
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  * An <code>OutboundTopicConnectionFactory</code> instance is used for
35  * getting a PubSub connection to an underlying JORAM server.
36  */

37 public class OutboundTopicConnectionFactory
38              extends OutboundConnectionFactory
39              implements javax.jms.TopicConnectionFactory JavaDoc,
40                         java.io.Serializable JavaDoc,
41                         javax.resource.Referenceable JavaDoc
42 {
43   /**
44    * Constructs an <code>OutboundTopicConnectionFactory</code> instance.
45    *
46    * @param mcf Central manager for outbound connectivity.
47    * @param cxManager Manager for connection pooling.
48    */

49   OutboundTopicConnectionFactory(ManagedConnectionFactoryImpl mcf,
50                                  ConnectionManager JavaDoc cxManager) {
51     super(mcf, cxManager);
52     
53     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
54       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
55                                     "OutboundTopicConnectionFactory(" + mcf +
56                                     ", " + cxManager + ")");
57   }
58
59
60   /**
61    * Requests a PubSub connection for the default user, eventually returns an
62    * <code>OutboundTopicConnection</code> instance.
63    *
64    * @exception JMSSecurityException If connecting is not allowed.
65    * @exception IllegalStateException If the underlying JORAM server
66    * is not reachable.
67    * @exception JMSException Generic exception.
68    */

69   public javax.jms.TopicConnection JavaDoc createTopicConnection()
70     throws JMSException JavaDoc {
71     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
72       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createTopicConnection()");
73     
74     return createTopicConnection(mcf.userName, mcf.password);
75   }
76
77   /**
78    * Requests a PubSub connection for a given user, eventually returns an
79    * <code>OutboundConnection</code> instance.
80    *
81    * @exception JMSSecurityException If connecting is not allowed.
82    * @exception IllegalStateException If the underlying JORAM server
83    * is not reachable.
84    * @exception JMSException Generic exception.
85    */

86   public javax.jms.TopicConnection JavaDoc
87       createTopicConnection(String JavaDoc userName, String JavaDoc password)
88     throws JMSException JavaDoc {
89
90     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
91       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
92                                     this + " createTopicConnection(" + userName +
93                                     ", " + password + ")");
94
95     try {
96       TopicConnectionRequest cxRequest =
97         new TopicConnectionRequest(userName, password);
98
99       Object JavaDoc o = cxManager.allocateConnection(mcf, cxRequest);
100
101     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
102       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
103                                     this + " createTopicConnection TopicConnection = " + o);
104
105       return (javax.jms.TopicConnection JavaDoc) o;
106     } catch (javax.resource.spi.SecurityException JavaDoc exc) {
107       throw new JMSSecurityException JavaDoc("Invalid user identification: " + exc);
108     } catch (javax.resource.spi.CommException JavaDoc exc) {
109       throw new IllegalStateException JavaDoc("Could not connect to the JORAM server: "
110                                       + exc);
111     } catch (javax.resource.ResourceException JavaDoc exc) {
112       throw new JMSException JavaDoc("Could not create connection: " + exc);
113     }
114   }
115 }
116
Popular Tags