com.monad.homerun.rule
Class Clause

java.lang.Object
  extended by com.monad.homerun.rule.Clause
All Implemented Interfaces:
java.io.Serializable

public class Clause
extends java.lang.Object
implements java.io.Serializable

A Clause is a related set of Conditions and Tasks forming part of a Rule. When a clause is applied, if the conditions test to true, the tasks are performed.

See Also:
Serialized Form

Constructor Summary
Clause()
           
Clause(Clause clause)
           
 
Method Summary
 void addCondition(Condition condition)
          Adds a condition to the end of the clause's condition list
 void addCondition(int index, Condition condition)
          Adds a condition to the clause's condition list at specified index
 void addTask(int index, Task task)
          Adds a task to the clause's task list at sepcified index
 void addTask(Task task)
          Adds a task to the end of the clause's list list
 void addTemplateVars(java.util.Map<java.lang.String,java.lang.Object> context)
          Adds any new template variables to list in context
 boolean apply(java.util.Map<java.lang.String,java.lang.Object> context)
          Apply the clause - test conditions and if true, perform tasks
 Condition getCondition(int index)
          Returns the condition at the specified index
 java.lang.String getConditionStr(int index)
          Returns a decription of the condition at the specified index
 int getNumConditions()
          Returns the number of conditions in the clause (may be 0)
 int getNumTasks()
          Returns the number of the tasks in the clause (must be at least 1 if clause is valid)
 Task getTask(int index)
          Returns the task at the specified index
 java.lang.String getTaskStr(int index)
          Returns a decription of the task at the specified index
 boolean isStartable(Invoker invoker)
          is the clause startable? A clause is startable if it has at least on observable condition.
 boolean performActions(java.util.Map<java.lang.String,java.lang.Object> context)
          Performs the list of tasks in the clause
 void removeCondition(int index)
          Removes a condition from the clause's condition list at specified index
 void removeTask(int index)
          Removes a task at the specified index
 void replaceCondition(int index, Condition condition)
          Replaces a condition at the specified index
 void replaceTask(int index, Task task)
          Replaces the task at specified index with a new task
 boolean testConditions(java.util.Map<java.lang.String,java.lang.Object> context)
          Test the clause's conditions
 boolean validate(java.util.Map<java.lang.String,java.lang.Object> context)
          Tests the clause for validity
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clause

public Clause()

Clause

public Clause(Clause clause)
Method Detail

addCondition

public void addCondition(Condition condition)
Adds a condition to the end of the clause's condition list

Parameters:
condition - Condition added to end of list

addCondition

public void addCondition(int index,
                         Condition condition)
Adds a condition to the clause's condition list at specified index

Parameters:
index - Insertion index into condition list
condition - Condition added to end of list

removeCondition

public void removeCondition(int index)
Removes a condition from the clause's condition list at specified index

Parameters:
index - Index at which condition will be removed

replaceCondition

public void replaceCondition(int index,
                             Condition condition)
Replaces a condition at the specified index

Parameters:
index - Index at which condition will be replaced
condition - Condition to replace existing condition

addTask

public void addTask(Task task)
Adds a task to the end of the clause's list list

Parameters:
task - Task to be added to task list

addTask

public void addTask(int index,
                    Task task)
Adds a task to the clause's task list at sepcified index

Parameters:
index - Index at which condition will be added
task - Task to be added to task list at specified index

removeTask

public void removeTask(int index)
Removes a task at the specified index

Parameters:
index - Index at which task will be removed

replaceTask

public void replaceTask(int index,
                        Task task)
Replaces the task at specified index with a new task

Parameters:
index - Index at which task will be replaced
task - Task to replace existing task

isStartable

public boolean isStartable(Invoker invoker)
is the clause startable? A clause is startable if it has at least on observable condition.

Returns:
startable true if clause is startable

validate

public boolean validate(java.util.Map<java.lang.String,java.lang.Object> context)
Tests the clause for validity

Parameters:
invoker -
callStack -
trace -
Returns:
status true if clause is valid, else false

apply

public boolean apply(java.util.Map<java.lang.String,java.lang.Object> context)
              throws NoResourceException
Apply the clause - test conditions and if true, perform tasks

Parameters:
invoker -
callStack -
trace -
Returns:
result true if clause sucessfully applied
Throws:
NoResourceException

testConditions

public boolean testConditions(java.util.Map<java.lang.String,java.lang.Object> context)
                       throws NoResourceException
Test the clause's conditions

Parameters:
invoker -
trace -
Returns:
result true if conditions are true, else false
Throws:
NoResourceException

performActions

public boolean performActions(java.util.Map<java.lang.String,java.lang.Object> context)
Performs the list of tasks in the clause

Parameters:
context - the invocation context
Returns:
status true if all tasks performed, otherwise false

addTemplateVars

public void addTemplateVars(java.util.Map<java.lang.String,java.lang.Object> context)
Adds any new template variables to list in context


getNumConditions

public int getNumConditions()
Returns the number of conditions in the clause (may be 0)

Returns:
numConditions the number of conditions

getNumTasks

public int getNumTasks()
Returns the number of the tasks in the clause (must be at least 1 if clause is valid)

Returns:
num the number of tasks

getCondition

public Condition getCondition(int index)
Returns the condition at the specified index

Parameters:
index - the condition index
Returns:
condition the Condition object

getTask

public Task getTask(int index)
Returns the task at the specified index

Parameters:
index - the task index
Returns:
task the Task object

getConditionStr

public java.lang.String getConditionStr(int index)
Returns a decription of the condition at the specified index

Parameters:
index - the condition index
Returns:
string a description of the condition

getTaskStr

public java.lang.String getTaskStr(int index)
Returns a decription of the task at the specified index

Parameters:
index - the task index
Returns:
string a description of the task


Copyright © 2006-2009 Richard Rodgers. All Rights Reserved.