Search in sources :

Example 11 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class ObrGogoCommand method list.

@Descriptor("list repository resources")
public void list(@Descriptor("display all versions") @Parameter(names = { "-v", "--verbose" }, presentValue = "true", absentValue = "false") boolean verbose, @Descriptor("optional strings used for name matching") String[] args) throws IOException, InvalidSyntaxException {
    Object svcObj = getRepositoryAdmin();
    if (svcObj == null) {
        return;
    }
    RepositoryAdmin ra = (RepositoryAdmin) svcObj;
    // Create a filter that will match presentation name or symbolic name.
    StringBuffer sb = new StringBuffer();
    if ((args == null) || (args.length == 0)) {
        sb.append("(|(presentationname=*)(symbolicname=*))");
    } else {
        StringBuffer value = new StringBuffer();
        for (int i = 0; i < args.length; i++) {
            if (i > 0) {
                value.append(" ");
            }
            value.append(args[i]);
        }
        sb.append("(|(presentationname=*");
        sb.append(value);
        sb.append("*)(symbolicname=*");
        sb.append(value);
        sb.append("*))");
    }
    // Use filter to get matching resources.
    Resource[] resources = ra.discoverResources(sb.toString());
    // Group the resources by symbolic name in descending version order,
    // but keep them in overall sorted order by presentation name.
    Map revisionMap = new TreeMap(new Comparator() {

        public int compare(Object o1, Object o2) {
            Resource r1 = (Resource) o1;
            Resource r2 = (Resource) o2;
            // Assume if the symbolic name is equal, then the two are equal,
            // since we are trying to aggregate by symbolic name.
            int symCompare = r1.getSymbolicName().compareTo(r2.getSymbolicName());
            if (symCompare == 0) {
                return 0;
            }
            // Otherwise, compare the presentation name to keep them sorted
            // by presentation name. If the presentation names are equal, then
            // use the symbolic name to differentiate.
            int compare = (r1.getPresentationName() == null) ? -1 : (r2.getPresentationName() == null) ? 1 : r1.getPresentationName().compareToIgnoreCase(r2.getPresentationName());
            if (compare == 0) {
                return symCompare;
            }
            return compare;
        }
    });
    for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
        Resource[] revisions = (Resource[]) revisionMap.get(resources[resIdx]);
        revisionMap.put(resources[resIdx], addResourceByVersion(revisions, resources[resIdx]));
    }
    // Print any matching resources.
    for (Iterator i = revisionMap.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        Resource[] revisions = (Resource[]) entry.getValue();
        String name = revisions[0].getPresentationName();
        name = (name == null) ? revisions[0].getSymbolicName() : name;
        System.out.print(name);
        if (verbose && revisions[0].getPresentationName() != null) {
            System.out.print(" [" + revisions[0].getSymbolicName() + "]");
        }
        System.out.print(" (");
        int revIdx = 0;
        do {
            if (revIdx > 0) {
                System.out.print(", ");
            }
            System.out.print(revisions[revIdx].getVersion());
            revIdx++;
        } while (verbose && (revIdx < revisions.length));
        if (!verbose && (revisions.length > 1)) {
            System.out.print(", ...");
        }
        System.out.println(")");
    }
    if ((resources == null) || (resources.length == 0)) {
        System.out.println("No matching bundles.");
    }
}
Also used : TreeMap(java.util.TreeMap) Comparator(java.util.Comparator) JarEntry(java.util.jar.JarEntry) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) Map(java.util.Map) Descriptor(org.apache.felix.service.command.Descriptor)

Example 12 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Arch method factories.

/**
 * Displays the list of public iPOJO factories.
 */
@Descriptor("Display iPOJO factories")
public void factories() {
    StringBuilder buffer = new StringBuilder();
    for (Factory m_factory : m_factories) {
        if (m_factory.getMissingHandlers().size() == 0) {
            buffer.append(format("Factory %s (VALID)%n", m_factory.getName()));
        } else {
            buffer.append(format("Factory %s (INVALID: %s)%n", m_factory.getName(), m_factory.getMissingHandlers()));
        }
    }
    for (TypeDeclaration type : m_types) {
        if (!type.isPublic()) {
            // give access to the underlying Factory or description (if valid)
            if (type.getStatus().isBound()) {
                buffer.append(format("Factory %s (UNKNOWN) - Private%n", type.getComponentName()));
            } else {
                // Unbound type means that required extension is not available
                // We'll say that the factory is INVALID even if in reality it's not even instantiated
                buffer.append(format("Factory %s (INVALID) - Private%n", type.getComponentName()));
                buffer.append(format("  -> %s", type.getStatus().getMessage()));
            }
        } else {
            if (!type.getStatus().isBound()) {
                buffer.append(format("Factory %s is not bound%n", type.getComponentName()));
                buffer.append(format("  -> %s%n", type.getStatus().getMessage()));
            }
        }
    }
    if (buffer.length() == 0) {
        buffer.append("No factories \n");
    }
    System.out.println(buffer.toString());
}
Also used : Factory(org.apache.felix.ipojo.Factory) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) TypeDeclaration(org.apache.felix.ipojo.extender.TypeDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Example 13 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Arch method instances.

/**
 * Displays iPOJO instances.
 */
@Descriptor("Display iPOJO instances")
public void instances() {
    StringBuilder buffer = new StringBuilder();
    for (Architecture m_arch : m_archs) {
        InstanceDescription instance = m_arch.getInstanceDescription();
        if (instance.getState() == ComponentInstance.VALID) {
            buffer.append(format("Instance %s -> valid%n", instance.getName()));
        }
        if (instance.getState() == ComponentInstance.INVALID) {
            buffer.append(format("Instance %s -> invalid%n", instance.getName()));
        }
        if (instance.getState() == ComponentInstance.STOPPED) {
            buffer.append(format("Instance %s -> stopped%n", instance.getName()));
        }
    }
    for (InstanceDeclaration instance : m_instances) {
        // Only print unbound instances (others already printed above)
        if (!instance.getStatus().isBound()) {
            buffer.append(format("Instance %s of type %s is not bound.%n", name(instance.getConfiguration()), instance.getConfiguration().get("component")));
            buffer.append(format("  Reason: %s", instance.getStatus().getMessage()));
            buffer.append("\n");
        }
    }
    if (buffer.length() == 0) {
        buffer.append("No instances \n");
    }
    System.out.println(buffer.toString());
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) InstanceDescription(org.apache.felix.ipojo.architecture.InstanceDescription) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Example 14 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class Arch method handlers.

/**
 * Displays the list of available handlers.
 */
@Descriptor("Display iPOJO handlers")
public void handlers() {
    PrintStream out = System.out;
    for (HandlerFactory m_handler : m_handlers) {
        String name = m_handler.getHandlerName();
        if ("composite".equals(m_handler.getType())) {
            name = name + " [composite]";
        }
        if (m_handler.getMissingHandlers().size() == 0) {
            out.println("Handler " + name + " (VALID)");
        } else {
            out.println("Handler " + name + " (INVALID : " + m_handler.getMissingHandlers() + ")");
        }
    }
    for (TypeDeclaration type : m_types) {
        if (!type.getStatus().isBound()) {
            out.println("HandlerFactory " + type.getComponentName() + " is not bound");
            out.println("  -> " + type.getStatus().getMessage());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) TypeDeclaration(org.apache.felix.ipojo.extender.TypeDeclaration) Descriptor(org.apache.felix.service.command.Descriptor)

Example 15 with Descriptor

use of org.apache.felix.service.command.Descriptor in project felix by apache.

the class ComponentCommands method enable.

@Descriptor("Enable a disabled component")
public boolean enable(@Descriptor("Name of the component") final String name) {
    boolean changed = false;
    for (ComponentDescriptionDTO comp : findComponents(name)) {
        if (!scr.isComponentEnabled(comp)) {
            scr.enableComponent(comp);
            changed = true;
        }
    }
    return changed;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) Descriptor(org.apache.felix.service.command.Descriptor)

Aggregations

Descriptor (org.apache.felix.service.command.Descriptor)31 ArrayList (java.util.ArrayList)13 ServiceReference (org.osgi.framework.ServiceReference)8 IOException (java.io.IOException)6 Bundle (org.osgi.framework.Bundle)6 StartLevel (org.osgi.service.startlevel.StartLevel)5 URL (java.net.URL)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 PrintStream (java.io.PrintStream)3 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3 HandlerFactory (org.apache.felix.ipojo.HandlerFactory)3 TypeDeclaration (org.apache.felix.ipojo.extender.TypeDeclaration)3 BundleException (org.osgi.framework.BundleException)3 File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 Factory (org.apache.felix.ipojo.Factory)2