Java Reference
In-Depth Information
Table 12.2
Blueprint manager value objects (continued)
Manager
Value
<reference>
A proxy object to the service registered in the OSGi service registry.
<reference-list>
A java.util.List containing proxies to the registered services or
ServiceReferences .
This capability makes it possible to define reasonably sophisticated constructions in
the component XML descriptions. Consider a contrived example in the following
XML snippet:
<bean class="com.acme.FooImpl">
<property name="services">
<map>
<entry key="bar">
<service interface="com.acme.Bar">
<bean class="com.acme.BarImpl"/>
</service>
</entry>
</map>
</property>
</bean>
In this example, you construct a Foo object into which you inject its services property
with a Map . For the map, you set the bar key to the ServiceRegistration object for a
service Bar . The Bar service is provided by an inlined bean, constructed from the
BarImpl class. The FooImpl class looks something like this:
public class FooImpl {
public void setServices(Map<String, ServiceRegistration> services) {
for (Map.Entry<String, ServiceRegistration> e : services.getEntrySet())
{
String key = e.getKey();
ServiceRegistration val = e.getValue();
System.out.println("Registered service " + key + "=" + val);
}
}
}
Here, the FooImpl class is injected with a property whose value is wholly constructed
from the Blueprint XML model. This is definitely a contrived example, but it shows
the flexibility of the Blueprint model.
SCOPES
As with manager values, Blueprint has inherited the concept of scope from Spring
Dynamic Modules. A scope can be applied to bean and service managers; it defines
the lifetime over which the specified manager is applicable. Blueprint defines two
scopes— singleton and prototype —but they imply subtly different behavior depending
on whether they're applied to a bean or a service manager, as shown in table 12.3.
 
Search WWH ::




Custom Search