Search in sources :

Example 6 with ComponentDependencyDeclaration

use of org.apache.felix.dm.ComponentDependencyDeclaration in project felix by apache.

the class FELIX4158_DependencyDeclarationTest method testServiceDependencyDeclaration.

public void testServiceDependencyDeclaration() {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createServiceDependency().setService(LogService.class, "(foo=bar)"));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "org.osgi.service.log.LogService (foo=bar)");
    Assert.assertEquals(cdds[0].getSimpleName(), "org.osgi.service.log.LogService");
    Assert.assertNotNull(cdds[0].getFilter());
    Assert.assertEquals(cdds[0].getFilter(), "(foo=bar)");
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component) LogService(org.osgi.service.log.LogService)

Example 7 with ComponentDependencyDeclaration

use of org.apache.felix.dm.ComponentDependencyDeclaration in project felix by apache.

the class FELIX4158_DependencyDeclarationTest method testConfigurationDependencyDeclaration.

public void testConfigurationDependencyDeclaration() {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createConfigurationDependency().setPid("foo"));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "foo");
    Assert.assertEquals(cdds[0].getSimpleName(), "foo");
    Assert.assertNull(cdds[0].getFilter());
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component)

Example 8 with ComponentDependencyDeclaration

use of org.apache.felix.dm.ComponentDependencyDeclaration in project felix by apache.

the class FELIX4158_DependencyDeclarationTest method testResourceDependencyDeclaration.

public void testResourceDependencyDeclaration() throws MalformedURLException {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createResourceDependency().setResource(new URL("file://localhost/path/to/file1.txt")));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "file://localhost/path/to/file1.txt");
    Assert.assertNotNull(cdds[0].getSimpleName());
    Assert.assertEquals(cdds[0].getSimpleName(), "file://localhost/path/to/file1.txt");
    Assert.assertNull(cdds[0].getFilter());
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component) URL(java.net.URL)

Example 9 with ComponentDependencyDeclaration

use of org.apache.felix.dm.ComponentDependencyDeclaration in project felix by apache.

the class DependencyGraph method getProviderComponents.

private List<ComponentNode> getProviderComponents(DependencyNode dependencyNode) {
    List<ComponentNode> result = new ArrayList<>();
    ComponentDependencyDeclaration cdd = dependencyNode.getDependencyDeclaration();
    if (!SERVICE.equals(cdd.getType())) {
        return result;
    }
    for (DependencyGraphNode n : m_componentToNode.values()) {
        ComponentNode componentNode = (ComponentNode) n;
        if (componentProvidesDependency(componentNode, dependencyNode)) {
            result.add(componentNode);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration)

Example 10 with ComponentDependencyDeclaration

use of org.apache.felix.dm.ComponentDependencyDeclaration in project felix by apache.

the class DependencyGraph method buildDependecyNodesAndEdges.

private void buildDependecyNodesAndEdges() {
    for (DependencyGraphNode node : m_componentToNode.values()) {
        ComponentNode componentNode = (ComponentNode) node;
        ComponentDependencyDeclaration[] dependencyDeclarations = componentNode.getComponentDeclaration().getComponentDependencies();
        for (ComponentDependencyDeclaration cdd : dependencyDeclarations) {
            if (dependencyMustBeAddedToGraph(cdd)) {
                DependencyNode dependencyNode = new DependencyNode(cdd);
                m_dependencyToNode.put(cdd, dependencyNode);
                // add edges from the component node to newly created dependency node
                componentNode.addSuccessor(dependencyNode);
                // add edges from the newly created dependency node to the components
                // providing those dependencies (only applicable to service dependencies)
                List<ComponentNode> providerComponents = getProviderComponents(dependencyNode);
                for (ComponentNode p : providerComponents) {
                    dependencyNode.addSuccessor(p);
                }
            }
        }
    }
}
Also used : ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration)

Aggregations

ComponentDependencyDeclaration (org.apache.felix.dm.ComponentDependencyDeclaration)10 Component (org.apache.felix.dm.Component)8 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)8 DependencyManager (org.apache.felix.dm.DependencyManager)7 ArrayList (java.util.ArrayList)2 URL (java.net.URL)1 StringTokenizer (java.util.StringTokenizer)1 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)1 Descriptor (org.apache.felix.service.command.Descriptor)1 Bundle (org.osgi.framework.Bundle)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 LogService (org.osgi.service.log.LogService)1