Java Reference
In-Depth Information
Listing 13.6 Standalone paint program main() method
public class Main {
private static Framework fwk;
private static PaintFrame frame = null;
private static ShapeTracker shapeTracker = null;
public static void main(String[] args) throws Exception {
addShutdownHook();
fwk = createFramework();
publishTrapezoidService();
createPaintFrame();
}
...
The performed functionality is a combination of the generic launcher and the old
bundle activator: adding a shutdown hook, creating a framework instance, and creat-
ing a paint frame. The only new task is publishing an external trapezoid shape service,
which you'll see is pretty much the same as publishing a normal service.
Let's continue to look into the details. Because adding a shutdown hook is basi-
cally identical to what you did for the generic launcher, we'll skip that step and go
directly to creating the framework instance.
CONFIGURING AND CREATING THE FRAMEWORK
The createFramework() method follows fairly closely to the launcher, so we'll go over
the details quickly. The method starts, like the launcher, with discovering which bun-
dles it should install into the framework instance:
...
private static Framework createFramework() throws Exception {
File[] files = new File("bundles").listFiles();
Arrays.sort(files);
List jars = new ArrayList();
for (int i = 0; i < files.length; i++)
if (files[i].getName().toLowerCase().endsWith(".jar"))
jars.add(files[i]);
...
Here you get the contents of the bundles directory in the current directory and add
all contained JAR files to a list. This is rather simplistic, but it's sufficient for this exam-
ple. Now you can create the framework instance and deploy the discovered bundles.
The following listing shows these steps.
Listing 13.7 Creating the framework instance and deploying discovered bundles
...
try {
List bundleList = new ArrayList();
Map m = new HashMap();
m.putAll(System.getProperties());
m.put(Constants.FRAMEWORK_STORAGE_CLEAN,
Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
m.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"org.foo.shape; version=\"4.0.0\"");
B Includes shape API
in system bundle
exports
Search WWH ::




Custom Search