Java Reference
In-Depth Information
Let's dig a little deeper into the details of precisely how you provide services using
Blueprint.
BLUEPRINT SERVICE ATTRIBUTES
At a glance, there appear to be only syntactic differences between the Declarative Ser-
vices version of this component and the Blueprint one. There's one big functional dif-
ference: the ability to define complex attribute objects. Blueprint introduces a factory
bean concept, which you use in the example to create an ImageIcon service property.
The code required to implement the factory bean is
public class IconFactory {
public static ImageIcon createIcon() {
return new ImageIcon(IconFactory.class.getResource("circle.png"));
}
}
This factory bean allows you to provide a class to perform the nontrivial actions
required to create an ImageIcon from the XML model. The factory-bean pattern also
lets Blueprint create objects with nontrivial constructors and use them in the compo-
nent as services, parameters, or service properties.
SERVICE INTERFACES
To p r o v i d e t h e c i r c l e 's SimpleShape service, you directly specify the interface name as
an attribute of the <service> element. Blueprint supports a couple of other options
for supplying the service interface: the <interfaces> element and the auto-export
attribute. To demonstrate, consider the following trivial XML bean definition:
<bean id="fooImpl" class="FooImpl"/>
This corresponds to a class definition like this:
public class FooImpl implements Foo { ... }
Given this bean and class definition, you can describe the component's provided Foo
service in any of the following equivalent ways:
<service id="foo" ref="fooImpl">
<interfaces>
<value>com.acme.Foo</value>
</interface>
</service>
<service id="foo" interface="com.acme.Foo" ref="fooImpl"/>
<service id="foo" auto-export="interfaces" ref="fooImpl"/>
The first is the longhand form of a service definition, which allows a Blueprint compo-
nent to export more than one interface for a given bean. The second is the shorthand
form for explicitly exporting a single service interface. The last is an automatic form,
where the service manager reflectively calculates the interfaces under which the bean
should be registered. For this last form, you must specify one of the following auto-
export attribute values:
Search WWH ::




Custom Search