com.ibm.commerce.rule
Class Rule

java.lang.Object
  |
  +--com.ibm.commerce.rule.Rule
All Implemented Interfaces:
RuleConstants

public final class Rule
extends java.lang.Object
implements RuleConstants

This class binds a condition to an action. It also contains methods that help convert a rule to and from XML format.


Field Summary
static java.lang.String COPYRIGHT
           
 
Fields inherited from interface com.ibm.commerce.rule.RuleConstants
XML_DTD_FRAGMENT, XML_INDENT
 
Constructor Summary
Rule(Condition condition, Action action)
          This constructor takes a Condition object and an Action object.
 
Method Summary
 Action getAction()
          Gets the action for this rule.
 java.lang.String getComment()
          Gets the comment for this rule.
 Condition getCondition()
          Gets the condition for this rule.
 java.lang.String getXMLDocument()
          Gets an XML document that describes this rule.
 java.lang.String getXMLFragment(java.lang.String indent)
          Gets an XML fragment that describes the rule.
 void invoke(Evaluator evaluator, ActionHandler handler)
          Invoke the rule.
static Rule loadRuleFromXML(org.w3c.dom.Element element)
          Loads a Rule object from an XML element object.
static Rule loadRuleFromXML(java.lang.String xml)
          Loads a Rule object from an XML document.
 void setAction(Action action)
          Sets the action for this rule.
 void setComment(java.lang.String comment)
          Sets the comment for this rule.
 void setCondition(Condition condition)
          Sets the condition for this rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

Rule

public Rule(Condition condition,
            Action action)
This constructor takes a Condition object and an Action object.
Method Detail

getAction

public Action getAction()
Gets the action for this rule.
Returns:
An Action object.

getComment

public java.lang.String getComment()
Gets the comment for this rule.
Returns:
A comment string.

getCondition

public Condition getCondition()
Gets the condition for this rule.
Returns:
A Condition object.

getXMLDocument

public java.lang.String getXMLDocument()
Gets an XML document that describes this rule. The XML document will conform to the following DTD:

<!DOCTYPE rule [
<!ELEMENT rule (comment?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition), action)>
<!ELEMENT comment EMPTY>
<!ATTLIST comment text CDATA #REQUIRED>
<!ELEMENT action (parameter*)>
<!ATTLIST action name CDATA #REQUIRED>
<!ELEMENT orListCondition (not?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition)+)>
<!ELEMENT andListCondition (not?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition)+)>
<!ELEMENT simpleCondition (not?, variable, operator, value, qualifier*)>
<!ELEMENT openCondition (not?, parameter*)>
<!ATTLIST openCondition name CDATA #REQUIRED>
<!ELEMENT trueCondition (not?)>
<!ELEMENT not EMPTY>
<!ELEMENT variable EMPTY>
<!ATTLIST variable name CDATA #REQUIRED>
<!ELEMENT operator EMPTY>
<!ATTLIST operator name CDATA #REQUIRED>
<!ELEMENT value EMPTY>
<!ATTLIST value data CDATA #REQUIRED>
<!ELEMENT qualifier EMPTY>
<!ATTLIST qualifier name CDATA #REQUIRED>
<!ATTLIST qualifier data CDATA #REQUIRED>
<!ELEMENT parameter (parameter*)>
<!ATTLIST parameter name CDATA #REQUIRED>
<!ATTLIST parameter value CDATA #REQUIRED>
]>

Returns:
An XML document.

getXMLFragment

public java.lang.String getXMLFragment(java.lang.String indent)
Gets an XML fragment that describes the rule. This XML fragment will conform to the following DTD fragment:

<!ELEMENT rule (comment?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition), action)>
<!ELEMENT comment EMPTY>
<!ATTLIST comment text CDATA #REQUIRED>
<!ELEMENT action (parameter*)>
<!ATTLIST action name CDATA #REQUIRED>
<!ELEMENT orListCondition (not?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition)+)>
<!ELEMENT andListCondition (not?, (orListCondition | andListCondition | simpleCondition | trueCondition | openCondition)+)>
<!ELEMENT simpleCondition (not?, variable, operator, value, qualifier*)>
<!ELEMENT openCondition (not?, parameter*)>
<!ATTLIST openCondition name CDATA #REQUIRED>
<!ELEMENT trueCondition (not?)>
<!ELEMENT not EMPTY>
<!ELEMENT variable EMPTY>
<!ATTLIST variable name CDATA #REQUIRED>
<!ELEMENT operator EMPTY>
<!ATTLIST operator name CDATA #REQUIRED>
<!ELEMENT value EMPTY>
<!ATTLIST value data CDATA #REQUIRED>
<!ELEMENT qualifier EMPTY>
<!ATTLIST qualifier name CDATA #REQUIRED>
<!ATTLIST qualifier data CDATA #REQUIRED>
<!ELEMENT parameter (parameter*)>
<!ATTLIST parameter name CDATA #REQUIRED>
<!ATTLIST parameter value CDATA #REQUIRED>

Returns:
An XML fragment.

invoke

public void invoke(Evaluator evaluator,
                   ActionHandler handler)
Invoke the rule. If the condition evaluates to true, then the action is performed.
Parameters:
evaluator - The Evaluator that is used to evaluate the condition.
handler - The ActionHandler that is used to perform the action.

loadRuleFromXML

public static Rule loadRuleFromXML(org.w3c.dom.Element element)
Loads a Rule object from an XML element object.
Parameters:
element - An XML Element object.
Returns:
A Rule object that matches the XML.

loadRuleFromXML

public static Rule loadRuleFromXML(java.lang.String xml)
Loads a Rule object from an XML document.
Parameters:
xml - An XML document.
Returns:
A Rule object that matches the XML.

setAction

public void setAction(Action action)
Sets the action for this rule.
Parameters:
action - An Action object.

setComment

public void setComment(java.lang.String comment)
Sets the comment for this rule.
Parameters:
comment - A comment string.

setCondition

public void setCondition(Condition condition)
Sets the condition for this rule.
Parameters:
condition - A Condition object.