01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.query;
06:
07: /**
08: * Nested expressions are used when constructing a workflow query.
09: * A nested expression consists of:
10: * <li>one or more expressions: Each of them can again be a NestedExpression.
11: * <li>operator: The operator used to evaluate the value of the nested expression
12: * from the specified sub expressions.
13: *
14: * @author Christine Zimmermann
15: */
16: public class NestedExpression extends Expression {
17: //~ Static fields/initializers /////////////////////////////////////////////
18:
19: /**
20: * Constant to specify that all the expressions specified must evaluate to true for
21: * an item to be included in the search results.
22: */
23: public final static int AND = 6;
24:
25: /**
26: * Constant to specify that at least one of the expressions specified must evaluate to true
27: * for an item to be included in the search results.
28: */
29: public final static int OR = 7;
30:
31: //~ Instance fields ////////////////////////////////////////////////////////
32:
33: private Expression[] expressions = null;
34: private int expressionOperator = AND;
35:
36: //~ Constructors ///////////////////////////////////////////////////////////
37:
38: public NestedExpression() {
39: }
40:
41: /**
42: * Create a NestedExpression that consists of multiple expressions.
43: * @param expressions an array of expressions for this query.
44: * @param operator {@link NestedExpression#AND} or {@link NestedExpression#OR}.
45: */
46: public NestedExpression(Expression[] expressions, int operator) {
47: this .expressions = expressions;
48: this .expressionOperator = operator;
49: }
50:
51: //~ Methods ////////////////////////////////////////////////////////////////
52:
53: public Expression getExpression(int index) {
54: return expressions[index];
55: }
56:
57: /**
58: * Get the number of expressions in this query.
59: */
60: public int getExpressionCount() {
61: return expressions.length;
62: }
63:
64: public void setExpressionOperator(int expressionOperator) {
65: this .expressionOperator = expressionOperator;
66: }
67:
68: /**
69: * @return {@link NestedExpression#AND} if all the expressions must match,
70: * or {@link NestedExpression#OR} if only one must match.
71: */
72: public int getExpressionOperator() {
73: return this .expressionOperator;
74: }
75:
76: public void setExpressions(Expression[] expressions) {
77: this .expressions = expressions;
78: }
79:
80: public boolean isNested() {
81: return true;
82: }
83: }
|