Ejemplo n.º 1
0
  public SearchResult searchCommand(String name, String[] args) {
    CommandContainer command = commandMap.get(name);

    // Try to find the deepest available sub-command
    int index = 0;
    boolean subFound;

    if (args.length > 0) {
      do {
        subFound = false;

        Set<CommandContainer> childs = command.getChildCommands();

        if (childs != null) {
          for (CommandContainer child : childs) {
            if (child.getName().equals(args[index])) {
              command = child;
              index++;
              subFound = true;
              break;
            }
          }
        }
      } while (index < args.length && subFound);
    }

    SearchResult result = new SearchResult();
    result.container = command;
    result.deepness = index;

    return result;
  }
Ejemplo n.º 2
0
  public void unregisterCommands(Class<?> clazz, CommandContainer base) {
    Iterator<CommandContainer> iterator;

    if (base == null) {
      iterator = commandMap.values().iterator();
    } else {
      iterator = base.getChildCommands().iterator();
    }

    unregisterRecursively(clazz, iterator);
  }
Ejemplo n.º 3
0
  private void unregisterRecursively(Class<?> clazz, Iterator<CommandContainer> iterator) {
    while (iterator.hasNext()) {
      CommandContainer container = iterator.next();
      Method method = container.getCommandMethod();
      Set<CommandContainer> childs = container.getChildCommands();

      if (method.getDeclaringClass() == clazz) {
        iterator.remove();
      } else if (childs != null && !childs.isEmpty()) {
        unregisterRecursively(clazz, childs.iterator());
      }
    }
  }