org.zilonis.shell
Class GenericEventHandler

java.lang.Object
  extended by org.zilonis.shell.GenericEventHandler
All Implemented Interfaces:
ParserEventHandler

public class GenericEventHandler
extends java.lang.Object
implements ParserEventHandler


Field Summary
protected  java.io.PrintStream console
           
protected static java.util.logging.Logger logger
           
protected  boolean prettyPrint
           
protected  Rete rete
           
protected  Scope scope
           
protected  java.io.PrintStream stderr
           
 
Constructor Summary
GenericEventHandler(Rete rete)
           
GenericEventHandler(Rete rete, java.io.PrintStream console)
           
 
Method Summary
protected  Action actionTemplate(java.lang.String strId, int type, java.lang.String clazz, antlr.collections.AST child)
           
protected  Action actionTemplateForClass(java.lang.String strId, int type, java.lang.String clazz, antlr.collections.AST child)
           
 void addProduction(java.lang.String name, int salience, Condition condition, Action action)
           
protected  Condition addRemainingAttributes(java.lang.String id, java.util.LinkedList<AttributeValuePair> attributesList, Condition condition)
          This method adds the new required conditions to allow the modify actions remove the correct WME
 void assertTriplet(Triplet triplet)
           
protected  Condition conditionTemplate(java.lang.String id, java.lang.String clazz, antlr.collections.AST child)
           
protected  Condition conditionTemplateForClass(java.lang.String id, java.lang.String clazz, antlr.collections.AST child)
           
 void defineAnonymousFact(java.lang.String id, java.lang.String clazz, antlr.collections.AST template)
           
 void defineClassFact(java.lang.String id, java.lang.String clazz, antlr.collections.AST template)
           
 void defineFact(antlr.collections.AST template)
           
 Condition defineRule(java.lang.String name, int salience, antlr.collections.AST conditionList, antlr.collections.AST actionList)
           
 void endDocument()
           
 void error(java.lang.Exception e, java.lang.String message)
           
protected  Action getAction(int id, antlr.collections.AST action, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Action getActionList(antlr.collections.AST actionList, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Action getActionTemplate(int id, int type, antlr.collections.AST actionTemplate)
           
protected  Condition getAssignmentCondition(java.lang.String id, antlr.collections.AST condition, antlr.collections.AST action, java.util.HashMap<java.lang.String,Entity> symbolTable)
          generates the conditions for an assignment on the left hand side example: (defrule wholesalerPricing ?x <- (SKU (wholesalerOnly true) (sellPrice ?price)) => (modify ?x (sellPrice 0) (listPrice (* ?price 0.75) (discountPrice (* 0.5 ?price)))) needs to be: (defrule wholesalerPricing (?id clazz SKU) // getConditionTemplate returns from here (?id wholesalerOnly true) (?id sellPrice ?price) // to here (?id listPrice ?id_var_1) (?id discountPrice ?id_var_2) => (retract (?id listPrice ?id_var_1)) (retract (?id discountPrice ?id_var_2)) (retract (?id sellPrice ?price)) (assert (?id sellPrice 0)) (assert (?id listPrice (* ?price 0.75))) (assert (?id discountPrice (* ?price 0.5)))) for achieving that, we first iterate over the actions to select the attributes that will be modified on the selected object.
protected  java.util.LinkedList<AttributeValuePair> getAttributesThatModifyActionsUseFromVariable(java.lang.String id, java.lang.String variable, antlr.collections.AST action)
          this method returns the that the modify actions modify on the specified variables the values are generated dynamically based on the id
protected  Condition getCondition(IdGenerator idGenerator, antlr.collections.AST condition, antlr.collections.AST action, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Condition getConditionList(antlr.collections.AST conditionList, antlr.collections.AST actionList, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Condition getConditionList(IdGenerator idGenerator, antlr.collections.AST conditionList, antlr.collections.AST actionList, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Condition getConditionTemplate(java.lang.String id, antlr.collections.AST conditionTemplate)
           
protected  Action getExpressionAction(int id, antlr.collections.AST action, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
protected  Action getModifyAction(antlr.collections.AST action, java.util.HashMap<java.lang.String,Entity> symbolTable)
           
 Rete getRete()
           
protected  Action getRetractAction(Condition c)
           
 Scope getScope()
           
 Condition getTestCondition(antlr.collections.AST condition)
           
 java.lang.String[] getVariables(antlr.collections.AST ast)
           
 WME jumpUntilNewId(WME wme)
           
 void link()
          Used only in UI tools.
 void listFacts()
           
 void loadFile(antlr.collections.AST filename)
           
 void noPrettyPrint()
           
 void prettyPrint()
           
protected  void replace(java.util.LinkedList<AttributeValuePair> attributesList, java.lang.String attribute, java.lang.String value)
           
protected  void replaceAttributesThatAreInConditions(java.util.LinkedList<AttributeValuePair> attributesList, Condition condition)
          We check each condition to make sure that the conditions that were already in the rule are not define twice
 void retractAllFacts()
           
 void retractTriplet(Triplet triplet)
           
 void run()
           
protected  void setConditionsAndSalienceTo(Action action, Condition earlierCondition, int salience)
           
 void setConsole(java.io.PrintStream console)
           
 void setScope(Scope scope)
           
 void startDocument()
           
 void unlink()
          Used by the UI tools To unlink the creation of rules from the UI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rete

protected Rete rete

scope

protected Scope scope

console

protected java.io.PrintStream console

stderr

protected java.io.PrintStream stderr

prettyPrint

protected boolean prettyPrint

logger

protected static final java.util.logging.Logger logger
Constructor Detail

GenericEventHandler

public GenericEventHandler(Rete rete)

GenericEventHandler

public GenericEventHandler(Rete rete,
                           java.io.PrintStream console)
Method Detail

getRete

public Rete getRete()

setScope

public void setScope(Scope scope)

getScope

public Scope getScope()

setConsole

public void setConsole(java.io.PrintStream console)

run

public void run()
Specified by:
run in interface ParserEventHandler

retractAllFacts

public void retractAllFacts()
Specified by:
retractAllFacts in interface ParserEventHandler

prettyPrint

public void prettyPrint()
Specified by:
prettyPrint in interface ParserEventHandler

noPrettyPrint

public void noPrettyPrint()
Specified by:
noPrettyPrint in interface ParserEventHandler

unlink

public void unlink()
Used by the UI tools To unlink the creation of rules from the UI

Specified by:
unlink in interface ParserEventHandler

link

public void link()
Description copied from interface: ParserEventHandler
Used only in UI tools. If the link is called, it is expected that the UI will react to the commands that are executed

Specified by:
link in interface ParserEventHandler

listFacts

public void listFacts()
Specified by:
listFacts in interface ParserEventHandler

jumpUntilNewId

public WME jumpUntilNewId(WME wme)

loadFile

public void loadFile(antlr.collections.AST filename)
Specified by:
loadFile in interface ParserEventHandler

defineFact

public void defineFact(antlr.collections.AST template)
Specified by:
defineFact in interface ParserEventHandler

defineAnonymousFact

public void defineAnonymousFact(java.lang.String id,
                                java.lang.String clazz,
                                antlr.collections.AST template)

defineClassFact

public void defineClassFact(java.lang.String id,
                            java.lang.String clazz,
                            antlr.collections.AST template)

defineRule

public Condition defineRule(java.lang.String name,
                            int salience,
                            antlr.collections.AST conditionList,
                            antlr.collections.AST actionList)
Specified by:
defineRule in interface ParserEventHandler

setConditionsAndSalienceTo

protected void setConditionsAndSalienceTo(Action action,
                                          Condition earlierCondition,
                                          int salience)

getConditionList

protected Condition getConditionList(antlr.collections.AST conditionList,
                                     antlr.collections.AST actionList,
                                     java.util.HashMap<java.lang.String,Entity> symbolTable)

getConditionList

protected Condition getConditionList(IdGenerator idGenerator,
                                     antlr.collections.AST conditionList,
                                     antlr.collections.AST actionList,
                                     java.util.HashMap<java.lang.String,Entity> symbolTable)

getCondition

protected Condition getCondition(IdGenerator idGenerator,
                                 antlr.collections.AST condition,
                                 antlr.collections.AST action,
                                 java.util.HashMap<java.lang.String,Entity> symbolTable)

getTestCondition

public Condition getTestCondition(antlr.collections.AST condition)

getVariables

public java.lang.String[] getVariables(antlr.collections.AST ast)

getAssignmentCondition

protected Condition getAssignmentCondition(java.lang.String id,
                                           antlr.collections.AST condition,
                                           antlr.collections.AST action,
                                           java.util.HashMap<java.lang.String,Entity> symbolTable)
generates the conditions for an assignment on the left hand side example: (defrule wholesalerPricing ?x <- (SKU (wholesalerOnly true) (sellPrice ?price)) => (modify ?x (sellPrice 0) (listPrice (* ?price 0.75) (discountPrice (* 0.5 ?price)))) needs to be: (defrule wholesalerPricing (?id clazz SKU) // getConditionTemplate returns from here (?id wholesalerOnly true) (?id sellPrice ?price) // to here (?id listPrice ?id_var_1) (?id discountPrice ?id_var_2) => (retract (?id listPrice ?id_var_1)) (retract (?id discountPrice ?id_var_2)) (retract (?id sellPrice ?price)) (assert (?id sellPrice 0)) (assert (?id listPrice (* ?price 0.75))) (assert (?id discountPrice (* ?price 0.5)))) for achieving that, we first iterate over the actions to select the attributes that will be modified on the selected object. From those actions we get the variables. In the above example that would include listPrice and discountPrice. This operation is done in getAttributesThatModifyActionsUseFromVariable After that, we modify the attributes that are already in use in the conditions. Then we add the attributes that were left as another condition to the condition list. and finally creating the entity for the symbol table to be use when generating the actions


addRemainingAttributes

protected Condition addRemainingAttributes(java.lang.String id,
                                           java.util.LinkedList<AttributeValuePair> attributesList,
                                           Condition condition)
This method adds the new required conditions to allow the modify actions remove the correct WME


replaceAttributesThatAreInConditions

protected void replaceAttributesThatAreInConditions(java.util.LinkedList<AttributeValuePair> attributesList,
                                                    Condition condition)
We check each condition to make sure that the conditions that were already in the rule are not define twice


replace

protected void replace(java.util.LinkedList<AttributeValuePair> attributesList,
                       java.lang.String attribute,
                       java.lang.String value)

getAttributesThatModifyActionsUseFromVariable

protected java.util.LinkedList<AttributeValuePair> getAttributesThatModifyActionsUseFromVariable(java.lang.String id,
                                                                                                 java.lang.String variable,
                                                                                                 antlr.collections.AST action)
this method returns the that the modify actions modify on the specified variables the values are generated dynamically based on the id


getConditionTemplate

protected Condition getConditionTemplate(java.lang.String id,
                                         antlr.collections.AST conditionTemplate)

conditionTemplateForClass

protected Condition conditionTemplateForClass(java.lang.String id,
                                              java.lang.String clazz,
                                              antlr.collections.AST child)

conditionTemplate

protected Condition conditionTemplate(java.lang.String id,
                                      java.lang.String clazz,
                                      antlr.collections.AST child)

getActionList

protected Action getActionList(antlr.collections.AST actionList,
                               java.util.HashMap<java.lang.String,Entity> symbolTable)

getAction

protected Action getAction(int id,
                           antlr.collections.AST action,
                           java.util.HashMap<java.lang.String,Entity> symbolTable)

getExpressionAction

protected Action getExpressionAction(int id,
                                     antlr.collections.AST action,
                                     java.util.HashMap<java.lang.String,Entity> symbolTable)

getModifyAction

protected Action getModifyAction(antlr.collections.AST action,
                                 java.util.HashMap<java.lang.String,Entity> symbolTable)

getRetractAction

protected Action getRetractAction(Condition c)

getActionTemplate

protected Action getActionTemplate(int id,
                                   int type,
                                   antlr.collections.AST actionTemplate)

actionTemplateForClass

protected Action actionTemplateForClass(java.lang.String strId,
                                        int type,
                                        java.lang.String clazz,
                                        antlr.collections.AST child)

actionTemplate

protected Action actionTemplate(java.lang.String strId,
                                int type,
                                java.lang.String clazz,
                                antlr.collections.AST child)

startDocument

public void startDocument()

endDocument

public void endDocument()

assertTriplet

public void assertTriplet(Triplet triplet)

retractTriplet

public void retractTriplet(Triplet triplet)

addProduction

public void addProduction(java.lang.String name,
                          int salience,
                          Condition condition,
                          Action action)

error

public void error(java.lang.Exception e,
                  java.lang.String message)