|
Rule Execution Server API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ilog.rules.engine.IlrRuleset
public class IlrRuleset
IlrRuleset
represents an entity that manages a set of rules.
Rules in the ruleset come from a ruleset archive. This archive is parsed
using an IlrRulesetArchiveParser
instance.
The ruleset then exhibits the rule objects it contains.
This class together with IlrContext
constitute the
main classes of the ilog.rules.engine
package. In IBM Decision Server,
the rule engine is an instance of IlrContext
, the rule engine
is simply a Java object.
An IlrContext
is an execution context that initially contains
all the rules of the ruleset. A context is created using a ruleset, to
which it is said to be attached. The ruleset owns a list of contexts.
Instances of IlrContext
can be created from a ruleset.
An IlrContext
can be derived to include additional fields and
methods. These methods and fields can be used in the rules. To create a
ruleset, the class of the execution context must be supplied. The class of
the execution context defines the set of methods and fields to which the rules
have access.
Since ILOG JRules 5.0, the derivation of IlrContext
has been
deprecated. You should use ruleset variables to add new fields to the execution
context.
Since ILOG JRules 6.5, the parsing of the IRL text format is restricted to expert users. Most of the IRL text parsing methods have been deprecated. Only the most generic ones have not been deprecated in order to support the use case where the rules are generated dynamically as IRL text or factory tree objects.
Warning: IlrRuleset
uses Java serialization. An
object can only be deserialized with the same version of Java used to serialize
it. The current serialization support is appropriate for short term
storage or RMI between applications running the same version of Java.
IlrContext
,
IlrBadContextException
,
Serialized Form
Constructor Summary | |
---|---|
IlrRuleset()
Constructs an IlrRuleset using the type IlrContext . |
|
IlrRuleset(Class contextClass)
Deprecated. Context subclassing is deprecated; use ruleset variables to hold execution data. |
|
IlrRuleset(IlrClass contextClass)
Deprecated. Context subclassing is deprecated; use ruleset variables to hold execution data. |
|
IlrRuleset(IlrReflect reflect)
Constructs an IlrRuleset using an IlrReflect . |
|
IlrRuleset(IlrRuleset ruleset)
Constructs an IlrRuleset from another IlrRuleset . |
Method Summary | |
---|---|
void |
addRule(IlrRule rule)
Deprecated. As of JRules 6.5 this method has been deprecated, considering the severe restrictions on its usage. For a consistent add operation use incremental parsing on a single ruleset instead of relying on this method. |
void |
addRules(IlrRule[] rules)
Deprecated. As of JRules 6.5 this method has been deprecated, considering the severe restrictions on its usage. For a consistent add operation use incremental parsing on a single ruleset instead of relying on this method. |
boolean |
containsRule(IlrRule rule)
Tests whether the ruleset contains a rule, that means tests whether one package of the ruleset contains the rule. |
Vector |
getAllContexts()
Returns the contexts created (and therefore attached) using this ruleset. |
IlrFunction[] |
getAllFunctions()
Returns all the functions in the ruleset, that means all functions in all ruleset packages. |
IlrRule[] |
getAllRules()
Returns all the rules in the ruleset, that means all the rules in all ruleset packages. |
IlrTask[] |
getAllTasks()
Returns all the tasks in the ruleset, that means all the tasks of all ruleset packages. |
boolean |
getBooleanProperty(String propname,
boolean def)
Gets the value of a boolean property. |
Class |
getContextClass()
Returns the context class of this ruleset. |
IlrPackage |
getDefaultPackage()
Returns the default package of the ruleset. |
double |
getDoubleProperty(String propname,
double def)
Gets the value of a float property. |
IlrFunction |
getFunction(String name,
Class[] argumentTypes)
Returns the function in the ruleset whose name is name and whose arguments types are those passed as
parameter. |
IlrFunction |
getFunction(String name,
IlrType[] argumentTypes)
Returns the function in the ruleset whose name is name and whose arguments types are those passed as
parameter. |
Map |
getHierarchicalProperties()
Returns the hierarchical properties attached to the ruleset. |
IlrHierarchicalProperty |
getHierarchicalProperty(String name)
Returns the hierarchical property attached to the ruleset whose name is equals to the given parameter. |
int |
getIntProperty(String propname,
int def)
Gets the value of an int property. |
int |
getMessageNumber()
Returns the number of errors detected during the last parsing operation. |
PrintWriter |
getMessageWriter()
Returns the PrintWriter object to which error messages are printed. |
String |
getName()
Gets the name of the ruleset. |
IlrPackage |
getPackage(String name)
Returns the specified package from the ruleset. |
IlrPackage[] |
getPackages()
Gets the packages of this ruleset. |
IlrRule[] |
getPacketRules(String packetName)
Deprecated. |
IlrPropertyList |
getProperties()
Gets the property list of this ruleset. |
Object |
getProperty(String propname,
Object def)
Gets the value of a property as an object. |
IlrReflect |
getReflect()
Gets the reflect object of this ruleset. |
IlrResources |
getResources()
Gets the resource bundle of this ruleset. |
IlrRule |
getRule(String ruleName)
Returns the rule whose name is given as the parameter. |
Iterator |
getRuleIterator()
Returns an iterator on the rules contained in the ruleset, that means on the rules contained in all ruleset packages. |
int |
getRuleNumber()
Returns the number of rules in this ruleset, that is the total of rules contained in all packages of this ruleset. |
protected List |
getRules()
|
IlrRulesetParameter[] |
getRulesetSignature()
Returns the signature of the ruleset. |
IlrRulesetParameter[] |
getRulesetVariables(int modifier)
Returns the ruleset variables for a specific modifier. |
IlrRulesetParameter[] |
getSignature()
Deprecated. |
String |
getStringProperty(String propname,
String def)
Gets the value of a string property. |
IlrTask |
getTask(String name)
Returns the task defined in the ruleflow and whose name is the one passed as the parameter. |
boolean |
isLocked()
Returns true if the ruleset is locked. |
IlrRulesetFactory |
makeFactory()
Builds a factory object that represents this ruleset. |
void |
mergeRules(IlrRuleset ruleset)
Deprecated. As of JRules 6.5 this method has been deprecated, considering the severe restrictions on its usage. For a consistent merge operation use incremental parsing on a single ruleset instead of relying on this method. |
boolean |
optimize(IlrRulesetOptimConfig config)
Optimizes the rules. |
boolean |
parseFactory(IlrRulesetFactory factory)
Parses the ruleset factory. |
boolean |
parseFile(File file)
Deprecated. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives. If it is necessary to load rules directly from IRL text, see parseStream(java.io.InputStream) or parseReader(java.io.Reader) |
boolean |
parseFileName(String fileName)
Deprecated. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives. If it is necessary to load rules directly from IRL text, see parseStream(java.io.InputStream) or parseReader(java.io.Reader) |
boolean |
parseReader(Reader reader)
Parses the supplied java.io.Reader . |
boolean |
parseStream(InputStream stream)
Parses the stream provided as its argument. |
boolean |
parseString(String source)
Deprecated. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives. If it is necessary to load rules directly from IRL text, see parseStream(java.io.InputStream) or parseReader(java.io.Reader) |
boolean |
parseURL(URL url)
Deprecated. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives. If it is necessary to load rules directly from IRL text, see parseStream(java.io.InputStream) or parseReader(java.io.Reader) |
void |
removeMetadata()
Removes metadata from rules and from the Rete network. |
void |
removeMetadata(boolean fromRules,
boolean fromRete)
Removes metadata from rules and from the Rete network. |
void |
removeRule(IlrRule rule)
Removes a rule from the ruleset. |
void |
removeRules(IlrRule[] rules)
Removes rules from the packages that contain them. |
void |
replaceRule(IlrRule newRule)
Deprecated. As of JRules 6.5 this method has been deprecated, considering the severe restrictions on its usage. For a consistent replace operation use incremental parsing on a single ruleset instead of relying on this method. |
void |
setAllowPackageDeclaration(boolean ng)
Specifies whether the ruleset code may contain a package declaration. |
void |
setApplication(String application)
Deprecated. As of JRules 7.0, this method has no effect. |
void |
setMessageWriter(PrintWriter writer)
Sets the error message writer of the ruleset. |
void |
setName(String name)
Sets the name of the ruleset. |
void |
setResources(IlrResources resources)
Sets the resource bundle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IlrRuleset()
IlrRuleset
using the type IlrContext
. The rules in the ruleset will have
access only to the fields and methods defined in IlrContext
. Initially, the ruleset contains no rules.
This constructor creates a new IlrReflect
.
public IlrRuleset(IlrReflect reflect)
IlrRuleset
using an IlrReflect
. The context class of this ruleset is
IlrContext.class
.
reflect
- The reflect object of this ruleset.public IlrRuleset(Class contextClass)
IlrRuleset
using a specific context class. The context class must be a subclass of
IlrContext
. The context class can be obtained using the construct
MyDerivedContextClassName.class
or by the static method Class.forName
.
The constructor throws an IlrBadContextException
if the given class is not a subclass of
IlrContext
.
The scope of the rules in the ruleset will be the context class. These rules will have access to the fields and
methods defined in the subclass. Initially, the ruleset contains no rules. This constructor creates a new IlrReflect
.
contextClass
- A derived class of IlrContext
.public IlrRuleset(IlrClass contextClass)
IlrRuleset
using a specific context class. The context class must be a subclass of
IlrContext
.
The constructor throws an IlrBadContextException
if the given class is not a subclass of
IlrContext
.
The reflect object of this ruleset is the object model of the class descriptor passed as the argument.
contextClass
- A derived class of IlrContext
.public IlrRuleset(IlrRuleset ruleset)
IlrRuleset
from another IlrRuleset
. The new ruleset will have the same
context class and the same error output writer as the specified ruleset. It will contain no rules (the rules of the
supplied ruleset are not duplicated) and will have no context attached to it.
ruleset
- The ruleset constructor.Method Detail |
---|
public void setAllowPackageDeclaration(boolean ng)
true
. In
this case, a package declaration is allowed, and the definition of an artifact (such as a rule, function, or task)
with a name containing a '.' (period) character is not allowed.
To migrate IRL from JRules versions prior to JRules 6, this method needs to be called with the Boolean parameter set
to false
. In this case, a package declaration is not allowed, and artifact definitions whose names
contain a '.' character are allowed. For example, when an artifact named a.b
is encountered, a package
named a
is created and contains an artifact named b
.
public final IlrReflect getReflect()
public final String getName()
public final void setName(String name)
name
- The name of the ruleset. The argument can be null
.public final IlrPropertyList getProperties()
public final Class getContextClass()
public final Vector getAllContexts()
IlrContext
. Each context is attached to this ruleset. The length of the list can be
0.public Map getHierarchicalProperties()
null
. In the returned hash table, the key is the hierarchical property name, the value is the
hierarchical property ilog.rules.factory.IlrHierarchicalProperty
itself.
public IlrHierarchicalProperty getHierarchicalProperty(String name)
name
- The name of the hierarchical property we are looking for.
null
in case the
ruleset has no hierarchical property or in case no property is named as requested.public final IlrPackage getPackage(String name)
name
- The name of the package we are looking for.
null
in
case there is no such package.public final IlrPackage getDefaultPackage()
public final IlrPackage[] getPackages()
public final int getRuleNumber()
public final IlrRule getRule(String ruleName)
ruleName
- The name of the rule.
IlrRule
whose name is provided as the parameter, if this rule exists. Otherwise,
null
is returned.public final Iterator getRuleIterator()
remove
method of this iterator will throw an UnsupportedOperationException
.
IlrRule
instances.protected List getRules()
public final boolean containsRule(IlrRule rule)
rule
- A rule.
true
if the ruleset contains the rule. Otherwise, it returns false
.public final IlrRule[] getAllRules()
IlrRule
. The length of the array can be 0.public void addRule(IlrRule rule)
The usage of this method is strictly limited to the case of a new rule which does not make use of other elements from its declaring ruleset such as ruleset parameters, functions, and so on. The reason is that this method will only perform a shallow copy of the new rule to the recipient one without considering the replacement or the addition of all the ruleset elements on which the new rule may depend.
rule
- The rule to be added.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public void addRules(IlrRule[] rules)
The usage of this method is strictly limited to the case of new rules which do not make use of other elements from their declaring ruleset such as ruleset parameters, functions, and so on. The reason is that this method will only perform a shallow copy of the new rules to the recipient one without also considering the replacement or the addition of all the ruleset elements on which the new rules may depend.
rules
- The array of rules.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public void removeRule(IlrRule rule)
Note that the ruleset elements of which the rule may be the unique user, such as ruleset parameters, functions, and so on, are not automatically removed when the rule is removed.
rule
- The rule to be removed.public void removeRules(IlrRule[] rules)
rules
- The array of rules.removeRule(ilog.rules.engine.IlrRule)
public void replaceRule(IlrRule newRule)
The usage of this method is strictly limited to the case of a new rule which does not make use of other elements from its declaring ruleset such as ruleset parameters, functions, and so on. The reason is that this method will only perform a shallow replacement of the new rule in the recipient one without also considering the replacement or the addition of all the ruleset elements on which the new rule may depend.**
newRule
- The rule to be added. It will replace a rule with the same name.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public void mergeRules(IlrRuleset ruleset)
The usage of this method is strictly limited to the case of an argument ruleset which contains only rules or an initial action. This method should not be used once the rules or the initial action from the argument ruleset make use of other elements which are also declared in the argument ruleset such as ruleset parameters, functions, and so on. The reason is that this method will only perform a shallow merge of the rules from the argument ruleset to the recipient ruleset without also considering the merge of the other ruleset elements on which those rules may depend.
ruleset
- The ruleset that is merged with the current ruleset.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public final IlrFunction[] getAllFunctions()
IlrFunction[]
. The length of the array can be 0.public final IlrFunction getFunction(String name, Class[] argumentTypes)
name
and whose arguments types are those passed as
parameter.
name
- The name of the function we are looking for.argumentTypes
- The array of argument types, as Class
, that correspond to the signature of the
function we are looking for.
public final IlrFunction getFunction(String name, IlrType[] argumentTypes)
name
and whose arguments types are those passed as
parameter.
name
- The name of the function we are looking for.argumentTypes
- The array of argument types, as Class
, that correspond to the signature of the
function we are looking for.
public IlrTask getTask(String name)
null
if no such task exists.
name
- The name of a task to return.
name
.public final IlrTask[] getAllTasks()
IlrTask[]
. The length of the array can be 0.public IlrRulesetParameter[] getSignature()
IlrRulesetParameter
, each of them containing the type,
as an IlrClass
and the name of the variable.
IlrRulesetParameter
public IlrRulesetParameter[] getRulesetSignature()
IlrRulesetParameter
, each of them
containing the type, as an IlrClass
and the name of the variable.
IlrRulesetParameter
public IlrRulesetParameter[] getRulesetVariables(int modifier)
modifier
- A mask built from values defined in
ilog.rules.factory.IlrRulesetConstants
. The modifier
for local variables is 0
.
IlrRulesetParameter
objects. Each object
contains:
IlrClass
instance representing the type of the object.IlrRulesetParameter
,
IlrRulesetConstants.In
,
IlrRulesetConstants.Out
public final IlrResources getResources()
public final void setResources(IlrResources resources)
resources
- A resource bundle. It cannot be null
.public final boolean getBooleanProperty(String propname, boolean def)
propname
- The name of the property.def
- The default value to return if the property is not defined.public final String getStringProperty(String propname, String def)
propname
- The name of the property.def
- The default value to return if the property is not defined.public final int getIntProperty(String propname, int def)
propname
- The name of the property.def
- The default value to return if the property is not defined.public final double getDoubleProperty(String propname, double def)
propname
- The name of the property.def
- The default value to return if the property is not defined.public final Object getProperty(String propname, Object def)
propname
- The name of the property.def
- The default value to return if the property is not defined.public final PrintWriter getMessageWriter()
PrintWriter
object to which error messages are printed. Initially, the error message writer
is System.out
.
public final void setMessageWriter(PrintWriter writer)
writer
- the new writer to which error messages are printed.public final int getMessageNumber()
public final IlrRule[] getPacketRules(String packetName)
packetName
.
packetName
- the name of the packet.
IlrRule
. The length of the array can be 0.public IlrRulesetFactory makeFactory()
IlrTool
method
public boolean parseStream(InputStream stream)
RulesetDefinition
grammar rule.
This method can be used to load dynamically generated rulesets in IRL text format into the engine. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives; this method is provided for cases where rules are generated as IRL text by other (non-ILOG) tools.
If errors are detected during parsing, then they are printed to the error message stream and the method returns
false
to indicate that the parsing failed. Otherwise, no message is printed and the method returns
true
.
If the returned value is false
, all the definitions of the input unit are ignored including those that
are correct. The ruleset behaves as if the parsing operation had never happened.
If the returned value is true
, all the definitions are added to the ruleset. If there is an Initial
Action, the new definition overrides the old one (if one exists). For the rule definitions, the new rules are added
by means of the method mergeRules
: existing rules that have the same name are overridden. New rules are
simply added.
When new definitions are added to a ruleset, all the contexts attached to this ruleset are notified accordingly. Upon notification, each context uses the new rule definitions and updates its data structure accordingly. Rule instances may be added to or removed from the agenda as a consequence of these updates.
Note that this method creates a java.io.Reader
using the current encoding provided by the resources of
the IlrReflect
object.
stream
- The input unit.
true
if the parsing is successful, otherwise it returns false
.IlrRulesetArchiveParser
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public boolean parseURL(URL url)
parseStream(java.io.InputStream)
or parseReader(java.io.Reader)
java.net.URL
. The URL must be valid and accessible. This method opens a stream from
the URL and then calls the method parseStream
.
url
- The URL of the input unit.
true
if the URL is accessible and parsing is successful, otherwise it returns
false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
,
parseFileName(java.lang.String)
,
parseFile(java.io.File)
,
parseString(java.lang.String)
public boolean parseReader(Reader reader)
java.io.Reader
. See the method parseStream
for more details about the
rule parsing process.
This method can be used to load dynamically generated rulesets in IRL text format into the engine. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives; this method is provided for cases where rules are generated as IRL text by other (non-ILOG) tools.
reader
- The reader of the input unit.
true
if the content of the reader is parsed successfully, otherwise it returns
false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
public boolean parseFileName(String fileName)
parseStream(java.io.InputStream)
or parseReader(java.io.Reader)
parseStream
for
more details. This method creates a java.io.Reader
using the current encoding provided by the resources
of the IlrReflect
object.
fileName
- The file name of the input unit.
true
if the file is accessible and parsing is successful, otherwise it returns
false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
,
parseURL(java.net.URL)
,
parseFile(java.io.File)
,
parseString(java.lang.String)
public boolean parseFile(File file)
parseStream(java.io.InputStream)
or parseReader(java.io.Reader)
parseStream
for more
details. This method creates a java.io.Reader
using the current encoding provided by the resources of
the IlrReflect
object.
file
- The file of the input unit.
true
if the file is accessible and parsing is successful, otherwise it returns
false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
,
parseURL(java.net.URL)
,
parseFileName(java.lang.String)
,
parseString(java.lang.String)
public boolean parseString(String source)
parseStream(java.io.InputStream)
or parseReader(java.io.Reader)
parseStream
for more details.
source
- The string to be parsed.
true
if parsing is successful, otherwise it returns false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
,
parseFactory(ilog.rules.factory.IlrRulesetFactory)
,
parseURL(java.net.URL)
,
parseFile(java.io.File)
,
parseFileName(java.lang.String)
public boolean parseFactory(IlrRulesetFactory factory)
This method can be used to load dynamically generated rulesets in syntax tree format into the engine. The preferred method for loading rulesets generated by ILOG rule authoring tools is via ruleset archives; this method is provided for cases where rules are generated as tree objects by other (non-ILOG) tools.
factory
- The ruleset factory to be parsed.
true
if parsing is successful, otherwise it returns false
.IlrRulesetArchiveParser
,
parseStream(java.io.InputStream)
,
parseReader(java.io.Reader)
public void removeMetadata(boolean fromRules, boolean fromRete)
fromRules
- Is true if metadata is to be removed from the rules.fromRete
- Is true if metadata is to be removed from the Rete.public void removeMetadata()
removeMetadata(true,true)
.
public boolean optimize(IlrRulesetOptimConfig config)
The optimization triggers internal mechanisms so as to improve the performance of rule execution. In particular, some improvements are possible when the priorities applied to the rules are known at compile-time (static priorities).
The ruleset must not be attached to any context before optimization starts. Otherwise, an
IllegalArgumentException
is raised.
config
- The optimization configuration. This parameter may be null
. In that case, an
OptimConfig
instance is created internally with default values for attribute values.
true
if the optimization is valid.isLocked()
public boolean isLocked()
true
if the ruleset is locked.
true
if locked.optimize(IlrRulesetOptimConfig)
public void setApplication(String application)
application
- The SAM application name of the application.
|
Rule Execution Server API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |