public interface DeclarationBuilderService
// Obtain the service through the service registry
DeclarationBuilderService service = ...
// Get a fresh instance builder
DeclarationBuilder builder = service.newInstance("the.full.name.of.the.component.to.instantiate");
DeclarationHandle handle = builder.name("a-unique-name") // Make sure name is unique for the expected type
.configure()
.property("a-property", "a-value")
.property("another-property", "another-value")
.build();
// Push the InstanceDeclaration service in the registry
handle.publish();
Except the InstanceBuilder.build() call, all methods are optional:
InstanceBuilder.name(String): if no name is provided,
a default one will be generated by iPOJO.InstanceBuilder.version(String): if no version is provided,
the first un-versioned type will be used.InstanceBuilder.configure(): if no configuration is required, can be omitted.InstanceBuilder.type(String): can be used to change the InstanceBuilder.context(org.osgi.framework.BundleContext): by default, the bundle context
used to register the created Declaration is the one of the
caller. It can be changed though this method.DeclarationBuilderService service. Just like having a metadata.xml file in your
bundle that declares your instances. It is possible to override this default behavior using
InstanceBuilder.context(org.osgi.framework.BundleContext).InstanceDeclaration,
TypeDeclaration,
ExtensionDeclaration,
InstanceBuilder,
ConfigurationBuilder,
DeclarationHandle| Modifier and Type | Method and Description |
|---|---|
DeclarationHandle |
newExtension(java.lang.String name,
FactoryBuilder builder)
Declares a new extension (supports new types like component, composite, handler).
|
InstanceBuilder |
newInstance(java.lang.String type)
Declares a new anonymous instance of a given type.
|
InstanceBuilder |
newInstance(java.lang.String type,
java.lang.String name)
Declares a new instance of a given type.
|
InstanceBuilder |
newInstance(java.lang.String type,
java.lang.String name,
java.lang.String version)
Declares a new instance of a given type.
|
DeclarationHandle |
newType(org.apache.felix.ipojo.metadata.Element description)
Declares a new type using the given element description.
|
InstanceBuilder newInstance(java.lang.String type)
newInstance(type, null).type - name of the component to be instantiated (cannot be null).InstanceDeclarationInstanceBuilder newInstance(java.lang.String type, java.lang.String name)
newInstance(type, name, null).type - name of the component to be instantiated.name - name of the new instance (can be null)InstanceDeclarationInstanceBuilder newInstance(java.lang.String type, java.lang.String name, java.lang.String version)
type - name of the component to be instantiated.name - name of the new instance (can be null)version - version of the expected type (can be null)InstanceDeclarationDeclarationHandle newExtension(java.lang.String name, FactoryBuilder builder)
name - name of the type to support (no namespace to be provided)builder - associated factory builderIPojoFactory,
ExtensionDeclarationDeclarationHandle newType(org.apache.felix.ipojo.metadata.Element description)
description - description of the component typeTypeDeclarationCopyright © 2006-2014 The Apache Software Foundation. All Rights Reserved.