public ServerStateChangeException(String server, int operation, int curState) {
    super(server);
    this.mOperation = operation;
    this.mServer = server;
    this.mCurState = curState;

    if (operation == START_OPERATION) {
      setDetails(WDExConstants.START_FAILED, WDUtil.toArray(server, Server.stateName(curState)));
    } else {
      setDetails(WDExConstants.STOP_FAILED, WDUtil.toArray(server, Server.stateName(curState)));
    }
  }
Ejemplo n.º 2
0
  /**
   * Tokenizes a command string into a list.
   *
   * @throws Exception if the command cannot be tokenized
   */
  protected static LinkedList _tokenizeCommand(String cmd) throws Exception {

    LinkedList tokens = new LinkedList();
    int startIndex = 0;
    int dQuoteAt = cmd.indexOf('"');
    int sQuoteAt = cmd.indexOf('\'');

    if (dQuoteAt == -1 && sQuoteAt == -1) {
      StringTokenizer st = new StringTokenizer(cmd.trim());
      while (st.hasMoreTokens()) {
        tokens.add(st.nextToken());
      }
      return tokens;
    }

    char[] chArray = cmd.trim().toCharArray();

    int endIndex = 0;
    boolean inQuotes = false;
    char c = 0;
    char lastc = 0;
    char lastqc = 0;
    StringBuffer sb = new StringBuffer(80);

    while (endIndex < chArray.length) {
      c = chArray[endIndex];
      if (!Character.isWhitespace(c)) {
        if (c == '"' || c == '\'') {
          if (inQuotes && lastc != '\\' && lastqc == c) {
            tokens.add(sb.toString());
            inQuotes = false;
            sb.setLength(0);
          } else if (!inQuotes) {
            inQuotes = true;
            lastqc = c;
          } else {
            sb.append(c);
          }
        } else if (c == '\\') {
          if (lastc == '\\') sb.append(c);
        } else {
          sb.append(c);
        }
      } else {
        if (inQuotes) {
          sb.append(c);
        } else {
          if (sb.length() > 0) {
            tokens.add(sb.toString());
            sb.setLength(0);
          }
        }
      }
      lastc = c;
      ++endIndex;
    }

    if (inQuotes) {
      throw new Exception(
          WDExUtil.formatMessage(WDExConstants.UNTERMINATED_STRING, WDUtil.toArray(cmd)));
    }
    return tokens;
  }