Java Reference
In-Depth Information
Table 12.1
Blueprint component container managers (continued)
Manager
Description
Reference list
Gets one or more services from the OSGi service registry for the component based on
the service interface and an optional filter over the service properties
Service
Allows components to provide OSGi services
Environment
Provides components access to the OSGi framework and the Blueprint container,
including the bundle context of the component
Let's now look at a concrete example of Blueprint in action.
12.1.2
Providing services with Blueprint
In this section, we'll explore how to use the Blueprint specification to build the
example paint program. As with Declarative Services from the previous chapter, we'll
start by looking at the converted circle bundle. Again, this bundle no longer con-
tains a bundle activator class, but it does contain the circle.xml file shown in the fol-
lowing listing.
Listing 12.1 Blueprint component definition for the circle component
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="circle" class="org.foo.shape.circle.Circle" />
<service id="shape" interface="org.foo.shape.SimpleShape" ref="circle">
<service-properties>
<entry key="simple.shape.name" value="Circle"/>
<entry key="simple.shape.icon">
<bean class="org.foo.shape.circle.IconFactory"
factory-method="createIcon"/>
</entry>
</service-properties>
</service>
</blueprint>
Notice that Blueprint uses a different XML syntax than Declarative Services. If you're
familiar with Spring, some of this XML should look a little familiar. For example, Blue-
print uses the <bean> element to describe components, which you use here to define
the circle component. You also use it again to specify a value for a service property.
Spring users should also be familiar with the <entry> element, which is used by
Spring and Blueprint to define the entries of map objects. You use <entry> in this
case to define the service properties for your service interface. Some less familiar
aspects are as follows:
The top-level <blueprint> element (with a new namespace) as compared to
the classic <beans> element from Spring
The <service> element, which you use to publish the bean associated with the
ref identifier circle into the OSG i service registry with the declared set of
nested service properties
 
Search WWH ::




Custom Search