KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > walend > somnifugi > SomniQueueConnectionFactory


1 package net.walend.somnifugi;
2
3 import java.util.Hashtable JavaDoc;
4
5 import javax.naming.Name JavaDoc;
6 import javax.naming.Context JavaDoc;
7
8 import javax.naming.spi.ObjectFactory JavaDoc;
9
10 import javax.jms.QueueConnectionFactory JavaDoc;
11 import javax.jms.QueueConnection JavaDoc;
12 import javax.jms.Connection JavaDoc;
13 import javax.jms.JMSException JavaDoc;
14
15 /**
16 A source for SomniQueueConnections.
17
18
19 @author <a HREF="http://walend.net">David Walend</a> <a HREF="mailto:david@walend.net">david@walend.net</a>
20  */

21
22 public class SomniQueueConnectionFactory
23     implements QueueConnectionFactory JavaDoc, ObjectFactory JavaDoc
24 {
25     private static Object JavaDoc guard = new Object JavaDoc();
26     private static int counter = 0;
27
28     public SomniQueueConnectionFactory()
29     {
30     }
31
32     //ConnectionFactory interface
33
/** Creates a connection with the default user identity.
34       * The connection is created in stopped mode. No messages
35       * will be delivered until the <code>Connection.start</code> method
36       * is explicitly called.
37       *
38       * @return a newly created connection
39       *
40       * @exception JMSException if the JMS provider fails to create the
41       * connection due to some internal error.
42       * @exception JMSSecurityException if client authentication fails due to
43       * an invalid user name or password.
44        * @since 1.1
45      */

46
47     public Connection JavaDoc createConnection() throws JMSException JavaDoc
48     {
49         return createQueueConnection();
50     }
51
52     /** Creates a connection with the specified user identity.
53       * The connection is created in stopped mode. No messages
54       * will be delivered until the <code>Connection.start</code> method
55       * is explicitly called.
56       *
57       * @param userName the caller's user name
58       * @param password the caller's password
59       *
60       * @return a newly created connection
61       *
62       * @exception JMSException if the JMS provider fails to create the
63       * connection due to some internal error.
64       * @exception JMSSecurityException if client authentication fails due to
65       * an invalid user name or password.
66       * @since 1.1
67       */

68
69     public Connection JavaDoc createConnection(String JavaDoc userName, String JavaDoc password)
70                          throws JMSException JavaDoc
71     {
72         return createQueueConnection(userName,password);
73     }
74
75     //QueueConnectionFactory interface
76
/** Creates a queue connection with the default user identity.
77 The connection is created in stopped mode. No messages
78 will be delivered until the <code>Connection.start</code> method
79 is explicitly called.
80       *
81 @return a newly created queue connection
82       *
83 @exception JMSException if the JMS provider fails to create the queue
84                         connection due to some internal error.
85 @exception JMSSecurityException if client authentication fails due to
86                         an invalid user name or password.
87       */

88     public QueueConnection JavaDoc createQueueConnection()
89         throws JMSException JavaDoc
90     {
91         return createQueueConnection(SomniJNDIBypass.IT.getQueueContext());
92     }
93
94     QueueConnection JavaDoc createQueueConnection(Context JavaDoc context)
95     {
96         synchronized(guard)
97             {
98                 String JavaDoc connectionID = "SomniQueueConnection"+counter;
99                 counter++;
100                 SomniQueueConnection result = new SomniQueueConnection(this,connectionID,context);
101                 SomniLogger.IT.config("Created "+connectionID);
102                 return result;
103             }
104     }
105
106     /** Creates a queue connection with the specified user identity.
107 The connection is created in stopped mode. No messages
108 will be delivered until the <code>Connection.start</code> method
109 is explicitly called.
110  
111 @param userName the caller's user name
112 @param password the caller's password
113  
114 @return a newly created queue connection
115       *
116 @exception JMSException if the JMS provider fails to create the queue
117                         connection due to some internal error.
118 @exception JMSSecurityException if client authentication fails due to
119                         an invalid user name or password.
120       */

121     public QueueConnection JavaDoc createQueueConnection(String JavaDoc userName, String JavaDoc password)
122         throws JMSException JavaDoc
123     {
124         SomniLogger.IT.warning("Somnifugi does not provide any security. Perhaps you shouldn't provide a userName and password.");
125         return createQueueConnection();
126     }
127
128     //ObjectFactory interface
129
public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc<?,?> environment)
130         throws Exception JavaDoc
131     {
132         return createQueueConnection(nameCtx);
133     }
134
135 }
136
137 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
138 All rights reserved.
139
140 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
141
142 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
143
144 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
145
146 Neither the name of the SomnifugiJMS Project, walend.net, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission from David Walend.
147
148 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
149
150 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
151 The net.walend.somnifugi.sql92 package is modified code from the openmq project, https://mq.dev.java.net/ , Copyright (c) of Sun, and carries the CDDL license, repeated here: You can obtain a copy of the license at https://glassfish.dev.java.net/public/CDDLv1.0.html. See the License for the specific language governing permissions and limitations under the License.
152
153 =================================================================================
154
155 For more information and the latest version of this software, please see http://somnifugi.sourceforge.net and http://walend.net or email <a HREF="mailto:david@walend.net">david@walend.net</a>.
156  */

157
Popular Tags