KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > query > NestedExpression


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.query;
6
7
8 /**
9  * Nested expressions are used when constructing a workflow query.
10  * A nested expression consists of:
11  * <li>one or more expressions: Each of them can again be a NestedExpression.
12  * <li>operator: The operator used to evaluate the value of the nested expression
13  * from the specified sub expressions.
14  *
15  * @author Christine Zimmermann
16  * @version $Revision: 1.3 $
17  */

18 public class NestedExpression extends Expression {
19     //~ Static fields/initializers /////////////////////////////////////////////
20

21     /**
22     * Constant to specify that all the expressions specified must evaluate to true for
23     * an item to be included in the search results.
24     */

25     public final static int AND = 6;
26
27     /**
28      * Constant to specify that at least one of the expressions specified must evaluate to true
29      * for an item to be included in the search results.
30      */

31     public final static int OR = 7;
32
33     //~ Instance fields ////////////////////////////////////////////////////////
34

35     private Expression[] expressions = null;
36     private int expressionOperator = AND;
37
38     //~ Constructors ///////////////////////////////////////////////////////////
39

40     public NestedExpression() {
41     }
42
43     /**
44     * Create a NestedExpression that consists of multiple expressions.
45     * @param expressions an array of expressions for this query.
46     * @param operator {@link NestedExpression#AND} or {@link NestedExpression#OR}.
47     */

48     public NestedExpression(Expression[] expressions, int operator) {
49         this.expressions = expressions;
50         this.expressionOperator = operator;
51     }
52
53     //~ Methods ////////////////////////////////////////////////////////////////
54

55     public Expression getExpression(int index) {
56         return expressions[index];
57     }
58
59     /**
60      * Get the number of expressions in this query.
61      */

62     public int getExpressionCount() {
63         return expressions.length;
64     }
65
66     public void setExpressionOperator(int expressionOperator) {
67         this.expressionOperator = expressionOperator;
68     }
69
70     /**
71      * @return {@link NestedExpression#AND} if all the expressions must match,
72      * or {@link NestedExpression#OR} if only one must match.
73      */

74     public int getExpressionOperator() {
75         return this.expressionOperator;
76     }
77
78     public void setExpressions(Expression[] expressions) {
79         this.expressions = expressions;
80     }
81
82     public boolean isNested() {
83         return true;
84     }
85 }
86
Popular Tags