Bundles, just like any Java code, can add properties to the
System properties. While it is always possible to define
System properties when the Java VM is started using the Java
VM argument -D, this is not convenient for bundles that are
loaded and unloaded without restarting the Java VM.
Another approach is for a bundle to add its properties to the
System properties when it starts, and to remove its
properties from the System properties when it stops. The
BaseBundleActivator class provides support for exactly this.
BaseBundleActivator implements the hook method
getPropertiesInputStream() that should be overridden by a
bundle that wishes to load properties into the System
properties. The method getPropertiesInputStream() returns
an InputStream on the properties that should be loaded into
the System properties.
BaseBundleActivator class provides the following query
methods for getting an InputStream on a properties file.
InputStream getFilePropertiesInputStream() throws IOException
InputStream getFilePropertiesInputStream(String) throws IOException
InputStream getResourcePropertiesInputStream() throws IOException
InputStream getResourcePropertiesInputStream(String) throws IOException
getFilePropertiesInputStream() returns an
InputStream on a properties file that resides in the Java
VM's current directory and has a filename that matches the bundle's
Bundle-SymbolicName. For example, if the bundle's
Bundle-SymbolicName is com.ibm.navigation,
this method will return an InputStream on the properties
file com.ibm.navigation.properties.
getFilePropertiesInputStream(String) returns an
InputStream on a properties file that resides in the Java
VM's current directory with a name that matches the specified name.
getResourcePropertiesInputStream() returns an
InputStream on a properties file that resides as a Java
resource in the package containing the bundle's activator. Just like
the file system equivalent, this method searches for a Java resource
with a filename that matches the bundle's
Bundle-SymbolicName.
getResourcePropertiesInputStream(String) returns
an InputStream on a properties file that resides as a Java
resource in the package containing the bundle's activator. Just like
the file system equivalent, this method searches for a Java resource
with a name that matches the specified name.
protected InputStream getPropertiesInputStream() throws IOException {
return getResourcePropertiesInputStream(); // Navigation.properties
}
protected InputStream getPropertiesInputStream() throws IOException {
return getResourcePropertiesInputStream("nav.properties");
}
Copyright © 2001, 2007 IBM Corporation and others. All Rights Reserved.