Skip Navigation

Using ConfigService and Configuring Properties

Before you begin, you need a plug-in project.

  1. Open the Dependencies tab in your plug-in project, and add the following plug-in dependencies:

    • com.sabre.edge.platform.core.common

    • org.eclipse.ui

    • org.eclipse.core.runtime

Putting the Specific Properties of a Plug-in into ConfigService

  1. Either create a new configuration properties file with the .properties extension, or use the existing plugin.properties file in your plug-in. In the file, add the configuration properties that are specific to this plug-in.

image051
  1. Type the properties in the form of key=value pairs to retrieve and wrap the values as the following types. (See the next table.)

Value Types of Configuration Properties for ConfigService

Value Type Syntax Example

String

keyString=some string
Example of an entry in the file:
url=www.somepage.com
This entry replaces keyString=string value.
Rule for adding a suffix:
KEY.SUFFIX=VALUE
Supported suffixes
Example that uses a suffix:
Include the following keys in your properties file:
url.cert=www.cert.sabre.com
url.prod=www.sabre.com
When you try to retrieve a key 'url', ConfigService returns www.cert.sabre.com when the CERT environment is used, and the service returns www.sabre.com for the PROD environment.

Boolean

keyBoolean=true

Long

keyLong=1000000

Map <String, String>

keyMap=map_key1,map_value1,map_key2,map_value2

  1. On the Build tab, add your configuration properties file to the binary build.

image053

 

  1. Open the Extensions tab. Click Add, and then add the com.sabre.edge.platform.core.config.properties extension point. (See the next figure.) Right-click the extension point, and choose New > contributor.

image055

  Only the file property is required for this extension point. In the file field, you are required to point to your configuration properties file.

Getting Specific Properties in a Plug-in from ConfigService

  1. Add or update the Activator class in your plug-in. To add or update this class, extend com.sabre.edge.platform.core.common.plugin.base.AbstractEdgeBasePlugin.

  2. Obtain a reference to the ConfigService service.

        Inside the Activator class, add the following code:

IBaseConfigService config = getConfigService();

        Outside of the Activator class, add the following code:

IBaseConfigService config = Activator.getDefault().getConfigService();

  1. The next table shows the methods that obtain the configuration properties in a plug-in. Use the method that corresponds to your property value type.

    • In the syntax example, replace key* with your key name.

    • Replace your.bundle.symbolic.name with your bundle symbolic name.

You can find the bundle symbolic name in MANIFEST.MF.

        Example in MANIFEST.MF:

Bundle-SymbolicName: your.bundle.symbolic.name

Methods for Obtaining Configuration Properties in a Plug-in

Property Value Type Syntax Example

String

String s = config.getLocalProperty("keyString", "your.bundle.symbolic.name");

Boolean

Boolean b = config.getLocalPropertyAsBoolean("keyBoolean", "your.bundle.symbolic.name");

Long

Long l = config.getLocalPropertyAsLong("keyLong", "your.bundle.symbolic.name");

Map <String, String>

Map <String, String> map = config.getLocalPropertyAsMap("keyMap", "your.bundle.symbolic.name");

Note
When you use return-object type methods, as in getLocalPropertyAs (String, String)* , be careful to match the type of the property value with the type of the object that the method returns. If you do not match these types correctly, an exception will be returned at runtime.

Note that getLocalProperty(String, String) ignores the property value type and returns a string value.