1 23 package org.objectweb.joram.client.jms.admin; 24 25 import java.io.*; 26 import java.util.*; 27 28 import javax.xml.parsers.SAXParser ; 29 import javax.xml.parsers.SAXParserFactory ; 30 31 import javax.naming.InitialContext ; 32 import javax.naming.NameAlreadyBoundException ; 33 import javax.naming.NamingException ; 34 35 import org.xml.sax.InputSource ; 36 import org.xml.sax.Attributes ; 37 import org.xml.sax.helpers.DefaultHandler ; 38 39 import org.xml.sax.SAXException ; 40 import org.xml.sax.SAXParseException ; 41 42 import java.lang.reflect.Method ; 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 58 public class JoramSaxWrapper extends DefaultHandler { 59 60 public static final String SCN = "scn:comp/"; 61 62 public JoramSaxWrapper() {} 63 64 65 static final String ELT_JORAMADMIN = "JoramAdmin"; 66 67 static final String ELT_ADMINMODULE = "AdminModule"; 68 69 static final String ELT_CONNECT = "connect"; 70 71 static final String ELT_COLLOCATEDCONNECT = "collocatedConnect"; 72 73 static final String ELT_CONNECTIONFACTORY = "ConnectionFactory"; 74 75 static final String ELT_TCP = "tcp"; 76 77 static final String ELT_LOCAL = "local"; 78 79 static final String ELT_HATCP = "hatcp"; 80 81 static final String ELT_HALOCAL = "halocal"; 82 83 static final String ELT_SOAP = "soap"; 84 85 static final String ELT_JNDI = "jndi"; 86 87 static final String ELT_USER = "User"; 88 89 static final String ELT_DESTINATION = "Destination"; 90 91 static final String ELT_QUEUE = "Queue"; 92 93 static final String ELT_TOPIC = "Topic"; 94 95 static final String ELT_DMQUEUE = "DMQueue"; 96 97 static final String ELT_PROPERTY = "property"; 98 99 static final String ELT_READER = "reader"; 100 101 static final String ELT_WRITER = "writer"; 102 103 static final String ELT_FREEREADER = "freeReader"; 104 105 static final String ELT_FREEWRITER = "freeWriter"; 106 107 static final String ELT_INITIALCONTEXT = "InitialContext"; 108 109 static final String ELT_CLUSTER_CF = "ClusterCF"; 110 111 static final String ELT_CLUSTER_QUEUE = "ClusterQueue"; 112 113 static final String ELT_CLUSTER_TOPIC = "ClusterTopic"; 114 115 static final String ELT_CLUSTER_ELEMENT = "ClusterElement"; 116 117 118 119 static final String ATT_NAME = "name"; 120 121 static final String ATT_LOGIN = "login"; 122 123 static final String ATT_PASSWORD = "password"; 124 125 static final String ATT_VALUE = "value"; 126 127 static final String ATT_HOST = "host"; 128 129 static final String ATT_PORT = "port"; 130 131 static final String ATT_CNXTIMER = "cnxTimer"; 132 133 static final String ATT_RELIABLECLASS = "reliableClass"; 134 135 static final String ATT_URL = "url"; 136 137 static final String ATT_TIMEOUT = "timeout"; 138 139 static final String ATT_SERVERID = "serverId"; 140 141 static final String ATT_TYPE = "type"; 142 143 static final String ATT_CLASSNAME = "className"; 144 145 static final String ATT_USER = "user"; 146 147 static final String ATT_DMQ = "dmq"; 148 149 static final String ATT_NBMAXMSG = "nbMaxMsg"; 150 151 static final String ATT_PARENT = "parent"; 152 153 static final String ATT_THRESHOLD = "threshold"; 154 155 static final String ATT_LOCATION = "location"; 156 157 static final String DFLT_LISTEN_HOST = "localhost"; 158 static final int DFLT_LISTEN_PORT = 16010; 159 160 static final String DFLT_CF = 161 "org.objectweb.joram.client.jms.tcp.TcpConnectionFactory"; 162 163 boolean result = true; 164 Object obj = null; 165 String name = null; 166 String login = null; 167 String password = null; 168 String value = null; 169 String host = null; 170 int port = -1; 171 int cnxTimer = -1; 172 String reliableClass = null; 173 String url = null; 174 int timeout = -1; 175 int serverId = -1; 176 String className = null; 177 String user = null; 178 String type = null; 179 Properties properties = null; 180 181 String 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 jndiCtx = null; 190 191 192 Hashtable cfs = new Hashtable(); 193 194 Hashtable users = new Hashtable(); 195 196 Hashtable queues = new Hashtable(); 197 198 Hashtable topics = new Hashtable(); 199 200 Hashtable dmqs = new Hashtable(); 201 202 203 Hashtable cluster = new Hashtable(); 204 205 String dmq = null; 206 int threshold = -1; 207 int nbMaxMsg = -1; 208 String parent = null; 209 210 213 String joramAdmName = "default"; 214 215 216 String conf = null; 217 218 Logger logger = null; 219 220 223 public boolean parse(Reader cfgReader, String cfgName) throws Exception { 224 this.joramAdmName = cfgName; 225 226 logger = JoramTracing.dbgAdmin; 227 228 SAXParserFactory factory = SAXParserFactory.newInstance(); 229 SAXParser parser = factory.newSAXParser(); 230 parser.parse(new InputSource (cfgReader), this); 231 232 return result; 233 } 234 235 243 public void fatalError(SAXParseException e) throws SAXException { 244 logger.log(BasicLevel.FATAL, 245 "fatal error parsing " + e.getPublicId() + 246 " at " + e.getLineNumber() + "." + e.getColumnNumber()); 247 throw e; 248 } 249 250 258 public void error(SAXParseException e) throws SAXException { 259 logger.log(BasicLevel.ERROR, 260 "error parsing " + e.getPublicId() + 261 " at " + e.getLineNumber() + "." + e.getColumnNumber()); 262 throw e; 263 } 264 265 266 274 public void warning(SAXParseException e) throws SAXException { 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 value) { 283 return value != null && value.length() > 0; 284 } 285 286 292 public void startDocument() throws SAXException { 293 if (logger.isLoggable(BasicLevel.DEBUG)) 294 logger.log(BasicLevel.DEBUG, "startDocument"); 295 } 296 297 308 public void startElement(String uri, 309 String localName, 310 String rawName, 311 Attributes atts) throws SAXException { 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 host = atts.getValue(ATT_HOST); 326 if (!isSet(host)) host = DFLT_LISTEN_HOST; 327 String value = atts.getValue(ATT_PORT); 329 if (value == null) 330 port = DFLT_LISTEN_PORT; 331 else 332 port = Integer.parseInt(value); 333 name = atts.getValue(ATT_NAME); 335 if (!isSet(name)) 336 name = AbstractConnectionFactory.getDefaultRootLogin(); 337 password = atts.getValue(ATT_PASSWORD); 339 if (!isSet(password)) 340 password = AbstractConnectionFactory.getDefaultRootPassword(); 341 value = atts.getValue(ATT_CNXTIMER); 343 if (value == null) 344 cnxTimer = 60; 345 else 346 cnxTimer = Integer.parseInt(value); 347 reliableClass = atts.getValue(ATT_RELIABLECLASS); 349 } catch (NumberFormatException exc) { 350 throw new Exception ("bad value for port: " + 351 atts.getValue(ATT_PORT) + 352 " or cnxTimer: " + 353 atts.getValue(ATT_CNXTIMER)); 354 } 355 } catch (Exception exc) { 356 throw new SAXException (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 exc) { 367 throw new SAXException (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 exc) { 375 throw new SAXException (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 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 exc) { 389 throw new Exception ("bad value for port: " + 390 atts.getValue(ATT_PORT)); 391 } 392 } catch (Exception exc) { 393 throw new SAXException (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 exc) { 401 throw new SAXException (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 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 exc) { 421 throw new Exception ("bad value for port: " + 422 atts.getValue(ATT_PORT)); 423 } 424 } catch (Exception exc) { 425 throw new SAXException (exc.getMessage(), exc); 426 } 427 } else if (rawName.equals(ELT_JNDI)) { 428 try { 429 jndiName = atts.getValue(ATT_NAME); 430 } catch (Exception exc) { 431 throw new SAXException (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 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 exc) { 451 throw new Exception ("bad value for serverId: " + 452 atts.getValue(ATT_SERVERID)); 453 } 454 } catch (Exception exc) { 455 throw new SAXException (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 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 exc) { 470 throw new Exception ("bad value for serverId: " + 471 atts.getValue(ATT_SERVERID)); 472 } 473 } catch (Exception exc) { 474 throw new SAXException (exc.getMessage(), exc); 475 } 476 } else if (rawName.equals(ELT_QUEUE)) { 477 try { 478 try { 479 name = atts.getValue(ATT_NAME); 480 String 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 exc) { 498 throw new Exception ("bad value for serverId: " + 499 atts.getValue(ATT_SERVERID)); 500 } 501 } catch (Exception exc) { 502 throw new SAXException (exc.getMessage(), exc); 503 } 504 } else if (rawName.equals(ELT_TOPIC)) { 505 try { 506 try { 507 name = atts.getValue(ATT_NAME); 508 String 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 exc) { 517 throw new Exception ("bad value for serverId: " + 518 atts.getValue(ATT_SERVERID)); 519 } 520 } catch (Exception exc) { 521 throw new SAXException (exc.getMessage(), exc); 522 } 523 } else if (rawName.equals(ELT_DMQUEUE)) { 524 try { 525 try { 526 name = atts.getValue(ATT_NAME); 527 String value = atts.getValue(ATT_SERVERID); 528 if (value == null) 529 serverId = AdminModule.getLocalServerId(); 530 else 531 serverId = Integer.parseInt(value); 532 } catch (NumberFormatException exc) { 533 throw new Exception ("bad value for serverId: " + 534 atts.getValue(ATT_SERVERID)); 535 } 536 } catch (Exception exc) { 537 throw new SAXException (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 exc) { 546 throw new SAXException (exc.getMessage(), exc); 547 } 548 } else if (rawName.equals(ELT_READER)) { 549 try { 550 user = atts.getValue(ATT_USER); 551 } catch (Exception exc) { 552 throw new SAXException (exc.getMessage(), exc); 553 } 554 } else if (rawName.equals(ELT_WRITER)) { 555 try { 556 user = atts.getValue(ATT_USER); 557 } catch (Exception exc) { 558 throw new SAXException (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 exc) { 570 throw new SAXException (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 ("unknown element \"" + rawName + "\""); 580 } 581 } 582 } 583 584 595 public void endElement(String uri, 596 String localName, 597 String rawName) throws SAXException { 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 if (isSet(jndiName)) 629 toBind.put(jndiName, obj); 630 jndiName = null; 631 if (isSet(name)) cfs.put(name, obj); 633 634 className = null; 635 obj = null; 636 } else if (rawName.equals(ELT_TCP)) { 637 Class clazz = Class.forName(className); 638 Class [] classParams = {new String ().getClass(), 639 Integer.TYPE, 640 new String ().getClass()}; 641 Method methode = clazz.getMethod("create", classParams); 642 Object [] objParams = {host, new Integer (port), reliableClass}; 643 obj = methode.invoke(null, objParams); 644 } else if (rawName.equals(ELT_LOCAL)) { 645 Class clazz = Class.forName(className); 646 Method methode = clazz.getMethod("create", new Class [0]); 647 obj = methode.invoke(null, new Object [0]); 648 } else if (rawName.equals(ELT_HATCP)) { 649 Class clazz = Class.forName(className); 650 Class [] classParams = {new String ().getClass(), 651 new String ().getClass()}; 652 Method methode = clazz.getMethod("create",classParams); 653 Object [] objParams = {url,reliableClass}; 654 obj = methode.invoke(null,objParams); 655 } else if (rawName.equals(ELT_HALOCAL)) { 656 Class clazz = Class.forName(className); 657 Method methode = clazz.getMethod("create", new Class [0]); 658 obj = methode.invoke(null, new Object [0]); 659 } else if (rawName.equals(ELT_SOAP)) { 660 Class clazz = Class.forName(className); 661 Class [] classParams = {new String ().getClass(), 662 Integer.TYPE, 663 Integer.TYPE}; 664 Method methode = clazz.getMethod("create", classParams); 665 Object [] objParams = {host, new Integer (port), new Integer (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 ("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 if (isSet(jndiName)) 734 toBind.put(jndiName, dest); 735 jndiName = null; 736 String name = dest.getAdminName(); 738 if (! isSet(name)) 739 name = dest.getName(); 740 if (dest instanceof Queue) { 741 queues.put(name, dest); 742 } else { 743 topics.put(name, dest); 745 } 746 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 if (isSet(jndiName)) 774 toBind.put(jndiName, queue); 775 jndiName = null; 776 String name = queue.getAdminName(); 778 if (! isSet(name)) name = queue.getName(); 779 queues.put(name, queue); 780 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 if (isSet(jndiName)) 810 toBind.put(jndiName, topic); 811 jndiName = null; 812 String name = topic.getAdminName(); 814 if (! isSet(name)) name = topic.getName(); 815 topics.put(name, topic); 816 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 if (isSet(jndiName)) 832 toBind.put(jndiName, dmq); 833 jndiName = null; 834 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 (properties); 847 } catch (NamingException 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 ) entries[i].getValue(), cf); 859 } 860 cluster.clear(); 861 862 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 ) entries[i].getValue(), queue); 876 if (i == 0) 877 root = queue; 878 else 879 root.addClusteredQueue(queue); 880 } 881 cluster.clear(); 882 883 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 ) entries[i].getValue(), topic); 897 if (i == 0) 898 root = topic; 899 else 900 root.addClusteredTopic(topic); 901 } 902 cluster.clear(); 903 904 if (isSet(jndiName)) 907 toBind.put(jndiName, clusterTopic); 908 jndiName = null; 909 } else { 910 throw new SAXException ("unknown element \"" + rawName + "\""); 911 } 912 } catch (SAXException exc) { 913 throw exc; 914 } catch (Exception exc) { 915 Exception cause = (Exception ) exc.getCause(); 916 if (cause != null) { 917 logger.log(BasicLevel.ERROR,"",cause); 918 throw new SAXException (cause.getMessage(), cause); 919 } else { 920 logger.log(BasicLevel.ERROR,"",exc); 921 throw new SAXException (exc.getMessage(), exc); 922 } 923 } 924 } 925 } 926 927 void configureDestination(Destination dest) throws Exception { 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 dmq) throws Exception { 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 968 public void endDocument() throws SAXException { 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 (); 976 977 for (Enumeration e = toBind.keys(); e.hasMoreElements();) { 978 String name = (String ) e.nextElement(); 979 StringBuffer buff = null; 980 StringTokenizer st = null; 981 if (name.startsWith(SCN)) { 982 buff = new StringBuffer (SCN); 983 st = new StringTokenizer(name.substring(SCN.length(), name.length()), "/"); 984 } else { 985 buff = new StringBuffer (); 986 st = new StringTokenizer(name, "/"); 987 } 988 buff.append((String ) st.nextToken()); 989 while (st.hasMoreTokens()) { 990 try { 991 jndiCtx.createSubcontext(buff.toString()); 992 } catch (NameAlreadyBoundException exc) { 993 if (logger.isLoggable(BasicLevel.DEBUG)) 994 logger.log(BasicLevel.DEBUG, "createSubcontext:: NameAlreadyBoundException" + buff.toString()); 995 } catch (NamingException exc) { 996 if (logger.isLoggable(BasicLevel.WARN)) 997 logger.log(BasicLevel.WARN, "createSubcontext", exc); 998 } 999 buff.append("/"); 1000 buff.append((String ) st.nextToken()); 1001 } 1002 jndiCtx.rebind(name, toBind.get(name)); 1003 } 1004 jndiCtx.close(); 1005 toBind.clear(); 1006 } catch (NamingException exc) { 1007 logger.log(BasicLevel.ERROR,"",exc); 1008 } 1009 } 1010} 1011 | Popular Tags |