org.jactr.scripting.condition
Class ScriptableCondition

java.lang.Object
  extended by org.jactr.scripting.condition.ScriptableCondition
All Implemented Interfaces:
ICondition

public class ScriptableCondition
extends java.lang.Object
implements ICondition

ScriptableCondition allows for custom actions. You set the script via setScript(String ) - it must contain a function matches(model, chunk, bindings) { return {true | false}; }

Author:
harrison

Field Summary
static java.lang.String DEFAULT_SCRIPT
          Description of the Field
 
Constructor Summary
ScriptableCondition()
          Constructor for the ScriptableCondition object
ScriptableCondition(java.lang.String script)
          Constructor for the ScriptableCondition object
 
Method Summary
 int bind(IModel model, java.util.Map<java.lang.String,java.lang.Object> variableBindings, boolean isIterative)
          Iteratively perform the resolution and binding for this condition.
 ScriptableCondition clone(IModel model, java.util.Map<java.lang.String,java.lang.Object> bindings)
          attempt to clone this condition before it will be bound in the instantiation phase.
 void dispose()
          Description of the Method
 java.lang.String getScript()
          Gets the script attribute of the ScriptableCondition object
 void setScriptString(java.lang.String str)
          Sets the script attribute of the ScriptableCondition object
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SCRIPT

public static final java.lang.String DEFAULT_SCRIPT
Description of the Field

See Also:
Constant Field Values
Constructor Detail

ScriptableCondition

public ScriptableCondition()
Constructor for the ScriptableCondition object


ScriptableCondition

public ScriptableCondition(java.lang.String script)
Constructor for the ScriptableCondition object

Parameters:
script - Description of the Parameter
Method Detail

clone

public ScriptableCondition clone(IModel model,
                                 java.util.Map<java.lang.String,java.lang.Object> bindings)
                          throws CannotMatchException
Description copied from interface: ICondition
attempt to clone this condition before it will be bound in the instantiation phase. We pass the current bindings so that the condition can do an early rejection if possible.

Specified by:
clone in interface ICondition
Returns:
a writable copy of the condition that will be bound
Throws:
CannotMatchException - if there is no way this condition can be matched

dispose

public void dispose()
Description of the Method

Specified by:
dispose in interface ICondition

getScript

public java.lang.String getScript()
Gets the script attribute of the ScriptableCondition object

Returns:
The script value

setScriptString

public void setScriptString(java.lang.String str)
Sets the script attribute of the ScriptableCondition object

Parameters:
str - The new script value

bind

public int bind(IModel model,
                java.util.Map<java.lang.String,java.lang.Object> variableBindings,
                boolean isIterative)
         throws CannotMatchException
Description copied from interface: ICondition
Iteratively perform the resolution and binding for this condition. If this condition defines any variables, they are placed into the bindings map for other conditions to exploit. Similarly, it will resolve any bindings that it needs in order to be matched. If at any point the condition determines that it cannot be matched, the exception is to be thrown. Similarly, if isIterative is false, and there are unresolved bindings, the exception should be thrown.
Otherwise, the number of unresolved bindings is returned which allows the instantiation calculation determine if another resolution round is required.

Specified by:
bind in interface ICondition
Returns:
number of unresolved variables
Throws:
CannotMatchException