⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joramsaxwrapper.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2005 - 2006 ScalAgent Distributed Technologies * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 * USA. * * Initial developer(s): ScalAgent Distributed Technologies * Contributor(s): Benoit Pelletier (Bull SA) */package org.objectweb.joram.client.jms.admin;import java.io.*;import java.util.*;import org.objectweb.joram.client.jms.JoramTracing;import org.objectweb.util.monolog.api.BasicLevel;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import javax.naming.InitialContext;import javax.naming.NamingException;import org.xml.sax.InputSource;import org.xml.sax.Attributes;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import java.lang.reflect.Method;import org.objectweb.joram.client.jms.admin.User;import org.objectweb.joram.client.jms.admin.DeadMQueue;import org.objectweb.joram.client.jms.Queue;import org.objectweb.joram.client.jms.Topic;import org.objectweb.joram.client.jms.Destination;/** * XML SAX Wrapper for Joram Admin configuration file. */public class JoramSaxWrapper extends DefaultHandler {  public JoramSaxWrapper() {}  /** Syntaxic name for JoramAdmin element */  static final String ELT_JORAMADMIN = "JoramAdmin";  /** Syntaxic name for AdminModule element */  static final String ELT_ADMINMODULE = "AdminModule";  /** Syntaxic name for connect element */  static final String ELT_CONNECT = "connect";  /** Syntaxic name for collocatedConnect element */  static final String ELT_COLLOCATEDCONNECT = "collocatedConnect";  /** Syntaxic name for ConnectionFactory element */  static final String ELT_CONNECTIONFACTORY = "ConnectionFactory";  /** Syntaxic name for tcp element */  static final String ELT_TCP = "tcp";  /** Syntaxic name for local element */  static final String ELT_LOCAL = "local";  /** Syntaxic name for hatcp element */  static final String ELT_HATCP = "hatcp";  /** Syntaxic name for halocal element */  static final String ELT_HALOCAL = "halocal";  /** Syntaxic name for soap element */  static final String ELT_SOAP = "soap";  /** Syntaxic name for jndi element */  static final String ELT_JNDI = "jndi";  /** Syntaxic name for User element */  static final String ELT_USER = "User";  /** Syntaxic name for Destination element */  static final String ELT_DESTINATION = "Destination";  /** Syntaxic name for Queue element */  static final String ELT_QUEUE = "Queue";  /** Syntaxic name for Topic element */  static final String ELT_TOPIC = "Topic";  /** Syntaxic name for Dead message Queue element */  static final String ELT_DMQUEUE = "DMQueue";  /** Syntaxic name for property element */  static final String ELT_PROPERTY = "property";  /** Syntaxic name for reader element */  static final String ELT_READER = "reader";  /** Syntaxic name for writer element */  static final String ELT_WRITER = "writer";  /** Syntaxic name for freeReader element */  static final String ELT_FREEREADER = "freeReader";  /** Syntaxic name for freeWriter element */  static final String ELT_FREEWRITER = "freeWriter";  /** Syntaxic name for InitialContext element */  static final String ELT_INITIALCONTEXT = "InitialContext";  /** Syntaxic name for Cluster element */  static final String ELT_CLUSTER = "Cluster";  /** Syntaxic name for name attribute */  static final String ATT_NAME = "name";  /** Syntaxic name for password attribute */  static final String ATT_PASSWORD = "password";  /** Syntaxic name for value attribute */  static final String ATT_VALUE = "value";  /** Syntaxic name for host attribute */  static final String ATT_HOST = "host";  /** Syntaxic name for port attribute */  static final String ATT_PORT = "port";  /** Syntaxic name for cnxTimer attribute */  static final String ATT_CNXTIMER = "cnxTimer";  /** Syntaxic name for reliableClass attribute */  static final String ATT_RELIABLECLASS = "reliableClass";  /** Syntaxic name for url attribute */  static final String ATT_URL = "url";  /** Syntaxic name for timeout attribute */  static final String ATT_TIMEOUT = "timeout";  /** Syntaxic name for serverId attribute */  static final String ATT_SERVERID = "serverId";  /** Syntaxic name for type attribute */  static final String ATT_TYPE = "type";  /** Syntaxic name for className attribute */  static final String ATT_CLASSNAME = "className";  /** Syntaxic name for user attribute */  static final String ATT_USER = "user";  /** Syntaxic name for dead message queue attribute */  static final String ATT_DMQ = "dmq";  /** Syntaxic name for nbMaxMsg attribute */  static final String ATT_NBMAXMSG = "nbMaxMsg";  /** Syntaxic name for parent attribute */  static final String ATT_PARENT = "parent";  /** Syntaxic name for threshold attribute */  static final String ATT_THRESHOLD = "threshold";  boolean result = true;  Object obj = null;  String name = null;  String password = null;  String value = null;  String host = null;  int port = -1;  int cnxTimer = -1;  String reliableClass = null;  String url = null;  int timeout = -1;  int serverId = -1;  String className = null;  String user = null;  String type = null;  Properties properties = null;  String jndiName = null;  boolean jndi = false;  Hashtable toBind = new Hashtable();  Vector readers = new Vector();  Vector writers = new Vector();  boolean freeReading = false;  boolean freeWriting = false;  Hashtable users = new Hashtable();  InitialContext jndiCtx = null;  Vector cluster = null;  Hashtable destinations = new Hashtable();  String dmq = null;  int threshold = -1;  int nbMaxMsg = -1;  String parent = null;  /**   * Name of joram admin to get from the file.   */  String joramAdmName = "default";  /** Working attribute used during configuration's */  String conf = null;  /**   *   */  public boolean parse(Reader cfgReader,                       String cfgName)    throws Exception {    this.joramAdmName = cfgName;    SAXParserFactory factory = SAXParserFactory.newInstance();    SAXParser parser = factory.newSAXParser();    parser.parse(new InputSource(cfgReader), this);    return result;  }  /**   * Handles notification of a non-recoverable parser error.   *   * @param e	The warning information encoded as an exception.   *   * @exception SAXException   *	Any SAX exception, possibly wrapping another exception.   */  public void fatalError(SAXParseException e) throws SAXException {    JoramTracing.dbgAdmin.log(BasicLevel.ERROR,                              "fatal error parsing " + e.getPublicId() +                              " at " + e.getLineNumber() + "." + e.getColumnNumber());    throw e;  }  /**   * Handles notification of a recoverable parser error.   *   * @param e	The warning information encoded as an exception.   *   * @exception SAXException   *	Any SAX exception, possibly wrapping another exception.   */  public void error(SAXParseException e) throws SAXException {    JoramTracing.dbgAdmin.log(BasicLevel.ERROR,                              "error parsing " + e.getPublicId() +                              " at " + e.getLineNumber() + "." + e.getColumnNumber());    throw e;  }  /**   * Handles notification of a parser warning.   *   * @param e	The warning information encoded as an exception.   *   * @exception SAXException   *	Any SAX exception, possibly wrapping another exception.   */  public void warning(SAXParseException e) throws SAXException {    JoramTracing.dbgAdmin.log(BasicLevel.ERROR,                              "warning parsing " + e.getPublicId() +                              " at " + e.getLineNumber() + "." + e.getColumnNumber());    throw e;  }  private boolean isSet(String value) {    return value != null && value.length() > 0;  }  /**   * Initializes parsing of a document.   *   * @exception SAXException   *	unspecialized error   */  public void startDocument() throws SAXException {    if (JoramTracing.dbgAdmin.isLoggable(BasicLevel.DEBUG))      JoramTracing.dbgAdmin.log(BasicLevel.DEBUG, "startDocument");  }  /**   * Receive notification of the start of an element.   *   * @param uri		The Namespace URI   * @param localName	The local name   * @param rawName	The qualified name   * @param atts	The attributes attached to the element.   *   * @exception SAXException   *	unspecialized error   */  public void startElement(String uri,			   String localName,			   String rawName,			   Attributes atts) throws SAXException {    if (JoramTracing.dbgAdmin.isLoggable(BasicLevel.DEBUG))      JoramTracing.dbgAdmin.log(BasicLevel.DEBUG, "startElement: " + rawName);    if (rawName.equals(ELT_JORAMADMIN)) {      conf = atts.getValue(ATT_NAME);      if (conf == null) conf = joramAdmName;    } else if (joramAdmName.equals(conf)) {      if (rawName.equals(ELT_ADMINMODULE)) {      } else if (rawName.equals(ELT_CONNECT)) {        try {          try {            host = atts.getValue(ATT_HOST);            if (!isSet(host))              host = "localhost";            String value = atts.getValue(ATT_PORT);            if (value == null)              port = 16010;            else              port = Integer.parseInt(value);            name = atts.getValue(ATT_NAME);            if (!isSet(name))              name = "root";            password = atts.getValue(ATT_PASSWORD);            if (!isSet(password))              password = "root";            value = atts.getValue(ATT_CNXTIMER);            if (value == null)              cnxTimer = 60;            else              cnxTimer = Integer.parseInt(value);            reliableClass = atts.getValue(ATT_RELIABLECLASS);          } catch (NumberFormatException exc) {            throw new Exception("bad value for port: " +                                atts.getValue(ATT_PORT) +                                " or cnxTimer: " +                                atts.getValue(ATT_CNXTIMER));          }        } catch (Exception exc) {          throw new SAXException(exc.getMessage(), exc);        }      } else if (rawName.equals(ELT_COLLOCATEDCONNECT)) {        try {          name = atts.getValue(ATT_NAME);          if (!isSet(name))            name = "root";          password = atts.getValue(ATT_PASSWORD);          if (!isSet(password))            password = "root";        } catch (Exception exc) {          throw new SAXException(exc.getMessage(), exc);        }      } else if (rawName.equals(ELT_CONNECTIONFACTORY)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -