Java Reference
In-Depth Information
You'll also reuse the trick for populating the database, as follows.
Listing 10.2
Populating the foreign food database
public class InventoryPopulater {
private Inventory inventory;
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
public void populate() {
boolean isInventoryPopulated = (inventory.getFoodCount() > 0);
if (!isInventoryPopulated) {
inventory.createFood("Foreign Sushi", 3.45, 10);
inventory.createFood("Foreign Borscht", 1.81, 15);
}
}
}
Once again, you can use Blueprint to glue everything together, as shown in the follow-
ing listing.
Listing 10.3
Exposing your remote service
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<service interface="fancyfoods.offers.SpecialOffer">
Mark your service
remotable
<service-properties>
<entry key="service.exported.interfaces"
value="fancyfoods.offers.SpecialOffer"/>
</service-properties>
<bean class="fancyfoods.department.foreign.ForeignFoodOffer">
<property name="inventory" ref="inventory"/>
</bean>
</service>
<reference id="inventory" interface="fancyfoods.food.Inventory"/>
<bean class="fancyfoods.department.foreign.InventoryPopul ate r"
activation="eager" init-method="populate">
<property name="inventory" ref="inventory"/>
</bean>
</blueprint>
Having built your bundle, you can deploy it into your test environment along with the
API , datasource, and persistence bundles. You can also see your remote service regis-
tered in the Service Registry (see figure 10.9).
Eagerly populate
database
 
Search WWH ::




Custom Search