ilog.rules.factory

Class IlrRulesetFactory

  • java.lang.Object
    • ilog.rules.factory.IlrRulesetFactory
  • All Implemented Interfaces:
    java.io.Serializable


    public class IlrRulesetFactory
    extends java.lang.Object
    implements java.io.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 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,
                         java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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(java.lang.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 java.util.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(java.lang.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(java.lang.String name,
                                             java.lang.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(java.lang.String name,
                                     java.lang.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 java.util.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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(java.lang.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 java.lang.Object getXOMPropertyType(java.lang.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(java.lang.Object type,
                                      java.lang.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(java.lang.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(java.lang.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,
                              java.lang.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,
                              java.lang.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(java.lang.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(java.lang.String pkgName,
                                     java.lang.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(java.lang.String name,
                                 java.util.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,
                     java.lang.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.

© Copyright IBM Corp. 1987, 2017