View Javadoc

1   /*
2    * Copyright 2002,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.jelly.expression;
17  
18  import java.util.Iterator;
19  
20  import org.apache.commons.jelly.JellyContext;
21  
22  /*** <p><code>Expression</code> represents an arbitrary expression using some pluggable
23    * expression language.</p>
24    *
25    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26    * @version $Revision: 155420 $
27    */
28  public interface Expression {
29  
30      /***
31       * @return the textual representation of this expression
32       */
33      public String getExpressionText();
34  
35      /***
36       * Evaluates the expression with the given context
37       * and returns the result
38       */
39      public Object evaluate(JellyContext context);
40  
41      /***
42       * Evaluates the expression with the given context
43       * coercing the result to be a String.
44       */
45      public String evaluateAsString(JellyContext context);
46  
47      /***
48       * Evaluates the expression with the given context
49       * coercing the result to be a boolean.
50       */
51      public boolean evaluateAsBoolean(JellyContext context);
52  
53      /***
54       * Evaluates the expression with the given context
55       * coercing the result to be an Iterator.
56       */
57      public Iterator evaluateAsIterator(JellyContext context);
58  
59      /***
60       * This method evaluates the expression until a value (a non-Expression) object
61       * is returned.
62       * If the expression returns another expression, then the nested expression is evaluated.
63       * <p>
64       * Sometimes when Jelly is used inside Maven the value
65       * of an expression can actually be another expression.
66       * For example if a properties file is read, the values of variables
67       * can actually be expressions themselves.
68       * <p>
69       * e.g. ${foo.bar} can lookup "foo.bar" in a Maven context
70       * which could actually be another expression.
71       * <p>
72       * So using this method, nested expressions can be evaluated to the
73       * actual underlying value object.
74       */
75      public Object evaluateRecurse(JellyContext context);
76  }