Edit the Application-ImportService
header in the OSGi
application manifest so that it identifies one or more service interfaces
to be imported. The following example header specifies
that the example.Greeting service interface be imported:
Application-ImportService: example.Greeting
A
Blueprint reference explicitly requests an imported service by filtering
for the service.imported property. Remote services
use pass-by-value semantics instead of pass-by-reference semantics
for local services within the application. The following example shows
a Blueprint component with such a reference:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="helloWorldComponent" class="example.HelloWorldImpl"
<property name="greetingList" ref="greetingRef"/>
</bean>
<service id="helloWorld" ref="helloWorldComponent"
interface="example.HelloWorld">
<service-properties>
<entry key="service.exported.interfaces" value="*"/>
</service-properties>
</service>
<reference-list id="greetingRef" interface="example.Greeting"
filter="(&(service.imported=*))"/>
</blueprint>
Configure
an SCA reference that corresponds to each
imported service in the component. Use the fully qualified
interface name for the SCA reference name.
For
example, add the example.Greeting reference that
is shown in the Blueprint component from step 3 to the SCA composite
definition from step 2:
<?xml version="1.0" encoding="UTF-8"?>
<composite
xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:scafp="http://www.ibm.com/xmlns/prod/websphere/sca/1.0/2007/06"
targetNamespace="http://www.example.com"
name="HelloWorldComposite">
<component name="HelloWorldComponent">
<scafp:implementation.osgiapp
applicationSymbolicName="helloworldApp"
applicationVersion="1.0.0"/>
<service name="helloWorld">
<binding.sca>
</service>
<reference name="example.Greeting">
<binding.sca uri=”MyGreetingComponent”>
</reference>
</component>
</composite>
The example uses binding.sca for
the reference binding. The reference can use one or more of the other
bindings that SCA supports.
An SCA reference for an implementation.osgiapp component
implicitly has 0-to-many for the multiplicity attribute (multiplicity='0..n').
This means you can wire the reference to 0, 1, or multiple services
depending upon the requirements of the application. As to the multiplicity
attribute:
- A blueprint reference-list element
selects multiple
services. The blueprint implementation cannot make any assumptions
about the order of the services in the reference list compared to
the order of bindings in the composite definition.
- A blueprint reference element
selects a single
service. If the SCA reference provides more than one binding, the
selection of which binding is used is unspecified. If the SCA reference
does not provide any bindings, the dependency is unsatisfied. If
the reference is mandatory, the bean might not start.
You
can override the multiplicity attribute on the SCA reference,
setting 1-to-many ('1..n') or 1-to-1 ('1..1'),
to ensure that a particular number of bindings is specified.