Java Reference
In-Depth Information
return (FrameworkFactory) Class.forName(s).newInstance();
}
}
} finally {
if (br != null) br.close();
}
}
throw new Exception("Could not find framework factory.");
}
The getFrameworkFactory() method in listing 13.2 isn't as robust as it could be, but
it's sufficient to get the job done. It queries for the standard service-provider configu-
ration file B . If it finds one, it reads the content of the file. Within the loop, it
searches for the first line not starting with # (the comment character) and assumes
that the line contains the name of the concrete class it should instantiate at C . The
method throws an exception if an error occurs during this process or if a factory pro-
vider couldn't be found.
This method is fairly simple and will work for all R4.2-compliant frameworks; you'll
use it for the generic launcher in section 13.2. Next, we'll look into how you use the
factory service to configure a framework instance.
Instantiates
provider class C
13.1.3
Configuring a framework
When you have a framework factory service, you can create an instance of Framework .
Typically, you don't use a default framework instance; instead, you often want to con-
figure it in some way, such as setting the directory where the framework should store
cached bundles. This is why FrameworkFactory.newInstance() takes a Map , so you
can pass in configuration properties for the created framework instance.
No configuration required
You don't have to pass in configuration properties when creating a framework; null
is an acceptable configuration. The OSGi specification says framework implementa-
tions must use reasonable defaults, but it doesn't explicitly define all of them. This
means some defaults are implementation-specific. For example, by default the
Apache Felix framework caches installed bundles in a felix-cache/ directory in the cur-
rent directory, whereas the Equinox framework uses configuration/org.eclipse.osgi/
bundles/ in the directory where the Equinox JAR file is located. Be aware that you
won't necessarily get the same behavior unless you explicitly configure it.
Prior OSG i specifications defined a few standard configuration properties; but until
the framework factory API , there was no standard way to set them. As part of the R4.2
specification process, several new standard configuration properties were also intro-
duced. Table 13.1 shows some of the standard configuration properties.
The properties listed in table 13.1 can be put into a Map and passed into the Frame-
workFactory.newInstance() method to configure the resulting framework instance;
 
Search WWH ::




Custom Search