Java Reference
In-Depth Information
Listing 3.8
The DesperateCheeseOffer class
public class DesperateCheeseOffer implements SpecialOffer {
private Inventory inventory;
Inventory gets
public void setInventory(Inventory inventory) {
this.inventory = inventory;
public String getDescription() {
return "A wonderful surprise for someone cheesy.";
public Food getOfferFood() {
List<Food> cheeses =
inventory.getFoodsWhoseNameContains("cheese", 1);
Food leastPopularCheese = cheeses.get(0);
return leastPopularCheese;
Food list already
sorted, so you can
take first food
Build a bundle containing the blueprint.xml and the DesperateCheeseOffer class (and
a manifest). When you drop this bundle into the load directory, you should find that the
front page of the Fancy Foods shop has gotten a lot more exciting (figure 3.10).
If you get the persistence wrong, you'll find that the cheese offer isn't listed. If the
dependencies of the DesperateCheeseOffer aren't available, Blueprint won't instanti-
ate the cheese offer and it won't publish a SpecialOffer service. Using the OSG i con-
sole's ss and bundle commands can usually help track down the weak link in the
dependency chain.
After you've fixed and rebuilt the misconfigured bundle, you'll find that things
kick into life without any restarts or manual interventions on your part. All that's
required is a refresh of the web page for the cheese offer to appear. (And if you stop
Figure 3.10 After the addition of the cheese department, datasource, and persistence bundles, the
Fancy Foods shop has a new special offer, driven from the cheese stock levels in the database.
Search WWH ::

Custom Search