Rule Execution Server API

ilog.rules.util.prefs
Class IlrPropertyManager

java.lang.Object
  extended by ilog.rules.util.prefs.IlrPropertyManager
Direct Known Subclasses:
IlrMessages, IlrPreferences

public abstract class IlrPropertyManager
extends Object

A manager of property files.

A IlrPropertyManager manages a hierarchy of IlrPropertyBundle. Each property bundle corresponds to a directory and a set of files under this directory. Each file is structured as a list of key=value couples. The name of the files is given by the pattern: <slashedPrefix>/<slashedFullname>/<baseClassname>_<suffix>.properties.

A property bundle loads the property files using the java.util.property.getBundle(String, Locale, ClassLoader) method in the order given by the double sorting criteria: suffixes order + prefix order. The content of each file is added to a common table. The properties of a file loaded later replace the same properties of a file loaded earlier.

For instance, if we set the prefixes and the suffixes of a property manager to {"ilog.rules", "appli", ""} and {"", "dev"} respectively, the loading of the b1.b2 preferences bundle will load the associated files in the following order:

ilog/rules/b1/b2/preferences.properties
appli/b1/b2/preferences.properties
b1/b2/preferences.properties
ilog/rules/b1/b2/preferences_dev.properties
appli/b1/b2/preferences_dev.properties
b1/b2/preferences_dev.properties

When there is more than one suffix, a file with the first suffix must be found before carrying on with the other suffixes.

Once loaded, the property bundle contains a set of key and their associated value. A property key is composed of a list of name separated by the "." character. To retrieve the value associated to a key, the property manager queries the property bundles starting from the root bundle and following the path given by the name list of the key. For instance, if the key is "b1.b2.key", the search will be:

The search stops as soon as the key is found. By default, the depth of the search is limited to the bundles of depth 2.

The modification of the property manager properties (prefixes, suffixes, class loader, locale, maximum search depth) will reset the property manager: the cache will be cleared and the property bundles will be reloaded on demand.


Constructor Summary
protected IlrPropertyManager()
          Sole constructor
 
Method Summary
 void addPrefix(String prefix)
          Add the specified prefix at the end of the prefix list.
 void addSuffix(String suffix)
          Add the specified suffix at the end of the prefix list.
 IlrPropertyBundle findPropertyBundle(String key)
          Return the property bundle that contains the key name.
 IlrPropertyBundle findPropertyBundle(String key, Locale locale)
          Return the property bundle that contains the key name.
protected abstract  String getBaseClassName()
          Returns the resource bundle base class name.
 ClassLoader getClassLoader()
          Returns the class loader used to load the java.util.ResourceBundle instances
 Locale getLocale()
          Returns the locale used to load the java.util.ResourceBundle instances
 int getMaximumDepth()
          Returns the maximum key search depth.
 String[] getPrefixes()
          Returns an array containing all the prefixes in their order of use.
 IlrPropertyBundle getPropertyBundle(String bundleName)
          Returns the property bundle named name.
 IlrPropertyBundle getPropertyBundle(String bundleName, Locale locale)
          Returns the property bundle named name.
 String[] getSuffixes()
          Returns an array containing all the suffixes in their order of use.
 String getValue(String key)
          Return the String associated to the key key or nullValue if the key is not found
 String getValue(String key, Locale locale)
          Return the String associated to the key key or nullValue if the key is not found
 String getValue(String key, String defaultValue)
          Return the String associated to the key key or defaultValue if the key is not found
 String getValue(String key, String defaultValue, Locale locale)
          Return the String associated to the key key or defaultValue if the key is not found
 void insertPrefixAt(String prefix, int index)
          Insert the specified prefix to the specified position.
 void insertSuffixAt(String suffix, int index)
          Insert the specified suffix to the specified position.
 void removePrefixAt(int index)
          Remove the prefix at the specified position in the prefix list.
 void removeSuffixAt(int index)
          Remove the suffix at the specified position in the suffix list.
 void setClassLoader(ClassLoader cl)
          Sets the class loader to load the java.util.ResourceBundle instances.
 void setLocale(Locale locale)
          Sets the locale to use to load the ResourceBundle.
 void setMaximumDepth(int maxDepth)
          Sets the maximum key search depth.
 void setPrefixes(String[] prefixes)
          Set the prefixes to use.
 void setSuffixes(String[] suffixes)
          Set the suffixes to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlrPropertyManager

protected IlrPropertyManager()
Sole constructor

Method Detail

getPrefixes

public String[] getPrefixes()
Returns an array containing all the prefixes in their order of use.

Returns:
An array containing all the prefixes in their order of use.

setPrefixes

public void setPrefixes(String[] prefixes)
Set the prefixes to use.

Parameters:
prefixes - An sorted array containing the prefixes to use.

insertPrefixAt

public void insertPrefixAt(String prefix,
                           int index)
Insert the specified prefix to the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
prefix - Prefix to be inserted.
index - Index at which the specified prefix is to be inserted.

addPrefix

public void addPrefix(String prefix)
Add the specified prefix at the end of the prefix list.

Parameters:
prefix - Prefix to be added.

removePrefixAt

public void removePrefixAt(int index)
Remove the prefix at the specified position in the prefix list.

Parameters:
index - The index of the prefix to be removed.

getSuffixes

public String[] getSuffixes()
Returns an array containing all the suffixes in their order of use.


setSuffixes

public void setSuffixes(String[] suffixes)
Set the suffixes to use.

Parameters:
suffixes - An sorted array containing the suffixes to use.

insertSuffixAt

public void insertSuffixAt(String suffix,
                           int index)
Insert the specified suffix to the specified position.

Parameters:
suffix - Suffix to be inserted.
index - Index at which the specified suffix is to be inserted.

addSuffix

public void addSuffix(String suffix)
Add the specified suffix at the end of the prefix list.

Parameters:
suffix - Suffix to be added.

removeSuffixAt

public void removeSuffixAt(int index)
Remove the suffix at the specified position in the suffix list.

Parameters:
index - The index of the suffix to be removed.

getMaximumDepth

public int getMaximumDepth()
Returns the maximum key search depth. The default value is 2.

Returns:
The maximum key search depth.

setMaximumDepth

public void setMaximumDepth(int maxDepth)
Sets the maximum key search depth.

Parameters:
maxDepth - The maximum depth to set.

getLocale

public Locale getLocale()
Returns the locale used to load the java.util.ResourceBundle instances


setLocale

public void setLocale(Locale locale)
Sets the locale to use to load the ResourceBundle.

Parameters:
locale - The new locale.

getBaseClassName

protected abstract String getBaseClassName()
Returns the resource bundle base class name.


getClassLoader

public ClassLoader getClassLoader()
Returns the class loader used to load the java.util.ResourceBundle instances


setClassLoader

public void setClassLoader(ClassLoader cl)
Sets the class loader to load the java.util.ResourceBundle instances.

Parameters:
cl - The new class loader.

getPropertyBundle

public IlrPropertyBundle getPropertyBundle(String bundleName)
Returns the property bundle named name.


getPropertyBundle

public IlrPropertyBundle getPropertyBundle(String bundleName,
                                           Locale locale)
Returns the property bundle named name.


findPropertyBundle

public IlrPropertyBundle findPropertyBundle(String key)
Return the property bundle that contains the key name.


findPropertyBundle

public IlrPropertyBundle findPropertyBundle(String key,
                                            Locale locale)
Return the property bundle that contains the key name.


getValue

public String getValue(String key,
                       String defaultValue)
Return the String associated to the key key or defaultValue if the key is not found


getValue

public String getValue(String key,
                       String defaultValue,
                       Locale locale)
Return the String associated to the key key or defaultValue if the key is not found


getValue

public String getValue(String key)
Return the String associated to the key key or nullValue if the key is not found


getValue

public String getValue(String key,
                       Locale locale)
Return the String associated to the key key or nullValue if the key is not found


Rule Execution Server API

© Copyright IBM Corp. 1987, 2013