예제 #1
0
파일: ListAction.java 프로젝트: raulk/karaf
  @Override
  protected Object doScrAction(ScrService scrService) throws Exception {
    ShellTable table = new ShellTable();
    table.column("ID");
    table.column("State");
    table.column("Component Name");

    Component[] components = scrService.getComponents();
    Arrays.sort(components, idComparator);
    for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
      if (showHidden) {
        // we display all because we are overridden
        table
            .addRow()
            .addContent(
                component.getId(), ScrUtils.getState(component.getState()), component.getName());
      } else {
        if (ScrActionSupport.isHiddenComponent(component)) {
          // do nothing
        } else {
          // we aren't hidden so print it
          table
              .addRow()
              .addContent(
                  component.getId(), ScrUtils.getState(component.getState()), component.getName());
        }
      }
    }
    table.print(System.out);

    return null;
  }
 /** @see */
 public Component getComponent(final long componentId) {
   final List<? extends Component> all = scr.getAllComponents();
   for (final Component component : all) {
     if (component.getId() == componentId) {
       return component;
     }
   }
   return null;
 }
  private static final void printComponents(final PrintWriter pw, final Component[] components) {
    if (components == null || components.length == 0) {
      pw.println("  No Components Registered");
    } else {
      // order components by id
      TreeMap componentMap = new TreeMap();
      for (int i = 0; i < components.length; i++) {
        Component component = components[i];
        componentMap.put(new Long(component.getId()), component);
      }

      // render components
      for (Iterator ci = componentMap.values().iterator(); ci.hasNext(); ) {
        Component component = (Component) ci.next();
        component(pw, component);
      }
    }
  }
  private static final void component(PrintWriter pw, Component component) {

    pw.print(component.getId());
    pw.print("=[");
    pw.print(component.getName());
    pw.println("]");

    pw.println(
        "  Bundle"
            + component.getBundle().getSymbolicName()
            + " ("
            + component.getBundle().getBundleId()
            + ")");
    pw.println("  State=" + toStateString(component.getState()));
    pw.println("  DefaultState=" + (component.isDefaultEnabled() ? "enabled" : "disabled"));
    pw.println("  Activation=" + (component.isImmediate() ? "immediate" : "delayed"));

    listServices(pw, component);
    listReferences(pw, component);
    listProperties(pw, component);

    pw.println();
  }