Blueprint and injection
Blueprint is also used to wire together components of an application declaratively. The technique that is used is called injection, and it is used extensively throughout InfoSphere® MDM.
<service id="Component.Party"
interface="com.dwl.tcrm.coreParty.interfaces.IParty">
<bean class="com.dwl.tcrm.coreParty.component.TCRMPartyComponent" >
<property name="BObjQueryFactory">
<reference interface="...PartyModuleBObjQueryFactory"
availability="optional"/>
</property>
<property name="BObjPersistenceFactory">
<reference interface="...PartyModuleBObjPersistenceFactory"
availability="optional"/>
</property>
</bean>
</service>
<property name="BObjPersistenceFactory">
<reference interface="...PartyModuleBObjPersistenceFactory"
availability="optional"/>
</property>
In this a snippet, a property in a
blueprint file equates to a member variable in the TCRMPartyComponent
bean. The property name is BObjPersistenceFactory and if you look
in the TCRMPartyComponent class you’ll find these lines: 298 private PartyModuleBObjQueryFactory bObjQueryFactory = null;
299 private PartyModuleBObjPersistenceFactory bObjPersitenceFactory = null;
The name of the property in blueprint equates to the member variable
name in the bean. You’ll also find corresponding getter and setter
methods for those two variables. This property has a <reference>
to
an interface named "...PartyModuleBObjPersistenceFactory"
(the
full package name is omitted for brevity). Remember that services
are defined by their interface, and so this property has a reference
to a service.
<service id="PartyModule.BObjPersistenceFactory"
interface="...PartyModuleBObjPersistenceFactory">
<bean class="...query.PartyModuleBObjQueryFactoryImpl" />
</service>
This is where the service to which the previous
snipped referred is defined.When the bundle or bundles containing the previous blueprint definitions start, the OSGi Blueprint container will automatically inject the PartyModuleBObjPersistenceFactory service into the TCRMPartyComponent using the appropriate setter methods. You will not need to worry about where it came from. That’s injection.