Search in sources :

Example 1 with InstanceDeclaration

use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.

the class DefaultConfigurationBuilderTestCase method testPropertyRemoval.

public void testPropertyRemoval() throws Exception {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(parent);
    builder.property("a", "b");
    InstanceDeclaration declaration = (InstanceDeclaration) builder.build();
    assertEquals(declaration.getConfiguration().get("a"), "b");
    builder.remove("a");
    InstanceDeclaration declaration2 = (InstanceDeclaration) builder.build();
    assertNull(declaration2.getConfiguration().get("a"));
}
Also used : InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration)

Example 2 with InstanceDeclaration

use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.

the class DefaultConfigurationBuilderTestCase method testPropertyAdditionReUse.

public void testPropertyAdditionReUse() throws Exception {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(parent);
    builder.property("a", "b");
    // First built instance
    InstanceDeclaration declaration = (InstanceDeclaration) builder.build();
    assertEquals(declaration.getConfiguration().get("a"), "b");
    // Second built instance
    builder.property("c", "d");
    InstanceDeclaration declaration2 = (InstanceDeclaration) builder.build();
    assertEquals(declaration2.getConfiguration().get("a"), "b");
    assertEquals(declaration2.getConfiguration().get("c"), "d");
    // Verify that first instance is not modified
    assertNull(declaration.getConfiguration().get("c"));
}
Also used : InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration)

Example 3 with InstanceDeclaration

use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.

the class DefaultInstanceBuilderTestCase method testVersionConfiguration.

public void testVersionConfiguration() throws Exception {
    InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type").name("John").version("1.0");
    DeclarationHandle handle = builder.build();
    InstanceDeclaration did = (InstanceDeclaration) handle;
    assertEquals("type", did.getComponentName());
    assertEquals("John", did.getInstanceName());
    assertEquals("1.0", did.getComponentVersion());
    Dictionary<String, Object> configuration = did.getConfiguration();
    assertEquals("John", configuration.get(Factory.INSTANCE_NAME_PROPERTY));
    assertEquals("1.0", configuration.get(Factory.FACTORY_VERSION_PROPERTY));
}
Also used : DefaultInstanceDeclaration(org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle) InstanceBuilder(org.apache.felix.ipojo.extender.InstanceBuilder)

Example 4 with InstanceDeclaration

use of org.apache.felix.ipojo.extender.InstanceDeclaration in project felix by apache.

the class DefaultInstanceBuilderTestCase method testNameConfiguration.

public void testNameConfiguration() throws Exception {
    InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type").name("John");
    DeclarationHandle handle = builder.build();
    InstanceDeclaration did = (InstanceDeclaration) handle;
    assertEquals("type", did.getComponentName());
    assertEquals("John", did.getInstanceName());
    assertNull(did.getComponentVersion());
    Dictionary<String, Object> configuration = did.getConfiguration();
    assertEquals("John", configuration.get(Factory.INSTANCE_NAME_PROPERTY));
}
Also used : DefaultInstanceDeclaration(org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle) InstanceBuilder(org.apache.felix.ipojo.extender.InstanceBuilder)

Example 5 with InstanceDeclaration

use of org.apache.felix.ipojo.extender.InstanceDeclaration 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)

Aggregations

InstanceDeclaration (org.apache.felix.ipojo.extender.InstanceDeclaration)9 DeclarationHandle (org.apache.felix.ipojo.extender.DeclarationHandle)3 InstanceBuilder (org.apache.felix.ipojo.extender.InstanceBuilder)3 DefaultInstanceDeclaration (org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration)3 Architecture (org.apache.felix.ipojo.architecture.Architecture)2 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)2 Descriptor (org.apache.felix.service.command.Descriptor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1