commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression Expression.java ExpressionSupport.java
Date Fri, 20 Sep 2002 13:15:16 GMT
jstrachan    2002/09/20 06:15:16

  Modified:    jelly/src/java/org/apache/commons/jelly/expression
                        Expression.java ExpressionSupport.java
  Log:
  Added support for evaluateAsValue() which (though I don't like the name) will evaluate any
nested expressions.
  
  The evaluateAsString(), evaluateAsIterator() and evaluateAsBoolean() methods now use this
new method.
  
  The reason for this is that sometimes an expression may evaluate to be an Expression object.
So the evaluateAsValue() will evaluate the expression, then if the result is another Expression
it will keep evaluating it, recursively until its not an Expression.
  
  Care should be taken when making infinite Expression nesting!
  
  The reason for this fix is that often Maven will populate the Maven JellyContext with variables
which are Expressions (rather than the values of the expressions). So that ${maven.foo} when
evaluated would lookup the value of 'maven.foo', which could return an Expression.
  This change will hopefully provide auto-unwrapping of these 'nested expressions'
  
  Revision  Changes    Path
  1.5       +23 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Expression.java	17 May 2002 15:18:15 -0000	1.4
  +++ Expression.java	20 Sep 2002 13:15:16 -0000	1.5
  @@ -96,4 +96,22 @@
        * coercing the result to be an Iterator.
        */
       public Iterator evaluateAsIterator(JellyContext context);
  +
  +    /**
  +     * This method evaluates the expression until a value (a non-Expression) object
  +     * is returned. 
  +     * If the expression returns another expression, then the nested expression is evaluated.
  +     * <p>
  +     * Sometimes when Jelly is used inside Maven the value
  +     * of an expression can actually be another expression.
  +     * For example if a properties file is read, the values of variables
  +     * can actually be expressions themselves.
  +     * <p>
  +     * e.g. ${foo.bar} can lookup "foo.bar" in a Maven context
  +     * which could actually be another expression.
  +     * <p>
  +     * So using this method, nested expressions can be evaluated to the
  +     * actual underlying value object.
  +     */
  +    public Object evaluateAsValue(JellyContext context);
   }
  
  
  
  1.7       +24 -8     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java
  
  Index: ExpressionSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExpressionSupport.java	13 Jul 2002 01:03:27 -0000	1.6
  +++ ExpressionSupport.java	20 Sep 2002 13:15:16 -0000	1.7
  @@ -88,16 +88,32 @@
   
       // inherit javadoc from interface
       public String evaluateAsString(JellyContext context) {
  -        Object value = evaluate(context);
  +        Object value = evaluateAsValue(context);
  +        // sometimes when Jelly is used inside Maven the value
  +        // of an expression can actually be an expression.
  +        // e.g. ${foo.bar} can lookup "foo.bar" in a Maven context
  +        // which could actually be an expression
  +      
           if ( value != null ) {
               return value.toString();
           }
           return null;
       }
   
  +
       // inherit javadoc from interface
  -    public boolean evaluateAsBoolean(JellyContext context) {
  +    public Object evaluateAsValue(JellyContext context) {
           Object value = evaluate(context);
  +        if (value instanceof Expression) {
  +            Expression expression = (Expression) value;
  +            return expression.evaluateAsValue(context);
  +        }
  +        return value;
  +    }
  +    
  +    // inherit javadoc from interface
  +    public boolean evaluateAsBoolean(JellyContext context) {
  +        Object value = evaluateAsValue(context);
           if ( value instanceof Boolean ) {
               Boolean b = (Boolean) value;
               return b.booleanValue();
  @@ -127,7 +143,7 @@
   
       // inherit javadoc from interface
       public Iterator evaluateAsIterator(JellyContext context) {
  -        Object value = evaluate(context);
  +        Object value = evaluateAsValue(context);
           if ( value == null ) {
               return EMPTY_ITERATOR;
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message