KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > transport > jms > JMSConnectorFactory


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001, 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.transport.jms;
57
58 import org.jboss.axis.components.jms.JMSVendorAdapter;
59 import org.jboss.axis.components.jms.JMSVendorAdapterFactory;
60
61 import java.util.HashMap JavaDoc;
62
63 /**
64  * JMSConnectorFactory is a factory class for creating JMSConnectors. It can
65  * create both client connectors and server connectors. A server connector
66  * is configured to allow asynchronous message receipt, while a client
67  * connector is not.
68  *
69  * @author Jaime Meritt (jmeritt@sonicsoftware.com)
70  * @author Richard Chung (rchung@sonicsoftware.com)
71  * @author Dave Chappell (chappell@sonicsoftware.com)
72  */

73 public class JMSConnectorFactory
74 {
75    /**
76     * Static method to create a server connector. Server connectors can
77     * accept incoming requests.
78     *
79     * @param connectorConfig
80     * @param cfConfig
81     * @param username
82     * @param password
83     * @return
84     * @throws Exception
85     */

86    public static JMSConnector createServerConnector(HashMap JavaDoc connectorConfig,
87                                                     HashMap JavaDoc cfConfig,
88                                                     String JavaDoc username,
89                                                     String JavaDoc password)
90            throws Exception JavaDoc
91    {
92       return createConnector(connectorConfig, cfConfig, true,
93               username, password);
94    }
95
96    /**
97     * Static method to create a client connector. Client connectors cannot
98     * accept incoming requests.
99     *
100     * @param connectorConfig
101     * @param cfConfig
102     * @param username
103     * @param password
104     * @return
105     * @throws Exception
106     */

107    public static JMSConnector createClientConnector(HashMap JavaDoc connectorConfig,
108                                                     HashMap JavaDoc cfConfig,
109                                                     String JavaDoc username,
110                                                     String JavaDoc password)
111            throws Exception JavaDoc
112    {
113       return createConnector(connectorConfig, cfConfig, false,
114               username, password);
115    }
116
117    private static JMSConnector createConnector(HashMap JavaDoc connectorConfig,
118                                                HashMap JavaDoc cfConfig,
119                                                boolean allowReceive,
120                                                String JavaDoc username,
121                                                String JavaDoc password)
122            throws Exception JavaDoc
123    {
124       if (connectorConfig != null)
125          connectorConfig = (HashMap JavaDoc)connectorConfig.clone();
126       int numRetries = MapUtils.removeIntProperty(connectorConfig,
127               JMSConstants.NUM_RETRIES,
128               JMSConstants.DEFAULT_NUM_RETRIES);
129
130       int numSessions = MapUtils.removeIntProperty(connectorConfig,
131               JMSConstants.NUM_SESSIONS,
132               JMSConstants.DEFAULT_NUM_SESSIONS);
133
134       long connectRetryInterval = MapUtils.removeLongProperty(connectorConfig,
135               JMSConstants.CONNECT_RETRY_INTERVAL,
136               JMSConstants.DEFAULT_CONNECT_RETRY_INTERVAL);
137
138       long interactRetryInterval = MapUtils.removeLongProperty(connectorConfig,
139               JMSConstants.INTERACT_RETRY_INTERVAL,
140               JMSConstants.DEFAULT_INTERACT_RETRY_INTERVAL);
141
142       long timeoutTime = MapUtils.removeLongProperty(connectorConfig,
143               JMSConstants.TIMEOUT_TIME,
144               JMSConstants.DEFAULT_TIMEOUT_TIME);
145
146       String JavaDoc clientID = MapUtils.removeStringProperty(connectorConfig,
147               JMSConstants.CLIENT_ID,
148               null);
149       String JavaDoc domain = MapUtils.removeStringProperty(connectorConfig,
150               JMSConstants.DOMAIN,
151               JMSConstants.DOMAIN_DEFAULT);
152
153       if (cfConfig == null)
154          throw new IllegalArgumentException JavaDoc("noCfConfig");
155
156       JMSVendorAdapter adapter = JMSVendorAdapterFactory.getJMSVendorAdapter();
157       if (domain.equals(JMSConstants.DOMAIN_QUEUE))
158       {
159          return new QueueConnector(adapter.getQueueConnectionFactory(cfConfig),
160                  numRetries, numSessions, connectRetryInterval,
161                  interactRetryInterval, timeoutTime,
162                  allowReceive, clientID, username, password,
163                  adapter);
164       }
165       else // domain is Topic
166
{
167          return new TopicConnector(adapter.getTopicConnectionFactory(cfConfig),
168                  numRetries, numSessions, connectRetryInterval,
169                  interactRetryInterval, timeoutTime,
170                  allowReceive, clientID, username, password,
171                  adapter);
172       }
173    }
174 }
Popular Tags