Java Reference
In-Depth Information
package fancyfoods.offers;
import java.util.List;
public interface CurrentOffers {
public List<SpecialOffer> getCurrentOffers();
}
Next, we'll need a new bundle, with another blueprint.xml file. We'll call this bundle
fancyfoods.business and its manifest will need to look something like the following
listing.
Listing 2.9
The manifest of the fancyfoods.business bundle
Manifest-Version: 1.0
Bundle-Name: Fancy Foods Business Logic
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-SymbolicName: fancyfoods.business
Bundle-Version: 1.0.0
Bundle-ManifestVersion: 2
Import-Package: fancyfoods.food;version="[1.0, 2.0)",
fancyfoods.offers;version="[1.0, 2.0)"
Like the chocolate department bundle, our bundle will use Blueprint to publish a ser-
vice. In this case, the bean we're exposing as a service also has dependencies injected
into it.
Listing 2.10
Using Blueprint to inject dependencies
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<service
interface="fancyfoods.offers.CurrentOffers"
ref="offerAggregator" />
<bean
id="offerAggregator"
class="fancyfoods.offers.impl.OfferAggregator">
<property
name="offers"
ref="specialOffers" />
</bean>
<reference-list
id="specialOffers"
interface="fancyfoods.offers.SpecialOffer" />
</blueprint>
The implementation of the OfferAggregator doesn't need to instantiate the special
offers it's going to be aggregating—the container injects them. A null check isn't
needed, either, because the container won't instantiate the class unless its dependen-
cies are available.
Expose
service
Inject property
to setOffers()
method
Pass in all SpecialOffers
to setOffers()
 
Search WWH ::




Custom Search