Java Reference
In-Depth Information
The final lifecycle-related issue we'll discuss is how Blueprint components gain
access to the underlying OSG i execution environment.
ENVIRONMENT MANAGER
As you've seen so far, the Blueprint specification uses managers to control various
aspects (such as services, references, and beans) of a component. Each manager
defines and controls the specific lifecycle characteristics of its associated aspect. The
same pattern is applied to entities outside of the component; these are called environ-
ment managers . In this case, environment managers are effectively property-value mac-
ros. They come in four types:
blueprintContainer —Provides access to the Blueprint container object and
allows various forms of component introspection
blueprintBundle —Provides access to the Blueprint bundle's Bundle object
blueprintBundleContext —Provides access to the Blueprint bundle's Bundle-
Context object
blueprintConverter —Provides access to an object implementing the Con-
verter interface, which we'll discuss shortly
Let's look at how you use the blueprintBundleContext manager in the paint applica-
tion to access the BundleContext . The WindowListener needs the bundle context so it
can retrieve the system bundle to shut down the OSG i framework when the paint
frame is closed. In the following snippet's WindowListener component XML descrip-
tion, you use the environment manager to inject the bundle context into the Window-
Listener class as a property:
<bean id="listener" class="org.foo.windowlistener.WindowListener">
<property name="bundleContext" ref="blueprintBundleContext" />
</bean>
This follows the same pattern as the reference-injection mechanism of accessing ser-
vice references. The implementation code in the WindowListener class looks like this:
private BundleContext m_context;
...
public void setBundleContext(BundleContext context) {
m_context = context;
}
The bundle context ends up being injected using an ordinary setter method.
With this, we'll conclude the discussion of the Blueprint version of the paint pro-
gram. To see it in action, go to the chapter12/paint-example-bp/ directory of the topic's
companion code. Type ant to build the example and java -jar launcher.jar bundles/
to run it. This example uses the Apache Aries ( http://incubator.apache.org/aries/ )
implementation of the Blueprint specification.
In the final section on Blueprint, we'll look at some other advanced features it
provides.
 
Search WWH ::




Custom Search