Java Reference
In-Depth Information
Shape
API
Paint
Triangle
Square
Circle
Figure 2.14 Logical structure of the paint program with separate modules for each
shape implementation
The paint program implementation bundle depends on Swing, the public API bundle,
and all three shape bundles. Figure 2.14 depicts the new structure of the paint program.
Now you have five bundles (shape API , circle, square, triangle, and paint). Great.
But what do you do with these bundles? The initial version of the paint program had a
static main() method on PaintFrame to launch it; do you still use it to launch the pro-
gram? You could use it by putting all the bundle JAR files on the class path, because all
the example bundles can function as standard JAR files, but this would defeat the pur-
pose of modularizing the application. There'd be no enforcement of modular bound-
aries or consistency checking. To get these benefits, you must launch the paint
program using the OSG i framework. Let's look at what you need to do.
2.6.2
Launching the new paint program
The focus of this chapter is on using the module layer, but you can't launch the appli-
cation without a little help from the lifecycle layer. Instead of putting the cart before
the horse and talking about the lifecycle layer now, we created a generic OSG i bundle
launcher to launch the paint program for you. This launcher is simple: you execute it
from the command line and specify a path to a directory containing bundles; it cre-
ates an OSG i framework and deploys all bundles in the specified directory. The cool
part is that this generic launcher hides all the details and OSG i-specific API from you.
We'll discuss the launcher in detail in chapter 13.
Just deploying the paint bundles into an OSG i framework isn't sufficient to start
the paint program; you still need some way to kick-start it. You can reuse the paint pro-
gram's original static main() method to launch the new modular version. To get this
to work with the bundle launcher, you need to add the following metadata from the
original paint program to the paint program bundle manifest:
Main-Class: org.foo.paint.PaintFrame
As in the original paint program, this is standard JAR file metadata for specifying the
class containing the application's static main() method. Note that this feature isn't
Search WWH ::




Custom Search