Java Reference
In-Depth Information
}
public void createShape(String name) {
ComponentFactory factory = factoryRef.get();
if ( factory == null )
throw new IllegalStateException("No factory registered");
Hashtable config = new Hashtable();
config.set("name", name);
factory.newInstance(config);
}
}
The component factory is registered with the ShapeManager component using callback
methods B . You use the factory.newInstance() method to instruct the Declarative
Services runtime to build another instance of a shape with the specified name C , which
will then be registered in the OSG i registry as before.
C
Builds shape
instance
Component factories vs. Configuration Admin Service factories
The component factory provides an alternative mechanism to the Configuration Ad-
min managed service factory approach mentioned earlier. Which approach you take
is largely a matter of preference. Note that the component factory approach and the
managed service factory approach are mutually exclusive: it's not possible to create
a component factory that is instantiated by a factory PID.
This concludes our introduction to component models in OSG i and review of the Declar-
ative Services specification. If you want a closer look at the Declarative Services version
of the paint program, go to the chapter11/paint-example-ds/ directory of the compan-
ion code. Type ant to build the example and java -jar launcher.jar bundles to run
it. The example uses the Apache Felix Service Component Runtime (SCR; http://
felix.apache.org/site/apache-felix-service-component-runtime.html ) implementation
of Declarative Services.
11.4
Summary
In this chapter, we reviewed the general principles and motivation of component-
oriented programming and looked at how components and modules intersect and
interact in an OSG i context. The topics we discussed included the following:
Components are application building blocks that adhere to a component
model.
Components further support separation of concerns by separating interface
from implementation.
Components support external management of concerns, allowing you to
offload mundane and potentially error-prone tasks to component frameworks.
The OSG i framework is a component framework, where bundles are equivalent
to components that interact via services.
Search WWH ::




Custom Search