|
BEA Systems, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.beasys.commerce.util.ExpressionHelper
Helper class to handle dealing with Expression, Criteria, and Logical objects.
Expression
,
Criteria
,
Logical
Constructor Summary | |
ExpressionHelper()
|
Method Summary | |
static java.lang.String |
fromStringLiteral(java.lang.String in)
Convert a String literal (which may contain quoted characters) into a corresponding String value. |
static Logical |
join(Expression expr1,
Expression expr2)
Join together two expression via an AND expression. |
static Expression |
normalize(Expression expr)
Normalize an Expression. |
static Expression |
parse(java.lang.String queryStr)
Convert a query expression string into an Expression object. |
static void |
printTree(int depth,
java.io.PrintWriter out,
Expression expr)
For debug purposes, print the given expression as a tree at the given depth. |
static void |
printTree(java.io.PrintWriter out,
Expression expr)
For debug purposes, print the given expression as a tree. |
static java.lang.String |
toString(Criteria c)
Return a string representation of the given criteria. |
static java.lang.String |
toString(Expression expr)
Get a string representation of the given expression. |
static java.lang.String |
toString(Logical l)
Return a string representation of the given Logical. |
static java.lang.String |
toStringLiteral(java.lang.String in)
Get a String literal from a Java string. |
static java.lang.String |
toTree(Expression expr)
For debug purposes, return a tree representation of the given expression. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ExpressionHelper()
Method Detail |
public static Expression parse(java.lang.String queryStr) throws java.lang.IllegalArgumentException
The string should follow the query syntax specified in the
Personalization Server documentation. The expression syntax is
tree-based, with each leaf in the tree beinging of the form "property
comparator value" (e.g. "identifier == '1234'"). String literal values
are enclosed in single quotes (back-slash is the quoting character,
unicode character not yet supported). Boolean literal are either the
"true" or "false" keyword (without quotes). Number literals are Java
form (scientific notation is supported). Time literals are presented
in "toDate(['formatStr'], 'dateStr')" format. formatStr must be a valid
java.text.SimpleDateFormat format string; if omitted, 'MM/dd/yyyy
HH:mm:ss z' is used. Also, the "now" keyword specifies the current
time/date. Collections cannot be represented in the
expression syntax. The valid comparision operators are = (or ==),
!=, <, >, <=, >=, "like", and "contains".
The "like" operator expects
the pattern (which is the value of the leaf) to use * (match all) and ?
(match any). To specify a property names
which contain non-identifier characters (e.g. whitespace, double quotes,
dashes), you can use the "toProperty('property name')" form in the
left-hand-side.
Each branch in the tree is comprised of 1 or more leafs or branches
separated by either "&&" (boolean AND) or "||" (boolean OR).
They can be enclosed in parenthesis for clearity and ordering (AND has
precendance over OR). Additionally, "!" marks a branch as using
negative logical (boolean NOT). The "!" operator can only be used
preceding an open parenthesis.
Examples of valid expression strings:
queryStr
- the query expression stringnormalize(com.beasys.commerce.foundation.expression.Expression)
public static Logical join(Expression expr1, Expression expr2)
expr1
- the first expression.expr2
- the second expression.public static Expression normalize(Expression expr)
This will remove:
expr
- the incoming expression.public static java.lang.String toString(Expression expr)
Pretty much, a string generated from this method can be parse()'ed into the equivalent (not neccessarily identical) expression tree.
expr
- the expression.public static java.lang.String toString(Criteria c)
public static java.lang.String toString(Logical l)
public static java.lang.String toTree(Expression expr)
public static void printTree(java.io.PrintWriter out, Expression expr)
out
- the output stream to print on.expr
- the expression.public static void printTree(int depth, java.io.PrintWriter out, Expression expr)
depth
- the depth of this expression in the tree.out
- the output stream to print on.expr
- the expression.public static java.lang.String fromStringLiteral(java.lang.String in)
This does not currently support quoted hex or unicode characters.
in
- the input string literal.public static java.lang.String toStringLiteral(java.lang.String in)
This will quote some special characters with back-slashes.
This does not currently quote unicode character correctly.
|
BEA Systems, Inc. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |