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

📄 commandwrapper.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    * "sysprop/?trace[core]=true" would return 'true'    * Lenght is guaranteed to be >= 1    * @exception XmlBlasterException if no value found    */   public final String[] getArgs() throws XmlBlasterException {      if (key == null && this.args == null)         parseKeyValue();      return this.args;   }   /**    * @return If set() is invoked the value before the "="    * "sysprop/?trace[core]=true" would return 'trace[core]'    * @exception XmlBlasterException if no value found    */   public final String getKey() throws XmlBlasterException {      if (key == null && args == null)         parseKeyValue();      return key;   }   /**    * set client/publish/1/?addRemoteProperty=arg1&arg2    * @throws XmlBlasterException    */   private void parseKeyValue() throws XmlBlasterException {      int qIndex = cmd.indexOf("?");      if (qIndex < 1 || cmd.length() <= (qIndex+1)) {         log.warning("parseKeyValue(): Invalid command '" + cmd + "', can't find '?'");         throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parseKeyValue", "Invalid command '" + cmd + "', can't find '?'");      }      // "addRemoteProperty=arg1&arg2"      String propString = cmd.substring(qIndex+1);      int equalsIndex = propString.indexOf("=");      if (equalsIndex < 1 || propString.length() <= (equalsIndex+1)) {         this.key = propString;         this.args = null;         return; // a getXy()         //log.warn(ME, "parseKeyValue(): Invalid command '" + cmd + "', can't find '='");         //throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parseKeyValue", "Invalid command '" + cmd + "', can't find '='");      }            this.key = propString.substring(0, equalsIndex);      // "arg1&arg2"      this.argsString = propString.substring(equalsIndex+1).trim();             this.args = StringPairTokenizer.parseLine(argsString, '&');      if (this.args.length < 1) {         log.warning("parseKeyValue(): Invalid command '" + cmd + "', can't find value behind '='");         throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parseKeyValue", "Invalid command '" + cmd + "', can't find value behind '='");      }      /*      StringTokenizer tokenizer = new StringTokenizer(propString.trim(), PROP_SEPARATOR); // "&"      boolean keyAlreadyAssigned = false;      while (tokenizer.hasMoreTokens()) {         String pair = tokenizer.nextToken().trim();         if (pair.length() < 1) continue;         int equalsIndex = pair.indexOf("=");                  //if (equalsIndex < 1 || pair.length() <= (equalsIndex+1)) {         //   log.warn(ME, "parseKeyValue(): Invalid command '" + cmd + "', can't find assignment '='");         //   //Thread.currentThread().dumpStack();         //   throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parseKeyValue", "Invalid command '" + cmd + "', can't find assignment '='");         //}               String tmpKey = pair.substring(0,equalsIndex).trim();                  String tmpKey = null;         String tmpValue = null;         if (equalsIndex < 1 || pair.length() <= (equalsIndex+1)) {            tmpKey = pair.trim();            tmpValue = null;         }         else {            tmpKey = pair.substring(0,equalsIndex).trim();            tmpValue = pair.substring(equalsIndex+1);         }          if (tmpKey.indexOf(XMLBLASTER_PREFIX) < 0) {            if (keyAlreadyAssigned)               throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, "only one key which does not start with '" + XMLBLASTER_PREFIX + "' can be assigned");            this.key = tmpKey;            this.value = tmpValue;         }         else this.props.put(tmpKey, tmpValue);      }      */   }   /**    * @return The original command, with added absolute path if the original was relative, e.g.    *         /node/heron/?runlevel    */   public final String getCommand() {      return cmd;   }   /**    * @return The original command, with added absolute path if the original was relative    *         and stripped "=bla" at the end.    */   public final String getCommandStripAssign() throws XmlBlasterException {      int equalsIndex = cmd.lastIndexOf("=");      if (equalsIndex < 1 || cmd.length() <= (equalsIndex+1)) {         //log.warning("getCommandStripAssign(): Invalid command '" + cmd + "', can't find assignment '='");         //throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".getCommandStripAssign", "Invalid command '" + cmd + "', can't find assignment '='");         return cmd;      }      return cmd.substring(0,equalsIndex).trim();   }   /**    * Dump state of this object into a XML ASCII string.    */   public final String toXml() {      return toXml((String)null);   }   /**    * Dump state of this object into a XML ASCII string.    * @param extraOffset indenting of tags for nice output    */   public synchronized final String toXml(String extraOffset) {      StringBuffer sb = new StringBuffer(1024);      String offset = "\n   ";      if (extraOffset == null) extraOffset = "";      offset += extraOffset;      sb.append(offset).append("<commandWrapper>");      sb.append(offset).append("  <cmd>").append(cmd).append("</cmd>");      sb.append(offset).append("  <root>").append(root).append("</root>");      sb.append(offset).append("  <nodeId>").append(clusterNodeId).append("</nodeId");      sb.append(offset).append("  <third>").append(third).append("</third");      sb.append(offset).append("  <tail>").append(third).append("</tail");      sb.append(offset).append("</commandWrapper>");      return sb.toString();   }      //public QueryQosData getQueryQosData() {   //   return this.qosData;   //}   //public QueryKeyData getQueryKeyData() {   //   return this.keyData;   //}   /**    * Strips a given command (the oid of a queryKey before any any modification) by     * removing the starting '__cmd:' subtring. So for example the input string    * '__cmd:/node/heron/?numClients' will be stripped to '/node/heron/?numClients'.    * @param glob    * @param command the input string (the original oid) to be stripped.    * @return    * @throws XmlBlasterException    */   public static String stripCommand(ServerScope glob, String command) throws XmlBlasterException {      if (command == null) {         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CommandWrapper.stripCommand", "Ignoring your empty command.");      }      command = command.trim();      if (!command.startsWith("__cmd:") || command.length() < ("__cmd:".length() + 1)) {         return command; //throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CommandWrapper.stripCommand", "Ignoring your empty command '" + command + "'.");      }      int dotIndex = command.indexOf(":");      return command.substring(dotIndex+1).trim();  // "/node/heron/?numClients"   }      /*    * This has to be invoked after the command has been parsed    * @param value the non-null string containing the qos specification.    *        for example if the entire command is    * '__cmd:/node/heron/?numClients&xmlBlaster.qos=<qos>......</qos>'      * @param keyData must be non null    * @param qosData   private void fillKeyAndQos() throws XmlBlasterException {      if (this.qosData != null) return;            // String qosLitteral = (String)this.props.get("xmlBlaster.qos");      // TODO fix this hack. Currently only one property is allowed: xmlBlaster.qos      int qosPos = this.cmd.indexOf("&xmlBlaster.qos=");      String qosLitteral =null;      if (qosPos > -1)          qosLitteral = this.cmd.substring(qosPos + "&xmlBlaster.qos=".length());      // end of the brutal hack            if (qosLitteral == null)          this.qosData = new QueryQosData(this.glob, MethodName.GET);      else {         QueryQosSaxFactory factory = new QueryQosSaxFactory(this.glob);         this.qosData = factory.readObject(qosLitteral);      }      if (this.sixth == null) {         this.keyData.setOid("__cmd:" + this.cmd);      }      else {         int pos = this.sixth.indexOf('&');         if (pos > -1) this.sixth = this.sixth.substring(0, pos);         pos = this.cmd.indexOf('&');         String tmpCmd = "";         if (pos > -1) tmpCmd = this.cmd.substring(0, pos);         this.keyData.setOid("__cmd:" + tmpCmd);      }         }*/   /**    * @return Returns the argsString.    */   public String getArgsString() {      return this.argsString;   }   /**    * @param argsString The argsString to set.    */   public void setArgs(String[] args) {      this.args = args;   }}

⌨️ 快捷键说明

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