com.knowgate.rules
Class RuleExecution

java.lang.Object
  extended by com.knowgate.rules.RuleExecution

public abstract class RuleExecution
extends java.lang.Object

RuleExecution

RuleExecution represents an abstract operation performed on a set of data. Rule Executions are composed of three items:
1. The Parameters Collection
2. The Assertions Collection
3. The Rule Execution Code
Also RuleExecution can used additional global properties and asserts from its parent RuleEngine.


Constructor Summary
RuleExecution(RuleEngine oEngine)
          Create RuleExecution on given RuleEngine
RuleExecution(RuleExecution oRexec)
          Create copy from another RuleExecution
 
Method Summary
 void clear()
          Clear all parameters and asserts
 boolean getAssert(java.lang.String sAssertKey)
          Get status of a given fact
 java.util.HashMap<java.lang.String,java.lang.Boolean> getAssertMap()
          Get map of assertions used by this RuleExecution
abstract  java.lang.Object getExplanation()
          Get explanation about how the last result of applying this rule was computed This method must be implemented on eeach derived class for providing the actual behaviour of the RuleExecution instance
 java.lang.Object getParam(java.lang.String sKey)
          Get parameter value
 java.lang.Object getParam(java.lang.String sKey, java.lang.Object oDefault)
          Get parameter value
 java.util.Date getParamDate(java.lang.String sKey)
          Get parameter as java.util.Date
 java.util.Date getParamDate(java.lang.String sKey, java.util.Date dtDefault)
          Get parameter as java.util.Date
 java.math.BigDecimal getParamDec(java.lang.String sKey)
          Get parameter as BigDecimal
 java.math.BigDecimal getParamDec(java.lang.String sKey, java.math.BigDecimal oDefault)
          Get parameter as BigDecimal
 java.lang.Integer getParamInt(java.lang.String sKey)
          Get parameter as Integer
 java.lang.Integer getParamInt(java.lang.String sKey, java.lang.Integer iDefault)
          Get parameter as Integer
 java.util.HashMap<java.lang.String,java.lang.Object> getParamMap()
          Get map of parameters used by this RuleExecution
 java.lang.String getParamStr(java.lang.String sKey)
          Get parameter as String
 java.lang.String getParamStr(java.lang.String sKey, java.lang.String sDefault)
          Get parameter as String
abstract  java.lang.Object getResult()
          Get result of applying this rule This method must be implemented on eeach derived class for providing the actual behaviour of the RuleExecution instance
 RuleEngine getRuleEngine()
          Get RuleEngine to which this RuleExecution belongs
 boolean isDefined(java.lang.String sKey)
          Find out whether or not a given parameter has a defined value
 boolean isNull(java.lang.String sKey)
          Find out whether or not a given parameter is null
 void resetParam(java.lang.String sKey)
          Remove parameter value
 void setAssert(java.lang.String sAssertKey, boolean bTrueOrFalse)
          Set true or false status for a fact
 void setParam(java.lang.String sKey, java.lang.Object oValue)
          Set value for parameter If parameter already exists then its value is replaced with the new one
 void setParams(java.util.Map oMap)
          Set values for a set of parameters If parameters already exist then theirs values are replaced with the new ones
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleExecution

public RuleExecution(RuleEngine oEngine)
Create RuleExecution on given RuleEngine

Parameters:
oEngine - RuleEngine

RuleExecution

public RuleExecution(RuleExecution oRexec)
Create copy from another RuleExecution

Parameters:
oRexec - RuleExecution
Method Detail

clear

public void clear()
Clear all parameters and asserts


getRuleEngine

public RuleEngine getRuleEngine()
Get RuleEngine to which this RuleExecution belongs

Returns:
RuleEngine

setAssert

public void setAssert(java.lang.String sAssertKey,
                      boolean bTrueOrFalse)
Set true or false status for a fact

Parameters:
sAssertKey - String A unique key in this RuleExecution for the fact
bTrueOrFalse - boolean

getAssert

public boolean getAssert(java.lang.String sAssertKey)
Get status of a given fact

Parameters:
sAssertKey - String A unique key in this RuleExecution for the fact
Returns:
boolean If no assertion with given key is found then false is returned.

getParamMap

public java.util.HashMap<java.lang.String,java.lang.Object> getParamMap()
Get map of parameters used by this RuleExecution

Returns:
HashMap

getAssertMap

public java.util.HashMap<java.lang.String,java.lang.Boolean> getAssertMap()
Get map of assertions used by this RuleExecution

Returns:
HashMap

isNull

public boolean isNull(java.lang.String sKey)
Find out whether or not a given parameter is null

Parameters:
sKey - String Parameter name
Returns:
boolean If parameter is null or if it has not defined value then the return value is true, else if the parameter is defined and has a value other than null the return value is false

isDefined

public boolean isDefined(java.lang.String sKey)
Find out whether or not a given parameter has a defined value

Parameters:
sKey - String Parameter Name
Returns:
boolean

setParam

public void setParam(java.lang.String sKey,
                     java.lang.Object oValue)

Set value for parameter

If parameter already exists then its value is replaced with the new one

Parameters:
sKey - String Parameter name
oValue - Object

resetParam

public void resetParam(java.lang.String sKey)
Remove parameter value

Parameters:
sKey - String Parameter name

setParams

public void setParams(java.util.Map oMap)
Set values for a set of parameters If parameters already exist then theirs values are replaced with the new ones

Parameters:
oMap - Map of values to be set

getParam

public java.lang.Object getParam(java.lang.String sKey)

Get parameter value

Parameters:
sKey - String Parameter Name
Returns:
Object If parameter is undefined then return value is null

getParam

public java.lang.Object getParam(java.lang.String sKey,
                                 java.lang.Object oDefault)

Get parameter value

Parameters:
sKey - String Parameter Name
oDefault - Default value
Returns:
Object If parameter is undefined then return value is oDefault

getParamStr

public java.lang.String getParamStr(java.lang.String sKey,
                                    java.lang.String sDefault)
Get parameter as String

Parameters:
sKey - String Parameter Name
sDefault - String Default value
Returns:
String

getParamStr

public java.lang.String getParamStr(java.lang.String sKey)
Get parameter as String

Parameters:
sKey - String Parameter Name
Returns:
String

getParamDate

public java.util.Date getParamDate(java.lang.String sKey,
                                   java.util.Date dtDefault)
                            throws java.lang.ClassCastException
Get parameter as java.util.Date

Parameters:
sKey - String Parameter Name
dtDefault - Date Default value
Returns:
Date If parameter is undefined then return value is dtDefault
Throws:
java.lang.ClassCastException

getParamDate

public java.util.Date getParamDate(java.lang.String sKey)
                            throws java.lang.ClassCastException
Get parameter as java.util.Date

Parameters:
sKey - String Parameter Name
Returns:
Date If parameter is undefined then return value is null
Throws:
java.lang.ClassCastException

getParamDec

public java.math.BigDecimal getParamDec(java.lang.String sKey,
                                        java.math.BigDecimal oDefault)
                                 throws java.lang.ClassCastException
Get parameter as BigDecimal

Parameters:
sKey - String Parameter Name
oDefault - BigDecimal
Returns:
BigDecimal If parameter is undefined then return value is dtDefault
Throws:
java.lang.ClassCastException

getParamDec

public java.math.BigDecimal getParamDec(java.lang.String sKey)
                                 throws java.lang.ClassCastException
Get parameter as BigDecimal

Parameters:
sKey - String Parameter Name
Returns:
BigDecimal
Throws:
java.lang.ClassCastException

getParamInt

public java.lang.Integer getParamInt(java.lang.String sKey,
                                     java.lang.Integer iDefault)
                              throws java.lang.ClassCastException
Get parameter as Integer

Parameters:
sKey - String Parameter Name
iDefault - Integer Default value
Returns:
Integer If parameter is undefined then return value is iDefault
Throws:
java.lang.ClassCastException

getParamInt

public java.lang.Integer getParamInt(java.lang.String sKey)
                              throws java.lang.ClassCastException
Get parameter as Integer

Parameters:
sKey - String Parameter Name
Returns:
Integer If parameter is undefined then return value is null
Throws:
java.lang.ClassCastException

getResult

public abstract java.lang.Object getResult()
                                    throws RuleExecutionException

Get result of applying this rule

This method must be implemented on eeach derived class for providing the actual behaviour of the RuleExecution instance

Returns:
Object
Throws:
RuleExecutionException

getExplanation

public abstract java.lang.Object getExplanation()
                                         throws RuleExecutionException

Get explanation about how the last result of applying this rule was computed

This method must be implemented on eeach derived class for providing the actual behaviour of the RuleExecution instance

Returns:
Object
Throws:
RuleExecutionException