Java Reference
In-Depth Information
public class Activator implements BundleContext {
...
private int getPort(BundleContext context) {
String port = context.getProperty("org.foo.shell.port");
if (port != null) {
return Integer.parseInt(port);
}
return 7070;
}
properties B
Retrieves
private int getMaxConnections(BundleContext context) {
String max = context.getProperty("org.foo.shell.connection.max");
if (max != null) {
return Integer.parseInt(max);
}
return 1;
}
}
This listing continues the activator implementation from listing 3.1; in the activator,
you use these two methods to get configuration properties. Here, the methods use the
BundleContext.getProperty() method to retrieve the properties B . This method
looks in the framework properties to find the value of the specified property. If it can't
find the property, it searches the system properties, returning null if the property
isn't found. For the shell, you return default values if no configured value is found.
The OSG i specification also defines some standard framework properties, shown in
table 3.1. If you need to use these standard properties, you can use the constants for
them defined in the org.osgi.framework.Constants class.
Table 3.1
Standard OSGi framework properties
Property name
Description
org.osgi.framework.version
OSGi framework version
org.osgi.framework.vendor
Framework implementation vendor
org.osgi.framework.language
Language being used; see ISO 639 for possible values
org.osgi.framework.os.name
Host computer operating system
org.osgi.framework.os.version
Host computer operating system version number
org.osgi.framework.processor
Host computer processor name
There you have it: your first real interaction with the OSG i framework. This is only a
small part of the API that you can use in your bundles, but we'll cover a lot of ground
in the next section, so don't worry. And those of you thinking, “Hey, this configuration
mechanism seems overly simplistic!” are correct. There are other, more sophisticated
ways to configure your bundle, but we won't discuss them until chapter 9. Bundle prop-
erties are the simplest mechanism available and should only be used for properties that
Search WWH ::




Custom Search