Search in sources :

Example 21 with ComponentDescriptionDTO

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

the class ComponentCommands method findComponents.

private List<ComponentDescriptionDTO> findComponents(String name) {
    String lowerName = name.toLowerCase();
    List<ComponentDescriptionDTO> matches = new LinkedList<>();
    for (ComponentDescriptionDTO dto : scr.getComponentDescriptionDTOs()) {
        if (dto.name.equalsIgnoreCase(name)) {
            // Exact match, return only this component.
            return Collections.singletonList(dto);
        }
        if (dto.name.toLowerCase().contains(lowerName))
            matches.add(dto);
    }
    return matches;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) LinkedList(java.util.LinkedList)

Example 22 with ComponentDescriptionDTO

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

the class ComponentCommands method disable.

@Descriptor("Disable an enabled component")
public boolean disable(@Descriptor("Name of the component") final String name) {
    boolean changed = false;
    for (ComponentDescriptionDTO comp : findComponents(name)) {
        if (scr.isComponentEnabled(comp)) {
            scr.disableComponent(comp);
            changed = true;
        }
    }
    return changed;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) Descriptor(org.apache.felix.service.command.Descriptor)

Example 23 with ComponentDescriptionDTO

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

the class ServiceComponentRuntimeImpl method getComponentDescriptionDTOs.

/**
 * @see org.osgi.service.component.runtime.ServiceComponentRuntime#getComponentDescriptionDTOs(org.osgi.framework.Bundle[])
 */
public Collection<ComponentDescriptionDTO> getComponentDescriptionDTOs(Bundle... bundles) {
    List<ComponentHolder<?>> holders;
    if (bundles == null || bundles.length == 0) {
        holders = componentRegistry.getComponentHolders();
    } else {
        holders = componentRegistry.getComponentHolders(bundles);
    }
    List<ComponentDescriptionDTO> result = new ArrayList<ComponentDescriptionDTO>(holders.size());
    for (ComponentHolder<?> holder : holders) {
        ComponentDescriptionDTO dto = holderToDescription(holder);
        if (dto != null) {
            result.add(dto);
        }
    }
    return result;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentHolder(org.apache.felix.scr.impl.manager.ComponentHolder) ArrayList(java.util.ArrayList)

Example 24 with ComponentDescriptionDTO

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

the class ServiceComponentRuntimeImpl method holderToDescription.

private ComponentDescriptionDTO holderToDescription(ComponentHolder<?> holder) {
    ComponentDescriptionDTO dto = new ComponentDescriptionDTO();
    ComponentMetadata m = holder.getComponentMetadata();
    dto.activate = m.getActivate();
    dto.bundle = bundleToDTO(holder.getActivator().getBundleContext());
    // immediately return if bundle is not active anymore
    if (dto.bundle == null) {
        return null;
    }
    dto.configurationPid = m.getConfigurationPid().toArray(new String[m.getConfigurationPid().size()]);
    dto.configurationPolicy = m.getConfigurationPolicy();
    dto.deactivate = m.getDeactivate();
    dto.defaultEnabled = m.isEnabled();
    dto.factory = m.getFactoryIdentifier();
    dto.immediate = m.isImmediate();
    dto.implementationClass = m.getImplementationClassName();
    dto.modified = m.getModified();
    dto.name = m.getName();
    dto.properties = deepCopy(m.getProperties());
    dto.references = refsToDTO(m.getDependencies());
    dto.scope = m.getServiceMetadata() == null ? null : m.getServiceMetadata().getScope().name();
    dto.serviceInterfaces = m.getServiceMetadata() == null ? EMPTY : m.getServiceMetadata().getProvides();
    return dto;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata)

Example 25 with ComponentDescriptionDTO

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

the class ComponentConfigurationPidTest method test_configurationpid_use_other_pid.

@Test
public void test_configurationpid_use_other_pid() throws Exception {
    final String pid = "ConfigurationPid.otherPid";
    final String name = "ConfigurationPid.componentName";
    deleteConfig(pid);
    delay();
    TestCase.assertNull(SimpleComponent.INSTANCE);
    getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    configure(pid);
    delay();
    findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
    TestCase.assertNotNull(SimpleComponent.INSTANCE);
    TestCase.assertEquals(PROP_NAME, SimpleComponent.INSTANCE.getProperty(PROP_NAME));
    deleteConfig(pid);
    delay();
    ComponentDescriptionDTO cd = checkConfigurationCount(name, 0, -1);
    TestCase.assertNull(SimpleComponent.INSTANCE);
    disableAndCheck(cd);
    TestCase.assertNull(SimpleComponent.INSTANCE);
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) Test(org.junit.Test)

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