Beispiel #1
0
  /**
   * Gets the information about an element's handlers in the current router configuration.
   *
   * @param el The element name.
   * @return Vector of HandlerInfo structures.
   * @exception NoSuchElementException If there is no such element in the current configuration.
   * @exception HandlerErrorException If the handler returned an error.
   * @exception PermissionDeniedException If the router would not let us access the handler.
   * @exception IOException If there was some other error accessing the handler (e.g., there was a
   *     stream or socket error, the ControlSocket returned an unknwon unknown error code, or the
   *     response could otherwise not be understood).
   * @see #HandlerInfo
   * @see #getConfigElementNames
   * @see #getRouterConfig
   * @see #getRouterFlatConfig
   */
  public Vector getElementHandlers(String elementName) throws ClickException, IOException {
    Vector v = new Vector();
    Vector vh;

    try {
      char[] buf = read(elementName, "handlers");
      vh = StringUtils.split(buf, 0, '\n');
    } catch (ClickException.NoSuchHandlerException e) {
      return v;
    }

    for (int i = 0; i < vh.size(); i++) {
      String s = (String) vh.elementAt(i);
      int j;
      for (j = 0; j < s.length() && !Character.isWhitespace(s.charAt(j)); j++)
        ; // find record split
      if (j == s.length())
        throw new ClickException.HandlerFormatException(elementName + ".handlers");
      HandlerInfo hi = new HandlerInfo(elementName, s.substring(0, j).trim());
      while (j < s.length() && Character.isWhitespace(s.charAt(j))) j++;
      for (; j < s.length(); j++) {
        char c = s.charAt(j);
        if (Character.toLowerCase(c) == 'r') hi.canRead = true;
        else if (Character.toLowerCase(c) == 'w') hi.canWrite = true;
        else if (Character.isWhitespace(c)) break;
      }
      v.addElement(hi);
    }
    return v;
  }
Beispiel #2
0
  private boolean checkHandlerWorkaround(
      String elementName, String handlerName, boolean writeHandler)
      throws ClickException, IOException {
    // If talking to an old ControlSocket, try the "handlers" handler
    // instead.
    String s = readString(elementName, "handlers");
    int pos = 0;

    // Find handler with same name.
    while (true) {
      pos = s.indexOf(handlerName, pos);
      if (pos < 0) // no such handler
      return false;
      if ((pos == 0 || s.charAt(pos - 1) == '\n')
          && Character.isWhitespace(s.charAt(pos + handlerName.length()))) break;
      pos++;
    }

    // we have a matching handler: will it be read/write suitable?
    char wantType = (writeHandler ? 'w' : 'r');
    for (pos += handlerName.length();
        pos < s.length() && Character.isWhitespace(s.charAt(pos));
        pos++) /* nada */ ;
    for (; pos < s.length(); pos++) {
      char c = s.charAt(pos);
      if (Character.toLowerCase(c) == wantType) return true;
      else if (Character.isWhitespace(c)) break;
    }
    return false;
  }