The Preferences Bundle provides the OSGi Preferences Service which stores and provides access to the preferences properties of bundles.
The JAR file of the Preferences Bundle is prefs.jar, and is located in the bundles folder.
The Preferences Bundle imports the following packages:
|
com.prosyst.mbs.services.prefs - Contains components intended for internal use only.
Preferences Bundle registers the OSGi Preferences Service, represented by interface
org.osgi.service.prefs.PreferencesService. The Preferences Bundle stores its preferences in a custom database in the DB Bundle, called "prefs_owndb".
The features of the OSGi Preferences Service are discussed in details in the OSGi Preferences Service Specification.
The figure below illustrates the usage model of the Preferences Service.
The code example below represents a simple bundle, that uses both interfaces,
PreferencesService and Preferences. A tree
like the shown above is created. The root, represents a node with the system
preferences. There are two more nodes. Each of the nodes represents the preferences
for a specified user. (For the example the users correspond to user1 and user2).
The put(String, String) method associates the specified
value with the specified key in this preference node. The string "FirstUser"
is the specified value for the user1. The get(String, String)method
returns the value associated with the specified key in this preference node.
By using getUsers() method, all the users could
be seen, as this method returns their names as strings.
package test.prefs; |
Make sure that DB Bundle is activated, before the installation the Preferences
Bundle. Otherwise, a
will be thrown. BackingStoreException
The Preferences Bundle has the following system properties:
|
To apply these properties, you should specify them in the default.prs file before framework startup. At runtime, you can use the set console command or the mConsole before the Preferences Bundle is started - otherwise, you have to restart the bundle to save the changes. For more information about using system properties, refer to the "System Properties" document from "Getting Started".