예제 #1
0
 @SuppressWarnings("deprecation")
 public static String getState(Component component) {
   switch (component.getState()) {
     case Component.STATE_DISABLED:
       return "disabled";
     case Component.STATE_ENABLING:
       return "enabling";
     case Component.STATE_ENABLED:
       return "enabled";
     case Component.STATE_UNSATISFIED:
       return "unsatisfied";
     case Component.STATE_ACTIVATING:
       return "activating";
     case Component.STATE_ACTIVE:
       return "active";
     case Component.STATE_REGISTERED:
       return "registered";
     case Component.STATE_FACTORY:
       return "factory";
     case Component.STATE_DEACTIVATING:
       return "deactivating";
     case Component.STATE_DISABLING:
       return "disabling";
     case Component.STATE_DISPOSING:
       return "disposing";
     case Component.STATE_DISPOSED:
       return "disposed";
     default:
       return "" + component.getState();
   }
 }
 /** @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;
 }
예제 #3
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;
  }
  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 void listServices(PrintWriter pw, Component component) {
    String[] services = component.getServices();
    if (services == null) {
      return;
    }

    pw.println("  ServiceType=" + (component.isServiceFactory() ? "service factory" : "service"));

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < services.length; i++) {
      if (i > 0) {
        buf.append(", ");
      }
      buf.append(services[i]);
    }

    pw.println("  Services=" + buf);
  }
  private static final void listReferences(PrintWriter pw, Component component) {
    Reference[] refs = component.getReferences();
    if (refs != null) {
      for (int i = 0; i < refs.length; i++) {

        pw.println(
            "  Reference="
                + refs[i].getName()
                + ", "
                + (refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied"));

        pw.println("    Service Name: " + refs[i].getServiceName());

        if (refs[i].getTarget() != null) {
          pw.println("  Target Filter: " + refs[i].getTarget());
        }

        pw.println("    Multiple: " + (refs[i].isMultiple() ? "multiple" : "single"));
        pw.println("    Optional: " + (refs[i].isOptional() ? "optional" : "mandatory"));
        pw.println("    Policy: " + (refs[i].isStatic() ? "static" : "dynamic"));

        // list bound services
        ServiceReference[] boundRefs = refs[i].getServiceReferences();
        if (boundRefs != null && boundRefs.length > 0) {
          for (int j = 0; j < boundRefs.length; j++) {
            pw.print("    Bound Service: ID ");
            pw.print(boundRefs[j].getProperty(Constants.SERVICE_ID));

            String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
            if (name == null) {
              name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
              if (name == null) {
                name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
              }
            }
            if (name != null) {
              pw.print(" (");
              pw.print(name);
              pw.print(")");
            }
            pw.println();
          }
        } else {
          pw.println("    No Services bound");
        }
      }
    }
  }
  private static final void listProperties(PrintWriter pw, Component component) {
    Dictionary props = component.getProperties();
    if (props != null) {

      pw.println("  Properties=");
      TreeSet keys = new TreeSet(Util.list(props.keys()));
      for (Iterator ki = keys.iterator(); ki.hasNext(); ) {
        String key = (String) ki.next();
        Object value = props.get(key);
        value = WebConsoleUtil.toString(value);
        if (value.getClass().isArray()) {
          value = Arrays.asList((Object[]) value);
        }
        pw.println("    " + key + "=" + value);
      }
    }
  }
  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();
  }