KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > administration > net > JmsAdminConnectionImpl


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: JmsAdminConnectionImpl.java,v 1.2 2005/05/03 13:57:11 tanderson Exp $
44  */

45 package org.exolab.jms.administration.net;
46
47 import java.rmi.NotBoundException JavaDoc;
48 import java.rmi.RemoteException JavaDoc;
49 import java.util.HashMap JavaDoc;
50 import java.util.Map JavaDoc;
51 import java.util.Vector JavaDoc;
52 import javax.jms.JMSException JavaDoc;
53
54 import org.apache.commons.logging.Log;
55 import org.apache.commons.logging.LogFactory;
56
57 import org.exolab.jms.administration.AdminConnection;
58 import org.exolab.jms.administration.JmsAdminServerIfc;
59 import org.exolab.jms.client.net.SharedORB;
60 import org.exolab.jms.net.orb.ORB;
61 import org.exolab.jms.net.registry.Registry;
62 import org.exolab.jms.server.net.RemoteJmsAdminConnectionIfc;
63 import org.exolab.jms.server.net.RemoteJmsAdminServerIfc;
64
65
66 /**
67  * This class is repsonsible for an admin connection to the RMI server
68  *
69  * @author <a HREF="mailto:mourikis@intalio.com">Jim Mourikis</a>
70  * @version $Revision: 1.2 $ $Date: 2005/05/03 13:57:11 $
71  * @see org.exolab.jms.administration.AdminConnectionFactory
72  */

73 public class JmsAdminConnectionImpl
74         implements JmsAdminServerIfc, AdminConnection {
75
76     /**
77      * The ORB.
78      */

79     private ORB _orb;
80
81     /**
82      * The admin connection.
83      */

84     private RemoteJmsAdminConnectionIfc _connection;
85
86
87     /**
88      * Construct a new <code>JmsAdminConnectionImpl</code>
89      *
90      * @param url the server URI
91      * @param username the client's username
92      * @param password the client's password
93      */

94     public JmsAdminConnectionImpl(String JavaDoc url, String JavaDoc username, String JavaDoc password)
95             throws JMSException JavaDoc {
96         Map JavaDoc properties = new HashMap JavaDoc();
97         properties.put(ORB.PROVIDER_URI, url);
98         if (username != null) {
99             properties.put(ORB.SECURITY_PRINCIPAL, username);
100         }
101         if (password != null) {
102             properties.put(ORB.SECURITY_CREDENTIALS, password);
103         }
104
105         Registry registry = null;
106         try {
107             _orb = SharedORB.getInstance();
108             registry = _orb.getRegistry(properties);
109         } catch (RemoteException JavaDoc exception) {
110             JMSException JavaDoc error = new JMSException JavaDoc(
111                     "Failed to get registry service for URL: " + url);
112             error.setLinkedException(exception);
113             throw error;
114         }
115
116         try {
117             RemoteJmsAdminServerIfc admin =
118                     (RemoteJmsAdminServerIfc) registry.lookup("admin");
119             _connection = admin.createConnection(username, password);
120         } catch (NotBoundException JavaDoc exception) {
121             throw new JMSException JavaDoc("Administration server is not bound in the registry for "
122                                    + "URL: " + url);
123         } catch (RemoteException JavaDoc exception) {
124             JMSException JavaDoc error = new JMSException JavaDoc("Failed to lookup OpenJMS administration server at URL: "
125                                                   + url);
126             error.setLinkedException(exception);
127             throw error;
128         }
129     }
130
131     // implementation of JmsAdminServerIfc.addDurableConsumer
132
public boolean addDurableConsumer(String JavaDoc topic, String JavaDoc name)
133             throws JMSException JavaDoc {
134         boolean result = false;
135         try {
136             result = _connection.addDurableConsumer(topic, name);
137         } catch (Exception JavaDoc exception) {
138             raise(exception);
139         }
140         return result;
141     }
142
143     // implementation of JmsAdminServerIfc.removeDurableConsumer
144
public boolean removeDurableConsumer(String JavaDoc name) throws JMSException JavaDoc {
145         boolean result = false;
146         try {
147             result = _connection.removeDurableConsumer(name);
148         } catch (Exception JavaDoc exception) {
149             raise(exception);
150         }
151         return result;
152     }
153
154     // implementation of JmsAdminServerIfc.durableConsumerExists
155
public boolean durableConsumerExists(String JavaDoc name) throws JMSException JavaDoc {
156         boolean result = false;
157         try {
158             result = _connection.durableConsumerExists(name);
159         } catch (Exception JavaDoc exception) {
160             raise(exception);
161         }
162         return result;
163     }
164
165     // implementation of JmsAdminServerIfc.getDurableConsumers
166
public Vector JavaDoc getDurableConsumers(String JavaDoc topic) throws JMSException JavaDoc {
167         Vector JavaDoc result = null;
168         try {
169             result = _connection.getDurableConsumers(topic);
170         } catch (Exception JavaDoc exception) {
171             raise(exception);
172         }
173         return result;
174     }
175
176     // implementation of JmsAdminServerIfc.unregisterConsumer
177
public boolean unregisterConsumer(String JavaDoc name) throws JMSException JavaDoc {
178         boolean result = false;
179         try {
180             result = _connection.unregisterConsumer(name);
181         } catch (Exception JavaDoc exception) {
182             raise(exception);
183         }
184         return result;
185     }
186
187     // implementation of JmsAdminServerIfc.isConnected
188
public boolean isConnected(String JavaDoc name) throws JMSException JavaDoc {
189         boolean result = false;
190         try {
191             result = _connection.isConnected(name);
192         } catch (Exception JavaDoc exception) {
193             raise(exception);
194         }
195         return result;
196     }
197
198     // implementation of JmsAdminServerIfc.addDestination
199
public boolean addDestination(String JavaDoc destination, Boolean JavaDoc queue)
200             throws JMSException JavaDoc {
201         boolean result = false;
202         try {
203             result = _connection.addDestination(destination, queue);
204         } catch (Exception JavaDoc exception) {
205             raise(exception);
206         }
207         return result;
208     }
209
210     // implementation of JmsAdminServerIfc.removeDestination
211
public boolean removeDestination(String JavaDoc name) throws JMSException JavaDoc {
212         boolean result = false;
213         try {
214             result = _connection.removeDestination(name);
215         } catch (Exception JavaDoc exception) {
216             raise(exception);
217         }
218         return result;
219     }
220
221     // implementation of JmsAdminServerIfc.destinationExists
222
public boolean destinationExists(String JavaDoc name) throws JMSException JavaDoc {
223         boolean result = false;
224         try {
225             result = _connection.destinationExists(name);
226         } catch (Exception JavaDoc exception) {
227             raise(exception);
228         }
229         return result;
230     }
231
232     // implementation of JmsAdminServerIfc.getAllDestinations
233
public Vector JavaDoc getAllDestinations() throws JMSException JavaDoc {
234         Vector JavaDoc result = null;
235         try {
236             result = _connection.getAllDestinations();
237         } catch (Exception JavaDoc exception) {
238             raise(exception);
239         }
240         return result;
241     }
242
243     // implementation of JmsAdminServerIfc.getDurableConsumerMessageCount
244
public int getDurableConsumerMessageCount(String JavaDoc topic, String JavaDoc name)
245             throws JMSException JavaDoc {
246         int result = 0;
247         try {
248             result = _connection.getDurableConsumerMessageCount(topic, name);
249         } catch (Exception JavaDoc exception) {
250             raise(exception);
251         }
252         return result;
253     }
254
255     // implementation of JmsAdminServerIfc.getDurableConsumerMessageCount
256
public int getQueueMessageCount(String JavaDoc queue) throws JMSException JavaDoc {
257         int result = 0;
258         try {
259             result = _connection.getQueueMessageCount(queue);
260         } catch (Exception JavaDoc exception) {
261             raise(exception);
262         }
263         return result;
264     }
265
266     // implementation of JmsAdminServerIfc.purgeMessages
267
public int purgeMessages() throws JMSException JavaDoc {
268         int result = 0;
269         try {
270             result = _connection.purgeMessages();
271         } catch (Exception JavaDoc exception) {
272             raise(exception);
273         }
274         return result;
275     }
276
277     // implementation of JmsAdminServerIfc.stopServer
278
public void stopServer() throws JMSException JavaDoc {
279         try {
280             _connection.stopServer();
281         } catch (Exception JavaDoc exception) {
282             raise(exception);
283         }
284     }
285
286     // implementation of JmsAdminServerIfc.close
287
public void close() {
288     }
289
290     // implementation of JmsAdminServerIfc.addUser
291
public boolean addUser(String JavaDoc username, String JavaDoc password)
292             throws JMSException JavaDoc {
293         boolean result = false;
294         try {
295             result = _connection.addUser(username, password);
296         } catch (Exception JavaDoc exception) {
297             raise(exception);
298         }
299         return result;
300     }
301
302     // implementation of JmsAdminServerIfc.getAllUsers
303
public Vector JavaDoc getAllUsers() throws JMSException JavaDoc {
304         Vector JavaDoc result = null;
305         try {
306             result = _connection.getAllUsers();
307         } catch (Exception JavaDoc exception) {
308             raise(exception);
309         }
310         return result;
311     }
312
313     // implementation of JmsAdminServerIfc.removeUser
314
public boolean removeUser(String JavaDoc username)
315             throws JMSException JavaDoc {
316         boolean result = false;
317         try {
318             result = _connection.removeUser(username);
319         } catch (Exception JavaDoc exception) {
320             raise(exception);
321         }
322         return result;
323     }
324
325     // implementation of JmsAdminServerIfc.changePassword
326
public boolean changePassword(String JavaDoc username, String JavaDoc password)
327             throws JMSException JavaDoc {
328         boolean result = false;
329         try {
330             result = _connection.changePassword(username, password);
331         } catch (Exception JavaDoc exception) {
332             raise(exception);
333         }
334         return result;
335     }
336
337     private void raise(Exception JavaDoc exception) throws JMSException JavaDoc {
338         if (exception instanceof JMSException JavaDoc) {
339             throw (JMSException JavaDoc) exception;
340         } else {
341             JMSException JavaDoc error = new JMSException JavaDoc(exception.getMessage());
342             error.setLinkedException(exception);
343             throw error;
344         }
345     }
346
347 }
348
Popular Tags