KickJava   Java API By Example, From Geeks To Geeks.

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


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>OutboundQueueConnectionFactory</code> instance is used for
35  * getting a PTP connection to an underlying JORAM server.
36  */

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

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

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

87   public javax.jms.QueueConnection JavaDoc
88       createQueueConnection(String JavaDoc userName, String JavaDoc password)
89     throws JMSException JavaDoc {
90     if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG))
91       AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG,
92                                     this + " createQueueConnection(" + userName +
93                                     ", " + password + ")");
94
95     try {
96       QueueConnectionRequest cxRequest =
97         new QueueConnectionRequest(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 + " createQueueConnection connection = " + o);
104
105       return (javax.jms.QueueConnection 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