Rule Execution Server API

ilog.rules.util.resources
Class IlrResources

java.lang.Object
  extended by ilog.rules.util.resources.IlrResources
All Implemented Interfaces:
Serializable

public final class IlrResources
extends Object
implements Serializable

This class manages a resource bundle used for configuring the engine.

A resource bundle is a list of properties with associated values. During creation, the user can specify the initial resources to load into the bundle. Later on, the user can call one of the methods for loading more resources. Each time a resource stream is loaded, a symbolic name is appended to a list. This provides a mean for identifying the resource streams which have been loaded and to avoid loading a same stream several times. Moreover, the class may be set a ClassLoader to be used for finding the resource files. See the User's Manual for more details.

Since:
4.0
See Also:
Serialized Form

Constructor Summary
IlrResources()
          Constructs a resource bundle with no arguments.
IlrResources(boolean init)
          Constructs a resource bundle with a boolean argument.
IlrResources(IlrResources initial)
          Constructs a resource bundle using another resource bundle.
IlrResources(Reader reader)
          Constructs a resource bundle and initializes its content using a reader.
 
Method Summary
 void clear()
          Clears the properties and their associated values in this resource bundle.
 void clearToDefaults()
          Clears all the properties and their associated values, and then loads the engine's default settings from the file /ilog/rules/engine/engine.conf provided in the IBM Decision server engine Jar files.
 boolean containsKey(String key)
          Tests whether a particular string is a key of the property map.
 boolean containsName(String name)
          Tests if a stream of some name has already been loaded.
 Set entrySet()
          Returns a set view of the hash table used to manage the associations between property names and their values.
 boolean forClass(Class cl)
          Loads a resource stream using a class.
 boolean forObject(Object obj)
          Loads a resource stream using an object.
 boolean forPackage(String pkg)
          Loads a resource stream using a package name.
 Object get(String key, Object def)
          Gets the property value associated to a key and returns a default value is the key does not exist.
 Object[] getArray(String key, Object[] def)
          Gets the property value associated to a key as an array of objects and returns a default value is the key does not exist.
 boolean getBoolean(String key, boolean def)
          Gets the property value associated to a key as a boolean value and returns a default value is the key does not exist.
 boolean[] getBooleanArray(String key, boolean[] def)
          Gets the property value associated to a key as an array of booleans and returns a default value is the key does not exist.
 char getChar(String key, char def)
          Gets the property value associated to a key as a char and returns a default value is the key does not exist.
 char[] getCharArray(String key, char[] def)
          Gets the property value associated to a key as a char array and returns a default value is the key does not exist.
 ClassLoader getClassLoader()
          Gets the class loader previously set.
 double getDouble(String key, double def)
          Gets the property value associated to a key as a double and returns a default value is the key does not exist.
 double[] getDoubleArray(String key, double[] def)
          Gets the property value associated to a key as a double array and returns a default value is the key does not exist.
 float getFloat(String key, float def)
          Gets the property value associated to a key as a float and returns a default value is the key does not exist.
 float[] getFloatArray(String key, float[] def)
          Gets the property value associated to a key as a float array and returns a default value is the key does not exist.
 int getInt(String key, int def)
          Gets the property value associated to a key as an int and returns a default value is the key does not exist.
 int[] getIntArray(String key, int[] def)
          Gets the property value associated to a key as an int array and returns a default value is the key does not exist.
 long getLong(String key, long def)
          Gets the property value associated to a key as a long and returns a default value is the key does not exist.
 long[] getLongArray(String key, long[] def)
          Gets the property value associated to a key as a long array and returns a default value is the key does not exist.
 String getName()
          Gets the resource name which has been appended the most lately, i.e.
 String[] getNames()
          Gets the names of the resource streams that have been loaded.
 String getString(String key, String def)
          Gets the property value associated to a key as a string and returns a default value is the key does not exist.
 String[] getStringArray(String key, String[] def)
          Gets the property value associated to a key as an array of strings and returns a default value is the key does not exist.
 boolean load(InputStream str)
          Loads a resource stream using an InputStream.
 boolean load(Reader reader)
          Loads a resource stream using a reader.
 boolean load(String filename)
          Loads a resource stream using a file name.
 void put(String key, Object value)
          Adds or rebinds the value associated to a property name.
 void putAll(IlrResources resources)
          Puts all the properties and values stored in the argument resource bundle into the current bundle.
 void putBoolean(String key, boolean value)
          Adds or rebinds a boolean value associated to a property name.
 void putChar(String key, char value)
          Adds or rebinds a char value associated to a property name.
 void putDouble(String key, double value)
          Adds or rebinds a double value associated to a property name.
 void putFloat(String key, float value)
          Adds or rebinds a float value associated to a property name.
 void putInt(String key, int value)
          Adds or rebinds a int value associated to a property name.
 void putLong(String key, long value)
          Adds or rebinds a long value associated to a property name.
 void putString(String key, String value)
          Adds or rebinds a string value associated to a property name.
 Object remove(String key)
          Removes an entry using its key if it exists.
 void setClassLoader(ClassLoader cl)
          Sets a class loader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlrResources

public IlrResources()
Constructs a resource bundle with no arguments. This method calls the other constructor with a boolean argument set to true in order to load the initial default resources.


IlrResources

public IlrResources(boolean init)
Constructs a resource bundle with a boolean argument. If the argument is false, the resource bundle is left empty.

If it is true, then the resource file /ilog/rules/engine/engine.conf provided in the IBM Decision Server engine Jar files is loaded. Following this, one of the following files is loaded:

The later operation is subject to the existence of the file and to the permission of the security manager. If the file does not exist, or the file can not be read, or permission is not granted for reading that file, the loading will simply be ignored.


IlrResources

public IlrResources(Reader reader)
Constructs a resource bundle and initializes its content using a reader. This constructor provides a way for reading resource files using another character set encoding than the default one of the system.

Parameters:
reader - A reader to load.

IlrResources

public IlrResources(IlrResources initial)
Constructs a resource bundle using another resource bundle. This resource bundle will be filled of the properties and values of the resource bundle passed as argument.

Method Detail

getClassLoader

public ClassLoader getClassLoader()
Gets the class loader previously set. There is no class loader set initially, thus the resource files are searched using the class loader which has loaded this class.

Returns:
A class loader, or null if no class loader has been set.

setClassLoader

public void setClassLoader(ClassLoader cl)
Sets a class loader. This method simply keeps the argument for further use for finding the resources.

Parameters:
cl - A class loader.

clear

public void clear()
Clears the properties and their associated values in this resource bundle. After this call, the resource bundle will contain no properties.


clearToDefaults

public void clearToDefaults()
Clears all the properties and their associated values, and then loads the engine's default settings from the file /ilog/rules/engine/engine.conf provided in the IBM Decision server engine Jar files. After this call, the resource bundle will contain only the IBM Decision server default settings.


putAll

public void putAll(IlrResources resources)
Puts all the properties and values stored in the argument resource bundle into the current bundle. For each of the entries found in the argument resource bundle, if the entry already exists in the current bundle, its value is rebound to the value of the entry in the passed bundle. Otherwise, the entry is added to the current bundle.

Parameters:
resources - A resource bundle from which the properties and values are copied.

entrySet

public Set entrySet()
Returns a set view of the hash table used to manage the associations between property names and their values. Each element in this set is a Map.Entry. For more details, refer to the entrySet() method of the Hashtable class.


load

public boolean load(Reader reader)
Loads a resource stream using a reader. After the loading, the value of the property meta.name will be appended to the list of names if the list does not already contain this name. In other words, if this is the first time that the reader is loaded and if the content defines a string value for meta.name property, and provided that there is no resource stream having the same name, then the name will be appended to the list.

Later on, you could know which resource streams have been loaded and implement specific code for loading resource streams only if they have not been loaded. Care should be taken in assigning a meaningful name. If the resource stream is for a package, then a package name is good for identifying the stream.

Parameters:
reader - The resource stream to load.
Returns:
true if the stream contains well formed properties, and false if the stream raises syntax errors or I/O exceptions.

load

public boolean load(InputStream str)
Loads a resource stream using an InputStream. This method redirects the loading to the method using Reader. If the property ilog.rules.engine.encoding is defined, its value is taken as the encoding for this operation. Otherwise, the system's default encoding is applied.

Parameters:
str - The resource stream to load.
Returns:
true if the stream contains well formed properties, and false if the stream raises syntax errors or I/O exceptions.
See Also:
load(java.io.Reader)

load

public boolean load(String filename)
Loads a resource stream using a file name. This method redirects the loading to the method using a Reader and applies the same encoding as for load(java.io.InputStream).

Returns:
true if the stream contains well formed properties, and false if the stream raises syntax errors or I/O
See Also:
load(java.io.Reader)

forPackage

public boolean forPackage(String pkg)
Loads a resource stream using a package name. A package name is a valid Java package name, for instance com.sun.mypackage. This method looks for a resource stream named /com/sun/mypackage/engine.conf. If one is found, it is loaded using the load(java.io.InputStream) method.

Parameters:
pkg - A well formed Java package name.
Returns:
true if the stream is found and its content is well-formed, and false if the stream is not found or there are syntax errors, or there are I/O exceptions.
See Also:
load(java.io.InputStream)

forClass

public boolean forClass(Class cl)
Loads a resource stream using a class. This method requests a resource stream named engine.conf to the passed class. If the stream is found, it is loaded using the load(java.io.InputStream) method.

Parameters:
cl - A Java class.
Returns:
true if the stream is found and its content is well-formed, and false if the stream is not found or there are syntax errors, or there are I/O exceptions.
See Also:
load(java.io.InputStream)

forObject

public boolean forObject(Object obj)
Loads a resource stream using an object. The method gets the class of the passed object and redirects the operation to forClass.

Parameters:
obj - An object.
Returns:
true if the stream is found and its content is well-formed, and false if the stream is not found or there are syntax errors, or there are I/O exceptions.
See Also:
forClass(java.lang.Class)

getNames

public String[] getNames()
Gets the names of the resource streams that have been loaded.

Returns:
An array of strings.
See Also:
load(java.io.Reader)

getName

public String getName()
Gets the resource name which has been appended the most lately, i.e. the last element of the name list.

Returns:
A string or null.

containsName

public boolean containsName(String name)
Tests if a stream of some name has already been loaded.

Parameters:
name - The name of the resource stream.
Returns:
true if the name is part of the loaded name list, and false otherwise.

get

public Object get(String key,
                  Object def)
Gets the property value associated to a key and returns a default value is the key does not exist.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getArray

public Object[] getArray(String key,
                         Object[] def)
Gets the property value associated to a key as an array of objects and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getString

public String getString(String key,
                        String def)
Gets the property value associated to a key as a string and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getStringArray

public String[] getStringArray(String key,
                               String[] def)
Gets the property value associated to a key as an array of strings and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getBoolean

public boolean getBoolean(String key,
                          boolean def)
Gets the property value associated to a key as a boolean value and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getBooleanArray

public boolean[] getBooleanArray(String key,
                                 boolean[] def)
Gets the property value associated to a key as an array of booleans and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getChar

public char getChar(String key,
                    char def)
Gets the property value associated to a key as a char and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getCharArray

public char[] getCharArray(String key,
                           char[] def)
Gets the property value associated to a key as a char array and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getInt

public int getInt(String key,
                  int def)
Gets the property value associated to a key as an int and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getIntArray

public int[] getIntArray(String key,
                         int[] def)
Gets the property value associated to a key as an int array and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getLong

public long getLong(String key,
                    long def)
Gets the property value associated to a key as a long and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getLongArray

public long[] getLongArray(String key,
                           long[] def)
Gets the property value associated to a key as a long array and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getFloat

public float getFloat(String key,
                      float def)
Gets the property value associated to a key as a float and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getFloatArray

public float[] getFloatArray(String key,
                             float[] def)
Gets the property value associated to a key as a float array and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getDouble

public double getDouble(String key,
                        double def)
Gets the property value associated to a key as a double and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

getDoubleArray

public double[] getDoubleArray(String key,
                               double[] def)
Gets the property value associated to a key as a double array and returns a default value is the key does not exist. Note that as a convenient method, runtime exceptions are thrown if the corresponding value is not of the requested type.

Parameters:
key - The property name.
def - The default value to be returned if the key does not exist.
Returns:
The value associated to the key, or def if the key does not exist.

remove

public Object remove(String key)
Removes an entry using its key if it exists.

Parameters:
key - The property name.
Returns:
The value to which the key has been bound, or null if the key is not an entry.

containsKey

public boolean containsKey(String key)
Tests whether a particular string is a key of the property map.

Parameters:
key - The property name.
Returns:
true is the passed argument is a key.

put

public void put(String key,
                Object value)
Adds or rebinds the value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putString

public void putString(String key,
                      String value)
Adds or rebinds a string value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putBoolean

public void putBoolean(String key,
                       boolean value)
Adds or rebinds a boolean value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putChar

public void putChar(String key,
                    char value)
Adds or rebinds a char value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putInt

public void putInt(String key,
                   int value)
Adds or rebinds a int value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putLong

public void putLong(String key,
                    long value)
Adds or rebinds a long value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putFloat

public void putFloat(String key,
                     float value)
Adds or rebinds a float value associated to a property name.

Parameters:
key - The property name.
value - The property value.

putDouble

public void putDouble(String key,
                      double value)
Adds or rebinds a double value associated to a property name.

Parameters:
key - The property name.
value - The property value.

Rule Execution Server API

© Copyright IBM Corp. 1987, 2013