KickJava   Java API By Example, From Geeks To Geeks.

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


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.TopicConnectionFactory JavaDoc;
11 import javax.jms.TopicConnection JavaDoc;
12 import javax.jms.JMSException JavaDoc;
13 import javax.jms.Connection JavaDoc;
14
15 /**
16 A factory that makes SomniTopicConnections.
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 SomniTopicConnectionFactory
23     implements TopicConnectionFactory JavaDoc, ObjectFactory JavaDoc
24 {
25     private static Object JavaDoc guard = new Object JavaDoc();
26     private static int counter = 0;
27
28     public SomniTopicConnectionFactory()
29     {
30     }
31
32     //ConnectionFactory methods
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 createTopicConnection();
50     }
51
52
53     /** Creates a connection with the specified user identity.
54       * The connection is created in stopped mode. No messages
55       * will be delivered until the <code>Connection.start</code> method
56       * is explicitly called.
57       *
58       * @param userName the caller's user name
59       * @param password the caller's password
60       *
61       * @return a newly created connection
62       *
63       * @exception JMSException if the JMS provider fails to create the
64       * connection due to some internal error.
65       * @exception JMSSecurityException if client authentication fails due to
66       * an invalid user name or password.
67       * @since 1.1
68       */

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

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

126     public TopicConnection JavaDoc createTopicConnection(String JavaDoc userName, String JavaDoc password)
127         throws JMSException JavaDoc
128     {
129         SomniLogger.IT.warning("Somnifugi does not provide any security. Perhaps you shouldn't provide a userName and password.");
130         return createTopicConnection();
131     }
132
133     //ObjectFactory interface
134
public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc<?,?> environment)
135         throws Exception JavaDoc
136     {
137         return createTopicConnection(nameCtx);
138     }
139
140 }
141
142 /* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 David Walend
143 All rights reserved.
144
145 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
146
147 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
148
149 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.
150
151 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.
152
153 Credits in redistributions in source or binary forms must include a link to http://somnifugi.sourceforge.net .
154
155 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.
156 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.
157
158 =================================================================================
159
160 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>.
161  */

162
Popular Tags