Rule Execution Server API

ilog.rules.factory
Class IlrRulesetFactory

java.lang.Object
  extended by ilog.rules.factory.IlrRulesetFactory
All Implemented Interfaces:
Serializable

public class IlrRulesetFactory
extends Object
implements Serializable

This class represents an input unit of the rule language. It is the main class of the factory API. An instance of this class can be obtained from an IlrRuleset object. Conversely, an IlrRuleset object can analyze the contents of an IlrRulesetFactory object to create rules.

Warning: Serialized objects of this class will not be compatible with future releases. The current serialization support is appropriate for short-term storage or RMI between applications running the same version of IBM Decision Server.

See Also:
IlrRuleset.makeFactory(), IlrRuleset.parseFactory(IlrRulesetFactory), Serialized Form

Constructor Summary
IlrRulesetFactory(IlrClass contextClass)
          Constructs a ruleset factory using a derived context class, in other words, any subclass of ilog.rules.engine.IlrContext.
IlrRulesetFactory(IlrReflect reflect)
          Constructs a ruleset factory using the base execution context class, in other words, ilog.rules.engine.IlrContext.class.
IlrRulesetFactory(IlrReflect reflect, Class contextClass)
          Constructs a ruleset factory using a derived context class, in other words, any subclass of ilog.rules.engine.IlrContext.
 
Method Summary
 void addFunction(IlrFunctionFactory function)
          Adds a function in a package.
 void addHasher(IlrHasher hasher)
          Adds a new hasher in the ruleset hasher list.
 void addInitialAction(IlrStatement action)
          Deprecated.  
 void addInstance(IlrClass clazz, IlrValue instance)
          Adds the specified value in the object list in which the rule engine looks for objects of the specified class.
 void addOverridingRelation(String name, ArrayList children)
          Declares an overriding relation between rule groups.
 void addPackage(IlrPackageFactory pkg)
          Adds a package in the ruleset.
 void addPackageVariable(IlrPackageFactory pkgF, IlrType clazz, String name, IlrValue value)
          Defines a package local variable.
 void addPropertyTypeDeclaration(Object type, String pptyName)
          Adds a property type declaration.
 void addRule(IlrRuleFactory rule)
          Adds a rule in its package.
 void addRulesetVariable(int modifier, IlrType clazz, String name, IlrValue value)
          Defines a ruleset variable.
 void addTask(IlrTaskFactory task)
          Adds a task to the tasks of the factory.
 void createInitialRule()
          Deprecated.  
 void declareHierarchicalProperty(IlrHierarchicalProperty ppty)
          Declares a hierarchical property.
 Enumeration enumerateFunctions()
          Gets an enumeration to visit all the functions of this factory, which means all the functions contained in all packages of this factory.
 Enumeration enumerateRules()
          Gets an enumeration to visit all the rules of this factory, that is, all the rules contained in all packages of this factory.
 Class getContextClass()
          Gets the context class of the ruleset factory.
 IlrContextValue getContextValue()
          Gets the context value of the ruleset factory.
 IlrPackageFactory getDefaultPackage()
          Returns the default package of the ruleset.
 IlrFunctionFactory getFunction(String name, Class[] argTypes)
          Gets a function factory by name and its signature.
 int getFunctionCount()
          Gets the number of functions in this factory, which means the total of functions contained by all packages of this factory.
 IlrFunctionFactory[] getFunctions()
          Gets the functions of this factory, which means the functions contained in all packages of this factory.
 IlrHierarchicalProperty getHierarchicalProperty(String name)
          Gets a hierarchical property by name.
 IlrStatement[] getInitialActions()
          Deprecated.  
 IlrFunctionFactory getMatchingFunction(String name, Class[] args)
          Gets a function factory by name and matching the signature parameter.
 IlrFunctionFactory getMatchingFunction(String name, IlrValue[] args)
          Gets a function factory by name and matching the signature parameter.
 String getName()
          Gets the name of the ruleset.
 IlrPackageFactory getPackage(String name)
          Returns a package by name.
 IlrPackageFactory[] getPackages()
          Gets the packages of this factory.
 IlrVariable getPackageVariable(String pkgName, String name)
          Returns the variable that implements the local variable whose name is passed as a parameter, in the given package.
 IlrPropertyList getProperties()
          Gets the property list of this ruleset factory.
 IlrReflect getReflect()
          Gets the reflect objects.
 IlrRuleFactory getRule(String name)
          Gets a rule factory by name.
 int getRuleCount()
          Gets the number of rules in this factory, which means the total of rules contained by all packages of this factory.
 ilog.rules.factory.IlrRuleOverridingFactory getRuleOverriding()
          Returns the rule overriding declarations.
 IlrRuleFactory[] getRules()
          Gets the rules of this factory, which means the rules contained in all packages of this factory.
 IlrVariable getRulesetVariable(String name)
          Returns the variable that implements the ruleset parameter.
 IlrRuleWriter getRuleWriter()
          Gets the rule writer used for writing the rules of this ruleset factory.
 IlrTaskFactory getTask(String name)
          Gets a task factory by name.
 IlrTaskFactory[] getTasks()
          Returns an array with all the tasks defined in the ruleset, which means all the tasks defined in all the packages of the ruleset.
 IlrClass getXOMContextClass()
          Gets the context class of the ruleset factory.
 Object getXOMPropertyType(String property)
          Returns the type of the given property.
 boolean isHierarchicalProperty(String name)
          Returns a boolean value indicating whether there is a hierarchical property defined in the ruleset with this name.
 void removeFunction(IlrFunctionFactory function)
          Removes a function from the package in which it is contained.
 void removeRule(IlrRuleFactory rule)
          Removes a rule from the package in which it is contained.
 void setHasher(IlrType clazz, String name, IlrValue value)
          Deprecated.  
 void setInstances(IlrClass clazz, IlrValue instances)
          Sets the instances of the specified class with which the rule engine will work.
 void setName(String name)
          Sets the name of the ruleset.
 void setRuleWriter(IlrRuleWriter ruleWriter)
          Sets the rule writer used to write the rules of this ruleset factory.
 String toLanguage()
          Converts this ruleset factory into the rule language as a rule input unit.
 String toLanguage(IlrFunctionFactory function)
          Converts a function factory into the rule language.
 String toLanguage(IlrPackageFactory pkg)
          Converts a package factory into the rule language.
 String toLanguage(IlrRuleFactory rule)
          Converts a rule factory into the rule language.
 String toLanguage(IlrTaskFactory task)
          Converts a task factory into the rule language.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlrRulesetFactory

public IlrRulesetFactory(IlrReflect reflect)
Constructs a ruleset factory using the base execution context class, in other words, ilog.rules.engine.IlrContext.class. The factory is attached to the passed reflect object.

Parameters:
reflect - A reflect.

IlrRulesetFactory

public IlrRulesetFactory(IlrReflect reflect,
                         Class contextClass)
Constructs a ruleset factory using a derived context class, in other words, any subclass of ilog.rules.engine.IlrContext. The rules contained in this ruleset factory will operate in any instance of the derived context class.

Parameters:
reflect - A reflect.
contextClass - The context class. This is a derived class of ilog.rules.engine.IlrContext.

IlrRulesetFactory

public IlrRulesetFactory(IlrClass contextClass)
Constructs a ruleset factory using a derived context class, in other words, any subclass of ilog.rules.engine.IlrContext. The rules contained in this ruleset factory will operate in any instance of the derived context class.

Parameters:
contextClass - The context class. This is a derived class of ilog.rules.engine.IlrContext.
Method Detail

getReflect

public final IlrReflect getReflect()
Gets the reflect objects.

Returns:
The reflect object of this ruleset factory.

getRuleWriter

public final IlrRuleWriter getRuleWriter()
Gets the rule writer used for writing the rules of this ruleset factory.

Returns:
A rule writer.

setRuleWriter

public final void setRuleWriter(IlrRuleWriter ruleWriter)
Sets the rule writer used to write the rules of this ruleset factory.

Parameters:
ruleWriter - A rule writer.

getName

public final String getName()
Gets the name of the ruleset. The name is a simple string that can be used to identify the ruleset. Initially the name of a ruleset is the name of its context class.

Returns:
The name of the ruleset.

setName

public final void setName(String name)
Sets the name of the ruleset.

Parameters:
name - The name of the ruleset. The argument can be null.

getProperties

public final IlrPropertyList getProperties()
Gets the property list of this ruleset factory.

Returns:
A property list.

getContextClass

public final Class getContextClass()
Gets the context class of the ruleset factory.

Returns:
The context class of the ruleset factory.

getXOMContextClass

public final IlrClass getXOMContextClass()
Gets the context class of the ruleset factory.

Returns:
The context class of the ruleset factory.

getContextValue

public final IlrContextValue getContextValue()
Gets the context value of the ruleset factory. The context value represents the ?context variable of the rule language.

Returns:
The context value.

createInitialRule

public final void createInitialRule()
Deprecated. 

Creates an empty initial rule. The actions of the initial rule can be added using the method #addInitialAction(IlrStatement) The initial rule is attached to the defaultPackage.


addInitialAction

public final void addInitialAction(IlrStatement action)
Deprecated. 

Adds an action to the initialization rule. The initial rule must be created previously using #createInitialRule() method. The initial rule is attached to the defaultPackage. The action is placed at the end of the initialization rule.

Parameters:
action - The action to be added.

getInitialActions

public final IlrStatement[] getInitialActions()
Deprecated. 

Gets the actions of the initialization rule. The initial rule is attached to the defaultPackage.

Returns:
The actions of the initialization rule, or null if no initial rule has been created.

addPackage

public final void addPackage(IlrPackageFactory pkg)
Adds a package in the ruleset.

Parameters:
pkg - The package to be added.

getPackage

public final IlrPackageFactory getPackage(String name)
Returns a package by name.

Parameters:
name - The name of the package factory.
Returns:
A package factory object whose name is name. When name is null, a null object is returned.

getDefaultPackage

public final IlrPackageFactory getDefaultPackage()
Returns the default package of the ruleset. The default package is the package whose name is the empty string.

Returns:
The ruleset default package.

getPackages

public final IlrPackageFactory[] getPackages()
Gets the packages of this factory.

Returns:
The packages of this factory.

addRule

public final void addRule(IlrRuleFactory rule)
Adds a rule in its package. If the rule does not specify its package, it is added in the default package.

Parameters:
rule - The rule to be added.

removeRule

public final void removeRule(IlrRuleFactory rule)
Removes a rule from the package in which it is contained.

Parameters:
rule - The rule to be removed.

getRule

public final IlrRuleFactory getRule(String name)
Gets a rule factory by name.

Parameters:
name - The name of the rule factory.
Returns:
A rule factory object whose name is name. When name is null, a null object is returned.

getRuleCount

public final int getRuleCount()
Gets the number of rules in this factory, which means the total of rules contained by all packages of this factory.

Returns:
The number of rules in this factory.

getRules

public final IlrRuleFactory[] getRules()
Gets the rules of this factory, which means the rules contained in all packages of this factory.

Returns:
The rules of this factory.

enumerateRules

public final Enumeration enumerateRules()
Gets an enumeration to visit all the rules of this factory, that is, all the rules contained in all packages of this factory.

Returns:
An enumeration to visit all the rules of this factory.

addFunction

public final void addFunction(IlrFunctionFactory function)
Adds a function in a package. If the function does not specify its packages, it is added to the default package of the factory. Otherwise, it is added to its package.

Parameters:
function - The function to be added.

removeFunction

public final void removeFunction(IlrFunctionFactory function)
Removes a function from the package in which it is contained.

Parameters:
function - The function to be removed.

getMatchingFunction

public final IlrFunctionFactory getMatchingFunction(String name,
                                                    IlrValue[] args)
Gets a function factory by name and matching the signature parameter.

Parameters:
name - The name of the function factory.
args - The type of the function arguments.
Returns:
A function factory object whose name is name. When name is null, a null object is returned.

getMatchingFunction

public final IlrFunctionFactory getMatchingFunction(String name,
                                                    Class[] args)
Gets a function factory by name and matching the signature parameter.

Parameters:
name - The name of the function factory.
args - The Java classes of the function arguments.
Returns:
A function factory object whose name is name. When name is null, a null object is returned.

getFunction

public final IlrFunctionFactory getFunction(String name,
                                            Class[] argTypes)
Gets a function factory by name and its signature.

Parameters:
name - The name of the function factory.
argTypes - The type of the function arguments.
Returns:
A function factory object whose name is name. When name is null, a null object is returned.

getFunctionCount

public final int getFunctionCount()
Gets the number of functions in this factory, which means the total of functions contained by all packages of this factory.

Returns:
The number of functions in this factory.

getFunctions

public final IlrFunctionFactory[] getFunctions()
Gets the functions of this factory, which means the functions contained in all packages of this factory.

Returns:
The functions of this factory.

enumerateFunctions

public final Enumeration enumerateFunctions()
Gets an enumeration to visit all the functions of this factory, which means all the functions contained in all packages of this factory.

Returns:
An enumeration to visit all the functions of this factory.

toLanguage

public String toLanguage()
Converts this ruleset factory into the rule language as a rule input unit.

Returns:
A string which represents an input unit of the language.
See Also:
IlrRuleWriter

toLanguage

public String toLanguage(IlrPackageFactory pkg)
Converts a package factory into the rule language. This method is provided as a convenient method to get around the rule writer. It uses an IlrRuleWriter internally.

Parameters:
pkg - The package factory to convert into rule language.
Returns:
A string which represents a package of the language.
See Also:
IlrRuleWriter

toLanguage

public String toLanguage(IlrRuleFactory rule)
Converts a rule factory into the rule language. This method is provided as a convenient method to get around the rule writer. It uses an IlrRuleWriter internally.

Parameters:
rule - The rule factory to convert into rule language.
Returns:
A string which represents a rule of the language.
See Also:
IlrRuleWriter

toLanguage

public String toLanguage(IlrFunctionFactory function)
Converts a function factory into the rule language. This method is provided as a convenient method to get around the rule writer. It uses an IlrRuleWriter internally.

Parameters:
function - The function factory to convert into rule language.
Returns:
A string which represents a function of the language.
See Also:
IlrRuleWriter

toLanguage

public String toLanguage(IlrTaskFactory task)
Converts a task factory into the rule language. This method is provided as a convenient method to get around the rule writer. It uses an IlrRuleWriter internally.

Parameters:
task - The task factory to convert into rule language.
Returns:
A string which represents a task of the language.
See Also:
IlrRuleWriter

addTask

public void addTask(IlrTaskFactory task)
Adds a task to the tasks of the factory. The task is placed at the end of the tasks.

Parameters:
task - The task to be added.

getTasks

public IlrTaskFactory[] getTasks()
Returns an array with all the tasks defined in the ruleset, which means all the tasks defined in all the packages of the ruleset.

Returns:
An array with the ruleset tasks

getTask

public final IlrTaskFactory getTask(String name)
Gets a task factory by name.

Parameters:
name - The name of the task factory.
Returns:
A task factory object whose name is name. When name is null, a null object is returned.

getXOMPropertyType

public Object getXOMPropertyType(String property)
Returns the type of the given property. If the property type has not been declared, the returned value is null. The property type can be either an IlrType or IlrHierarchicalProperty object.

Parameters:
property - The property name.
Returns:
The property type if it has been defined, or else null.

addPropertyTypeDeclaration

public void addPropertyTypeDeclaration(Object type,
                                       String pptyName)
Adds a property type declaration. Such a declaration is useful to make possible to access rule properties in a lightweight manner. For example, the expression ?rule.?location, where ?rule is an IlrRule variable and ?location a property defined on the rule, is possible if the type of the ?location property has been defined.

Parameters:
type - The type of the property to be declared. The type can be either an IlrType object or a hierarchical property implemented with an IlrHierarchicalProperty object. If the type is neither an IlrType nor an IlrHierarchicalProperty, an IllegalArgumentException is thrown.
pptyName - The name of the property to declare.

declareHierarchicalProperty

public void declareHierarchicalProperty(IlrHierarchicalProperty ppty)
Declares a hierarchical property.

Parameters:
ppty - A hierarchical property to declare to the ruleset.

getHierarchicalProperty

public IlrHierarchicalProperty getHierarchicalProperty(String name)
Gets a hierarchical property by name.

Parameters:
name - The name of the hierarchical property.
Returns:
A hierarchical property defined in the ruleset.

isHierarchicalProperty

public boolean isHierarchicalProperty(String name)
Returns a boolean value indicating whether there is a hierarchical property defined in the ruleset with this name.

Returns:
true if a hierarchical property whose name is name is defined in the ruleset, else it returns false.

addRulesetVariable

public void addRulesetVariable(int modifier,
                               IlrType clazz,
                               String name,
                               IlrValue value)
Defines a ruleset variable. The modifier will be IlrRulesetConstants.In, IlrRulesetConstants.InOut, IlrRulesetConstants.Out, or 0 for local variables. If another value is given, an IllegalArgumentException exception is thrown. An initial value can be given except for in or inout ruleset variables. A local variable is added to the default package; any other kind of variable is considered as part of the ruleset signature and therefore attached to the ruleset. If the variable contains any '.' characters, an IllegalArgumentException exception is thrown.

Parameters:
clazz - The parameter type.
name - The parameter name.
value - The initial value.
modifier - The parameter modifier.

addPackageVariable

public void addPackageVariable(IlrPackageFactory pkgF,
                               IlrType clazz,
                               String name,
                               IlrValue value)
Defines a package local variable. An initial value can be given. The variable is inserted in the given package.

Parameters:
pkgF - The package in which the variable is to be inserted.
clazz - The parameter type.
name - The parameter name.
value - The initial value.

getRulesetVariable

public IlrVariable getRulesetVariable(String name)
Returns the variable that implements the ruleset parameter. Its name is passed as a parameter. The variable is searched in the ruleset variables defined as in and inout ruleset variables. If it is not found, the variable name is searched in the ruleset variables defined as out.

Parameters:
name - The name of the requested variable.

getPackageVariable

public IlrVariable getPackageVariable(String pkgName,
                                      String name)
Returns the variable that implements the local variable whose name is passed as a parameter, in the given package.

Parameters:
pkgName - The package containing the variable.
name - The name of the variable we are looking for.

addOverridingRelation

public void addOverridingRelation(String name,
                                  ArrayList children)
Declares an overriding relation between rule groups. The first parameter is the group that overrides the other groups contained in the list given as the second parameter.

Parameters:
name - The name of the overrider group.
children - The list of overridden groups.

getRuleOverriding

public ilog.rules.factory.IlrRuleOverridingFactory getRuleOverriding()
Returns the rule overriding declarations.

Returns:
An IlrRuleOverridingFactory that models the rules overriding relations.

setInstances

public void setInstances(IlrClass clazz,
                         IlrValue instances)
Sets the instances of the specified class with which the rule engine will work. The given value must be of type java.util.Collection. For objects of this class bound in the rules condition part, the rule engine will not try to match with objects stored in the working memory, but it will take them from the specified collection.

Parameters:
clazz - The class for which the instances are specified.
instances - The collection of objects.

addInstance

public void addInstance(IlrClass clazz,
                        IlrValue instance)
Adds the specified value in the object list in which the rule engine looks for objects of the specified class.

Parameters:
clazz - The class for which the instances are specified.
instance - The value added in the object list for the specified class.

setHasher

public void setHasher(IlrType clazz,
                      String name,
                      IlrValue value)
Deprecated. 

Defines the hasher value for the specified class. The passed value must be of integer type.

Parameters:
clazz - The class for which the hasher is defined.
name - The name of the variable used in the expression of the hasher value.
value - The hasher value of integer type.

addHasher

public void addHasher(IlrHasher hasher)
Adds a new hasher in the ruleset hasher list.

Parameters:
hasher - The new hasher to be added in the ruleset hasher list.

Rule Execution Server API

© Copyright IBM Corp. 1987, 2013