Search in sources :

Example 6 with ComponentDescriptionDTO

use of org.osgi.service.component.runtime.dto.ComponentDescriptionDTO 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)

Example 7 with ComponentDescriptionDTO

use of org.osgi.service.component.runtime.dto.ComponentDescriptionDTO in project felix by apache.

the class ComponentConfigurationPrinter method printComponentsJson.

private final void printComponentsJson(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentConfigurationDTO> configurations, final boolean details) throws IOException {
    final JSONWriter jw = new JSONWriter(pw);
    jw.object();
    // $NON-NLS-1$
    jw.key("components");
    jw.array();
    // render disabled descriptions
    for (final ComponentDescriptionDTO cd : disabled) {
        plugin.component(jw, cd, null, details);
    }
    // render configurations
    for (final ComponentConfigurationDTO cfg : configurations) {
        plugin.component(jw, cfg.description, cfg, details);
    }
    jw.endArray();
    jw.endObject();
}
Also used : JSONWriter(org.apache.felix.utils.json.JSONWriter) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 8 with ComponentDescriptionDTO

use of org.osgi.service.component.runtime.dto.ComponentDescriptionDTO in project felix by apache.

the class ComponentConfigurationPrinter method printComponentsText.

private static final void printComponentsText(final PrintWriter pw, final List<ComponentDescriptionDTO> disabled, final List<ComponentDescriptionDTO> noConfig, final List<ComponentConfigurationDTO> configurations) {
    if (!disabled.isEmpty()) {
        pw.println(SEP);
        pw.println("Disabled components:");
        pw.println(SEP);
        for (final ComponentDescriptionDTO cd : disabled) {
            disabledComponent(pw, cd);
        }
        pw.println();
    }
    if (!noConfig.isEmpty()) {
        pw.println(SEP);
        pw.println("Components with missing configuration in Config Admin:");
        pw.println(SEP);
        for (final ComponentDescriptionDTO cd : noConfig) {
            disabledComponent(pw, cd);
        }
        pw.println();
    }
    pw.println(SEP);
    if (configurations.isEmpty()) {
        pw.println("Status: No Component Configurations");
        pw.println(SEP);
    } else {
        pw.println("Component Configurations:");
        pw.println(SEP);
        // order components by id
        TreeMap<Long, ComponentConfigurationDTO> componentMap = new TreeMap<Long, ComponentConfigurationDTO>();
        for (final ComponentConfigurationDTO cfg : configurations) {
            componentMap.put(new Long(cfg.id), cfg);
        }
        // render components
        for (final ComponentConfigurationDTO cfg : componentMap.values()) {
            component(pw, cfg);
        }
    }
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) TreeMap(java.util.TreeMap) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 9 with ComponentDescriptionDTO

use of org.osgi.service.component.runtime.dto.ComponentDescriptionDTO in project felix by apache.

the class ComponentConfigurationPrinter method print.

/**
 * @see org.apache.felix.inventory.InventoryPrinter#print(java.io.PrintWriter, org.apache.felix.inventory.Format, boolean)
 */
public void print(PrintWriter pw, Format format, boolean isZip) {
    final List<ComponentDescriptionDTO> noConfig = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
    final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs();
    for (final ComponentDescriptionDTO d : descs) {
        if (!scrService.isComponentEnabled(d)) {
            disabled.add(d);
        } else {
            final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
            if (configs.isEmpty()) {
                noConfig.add(d);
            } else {
                configurations.addAll(configs);
            }
        }
    }
    Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
    if (Format.JSON.equals(format)) {
        disabled.addAll(noConfig);
        try {
            printComponentsJson(pw, disabled, configurations, isZip);
        } catch (IOException ignore) {
        // ignore
        }
    } else {
        printComponentsText(pw, disabled, noConfig, configurations);
    }
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 10 with ComponentDescriptionDTO

use of org.osgi.service.component.runtime.dto.ComponentDescriptionDTO in project felix by apache.

the class InfoProvider method getBundleInfo.

/**
 * @see org.apache.felix.webconsole.bundleinfo.BundleInfoProvider#getBundleInfo(org.osgi.framework.Bundle,
 *      java.lang.String, java.util.Locale)
 */
public BundleInfo[] getBundleInfo(Bundle bundle, String webConsoleRoot, Locale locale) {
    final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
    final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs(bundle);
    for (final ComponentDescriptionDTO d : descs) {
        if (!scrService.isComponentEnabled(d)) {
            disabled.add(d);
        } else {
            final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
            if (configs.isEmpty()) {
                disabled.add(d);
            } else {
                configurations.addAll(configs);
            }
        }
    }
    Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
    if (configurations.isEmpty()) {
        return NO_INFO;
    }
    BundleInfo[] ret = new BundleInfo[configurations.size() + disabled.size()];
    int i = 0;
    for (final ComponentDescriptionDTO cfg : disabled) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    for (final ComponentConfigurationDTO cfg : configurations) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    return ret;
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Aggregations

ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)36 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)18 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)3 ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)3 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)3 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)3 Iterator (java.util.Iterator)2 TreeMap (java.util.TreeMap)2 Component (org.apache.felix.scr.Component)2 Descriptor (org.apache.felix.service.command.Descriptor)2 JSONWriter (org.apache.felix.utils.json.JSONWriter)2 ServiceReferenceDTO (org.osgi.framework.dto.ServiceReferenceDTO)2 SatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1