com.ibm.wbi.util
Class StructuredCondition

java.lang.Object
  |
  +--com.ibm.wbi.util.StructuredCondition

public class StructuredCondition
extends java.lang.Object

Used to parse, store, and evaluate a Boolean expression involving attribute-value pairs. It can handle arbitrary levels of parentheses, the operators & (boolean AND), | (boolean OR), and ! (unary boolean NOT).

The basic expressions for evaluating an attribute-value pair are: AttributeName = Value and AttributeName ~ Value. The '~' operator is a case-insensitive comparison. The Value can be the special value '%null%' which means that the given AttributeName should not be defined.

Values can also be expressed with a wildcard character(s). '*' at the beginning of the Value indicates that only the ends of the strings need match. Likewise, '*' at the end means only the beginnings of the strings need match. And '*' at both the beginning and end of the Value indicates that the Value only needs to be contained in the string.

Values can be enclosed within quotes (for example, "abc"). This allows characters that are normally treated as operators, such as &, to be included within a value. To enclose a quote within the quoted value, precede it with the backslash (\). If Java will parse the String, such as when you enter the String in Java code in double quotes or it is read from a properties file (persistent Section) such as one describing a MEG, you will need to use three backslashes:

 "beforequote\\\"afterquote"
 

If the value is not within quotes, spaces are allowed within values, but not at either end. Thus "User-Agent=*Windows CE*" is allowed, while "User-Agent= Windows " would be treated the same as "User-Agent=Windows". To include spaces at the beginning or end of a value, enclose the value in quotes.

Two special boolean values, %true% and %false%, can also be used. For example, a condition that is always true is "%true%". Example conditions are:


Constructor Summary
StructuredCondition()
          Construct a new empty StructuredCondition.
StructuredCondition(boolean compareAsLowerCaseOnly)
          Construct a new empty StructuredCondition.
 
Method Summary
 boolean getCompareAsLowerCaseOnly()
          Returns the flag whether field values should be compared lower case only.
 java.lang.String getCondition()
          Get the condition.
 java.util.Enumeration getFieldnames()
          Get the field names references in the condition
 void setCondition(java.lang.String condition)
          Set and parse the condition specified.
 void setCondition(java.lang.String condition, java.lang.String[] allowedRules)
          Set and parse the condition specified.
 void setCondition(java.lang.String condition, java.lang.String[] allowedRules, boolean caseSensitive)
          Set and parse the condition specified.
 boolean solve(java.util.Dictionary d)
          Determine if the condition solves the Attribute-Value pairs specified in the Dictionary parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredCondition

public StructuredCondition()
Construct a new empty StructuredCondition.

StructuredCondition

public StructuredCondition(boolean compareAsLowerCaseOnly)
Construct a new empty StructuredCondition.
Parameters:
compareAsLowerCaseOnly - Compares all values as lower case if true, otherwise uses case.
Method Detail

getCompareAsLowerCaseOnly

public boolean getCompareAsLowerCaseOnly()
Returns the flag whether field values should be compared lower case only.
Returns:
Boolean value.

setCondition

public void setCondition(java.lang.String condition)
                  throws IllegalConditionException
Set and parse the condition specified. There are no limitations on the rules (Attributes) allowed.
Parameters:
condition - The condition to parse.
Throws:
IllegalConditionException - If an error occurs parsing the condition.

setCondition

public void setCondition(java.lang.String condition,
                         java.lang.String[] allowedRules)
                  throws IllegalConditionException
Set and parse the condition specified. The only allowed rules (Attributes) are specified in the allowedRules array. If the array is of zero length, rules are not verified. The rules are not case sensitive.
Parameters:
condition - The condition to parse.
allowedRules - An array of the rules (Attributes) allowed, these rules may have wild cards, so for example, a rule of "re*" would allow rules such as "responseCode" or "requestHeader".
Throws:
IllegalConditionException - If an error occurs parsing the condition or a rule is invalid.

setCondition

public void setCondition(java.lang.String condition,
                         java.lang.String[] allowedRules,
                         boolean caseSensitive)
                  throws IllegalConditionException
Set and parse the condition specified. The only allowed rules (Attributes) are specified in the allowedRules array. If the array is of zero length, rules are not verified.
Parameters:
condition - The condition to parse.
allowedRules - An array of the rules (Attributes) allowed, these rules may have wild cards, so for example, a rule of "re*" would allow rules such as "responseCode" or "requestHeader".
caseSensitive - Determines if the rules should be verified as case sensitive.
Throws:
IllegalConditionException - If an error occurs parsing the condition or a rule is invalid.

getCondition

public java.lang.String getCondition()
Get the condition.
Returns:
The condition.

getFieldnames

public java.util.Enumeration getFieldnames()
Get the field names references in the condition
Returns:
an enumeration of the field names

solve

public boolean solve(java.util.Dictionary d)
Determine if the condition solves the Attribute-Value pairs specified in the Dictionary parameter.
Parameters:
d - the Attribute-Value pairs to check against.
Returns:
true if condition "solves" Dictionary; else false.