KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > admin > JoramSaxWrapper


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2005 - 2007 ScalAgent Distributed Technologies
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): ScalAgent Distributed Technologies
21  * Contributor(s): Benoit Pelletier (Bull SA)
22  */

23 package org.objectweb.joram.client.jms.admin;
24
25 import java.io.*;
26 import java.util.*;
27
28 import javax.xml.parsers.SAXParser JavaDoc;
29 import javax.xml.parsers.SAXParserFactory JavaDoc;
30
31 import javax.naming.InitialContext JavaDoc;
32 import javax.naming.NameAlreadyBoundException JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34
35 import org.xml.sax.InputSource JavaDoc;
36 import org.xml.sax.Attributes JavaDoc;
37 import org.xml.sax.helpers.DefaultHandler JavaDoc;
38
39 import org.xml.sax.SAXException JavaDoc;
40 import org.xml.sax.SAXParseException JavaDoc;
41
42 import java.lang.reflect.Method JavaDoc;
43
44 import org.objectweb.joram.client.jms.ConnectionFactory;
45 import org.objectweb.joram.client.jms.admin.User;
46 import org.objectweb.joram.client.jms.admin.DeadMQueue;
47 import org.objectweb.joram.client.jms.Queue;
48 import org.objectweb.joram.client.jms.Topic;
49 import org.objectweb.joram.client.jms.Destination;
50
51 import org.objectweb.joram.shared.JoramTracing;
52 import org.objectweb.util.monolog.api.BasicLevel;
53 import org.objectweb.util.monolog.api.Logger;
54
55 /**
56  * XML SAX Wrapper for Joram Admin configuration file.
57  */

58 public class JoramSaxWrapper extends DefaultHandler JavaDoc {
59
60   public static final String JavaDoc SCN = "scn:comp/";
61   
62   public JoramSaxWrapper() {}
63
64   /** Syntaxic name for JoramAdmin element */
65   static final String JavaDoc ELT_JORAMADMIN = "JoramAdmin";
66   /** Syntaxic name for AdminModule element */
67   static final String JavaDoc ELT_ADMINMODULE = "AdminModule";
68   /** Syntaxic name for connect element */
69   static final String JavaDoc ELT_CONNECT = "connect";
70   /** Syntaxic name for collocatedConnect element */
71   static final String JavaDoc ELT_COLLOCATEDCONNECT = "collocatedConnect";
72   /** Syntaxic name for ConnectionFactory element */
73   static final String JavaDoc ELT_CONNECTIONFACTORY = "ConnectionFactory";
74   /** Syntaxic name for tcp element */
75   static final String JavaDoc ELT_TCP = "tcp";
76   /** Syntaxic name for local element */
77   static final String JavaDoc ELT_LOCAL = "local";
78   /** Syntaxic name for hatcp element */
79   static final String JavaDoc ELT_HATCP = "hatcp";
80   /** Syntaxic name for halocal element */
81   static final String JavaDoc ELT_HALOCAL = "halocal";
82   /** Syntaxic name for soap element */
83   static final String JavaDoc ELT_SOAP = "soap";
84   /** Syntaxic name for jndi element */
85   static final String JavaDoc ELT_JNDI = "jndi";
86   /** Syntaxic name for User element */
87   static final String JavaDoc ELT_USER = "User";
88   /** Syntaxic name for Destination element */
89   static final String JavaDoc ELT_DESTINATION = "Destination";
90   /** Syntaxic name for Queue element */
91   static final String JavaDoc ELT_QUEUE = "Queue";
92   /** Syntaxic name for Topic element */
93   static final String JavaDoc ELT_TOPIC = "Topic";
94   /** Syntaxic name for Dead message Queue element */
95   static final String JavaDoc ELT_DMQUEUE = "DMQueue";
96   /** Syntaxic name for property element */
97   static final String JavaDoc ELT_PROPERTY = "property";
98   /** Syntaxic name for reader element */
99   static final String JavaDoc ELT_READER = "reader";
100   /** Syntaxic name for writer element */
101   static final String JavaDoc ELT_WRITER = "writer";
102   /** Syntaxic name for freeReader element */
103   static final String JavaDoc ELT_FREEREADER = "freeReader";
104   /** Syntaxic name for freeWriter element */
105   static final String JavaDoc ELT_FREEWRITER = "freeWriter";
106   /** Syntaxic name for InitialContext element */
107   static final String JavaDoc ELT_INITIALCONTEXT = "InitialContext";
108   /** Syntaxic name for Cluster CF */
109   static final String JavaDoc ELT_CLUSTER_CF = "ClusterCF";
110   /** Syntaxic name for Cluster Queue */
111   static final String JavaDoc ELT_CLUSTER_QUEUE = "ClusterQueue";
112   /** Syntaxic name for Cluster Topic */
113   static final String JavaDoc ELT_CLUSTER_TOPIC = "ClusterTopic";
114   /** Syntaxic name for Cluster element */
115   static final String JavaDoc ELT_CLUSTER_ELEMENT = "ClusterElement";
116
117
118   /** Syntaxic name for name attribute */
119   static final String JavaDoc ATT_NAME = "name";
120   /** Syntaxic name for login attribute */
121   static final String JavaDoc ATT_LOGIN = "login";
122   /** Syntaxic name for password attribute */
123   static final String JavaDoc ATT_PASSWORD = "password";
124   /** Syntaxic name for value attribute */
125   static final String JavaDoc ATT_VALUE = "value";
126   /** Syntaxic name for host attribute */
127   static final String JavaDoc ATT_HOST = "host";
128   /** Syntaxic name for port attribute */
129   static final String JavaDoc ATT_PORT = "port";
130   /** Syntaxic name for cnxTimer attribute */
131   static final String JavaDoc ATT_CNXTIMER = "cnxTimer";
132   /** Syntaxic name for reliableClass attribute */
133   static final String JavaDoc ATT_RELIABLECLASS = "reliableClass";
134   /** Syntaxic name for url attribute */
135   static final String JavaDoc ATT_URL = "url";
136   /** Syntaxic name for timeout attribute */
137   static final String JavaDoc ATT_TIMEOUT = "timeout";
138   /** Syntaxic name for serverId attribute */
139   static final String JavaDoc ATT_SERVERID = "serverId";
140   /** Syntaxic name for type attribute */
141   static final String JavaDoc ATT_TYPE = "type";
142   /** Syntaxic name for className attribute */
143   static final String JavaDoc ATT_CLASSNAME = "className";
144   /** Syntaxic name for user attribute */
145   static final String JavaDoc ATT_USER = "user";
146   /** Syntaxic name for dead message queue attribute */
147   static final String JavaDoc ATT_DMQ = "dmq";
148   /** Syntaxic name for nbMaxMsg attribute */
149   static final String JavaDoc ATT_NBMAXMSG = "nbMaxMsg";
150   /** Syntaxic name for parent attribute */
151   static final String JavaDoc ATT_PARENT = "parent";
152   /** Syntaxic name for threshold attribute */
153   static final String JavaDoc ATT_THRESHOLD = "threshold";
154   /** Syntaxic name for location attribute */
155   static final String JavaDoc ATT_LOCATION = "location";
156
157   static final String JavaDoc DFLT_LISTEN_HOST = "localhost";
158   static final int DFLT_LISTEN_PORT = 16010;
159
160   static final String JavaDoc DFLT_CF =
161     "org.objectweb.joram.client.jms.tcp.TcpConnectionFactory";
162
163   boolean result = true;
164   Object JavaDoc obj = null;
165   String JavaDoc name = null;
166   String JavaDoc login = null;
167   String JavaDoc password = null;
168   String JavaDoc value = null;
169   String JavaDoc host = null;
170   int port = -1;
171   int cnxTimer = -1;
172   String JavaDoc reliableClass = null;
173   String JavaDoc url = null;
174   int timeout = -1;
175   int serverId = -1;
176   String JavaDoc className = null;
177   String JavaDoc user = null;
178   String JavaDoc type = null;
179   Properties properties = null;
180
181   String JavaDoc jndiName = null;
182   Hashtable toBind = new Hashtable();
183
184   Vector readers = new Vector();
185   Vector writers = new Vector();
186   boolean freeReading = false;
187   boolean freeWriting = false;
188
189   InitialContext JavaDoc jndiCtx = null;
190
191   /** Contains ConnectionFactory defined in the current script */
192   Hashtable cfs = new Hashtable();
193   /** Contains all users defined in the current script */
194   Hashtable users = new Hashtable();
195   /** Contains all queues defined in the current script */
196   Hashtable queues = new Hashtable();
197   /** Contains all topics defined in the current script */
198   Hashtable topics = new Hashtable();
199   /** Contains all DMQ defined in the current script */
200   Hashtable dmqs = new Hashtable();
201
202   /** Temporary set of cluster's elements */
203   Hashtable cluster = new Hashtable();
204
205   String JavaDoc dmq = null;
206   int threshold = -1;
207   int nbMaxMsg = -1;
208   String JavaDoc parent = null;
209
210   /**
211    * Name of joram admin to get from the file.
212    */

213   String JavaDoc joramAdmName = "default";
214
215   /** Working attribute used during configuration's */
216   String JavaDoc conf = null;
217
218   Logger logger = null;
219
220   /**
221    * Launches the XML parser.
222    */

223   public boolean parse(Reader cfgReader, String JavaDoc cfgName) throws Exception JavaDoc {
224     this.joramAdmName = cfgName;
225
226     logger = JoramTracing.dbgAdmin;
227
228     SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
229     SAXParser JavaDoc parser = factory.newSAXParser();
230     parser.parse(new InputSource JavaDoc(cfgReader), this);
231
232     return result;
233   }
234
235   /**
236    * Handles notification of a non-recoverable parser error.
237    *
238    * @param e The warning information encoded as an exception.
239    *
240    * @exception SAXException
241    * Any SAX exception, possibly wrapping another exception.
242    */

243   public void fatalError(SAXParseException JavaDoc e) throws SAXException JavaDoc {
244     logger.log(BasicLevel.FATAL,
245                "fatal error parsing " + e.getPublicId() +
246                " at " + e.getLineNumber() + "." + e.getColumnNumber());
247     throw e;
248   }
249
250   /**
251    * Handles notification of a recoverable parser error.
252    *
253    * @param e The warning information encoded as an exception.
254    *
255    * @exception SAXException
256    * Any SAX exception, possibly wrapping another exception.
257    */

258   public void error(SAXParseException JavaDoc e) throws SAXException JavaDoc {
259     logger.log(BasicLevel.ERROR,
260                "error parsing " + e.getPublicId() +
261                " at " + e.getLineNumber() + "." + e.getColumnNumber());
262     throw e;
263   }
264
265
266   /**
267    * Handles notification of a parser warning.
268    *
269    * @param e The warning information encoded as an exception.
270    *
271    * @exception SAXException
272    * Any SAX exception, possibly wrapping another exception.
273    */

274   public void warning(SAXParseException JavaDoc e) throws SAXException JavaDoc {
275     if (logger.isLoggable(BasicLevel.WARN))
276       logger.log(BasicLevel.WARN,
277                  "warning parsing " + e.getPublicId() +
278                  " at " + e.getLineNumber() + "." + e.getColumnNumber());
279     throw e;
280   }
281
282   private final boolean isSet(String JavaDoc value) {
283     return value != null && value.length() > 0;
284   }
285
286   /**
287    * Initializes parsing of a document.
288    *
289    * @exception SAXException
290    * unspecialized error
291    */

292   public void startDocument() throws SAXException JavaDoc {
293     if (logger.isLoggable(BasicLevel.DEBUG))
294       logger.log(BasicLevel.DEBUG, "startDocument");
295   }
296
297   /**
298    * Receive notification of the start of an element.
299    *
300    * @param uri The Namespace URI
301    * @param localName The local name
302    * @param rawName The qualified name
303    * @param atts The attributes attached to the element.
304    *
305    * @exception SAXException
306    * unspecialized error
307    */

308   public void startElement(String JavaDoc uri,
309                String JavaDoc localName,
310                String JavaDoc rawName,
311                Attributes JavaDoc atts) throws SAXException JavaDoc {
312
313     if (logger.isLoggable(BasicLevel.DEBUG))
314       logger.log(BasicLevel.DEBUG, "startElement: " + rawName);
315
316     if (rawName.equals(ELT_JORAMADMIN)) {
317       conf = atts.getValue(ATT_NAME);
318       if (conf == null) conf = joramAdmName;
319     } else if (joramAdmName.equals(conf)) {
320       if (rawName.equals(ELT_ADMINMODULE)) {
321       } else if (rawName.equals(ELT_CONNECT)) {
322         try {
323           try {
324             // Get the hostname of server for administrator connection.
325
host = atts.getValue(ATT_HOST);
326             if (!isSet(host)) host = DFLT_LISTEN_HOST;
327             // Get the listen port of server for administrator connection.
328
String JavaDoc value = atts.getValue(ATT_PORT);
329             if (value == null)
330               port = DFLT_LISTEN_PORT;
331             else
332               port = Integer.parseInt(value);
333             // Get the username for administrator connection.
334
name = atts.getValue(ATT_NAME);
335             if (!isSet(name))
336               name = AbstractConnectionFactory.getDefaultRootLogin();
337             // Get the password for administrator connection.
338
password = atts.getValue(ATT_PASSWORD);
339             if (!isSet(password))
340               password = AbstractConnectionFactory.getDefaultRootPassword();
341             // Get the CnxTimer attribute for administrator connection.
342
value = atts.getValue(ATT_CNXTIMER);
343             if (value == null)
344               cnxTimer = 60;
345             else
346               cnxTimer = Integer.parseInt(value);
347             // Get the protocol implementation.
348
reliableClass = atts.getValue(ATT_RELIABLECLASS);
349           } catch (NumberFormatException JavaDoc exc) {
350             throw new Exception JavaDoc("bad value for port: " +
351                                 atts.getValue(ATT_PORT) +
352                                 " or cnxTimer: " +
353                                 atts.getValue(ATT_CNXTIMER));
354           }
355         } catch (Exception JavaDoc exc) {
356           throw new SAXException JavaDoc(exc.getMessage(), exc);
357         }
358       } else if (rawName.equals(ELT_COLLOCATEDCONNECT)) {
359         try {
360           name = atts.getValue(ATT_NAME);
361           if (!isSet(name))
362             name = AbstractConnectionFactory.getDefaultRootLogin();
363           password = atts.getValue(ATT_PASSWORD);
364           if (!isSet(password))
365             password = AbstractConnectionFactory.getDefaultRootPassword();
366         } catch (Exception JavaDoc exc) {
367           throw new SAXException JavaDoc(exc.getMessage(), exc);
368         }
369       } else if (rawName.equals(ELT_CONNECTIONFACTORY)) {
370         try {
371           name = atts.getValue(ATT_NAME);
372           className = atts.getValue(ATT_CLASSNAME);
373           if (!isSet(className)) className = DFLT_CF;
374         } catch (Exception JavaDoc exc) {
375           throw new SAXException JavaDoc(exc.getMessage(), exc);
376         }
377       } else if (rawName.equals(ELT_TCP)) {
378         try {
379           try {
380             host = atts.getValue(ATT_HOST);
381             if (!isSet(host)) host = DFLT_LISTEN_HOST;
382             String JavaDoc value = atts.getValue(ATT_PORT);
383             if (value == null)
384               port = DFLT_LISTEN_PORT;
385             else
386               port = Integer.parseInt(value);
387             reliableClass = atts.getValue(ATT_RELIABLECLASS);
388           } catch (NumberFormatException JavaDoc exc) {
389             throw new Exception JavaDoc("bad value for port: " +
390                                 atts.getValue(ATT_PORT));
391           }
392         } catch (Exception JavaDoc exc) {
393           throw new SAXException JavaDoc(exc.getMessage(), exc);
394         }
395       } else if (rawName.equals(ELT_LOCAL)) {
396       } else if (rawName.equals(ELT_HATCP)) {
397         try {
398           url = atts.getValue(ATT_URL);
399           reliableClass = atts.getValue(ATT_RELIABLECLASS);
400         } catch (Exception JavaDoc exc) {
401           throw new SAXException JavaDoc(exc.getMessage(), exc);
402         }
403       } else if (rawName.equals(ELT_HALOCAL)) {
404       } else if (rawName.equals(ELT_SOAP)) {
405         try {
406           try {
407             host = atts.getValue(ATT_HOST);
408             if (!isSet(host))
409               host = "localhost";
410             String JavaDoc value = atts.getValue(ATT_PORT);
411             if (value == null)
412               port = 16010;
413             else
414               port = Integer.parseInt(value);
415             value = atts.getValue(ATT_TIMEOUT);
416             if (value == null)
417               timeout = 60;
418             else
419               timeout = Integer.parseInt(value);
420           } catch (NumberFormatException JavaDoc exc) {
421             throw new Exception JavaDoc("bad value for port: " +
422                                 atts.getValue(ATT_PORT));
423           }
424         } catch (Exception JavaDoc exc) {
425           throw new SAXException JavaDoc(exc.getMessage(), exc);
426         }
427       } else if (rawName.equals(ELT_JNDI)) {
428         try {
429           jndiName = atts.getValue(ATT_NAME);
430         } catch (Exception JavaDoc exc) {
431           throw new SAXException JavaDoc(exc.getMessage(), exc);
432         }
433       } else if (rawName.equals(ELT_USER)) {
434         try {
435           try {
436             name = atts.getValue(ATT_NAME);
437             login = atts.getValue(ATT_LOGIN);
438             password = atts.getValue(ATT_PASSWORD);
439             String JavaDoc value = atts.getValue(ATT_SERVERID);
440             if (value == null)
441               serverId = AdminModule.getLocalServerId();
442             else
443               serverId = Integer.parseInt(value);
444             dmq = atts.getValue(ATT_DMQ);
445             value = atts.getValue(ATT_THRESHOLD);
446             if (value == null)
447               threshold = -1;
448             else
449               threshold = Integer.parseInt(value);
450           } catch (NumberFormatException JavaDoc exc) {
451             throw new Exception JavaDoc("bad value for serverId: " +
452                                 atts.getValue(ATT_SERVERID));
453           }
454         } catch (Exception JavaDoc exc) {
455           throw new SAXException JavaDoc(exc.getMessage(), exc);
456         }
457       } else if (rawName.equals(ELT_DESTINATION)) {
458         try {
459           try {
460             type = atts.getValue(ATT_TYPE);
461             name = atts.getValue(ATT_NAME);
462             String JavaDoc value = atts.getValue(ATT_SERVERID);
463             if (value == null)
464               serverId = AdminModule.getLocalServerId();
465             else
466               serverId = Integer.parseInt(value);
467             className = atts.getValue(ATT_CLASSNAME);
468             dmq = atts.getValue(ATT_DMQ);
469           } catch (NumberFormatException JavaDoc exc) {
470             throw new Exception JavaDoc("bad value for serverId: " +
471                                 atts.getValue(ATT_SERVERID));
472           }
473         } catch (Exception JavaDoc exc) {
474           throw new SAXException JavaDoc(exc.getMessage(), exc);
475         }
476       } else if (rawName.equals(ELT_QUEUE)) {
477         try {
478           try {
479             name = atts.getValue(ATT_NAME);
480             String JavaDoc value = atts.getValue(ATT_SERVERID);
481             if (value == null)
482               serverId = AdminModule.getLocalServerId();
483             else
484               serverId = Integer.parseInt(value);
485             className = atts.getValue(ATT_CLASSNAME);
486             dmq = atts.getValue(ATT_DMQ);
487             value = atts.getValue(ATT_THRESHOLD);
488             if (value == null)
489               threshold = -1;
490             else
491               threshold = Integer.parseInt(value);
492             value = atts.getValue(ATT_NBMAXMSG);
493             if (value == null)
494               nbMaxMsg = -1;
495             else
496               nbMaxMsg = Integer.parseInt(value);
497           } catch (NumberFormatException JavaDoc exc) {
498             throw new Exception JavaDoc("bad value for serverId: " +
499                                 atts.getValue(ATT_SERVERID));
500           }
501         } catch (Exception JavaDoc exc) {
502           throw new SAXException JavaDoc(exc.getMessage(), exc);
503         }
504       } else if (rawName.equals(ELT_TOPIC)) {
505         try {
506           try {
507             name = atts.getValue(ATT_NAME);
508             String JavaDoc value = atts.getValue(ATT_SERVERID);
509             if (value == null)
510               serverId = AdminModule.getLocalServerId();
511             else
512               serverId = Integer.parseInt(value);
513             className = atts.getValue(ATT_CLASSNAME);
514             dmq = atts.getValue(ATT_DMQ);
515             parent = atts.getValue(ATT_PARENT);
516           } catch (NumberFormatException JavaDoc exc) {
517             throw new Exception JavaDoc("bad value for serverId: " +
518                                 atts.getValue(ATT_SERVERID));
519           }
520         } catch (Exception JavaDoc exc) {
521           throw new SAXException JavaDoc(exc.getMessage(), exc);
522         }
523       } else if (rawName.equals(ELT_DMQUEUE)) {
524         try {
525           try {
526             name = atts.getValue(ATT_NAME);
527             String JavaDoc value = atts.getValue(ATT_SERVERID);
528             if (value == null)
529               serverId = AdminModule.getLocalServerId();
530             else
531               serverId = Integer.parseInt(value);
532           } catch (NumberFormatException JavaDoc exc) {
533             throw new Exception JavaDoc("bad value for serverId: " +
534                                 atts.getValue(ATT_SERVERID));
535           }
536         } catch (Exception JavaDoc exc) {
537           throw new SAXException JavaDoc(exc.getMessage(), exc);
538         }
539       } else if (rawName.equals(ELT_PROPERTY)) {
540         try {
541           if (properties == null)
542             properties = new Properties();
543           properties.put(atts.getValue(ATT_NAME),
544                          atts.getValue(ATT_VALUE));
545         } catch (Exception JavaDoc exc) {
546           throw new SAXException JavaDoc(exc.getMessage(), exc);
547         }
548       } else if (rawName.equals(ELT_READER)) {
549         try {
550           user = atts.getValue(ATT_USER);
551         } catch (Exception JavaDoc exc) {
552           throw new SAXException JavaDoc(exc.getMessage(), exc);
553         }
554       } else if (rawName.equals(ELT_WRITER)) {
555         try {
556           user = atts.getValue(ATT_USER);
557         } catch (Exception JavaDoc exc) {
558           throw new SAXException JavaDoc(exc.getMessage(), exc);
559         }
560       } else if (rawName.equals(ELT_FREEREADER)) {
561         freeReading = true;
562       } else if (rawName.equals(ELT_FREEWRITER)) {
563         freeWriting = true;
564       } else if (rawName.equals(ELT_INITIALCONTEXT)) {
565       } else if (rawName.equals(ELT_CLUSTER_ELEMENT)) {
566         try {
567           cluster.put(atts.getValue(ATT_NAME),
568                       atts.getValue(ATT_LOCATION));
569         } catch (Exception JavaDoc exc) {
570           throw new SAXException JavaDoc(exc.getMessage(), exc);
571         }
572       } else if (rawName.equals(ELT_CLUSTER_QUEUE)) {
573         cluster.clear();
574       } else if (rawName.equals(ELT_CLUSTER_TOPIC)) {
575         cluster.clear();
576       } else if (rawName.equals(ELT_CLUSTER_CF)) {
577         cluster.clear();
578       } else {
579     throw new SAXException JavaDoc("unknown element \"" + rawName + "\"");
580       }
581     }
582   }
583
584   /**
585    * Receive notification of the end of an element.
586    *
587    * @param uri The Namespace URI
588    * @param localName The local name
589    * @param rawName The qualified name
590    * @param atts The attributes attached to the element.
591    *
592    * @exception SAXException
593    * unspecialized error
594    */

595   public void endElement(String JavaDoc uri,
596              String JavaDoc localName,
597              String JavaDoc rawName) throws SAXException JavaDoc {
598
599     if (logger.isLoggable(BasicLevel.DEBUG))
600       logger.log(BasicLevel.DEBUG, "endElement: " + rawName);
601
602     if (rawName.equals(ELT_JORAMADMIN)) {
603       conf = null;
604     } else if (joramAdmName.equals(conf)) {
605       try {
606         if (rawName.equals(ELT_ADMINMODULE)) {
607         } else if (rawName.equals(ELT_CONNECT)) {
608           if (logger.isLoggable(BasicLevel.DEBUG))
609             logger.log(BasicLevel.DEBUG, "AdminModule.connect(" +
610                        host + "," +
611                        port + "," +
612                        name + "," +
613                        password + "," +
614                        cnxTimer + "," +
615                        reliableClass + ")");
616           AdminModule.connect(host,port,name,password,cnxTimer,reliableClass);
617         } else if (rawName.equals(ELT_COLLOCATEDCONNECT)) {
618           if (logger.isLoggable(BasicLevel.DEBUG))
619             logger.log(BasicLevel.DEBUG, "AdminModule.collocatedConnect(" +
620                        name + "," +
621                        password + ")");
622           AdminModule.collocatedConnect(name,password);
623         } else if (rawName.equals(ELT_CONNECTIONFACTORY)) {
624           if (logger.isLoggable(BasicLevel.DEBUG))
625             logger.log(BasicLevel.DEBUG, "cf \""+ name + "\"= " + obj);
626           // Bind the ConnectionFactory in JNDI.
627
// Be Careful, currently only one binding is handled.
628
if (isSet(jndiName))
629             toBind.put(jndiName, obj);
630           jndiName = null;
631           // Register the CF in order to handle it later (cluster, etc.)
632
if (isSet(name)) cfs.put(name, obj);
633
634           className = null;
635           obj = null;
636         } else if (rawName.equals(ELT_TCP)) {
637           Class JavaDoc clazz = Class.forName(className);
638           Class JavaDoc [] classParams = {new String JavaDoc().getClass(),
639                                   Integer.TYPE,
640                                   new String JavaDoc().getClass()};
641           Method JavaDoc methode = clazz.getMethod("create", classParams);
642           Object JavaDoc[] objParams = {host, new Integer JavaDoc(port), reliableClass};
643           obj = methode.invoke(null, objParams);
644         } else if (rawName.equals(ELT_LOCAL)) {
645           Class JavaDoc clazz = Class.forName(className);
646           Method JavaDoc methode = clazz.getMethod("create", new Class JavaDoc[0]);
647           obj = methode.invoke(null, new Object JavaDoc[0]);
648         } else if (rawName.equals(ELT_HATCP)) {
649           Class JavaDoc clazz = Class.forName(className);
650           Class JavaDoc [] classParams = {new String JavaDoc().getClass(),
651                                   new String JavaDoc().getClass()};
652           Method JavaDoc methode = clazz.getMethod("create",classParams);
653           Object JavaDoc[] objParams = {url,reliableClass};
654           obj = methode.invoke(null,objParams);
655         } else if (rawName.equals(ELT_HALOCAL)) {
656           Class JavaDoc clazz = Class.forName(className);
657           Method JavaDoc methode = clazz.getMethod("create", new Class JavaDoc[0]);
658           obj = methode.invoke(null, new Object JavaDoc[0]);
659         } else if (rawName.equals(ELT_SOAP)) {
660           Class JavaDoc clazz = Class.forName(className);
661           Class JavaDoc [] classParams = {new String JavaDoc().getClass(),
662                                   Integer.TYPE,
663                                   Integer.TYPE};
664           Method JavaDoc methode = clazz.getMethod("create", classParams);
665           Object JavaDoc[] objParams = {host, new Integer JavaDoc(port), new Integer JavaDoc(timeout)};
666           obj = methode.invoke(null, objParams);
667         } else if (rawName.equals(ELT_JNDI)) {
668         } else if (rawName.equals(ELT_USER)) {
669           if (logger.isLoggable(BasicLevel.DEBUG))
670             logger.log(BasicLevel.DEBUG, "User.create(" +
671                        name + "," +
672                        login + "," +
673                        password + "," +
674                        serverId + ")");
675           if (! isSet(login)) login = name;
676           User user = User.create(login, password, serverId);
677           users.put(name, user);
678
679           if (threshold > 0)
680             user.setThreshold(threshold);
681
682           if (isSet(dmq)) {
683             if (dmqs.containsKey(dmq)) {
684               user.setDMQ((DeadMQueue) dmqs.get(dmq));
685             } else {
686               logger.log(BasicLevel.ERROR,
687                          "User.create(): Unknown DMQ: " + dmq);
688             }
689           }
690         } else if (rawName.equals(ELT_DESTINATION)) {
691           Destination dest = null;
692           if (logger.isLoggable(BasicLevel.DEBUG))
693             logger.log(BasicLevel.DEBUG, "dest type =" + type);
694
695           if (type.equals("queue")) {
696             if (className == null)
697               className = "org.objectweb.joram.mom.dest.Queue";
698             if (logger.isLoggable(BasicLevel.DEBUG))
699               logger.log(BasicLevel.DEBUG, "Queue.create(" +
700                          serverId + "," +
701                          name + "," +
702                          className + "," +
703                          properties + ")");
704             dest = Queue.create(serverId,
705                                 name,
706                                 className,
707                                 properties);
708           } else if (type.equals("topic")) {
709             if (className == null)
710               className = "org.objectweb.joram.mom.dest.Topic";
711             if (logger.isLoggable(BasicLevel.DEBUG))
712               logger.log(BasicLevel.DEBUG, "Topic.create(" +
713                          serverId + "," +
714                          name + "," +
715                          className + "," +
716                          properties + ")");
717             dest = Topic.create(serverId,
718                                 name,
719                                 className,
720                                 properties);
721           } else
722             throw new Exception JavaDoc("type " + type + " bad value. (queue or topic)");
723
724           if (logger.isLoggable(BasicLevel.DEBUG))
725             logger.log(BasicLevel.DEBUG, "destination = " + dest);
726
727           properties = null;
728
729           configureDestination(dest);
730
731           // Bind the destination in JNDI.
732
// Be Careful, currently only one binding is handled.
733
if (isSet(jndiName))
734             toBind.put(jndiName, dest);
735           jndiName = null;
736           // Register the destination in order to handle it later.
737
String JavaDoc name = dest.getAdminName();
738           if (! isSet(name))
739             name = dest.getName();
740           if (dest instanceof Queue) {
741             queues.put(name, dest);
742           } else {
743             // It's a Topic
744
topics.put(name, dest);
745           }
746           // Fix DMQ if any
747
setDestinationDMQ(dest, dmq);
748         } else if (rawName.equals(ELT_QUEUE)) {
749           if (className == null)
750             className = "org.objectweb.joram.mom.dest.Queue";
751           if (logger.isLoggable(BasicLevel.DEBUG))
752             logger.log(BasicLevel.DEBUG, "Queue.create(" +
753                        serverId + "," +
754                        name + "," +
755                        className + "," +
756                        properties + ")");
757           Queue queue = Queue.create(serverId,
758                                      name,
759                                      className,
760                                      properties);
761           properties = null;
762
763           configureDestination(queue);
764
765           if (threshold > 0)
766             queue.setThreshold(threshold);
767
768           if (nbMaxMsg > 0)
769             queue.setNbMaxMsg(nbMaxMsg);
770
771           // Bind the queue in JNDI.
772
// Be Careful, currently only one binding is handled.
773
if (isSet(jndiName))
774             toBind.put(jndiName, queue);
775           jndiName = null;
776           // Register the queue in order to handle it later (cluster, etc.)
777
String JavaDoc name = queue.getAdminName();
778           if (! isSet(name)) name = queue.getName();
779           queues.put(name, queue);
780           // Fix DMQ if any
781
setDestinationDMQ(queue, dmq);
782         } else if (rawName.equals(ELT_TOPIC)) {
783           if (className == null)
784             className = "org.objectweb.joram.mom.dest.Topic";
785           if (logger.isLoggable(BasicLevel.DEBUG))
786             logger.log(BasicLevel.DEBUG, "Topic.create(" +
787                        serverId + "," +
788                        name + "," +
789                        className + "," +
790                        properties + ")");
791           Topic topic = Topic.create(serverId,
792                                      name,
793                                      className,
794                                      properties);
795           properties = null;
796
797           configureDestination(topic);
798
799           if (isSet(parent)) {
800             if (topics.containsKey(parent)) {
801               topic.setParent((Topic) topics.get(parent));
802             } else {
803               logger.log(BasicLevel.ERROR,
804                    "Topic.create(): Unknown parent: " + parent);
805             }
806           }
807           // Bind the topic in JNDI.
808
// Be Careful, currently only one binding is handled.
809
if (isSet(jndiName))
810             toBind.put(jndiName, topic);
811           jndiName = null;
812           // Register the topic in order to handle it later (cluster, etc.)
813
String JavaDoc name = topic.getAdminName();
814           if (! isSet(name)) name = topic.getName();
815           topics.put(name, topic);
816           // Fix DMQ if any
817
setDestinationDMQ(topic, dmq);
818         } else if (rawName.equals(ELT_DMQUEUE)) {
819           className = "org.objectweb.joram.mom.dest.DeadMQueue";
820           if (logger.isLoggable(BasicLevel.DEBUG))
821             logger.log(BasicLevel.DEBUG, "DeadMQueue.create(" +
822                        serverId + "," +
823                        name + ")");
824
825           DeadMQueue dmq = (DeadMQueue) DeadMQueue.create(serverId, name);
826
827           configureDestination(dmq);
828
829           // Bind the destination in JNDI.
830
// Be Careful, currently only one binding is handled.
831
if (isSet(jndiName))
832             toBind.put(jndiName, dmq);
833           jndiName = null;
834           // Register the DMQ in order to handle it later.
835
if (isSet(name))
836             dmqs.put(name, dmq);
837         } else if (rawName.equals(ELT_PROPERTY)) {
838         } else if (rawName.equals(ELT_READER)) {
839           readers.add(user);
840         } else if (rawName.equals(ELT_WRITER)) {
841           writers.add(user);
842         } else if (rawName.equals(ELT_FREEREADER)) {
843         } else if (rawName.equals(ELT_FREEWRITER)) {
844         } else if (rawName.equals(ELT_INITIALCONTEXT)) {
845           try {
846             jndiCtx = new javax.naming.InitialContext JavaDoc(properties);
847           } catch (NamingException JavaDoc exc) {
848             logger.log(BasicLevel.ERROR,"",exc);
849           }
850         } else if (rawName.equals(ELT_CLUSTER_ELEMENT)) {
851         } else if (rawName.equals(ELT_CLUSTER_CF)) {
852           Map.Entry entries[] = new Map.Entry [cluster.size()];
853           cluster.entrySet().toArray(entries);
854           ClusterConnectionFactory clusterCF = new ClusterConnectionFactory();
855
856           for (int i=0; i<entries.length; i++) {
857             ConnectionFactory cf = (ConnectionFactory) cfs.get(entries[i].getKey());
858             clusterCF.addConnectionFactory((String JavaDoc) entries[i].getValue(), cf);
859           }
860           cluster.clear();
861
862           // Bind the destination in JNDI.
863
// Be Careful, currently only one binding is handled.
864
if (isSet(jndiName))
865             toBind.put(jndiName, clusterCF);
866           jndiName = null;
867         } else if (rawName.equals(ELT_CLUSTER_QUEUE)) {
868           Map.Entry entries[] = new Map.Entry [cluster.size()];
869           cluster.entrySet().toArray(entries);
870           ClusterQueue clusterQueue = new ClusterQueue();
871
872           Queue root = null;
873           for (int i=0; i<entries.length; i++) {
874             Queue queue = (Queue) queues.get(entries[i].getKey());
875             clusterQueue.addDestination((String JavaDoc) entries[i].getValue(), queue);
876             if (i == 0)
877               root = queue;
878             else
879               root.addClusteredQueue(queue);
880           }
881           cluster.clear();
882
883           // Bind the destination in JNDI.
884
// Be Careful, currently only one binding is handled.
885
if (isSet(jndiName))
886             toBind.put(jndiName, clusterQueue);
887           jndiName = null;
888         } else if (rawName.equals(ELT_CLUSTER_TOPIC)) {
889           Map.Entry entries[] = new Map.Entry [cluster.size()];
890           cluster.entrySet().toArray(entries);
891           ClusterTopic clusterTopic = new ClusterTopic();
892
893           Topic root = null;
894           for (int i=0; i<entries.length; i++) {
895             Topic topic = (Topic) topics.get(entries[i].getKey());
896             clusterTopic.addDestination((String JavaDoc) entries[i].getValue(), topic);
897             if (i == 0)
898               root = topic;
899             else
900               root.addClusteredTopic(topic);
901           }
902           cluster.clear();
903
904           // Bind the destination in JNDI.
905
// Be Careful, currently only one binding is handled.
906
if (isSet(jndiName))
907             toBind.put(jndiName, clusterTopic);
908           jndiName = null;
909         } else {
910           throw new SAXException JavaDoc("unknown element \"" + rawName + "\"");
911         }
912       } catch (SAXException JavaDoc exc) {
913         throw exc;
914       } catch (Exception JavaDoc exc) {
915         Exception JavaDoc cause = (Exception JavaDoc) exc.getCause();
916         if (cause != null) {
917           logger.log(BasicLevel.ERROR,"",cause);
918           throw new SAXException JavaDoc(cause.getMessage(), cause);
919         } else {
920           logger.log(BasicLevel.ERROR,"",exc);
921           throw new SAXException JavaDoc(exc.getMessage(), exc);
922         }
923       }
924     }
925   }
926
927   void configureDestination(Destination dest) throws Exception JavaDoc {
928     if (freeReading)
929       dest.setFreeReading();
930     freeReading = false;
931
932     if (freeWriting)
933       dest.setFreeWriting();
934     freeWriting = false;
935
936     for (int i = 0; i < readers.size(); i++) {
937       User u = (User) users.get(readers.get(i));
938       if (u != null)
939         dest.setReader(u);
940     }
941     readers.clear();
942
943     for (int i = 0; i < writers.size(); i++) {
944       User u = (User) users.get(writers.get(i));
945       if (u != null)
946         dest.setWriter(u);
947     }
948     writers.clear();
949   }
950
951   void setDestinationDMQ(Destination dest, String JavaDoc dmq) throws Exception JavaDoc {
952     if (isSet(dmq)) {
953       if (dmqs.containsKey(dmq)) {
954         dest.setDMQ((DeadMQueue) dmqs.get(dmq));
955       } else {
956         logger.log(BasicLevel.ERROR,
957                    "Destination.create(): Unknown DMQ: " + dmq);
958       }
959     }
960   }
961
962   /**
963    * Finalizes parsing of a document.
964    *
965    * @exception SAXException
966    * unspecialized error
967    */

968   public void endDocument() throws SAXException JavaDoc {
969     if (logger.isLoggable(BasicLevel.DEBUG))
970       logger.log(BasicLevel.DEBUG, "endDocument");
971     AdminModule.disconnect();
972
973     try {
974       if (jndiCtx == null)
975         jndiCtx = new javax.naming.InitialContext JavaDoc();
976
977       for (Enumeration e = toBind.keys(); e.hasMoreElements();) {
978         String JavaDoc name = (String JavaDoc) e.nextElement();
979         StringBuffer JavaDoc buff = null;
980         StringTokenizer st = null;
981         if (name.startsWith(SCN)) {
982           buff = new StringBuffer JavaDoc(SCN);
983           st = new StringTokenizer(name.substring(SCN.length(), name.length()), "/");
984         } else {
985           buff = new StringBuffer JavaDoc();
986           st = new StringTokenizer(name, "/");
987         }
988         buff.append((String JavaDoc) st.nextToken());
989         while (st.hasMoreTokens()) {
990           try {
991             jndiCtx.createSubcontext(buff.toString());
992           } catch (NameAlreadyBoundException JavaDoc exc) {
993             if (logger.isLoggable(BasicLevel.DEBUG))
994               logger.log(BasicLevel.DEBUG, "createSubcontext:: NameAlreadyBoundException" + buff.toString());
995           } catch (NamingException JavaDoc exc) {
996             if (logger.isLoggable(BasicLevel.WARN))
997               logger.log(BasicLevel.WARN, "createSubcontext", exc);
998           }
999           buff.append("/");
1000          buff.append((String JavaDoc) st.nextToken());
1001        }
1002        jndiCtx.rebind(name, toBind.get(name));
1003      }
1004      jndiCtx.close();
1005      toBind.clear();
1006    } catch (NamingException JavaDoc exc) {
1007      logger.log(BasicLevel.ERROR,"",exc);
1008    }
1009  }
1010}
1011
Popular Tags