com.ibm.commerce.condition
Class Condition

java.lang.Object
  |
  +--com.ibm.commerce.condition.Condition
All Implemented Interfaces:
ConditionConstants
Direct Known Subclasses:
ConditionList, OpenCondition, SimpleCondition, TrueCondition

public abstract class Condition
extends java.lang.Object
implements ConditionConstants

The Condition class is an abstract class that is used to describe a boolean condition. It has several subclasses that can be combined to form complex expressions. There are public methods that can be used to help convert to and from XML format. The class can also be used to evaluate the condition.


Field Summary
static java.lang.String COPYRIGHT
          Copyright.
 
Fields inherited from interface com.ibm.commerce.condition.ConditionConstants
AND_LIST_CONDITION, OPEN_CONDITION, OPERATOR_CONTAINS, OPERATOR_DOES_NOT_CONTAIN, OPERATOR_DOES_NOT_END_WITH, OPERATOR_DOES_NOT_START_WITH, OPERATOR_ENDS_WITH, OPERATOR_EQUAL_TO, OPERATOR_GREATER_THAN, OPERATOR_GREATER_THAN_OR_EQUAL_TO, OPERATOR_LESS_THAN, OPERATOR_LESS_THAN_OR_EQUAL_TO, OPERATOR_NOT_EQUAL_TO, OPERATOR_STARTS_WITH, OR_LIST_CONDITION, SIMPLE_CONDITION, TRUE_CONDITION, XML_DTD_FRAGMENT, XML_INDENT
 
Constructor Summary
Condition()
          Default constructor.
 
Method Summary
abstract  java.lang.Object clone()
          Returns a clone of this condition object.
abstract  boolean evaluate(Evaluator evaluator)
          This abstract method must be implemented by subclasses of this class.
 boolean getNot()
          Returns true if the condition should have the boolean "NOT" operator applied to the condition.
 int getType()
          Gets the condition type.
 java.lang.String getXMLFragment(java.lang.String indent)
          Gets an XML fragment that describes this condition.
static Condition loadConditionFromXML(org.w3c.dom.Element element)
          Loads a condition object from an XML element object.
 void setNot(boolean not)
          Sets the "NOT" attribute of the condition.
protected  void setType(int type)
          Sets the type of the condition.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Copyright.
Constructor Detail

Condition

public Condition()
Default constructor.
Method Detail

clone

public abstract java.lang.Object clone()
Returns a clone of this condition object.
Overrides:
clone in class java.lang.Object
Returns:
A clone of this condition object.

evaluate

public abstract boolean evaluate(Evaluator evaluator)
This abstract method must be implemented by subclasses of this class. Passing an appropriate implementation of the Evaluator interface to this condition will result in the condition being evaluated. The result will indicate if the condition evaluates to true or false.
Parameters:
evaluator - Used to evaluate instances of SimpleCondition and OpenCondition.
Returns:
true if the condition evaluates to true.

getNot

public boolean getNot()
Returns true if the condition should have the boolean "NOT" operator applied to the condition.

getType

public int getType()
Gets the condition type. This type will be equal to one of the following constants: TRUE_CONDITION, OR_LIST_CONDITION, AND_LIST_CONDITION, SIMPLE_CONDITION or OPEN_CONDITION

getXMLFragment

public java.lang.String getXMLFragment(java.lang.String indent)
Gets an XML fragment that describes this condition. The XML document will conform to the following DTD fragment:

<!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>

Parameters:
indent - A string of whitespace that is prefixed to each line of XML produced by this method.
Returns:
An XML fragment representing this condition.

loadConditionFromXML

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

setNot

public void setNot(boolean not)
Sets the "NOT" attribute of the condition. If this is set to true, then it indicates that the boolean "NOT" operator should be applied to the condition.
Parameters:
not - Indicates if the NOT operator should be applied.

setType

protected void setType(int type)
Sets the type of the condition. This protected method is called by the concrete subclasses of this class during their construction.
Parameters:
type - The type of this condition.