The offer aggregator still has to know what adjustments to make, because the list of
adjuster classes is hardcoded. We hope at least some of you have just had a lightbulb
moment and realized that it's not just the list of special offers that could be injected by
Blueprint—the list of adjustments could also be injected. This would make the get-
CurrentOffers() method wonderfully short and generic.
How much should you use Blueprint and OSG i services? With a bit of determination,
it's probably possible to code an entire application without ever constructing one class
from another. This doesn't mean it's a good idea! Despite Blueprint's elegance, getting
an instance of an interface via Blueprint is a bit more work than just constructing the
darn thing. In many cases, the decoupling offered by Blueprint clearly justifies having
to write one or two lines of XML , but for some parts of your application, the transpar-
ency and concision of close coupling is fine. We'll discuss architectural patterns for
Blueprint and alternate dependency injection frameworks more in chapter 6.
In the case of Fancy Foods, using Blueprint to publish special offers feels right.
The list of special offers will be changing regularly, so hardcoding them isn't a good
idea. Each department will know what's best to offer when—pink chocolates at Valen-
tine's Day, cheese when it's approaching its sell-by date. The logic for aggregating the
offers, on the other hand, will probably always be centrally managed. You wouldn't
want a chocolate maniac in the chocolate department to be able to publish a rule that
always put chocolate offers first in the pile of promotions! Bearing this in mind, even
though you could rewrite the offer aggregator to be even more service-oriented, it's
probably not worth it—listing 2.11 is good as it is.
Blueprint beans can be wired together to get some pretty complex behavior. Blue-
print isn't a substitute for good, old-fashioned Java code, but it sometimes can make it
an awful lot shorter!
Spring and Blueprint
If you think this looks a lot like Spring Dynamic Modules, you're right. Blueprint is
based on Spring DM. Blueprint does have some areas of technical difference from
Spring DM, but the most significant difference is that Blueprint is an open standard.
We'll be coming back to Blueprint and some of its more advanced features in chap-
ter 6. For now, we'll show you how to get the web frontend talking to the current
Bridging JNDI and OSGi
The final piece is to hook these special offers up to the servlet. There's a snag,
though—most web container implementations aren't fully integrated with Blueprint
(and at the moment, there's nothing in the specification that says they should be).
The problem is that the Blueprint container takes a lot of control over the lifecycle of
Blueprint beans—it identifies when the services they require are present, instantiates
Search WWH ::