Search in sources :

Example 6 with InstanceDeclaration

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

the class DefaultConfigurationBuilderTestCase method testClear.

public void testClear() throws Exception {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(parent);
    builder.property("a", "b");
    builder.property("c", "d");
    InstanceDeclaration declaration = (InstanceDeclaration) builder.build();
    assertEquals(declaration.getConfiguration().get("a"), "b");
    builder.clear();
    InstanceDeclaration declaration2 = (InstanceDeclaration) builder.build();
    assertTrue(declaration2.getConfiguration().isEmpty());
}
Also used : InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration)

Example 7 with InstanceDeclaration

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

the class DefaultConfigurationBuilderTestCase method testPropertyAddition.

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

Example 8 with InstanceDeclaration

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

the class DefaultInstanceBuilderTestCase method testNoConfiguration.

public void testNoConfiguration() throws Exception {
    InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type");
    DeclarationHandle handle = builder.build();
    InstanceDeclaration did = (InstanceDeclaration) handle;
    assertEquals("type", did.getComponentName());
    assertEquals(InstanceDeclaration.UNNAMED_INSTANCE, did.getInstanceName());
    assertNull(did.getComponentVersion());
    Dictionary<String, Object> configuration = did.getConfiguration();
    assertTrue(configuration.isEmpty());
}
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 9 with InstanceDeclaration

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

the class Arch method instance.

/**
 * Displays the architecture of a specific instance.
 * @param instance the instance name
 */
@Descriptor("Display the architecture of a specific instance")
public void instance(@Descriptor("target instance name") String instance) {
    StringBuilder sb = new StringBuilder();
    for (Architecture m_arch : m_archs) {
        InstanceDescription id = m_arch.getInstanceDescription();
        if (id.getName().equalsIgnoreCase(instance)) {
            sb.append(id.getDescription());
            sb.append('\n');
        }
    }
    for (InstanceDeclaration instanceDeclaration : m_instances) {
        if (!instanceDeclaration.getStatus().isBound()) {
            if (instance.equals(name(instanceDeclaration.getConfiguration()))) {
                sb.append(format("InstanceDeclaration %s not bound to its factory%n", instance));
                sb.append(format(" type: %s%n", instanceDeclaration.getComponentName()));
                sb.append(format(" reason: %s%n", instanceDeclaration.getStatus().getMessage()));
                Throwable throwable = instanceDeclaration.getStatus().getThrowable();
                if (throwable != null) {
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    throwable.printStackTrace(new PrintStream(os));
                    sb.append(" throwable: ");
                    sb.append(os.toString());
                }
            }
        }
    }
    if (sb.length() == 0) {
        System.err.printf("Instance named '%s' not found", instance);
    } else {
        System.out.print(sb);
    }
}
Also used : PrintStream(java.io.PrintStream) Architecture(org.apache.felix.ipojo.architecture.Architecture) InstanceDescription(org.apache.felix.ipojo.architecture.InstanceDescription) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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