commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r795421 [1/2] - in /commons/proper/jexl/branches/2.0: ./ src/java/org/apache/commons/jexl/ src/java/org/apache/commons/jexl/util/ src/java/org/apache/commons/jexl/util/introspection/ src/test/org/apache/commons/jexl/
Date Sat, 18 Jul 2009 19:26:03 GMT
Author: rahul
Date: Sat Jul 18 19:26:02 2009
New Revision: 795421

URL: http://svn.apache.org/viewvc?rev=795421&view=rev
Log:
JEXL-20
 - Various checkstyle, Javadoc improvements
 - Exclude generated classes from test coverage

JEXL-59
 - ClassMap holds a reference to class

Thanks to patch by Henri Biestro <hbiestro at gmail dot com>.

Modified:
    commons/proper/jexl/branches/2.0/pom.xml
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionFactory.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionImpl.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/UnifiedJEXL.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/EnumerationIterator.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/ClassMap.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/Introspector.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectorBase.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/MethodMap.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/Uberspect.java
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
    commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/IssuesTest.java

Modified: commons/proper/jexl/branches/2.0/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/pom.xml?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/pom.xml (original)
+++ commons/proper/jexl/branches/2.0/pom.xml Sat Jul 18 19:26:02 2009
@@ -205,6 +205,14 @@
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>cobertura-maven-plugin</artifactId>
           <version>2.3</version>
+          <configuration>
+            <instrumentation>
+              <excludes>
+                <exclude>org/apache/commons/jexl/parser/*.class</exclude>
+                <exclude>apache/commons/jexl/**/*Test.class</exclude>
+              </excludes>
+            </instrumentation>
+          </configuration>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java Sat Jul 18 19:26:02 2009
@@ -105,6 +105,13 @@
      * @return a double
      */
     double toDouble(Object arg);
+
+    /**
+     * Coerce an object into a string.
+     * @param arg the object to coerce
+     * @return a double
+     */
+    String toString(Object arg);
         
     /**
      * Coerce an object into a big integer.
@@ -131,8 +138,8 @@
      * @return a value of the smallest type the original number will fit into.
      * @since 1.1
      */
-    public Number narrow(Number original);
-    
+    Number narrow(Number original);
+
     /**
      * Test if left == right.
      *
@@ -177,4 +184,4 @@
      * @return test result.
      */
     boolean greaterThanOrEqual(Object left, Object right);
-}
\ No newline at end of file
+}

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java Sat Jul 18 19:26:02 2009
@@ -66,38 +66,47 @@
 import org.apache.commons.jexl.parser.SimpleNode;
 
 import org.apache.commons.jexl.parser.ParserVisitor;
+
 /**
  * Helps pinpoint the cause of problems in expressions that fail during evaluation.
  * It rebuilds an expression string from the tree and the start/end offsets of the cause
- * in that string (TODO pretty print).
+ * in that string.
  * This implies that exceptions during evaluation should allways carry the node that's causing
  * the error.
  */
-public class Debugger implements ParserVisitor {
-    StringBuilder builder;
-    Node cause;
-    int start = 0;
-    int end = 0;
+final class Debugger implements ParserVisitor {
+    /** The builder to compose messages. */
+    private StringBuilder builder;
+    /** The cause of the issue to debug. */
+    private Node cause;
+    /** The starting character location offset of the cause in the builder. */
+    private int start;
+    /** The ending character location offset of the cause in the builder. */
+    private int end;
 
-    public Debugger() {
+    /**
+     * Creates a Debugger.
+     */
+    Debugger() {
         builder = new StringBuilder();
         cause = null;
         start = 0;
         end = 0;
     }
-    
+
     /**
      * Seeks the location of an error cause (a node) in an expression.
+     * @param node the node to debug
      * @return true if the cause was located, false otherwise
      */
-    public boolean debug(Node cause) {
+    public boolean debug(Node node) {
         start = 0;
         end = 0;
-        if (cause != null) {
+        if (node != null) {
             builder = new StringBuilder();
-            this.cause = cause;
+            this.cause = node;
             // make arg cause become the root cause
-            Node root = cause;
+            Node root = node;
             while (root.jjtGetParent() != null) {
                 root = root.jjtGetParent();
             }
@@ -119,6 +128,7 @@
     public int start() {
         return start;
     }
+
     /**
      * @return The end offset location of the cause in the expression
      */
@@ -127,7 +137,11 @@
     }
 
     /**
-     * Checks if a child node is the cause to debug & adds its representation to the rebuilt expression
+     * Checks if a child node is the cause to debug &amp; adds its representation
+     * to the rebuilt expression.
+     * @param node the child node
+     * @param data visitor pattern argument
+     * @return visitor pattern value
      */
     private Object accept(Node node, Object data) {
         if (node == cause) {
@@ -141,7 +155,12 @@
     }
 
     /**
-     * Checks if a terminal node is the the cause to debug & adds its representation to the rebuilt expression
+     * Checks if a terminal node is the the cause to debug &amp; adds its
+     * representation to the rebuilt expression.
+     * @param node the child node
+     * @param image the child node token image (may be null)
+     * @param data visitor pattern argument
+     * @return visitor pattern value
      */
     private Object check(Node node, String image, Object data) {
         if (node == cause) {
@@ -157,10 +176,14 @@
         }
         return data;
     }
-    
+
     /**
      * Checks if the children of a node using infix notation is the cause to debug,
-     * adds their representation to the rebuilt expression
+     * adds their representation to the rebuilt expression.
+     * @param node the child node
+     * @param infix the child node token
+     * @param data visitor pattern argument
+     * @return visitor pattern value
      */
     private Object infixChildren(Node node, String infix, Object data) {
         int num = node.jjtGetNumChildren();
@@ -286,8 +309,9 @@
         builder.append(" in ");
         accept(node.jjtGetChild(1), data);
         builder.append(") ");
-        if (node.jjtGetNumChildren() > 2)
+        if (node.jjtGetNumChildren() > 2) {
             accept(node.jjtGetChild(2), data);
+        }
         return data;
     }
 

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionFactory.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionFactory.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionFactory.java Sat Jul 18 19:26:02 2009
@@ -67,4 +67,4 @@
         return JexlEngine.getDefault().createExpression(expression);
     }
 
-}
\ No newline at end of file
+}

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionImpl.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionImpl.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/ExpressionImpl.java Sat Jul 18 19:26:02 2009
@@ -43,11 +43,11 @@
 
 
     /**
-     * do not let this be generally instantiated with a 'new'.
+     * Do not let this be generally instantiated with a 'new'.
      *
+     * @param engine the interpreter to evaluate the expression
      * @param expr the expression.
      * @param ref the parsed expression.
-     * @param interp the interpreter to evaluate the expression
      */
     ExpressionImpl(JexlEngine engine, String expr, SimpleNode ref) {
         expression = expr;
@@ -89,4 +89,4 @@
         return expr == null ? "" : expr;
     }
 
-}
+}
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java Sat Jul 18 19:26:02 2009
@@ -91,20 +91,20 @@
  */
 public class Interpreter implements ParserVisitor {
     /** The logger. */
-    protected final Log LOG;
+    protected final Log logger;
     /** The uberspect. */
     protected final Uberspect uberspect;
-    /** the arithmetic handler. */
+    /** The arithmetic handler. */
     protected final Arithmetic arithmetic;
     /** The map of registered functions. */
     protected final Map<String, Object> functions;
     /** The context to store/retrieve variables. */
     protected final JexlContext context;
-    /** Strict interpreter flag */
+    /** Strict interpreter flag. */
     protected final boolean strict;
-    /** Silent intepreter  flag */
+    /** Silent intepreter flag. */
     protected boolean silent;
-    /** Registers; 2 * {name, value} */
+    /** Registers made of 2 pairs of {register-name, value}. */
     protected Object[] registers = null;
     /** Dummy velocity info. */
     protected static final Info DUMMY = new Info("", 1, 1);
@@ -112,31 +112,32 @@
     protected static final Object[] EMPTY_PARAMS = new Object[0];
 
     /**
-     * Create the interpreter.
+     * Creates an interpreter.
      * @param jexl the engine creating this interpreter
-     * @param context the context to evaluate expression
+     * @param aContext the context to evaluate expression
      */
-    public Interpreter(JexlEngine jexl, JexlContext context) {
-        this.LOG = jexl.LOG;
+    public Interpreter(JexlEngine jexl, JexlContext aContext) {
+        this.logger = jexl.logger;
         this.uberspect = jexl.uberspect;
         this.arithmetic = jexl.arithmetic;
         this.functions = jexl.functions;
         this.strict = !this.arithmetic.isLenient();
         this.silent = jexl.silent;
-        this.context = context;
+        this.context = aContext;
     }
 
     /**
      * Sets whether this interpreter throws JexlException during evaluation.
-     * @param silent true means no JexlException will be thrown but will be logged
+     * @param flag true means no JexlException will be thrown but will be logged
      *        as info through the Jexl engine logger, false allows them to be thrown.
      */
-    public void setSilent(boolean silent) {
-        this.silent = silent;
+    public void setSilent(boolean flag) {
+        this.silent = flag;
     }
 
     /**
      * Checks whether this interpreter throws JexlException during evaluation.
+     * @return true if silent, false otherwise
      */
     public boolean isSilent() {
         return this.silent;
@@ -154,30 +155,15 @@
     public Object interpret(SimpleNode node) {
         try {
             return node.jjtAccept(this, null);
-        }
-        catch (JexlException xjexl) {
+        } catch (JexlException xjexl) {
             if (silent) {
-                LOG.warn(xjexl.getMessage(), xjexl.getCause());
+                logger.warn(xjexl.getMessage(), xjexl.getCause());
                 return null;
             }
             throw xjexl;
         }
     }
 
-    public String debug(SimpleNode node) {
-        return debug(node, null);
-    }
-
-    public String debug(SimpleNode node, int[] offsets) {
-        Debugger debug = new Debugger();
-        debug.debug(node);
-        if (offsets != null) {
-            offsets[0] = debug.start();
-            offsets[1] = debug.end();
-        }
-        return debug.data();
-    }
-
     /**
      * Gets the uberspect.
      * @return an {@link Uberspect}
@@ -188,10 +174,10 @@
 
     /**
      * Sets this interpreter registers for bean access/assign expressions.
-     * @param registers the array of registers
+     * @param theRegisters the array of registers
      */
-    protected void setRegisters(Object[] registers) {
-        this.registers = registers;
+    protected void setRegisters(Object[] theRegisters) {
+        this.registers = theRegisters;
     }
 
     /**
@@ -203,8 +189,8 @@
      * @return the left, right or parent node
      */
     protected Node findNullOperand(RuntimeException xrt, Node node, Object left, Object right) {
-        if (xrt instanceof NullPointerException &&
-                JexlException.NULL_OPERAND == xrt.getMessage()) {
+        if (xrt instanceof NullPointerException
+                && JexlException.NULL_OPERAND == xrt.getMessage()) {
             if (left == null) {
                 return node.jjtGetChild(0);
             }
@@ -238,8 +224,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.add(left, right);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "add error", xrt);
         }
@@ -250,19 +235,19 @@
         Object left = node.jjtGetChild(0).jjtAccept(this, data);
         try {
             boolean leftValue = arithmetic.toBoolean(left);
-            if (!leftValue)
+            if (!leftValue) {
                 return Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+            }
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt);
         }
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             boolean rightValue = arithmetic.toBoolean(right);
-            if (!rightValue)
+            if (!rightValue) {
                 return Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+            }
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt);
         }
         return Boolean.TRUE;
@@ -288,8 +273,9 @@
     public Object visit(ASTAssignment node, Object data) {
         // left contains the reference to assign to
         Node left = node.jjtGetChild(0);
-        if (!(left instanceof ASTReference))
+        if (!(left instanceof ASTReference)) {
             throw new JexlException(left, "illegal assignment form");
+        }
         // right is the value expression to assign
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
 
@@ -306,24 +292,27 @@
             objectNode = left.jjtGetChild(c);
             // evaluate the property within the object
             object = objectNode.jjtAccept(this, object);
-            if (object != null)
+            if (object != null) {
                 continue;
+            }
             isVariable &= objectNode instanceof ASTIdentifier;
             // if we get null back as a result, check for an ant variable
             if (isVariable) {
                 String name = ((ASTIdentifier) objectNode).image;
-                if (c == 0)
+                if (c == 0) {
                     variableName = new StringBuilder(name);
-                else {
+                } else {
                     variableName.append('.');
                     variableName.append(name);
                 }
                 object = context.getVars().get(variableName.toString());
                 // disallow mixing ant & bean with same root; avoid ambiguity
-                if (object != null)
+                if (object != null) {
                     isVariable = false;
-            } else
+                }
+            } else {
                 throw new JexlException(objectNode, "illegal assignment form");
+            }
         }
         // 2: last objectNode will perform assignement in all cases
         propertyNode = left.jjtGetChild(last);
@@ -332,8 +321,9 @@
             // deal with ant variable
             if (isVariable && object == null) {
                 if (variableName != null) {
-                    if (last > 0)
+                    if (last > 0) {
                         variableName.append('.');
+                    }
                     variableName.append(property);
                     property = variableName.toString();
                 }
@@ -345,10 +335,11 @@
             objectNode = propertyNode;
             ASTArrayAccess narray = (ASTArrayAccess) objectNode;
             Object nobject = narray.jjtGetChild(0).jjtAccept(this, object);
-            if (nobject == null)
+            if (nobject == null) {
                 throw new JexlException(objectNode, "array element is null");
-            else
+            } else {
                 object = nobject;
+            }
             // can have multiple nodes - either an expression, integer literal or
             // reference
             last = narray.jjtGetNumChildren() - 1;
@@ -385,8 +376,7 @@
             n = 1;
             long r = arithmetic.toLong(right);
             return new Long(l & r);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(n), "long coercion error", xrt);
         }
     }
@@ -397,8 +387,7 @@
         try {
             long l = arithmetic.toLong(left);
             return new Long(~l);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(0), "long coercion error", xrt);
         }
     }
@@ -414,8 +403,7 @@
             n = 1;
             long r = arithmetic.toLong(right);
             return new Long(l | r);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(n), "long coercion error", xrt);
         }
     }
@@ -431,8 +419,7 @@
             n = 1;
             long r = arithmetic.toLong(right);
             return new Long(l ^ r);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(n), "long coercion error", xrt);
         }
     }
@@ -453,10 +440,10 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.divide(left, right);
-        }
-        catch (RuntimeException xrt) {
-            if (!strict && xrt instanceof ArithmeticException)
+        } catch (RuntimeException xrt) {
+            if (!strict && xrt instanceof ArithmeticException) {
                 return 0.0;
+            }
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "divide error", xrt);
         }
@@ -464,30 +451,23 @@
 
     /** {@inheritDoc} */
     public Object visit(ASTEmptyFunction node, Object data) {
-
         Object o = node.jjtGetChild(0).jjtAccept(this, data);
-
         if (o == null) {
             return Boolean.TRUE;
         }
-
         if (o instanceof String && "".equals(o)) {
             return Boolean.TRUE;
         }
-
         if (o.getClass().isArray() && ((Object[]) o).length == 0) {
             return Boolean.TRUE;
         }
-
         if (o instanceof Collection<?> && ((Collection<?>) o).isEmpty()) {
             return Boolean.TRUE;
         }
-
         // Map isn't a collection
         if (o instanceof Map<?, ?> && ((Map<?, ?>) o).isEmpty()) {
             return Boolean.TRUE;
         }
-
         return Boolean.FALSE;
     }
 
@@ -497,8 +477,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.equals(left, right) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node, "== error", xrt);
         }
     }
@@ -557,8 +536,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.greaterThanOrEqual(left, right) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node, ">= error", xrt);
         }
     }
@@ -569,8 +547,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.greaterThan(left, right) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node, "> error", xrt);
         }
     }
@@ -580,20 +557,24 @@
         String name = node.image;
         if (data == null) {
             if (registers != null) {
-                if (registers[0].equals(name))
+                if (registers[0].equals(name)) {
                     return registers[1];
-                if (registers[2].equals(name))
+                }
+                if (registers[2].equals(name)) {
                     return registers[3];
+                }
             }
             Object value = context.getVars().get(name);
-            if (value == null &&
-                !(node.jjtGetParent() instanceof ASTReference) &&
-                !context.getVars().containsKey(name)) {
+            if (value == null
+                && !(node.jjtGetParent() instanceof ASTReference)
+                && !context.getVars().containsKey(name)) {
                 JexlException xjexl = new JexlException(node, "undefined variable " + name);
-                if (strict)
+                if (strict) {
                     throw xjexl;
-                if (!silent)
-                    LOG.warn(xjexl.getMessage());
+                }
+                if (!silent) {
+                    logger.warn(xjexl.getMessage());
+                }
             }
             return value;
         } else {
@@ -621,11 +602,9 @@
                 }
             }
             return result;
-        }
-        catch (JexlException error) {
+        } catch (JexlException error) {
             throw error;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(n), "if error", xrt);
         }
     }
@@ -653,8 +632,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.lessThanOrEqual(left, right) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node, "<= error", xrt);
         }
     }
@@ -665,8 +643,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.lessThan(left, right) ? Boolean.TRUE : Boolean.FALSE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             throw new JexlException(node, "< error", xrt);
         }
     }
@@ -738,21 +715,20 @@
             if (xjexl == null) {
                 return vm.invoke(data, params);
             }
-        }
-        catch (InvocationTargetException e) {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
             if (!(t instanceof Exception)) {
                 t = e;
             }
             xjexl = new JexlException(node, "method invocation error", t);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             xjexl = new JexlException(node, "method error", e);
         }
         if (xjexl != null) {
-            if (strict)
+            if (strict) {
                 throw xjexl;
-            LOG.warn(xjexl.getMessage(), xjexl.getCause());
+            }
+            logger.warn(xjexl.getMessage(), xjexl.getCause());
         }
         return null;
     }
@@ -762,8 +738,9 @@
         // objectNode 0 is the prefix
         String prefix = ((ASTIdentifier) node.jjtGetChild(0)).image;
         Object functor = functions.get(prefix);
-        if (functor == null)
+        if (functor == null) {
             throw new JexlException(node, "no such function namespace " + prefix);
+        }
         // objectNode 1 is the identifier , the others are parameters.
         String methodName = ((ASTIdentifier) node.jjtGetChild(1)).image;
 
@@ -796,21 +773,20 @@
             if (xjexl == null) {
                 return vm.invoke(functor, params);
             }
-        }
-        catch (InvocationTargetException e) {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getTargetException();
             if (!(t instanceof Exception)) {
                 t = e;
             }
             xjexl = new JexlException(node, "function invocation error", t);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             xjexl = new JexlException(node, "function error", e);
         }
         if (xjexl != null) {
-            if (strict)
+            if (strict) {
                 throw xjexl;
-            LOG.warn(xjexl.getMessage(), xjexl.getCause());
+            }
+            logger.warn(xjexl.getMessage(), xjexl.getCause());
         }
         return null;
     }
@@ -821,10 +797,10 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.mod(left, right);
-        }
-        catch (RuntimeException xrt) {
-            if (!strict && xrt instanceof ArithmeticException)
+        } catch (RuntimeException xrt) {
+            if (!strict && xrt instanceof ArithmeticException) {
                 return 0.0;
+            }
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "% error", xrt);
         }
@@ -836,8 +812,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.multiply(left, right);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "* error", xrt);
         }
@@ -849,8 +824,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.equals(left, right) ? Boolean.FALSE : Boolean.TRUE;
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "!= error", xrt);
         }
@@ -872,19 +846,19 @@
         Object left = node.jjtGetChild(0).jjtAccept(this, data);
         try {
             boolean leftValue = arithmetic.toBoolean(left);
-            if (leftValue)
+            if (leftValue) {
                 return Boolean.TRUE;
-        }
-        catch (RuntimeException xrt) {
+            }
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt);
         }
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             boolean rightValue = arithmetic.toBoolean(right);
-            if (rightValue)
+            if (rightValue) {
                 return Boolean.TRUE;
-        }
-        catch (RuntimeException xrt) {
+            }
+        } catch (RuntimeException xrt) {
             throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt);
         }
         return Boolean.FALSE;
@@ -910,9 +884,9 @@
             // if we get null back a result, check for an ant variable
             if (result == null && isVariable) {
                 String name = ((ASTIdentifier) theNode).image;
-                if (i == 0)
+                if (i == 0) {
                     variableName = new StringBuilder(name);
-                else {
+                } else {
                     variableName.append('.');
                     variableName.append(name);
                 }
@@ -920,13 +894,14 @@
             }
         }
         if (result == null) {
-            if (isVariable &&
-                !(node.jjtGetParent() instanceof ASTTernaryNode) &&
-                !vars.containsKey(variableName.toString())) {
+            if (isVariable
+                && !(node.jjtGetParent() instanceof ASTTernaryNode)
+                && !vars.containsKey(variableName.toString())) {
                 JexlException xjexl = new JexlException(node, "undefined variable " + variableName.toString());
-                if (strict)
+                if (strict) {
                     throw xjexl;
-                LOG.warn(xjexl.getMessage());
+                }
+                logger.warn(xjexl.getMessage());
             }
         }
         return result;
@@ -969,8 +944,7 @@
         Object right = node.jjtGetChild(1).jjtAccept(this, data);
         try {
             return arithmetic.subtract(left, right);
-        }
-        catch (RuntimeException xrt) {
+        } catch (RuntimeException xrt) {
             Node xnode = findNullOperand(xrt, node, left, right);
             throw new JexlException(xnode, "- error", xrt);
         }
@@ -979,9 +953,18 @@
     /** {@inheritDoc} */
     public Object visit(ASTTernaryNode node, Object data) {
         Object condition = node.jjtGetChild(0).jjtAccept(this, data);
-        if (node.jjtGetNumChildren() == 3)
-            return arithmetic.toBoolean(condition) ? node.jjtGetChild(1).jjtAccept(this, data) : node.jjtGetChild(2).jjtAccept(this, data);
-        return condition != null && !Boolean.FALSE.equals(condition) ? condition : node.jjtGetChild(1).jjtAccept(this, data);
+        if (node.jjtGetNumChildren() == 3) {
+            if (arithmetic.toBoolean(condition)) {
+                return node.jjtGetChild(1).jjtAccept(this, data);
+            } else {
+                return node.jjtGetChild(2).jjtAccept(this, data);
+            }
+        }
+        if (condition != null && !Boolean.FALSE.equals(condition)) {
+            return condition;
+        } else {
+            return node.jjtGetChild(1).jjtAccept(this, data);
+        }
     }
 
     /** {@inheritDoc} */
@@ -993,7 +976,6 @@
     public Object visit(ASTUnaryMinusNode node, Object data) {
         Node valNode = node.jjtGetChild(0);
         Object val = valNode.jjtAccept(this, data);
-
         if (val instanceof Byte) {
             byte valueAsByte = ((Byte) val).byteValue();
             return new Byte((byte) -valueAsByte);
@@ -1038,7 +1020,7 @@
     /**
      * Calculate the <code>size</code> of various types: Collection, Array,
      * Map, String, and anything that has a int size() method.
-     *
+     * @param node the node that gave the value to size
      * @param val the object to get the size of.
      * @return the size of val
      */
@@ -1060,8 +1042,7 @@
                 Integer result;
                 try {
                     result = (Integer) vm.invoke(val, params);
-                }
-                catch (Exception e) {
+                } catch (Exception e) {
                     throw new JexlException(node, "size() : error executing", e);
                 }
                 return result.intValue();
@@ -1071,17 +1052,26 @@
     }
 
     /**
-     * Get an attribute of an object.
+     * Gets an attribute of an object.
      *
      * @param object to retrieve value from
      * @param attribute the attribute of the object, e.g. an index (1, 0, 2) or
      *            key for a map
-     * @return the attribute.
+     * @return the attribute value
      */
     public Object getAttribute(Object object, Object attribute) {
         return getAttribute(object, attribute, null);
     }
 
+    /**
+     * Gets an attribute of an object.
+     *
+     * @param object to retrieve value from
+     * @param attribute the attribute of the object, e.g. an index (1, 0, 2) or
+     *            key for a map
+     * @param node the node that evaluated as the object
+     * @return the attribute value
+     */
     protected Object getAttribute(Object object, Object attribute, Node node) {
         if (object == null) {
             throw new JexlException(node, "object is null");
@@ -1090,8 +1080,7 @@
         if (object instanceof Map<?, ?>) {
             try {
                 return ((Map<Object, Object>) object).get(attribute);
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "get map element error", xrt);
             }
         }
@@ -1102,8 +1091,7 @@
             try {
                 int idx = arithmetic.toInteger(attribute);
                 return ((List<?>) object).get(idx);
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "get list element error", xrt);
             }
         }
@@ -1111,8 +1099,7 @@
             try {
                 int idx = arithmetic.toInteger(attribute);
                 return Array.get(object, idx);
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "get array element error", xrt);
             }
         }
@@ -1121,9 +1108,13 @@
         if (vg != null) {
             try {
                 return vg.invoke(object);
-            }
-            catch (Exception xany) {
-                throw node == null ? new RuntimeException(xany) : new JexlException(node, "get object property error", xany);
+            } catch (Exception xany) {
+                if (node == null) {
+                    throw new RuntimeException(xany);
+                }
+                else {
+                    throw new JexlException(node, "get object property error", xany);
+                }
             }
         }
 
@@ -1142,6 +1133,15 @@
         setAttribute(object, attribute, null);
     }
 
+    /**
+     * Sets an attribute of an object.
+     *
+     * @param object to set the value to
+     * @param attribute the attribute of the object, e.g. an index (1, 0, 2) or
+     *            key for a map
+     * @param value the value to assign to the object's attribute
+     * @param node the node that evaluated as the object
+     */
     protected void setAttribute(Object object, Object attribute, Object value, Node node) {
         if (object instanceof JexlContext) {
             ((JexlContext) object).getVars().put(attribute, value);
@@ -1152,8 +1152,7 @@
             try {
                 ((Map<Object, Object>) object).put(attribute, value);
                 return;
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "set map element error", xrt);
             }
         }
@@ -1162,8 +1161,7 @@
                 int idx = arithmetic.toInteger(attribute);
                 ((List<Object>) object).set(idx, value);
                 return;
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "set list element error", xrt);
             }
         }
@@ -1177,8 +1175,7 @@
                 int idx = arithmetic.toInteger(attribute);
                 Array.set(object, idx, value);
                 return;
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "set array element error", xrt);
             }
         }
@@ -1189,17 +1186,21 @@
         if (vs != null) {
             try {
                 vs.invoke(object, value);
-            }
-            catch (RuntimeException xrt) {
+            } catch (RuntimeException xrt) {
                 throw node == null ? xrt : new JexlException(node, "set object property error", xrt);
-            }
-            catch (Exception xany) {
-                throw node == null ? new RuntimeException(xany) : new JexlException(node, "set object property error", xany);
+            } catch (Exception xany) {
+                if (node == null) {
+                    throw new RuntimeException(xany);
+                } else {
+                    throw new JexlException(node, "set object property error", xany);
+                }
             }
             return;
         }
-        if (node == null)
-            new UnsupportedOperationException("unable to set object property, object:" + object + ", property: " + attribute);
+        if (node == null) {
+            new UnsupportedOperationException("unable to set object property, "
+                            + "object:" + object + ", property: " + attribute);
+        }
         throw new JexlException(node, "unable to set bean property", null);
     }
 }
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java Sat Jul 18 19:26:02 2009
@@ -24,16 +24,27 @@
  * @since 2.0
  */
 class JexlArithmetic implements Arithmetic {
+    /** Whether this Arithmetic instance behaves in strict or lenient mode. */
     protected boolean strict;
 
+    /**
+     * Creates a JexlArithmetic.
+     * @param lenient whether this arithmetic is lenient or strict
+     */
     JexlArithmetic(boolean lenient) {
         this.strict = !lenient;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void setLenient(boolean lenient) {
         this.strict = !lenient;
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
     public boolean isLenient() {
         return !this.strict;
     }
@@ -43,7 +54,7 @@
      * @return Long(0)
      */
     protected Object controlNullNullOperands() {
-        return strict? null : 0l;
+        return strict? null : 0L;
     }
 
     /**
@@ -485,7 +496,8 @@
             return ((Number) val).intValue();
         }
 
-        throw new IllegalArgumentException("Integer coercion exception. Can't coerce type: " + val.getClass().getName());
+        throw new IllegalArgumentException("Integer coercion exception. Can't coerce type: "
+                + val.getClass().getName());
     }
 
     
@@ -540,7 +552,8 @@
             return BigInteger.valueOf(i);
         }
         
-        throw new IllegalArgumentException("BigInteger coercion exception. Can't coerce type: " + val.getClass().getName());
+        throw new IllegalArgumentException("BigInteger coercion exception. Can't coerce type: "
+                + val.getClass().getName());
     }
     
     /**
@@ -568,7 +581,8 @@
             return new BigDecimal(i);
         }
         
-        throw new IllegalArgumentException("BigDecimal coercion exception. Can't coerce type: " + val.getClass().getName());
+        throw new IllegalArgumentException("BigDecimal coercion exception. Can't coerce type: "
+                + val.getClass().getName());
     }
     
     /**
@@ -602,7 +616,8 @@
             throw new IllegalArgumentException("Boolean->Double coercion exception");
         }
 
-        throw new IllegalArgumentException("Double coercion exception. Can't coerce type: " + val.getClass().getName());
+        throw new IllegalArgumentException("Double coercion exception. Can't coerce type: "
+                + val.getClass().getName());
     }
 
 
@@ -626,7 +641,7 @@
      * @param o Object to be analyzed.
      * @return true if it is a Float or a Double.
      */
-    public boolean isFloatingPoint(final Object o) {
+    protected boolean isFloatingPoint(final Object o) {
         return o instanceof Float || o instanceof Double;
     }
 
@@ -636,7 +651,7 @@
      * @param o Object to be analyzed.
      * @return true if Integer, Long, Byte, Short or Character.
      */
-    public boolean isNumberable(final Object o) {
+    protected boolean isNumberable(final Object o) {
         return o instanceof Integer
             || o instanceof Long
             || o instanceof Byte
@@ -653,7 +668,6 @@
      *
      * @param original the original number.
      * @return a value of the smallest type the original number will fit into.
-     * @since 1.1
      */
     public Number narrow(Number original) {
         if (original == null) {

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java Sat Jul 18 19:26:02 2009
@@ -49,8 +49,8 @@
  *  <li>Logging</li>
  * </ul>
  * </p>
- * <p>The <code>setSilent</code>and<code>setLenient</code> methods allow to fine-tune an engine instance behavior according to
- * various error control needs.
+ * <p>The <code>setSilent</code>and<code>setLenient</code> methods allow to fine-tune an engine instance behavior
+ * according to various error control needs.
  * </p>
  * <ul>
  * <li>When "silent" & "lenient" (not-strict):
@@ -93,44 +93,46 @@
     /**
      * The Log to which all JexlEngine messages will be logged.
      */
-    protected final Log LOG;
+    protected final Log logger;
     /**
      * The singleton ExpressionFactory also holds a single instance of
      * {@link Parser}.
      * When parsing expressions, ExpressionFactory synchronizes on Parser.
      */
     protected final Parser parser = new Parser(new StringReader(";")); //$NON-NLS-1$
-
     /**
      * Whether expressions evaluated by this engine will throw exceptions or 
      * return null.
      */
     protected boolean silent = false;
-
     /**
      *  The map of 'prefix:function' to object implementing the function.
      */
-    protected Map<String,Object> functions = Collections.EMPTY_MAP;
-
+    protected Map<String, Object> functions = Collections.EMPTY_MAP;
     /**
      * The expression cache.
      */
-    protected Map<String,SimpleNode> cache = null;
-
+    protected Map<String, SimpleNode> cache = null;
     /**
-     * An empty/static/non-mutable JexlContext used instead of null context
+     * An empty/static/non-mutable JexlContext used instead of null context.
      */
     protected static final JexlContext EMPTY_CONTEXT = new JexlContext() {
+        /** {@inheritDoc} */
         public void setVars(Map vars) {
             throw new UnsupportedOperationException("Immutable JexlContext");
         }
+        /** {@inheritDoc} */
         public Map getVars() {
             return java.util.Collections.EMPTY_MAP;
         }
     };
+    /**
+     * The default cache load factor.
+     */
+    private static final float LOAD_FACTOR = 0.75f;
 
     /**
-     * Creates a default engine
+     * Creates an engine with default arguments.
      */
     public JexlEngine() {
         this(null, null, null, null);
@@ -138,16 +140,16 @@
 
     /**
      * Creates a JEXL engine using the provided {@link Uberspect}, (@link Arithmetic) and logger.
-     * @param uberspect to allow different introspection behaviour
-     * @param arithmetic to allow different arithmetic behaviour
-     * @param funcs an optional map of functions (@see setFunctions)
+     * @param anUberspect to allow different introspection behaviour
+     * @param anArithmetic to allow different arithmetic behaviour
+     * @param theFunctions an optional map of functions (@see setFunctions)
      * @param log the logger for various messages
      */
-    public JexlEngine(Uberspect uberspect, Arithmetic arithmetic, Map<String,Object> funcs, Log log) {
-        this.uberspect = uberspect == null? Introspector.getUberspect() : uberspect;
-        this.arithmetic = arithmetic == null? new JexlArithmetic(true) : arithmetic;
-        if (funcs != null) {
-            this.functions = funcs;
+    public JexlEngine(Uberspect anUberspect, Arithmetic anArithmetic, Map<String, Object> theFunctions, Log log) {
+        this.uberspect = anUberspect == null ? Introspector.getUberspect() : anUberspect;
+        this.arithmetic = anArithmetic == null ? new JexlArithmetic(true) : anArithmetic;
+        if (theFunctions != null) {
+            this.functions = theFunctions;
         }
         if (log == null) {
             log = LogFactory.getLog(JexlEngine.class);
@@ -155,17 +157,17 @@
         if (log == null) {
             throw new NullPointerException("logger can not be null");
         }
-        this.LOG = log;
+        this.logger = log;
     }
-    
+
     /**
      * Sets whether this engine throws JexlException during evaluation when an error is triggered.
-     * @param silent true means no JexlException will occur, false allows them
+     * @param flag true means no JexlException will occur, false allows them
      */
-    public void setSilent(boolean silent) {
-        this.silent = silent;
+    public void setSilent(boolean flag) {
+        this.silent = flag;
     }
-    
+
     /**
      * Checks whether this engine throws JexlException during evaluation.
      */
@@ -176,30 +178,31 @@
     /**
      * Sets whether this engine triggers errors during evaluation when null is used as
      * an operand.
-     * @param lenient true means no JexlException will occur, false allows them
+     * @param flag true means no JexlException will occur, false allows them
      */
-    public void setLenient(boolean lenient) {
-        this.arithmetic.setLenient(lenient);
+    public void setLenient(boolean flag) {
+        this.arithmetic.setLenient(flag);
     }
 
     /**
      * Checks whether this engine triggers errors during evaluation when null is used as
      * an operand.
+     * @return true if lenient, false if strict
      */
     public boolean isLenient() {
         return this.arithmetic.isLenient();
     }
+
     /**
      * Sets a cache of the defined size for expressions.
      * @param size if not strictly positive, no cache is used.
      */
     public void setCache(int size) {
         // since the cache is only used during parse, use same sync object
-        synchronized(parser) {
+        synchronized (parser) {
             if (size <= 0) {
                 cache = null;
-            }
-            else if (cache == null || cache.size() != size) {
+            } else if (cache == null || cache.size() != size) {
                 cache = createCache(size);
             }
         }
@@ -230,10 +233,9 @@
      * is passed, the empty collection is used.
      */
     public void setFunctions(Map<String, Object> funcs) {
-        functions = funcs != null? funcs : Collections.EMPTY_MAP;
+        functions = funcs != null ? funcs : Collections.EMPTY_MAP;
     }
 
-
     /**
      * Retrieves the map of function namespaces.
      *
@@ -255,13 +257,12 @@
      *      expression or a reference.
      */
     public Expression createExpression(String expression)
-        throws ParseException {
+            throws ParseException {
         // Parse the expression
         SimpleNode tree = parse(expression);
         if (tree.jjtGetNumChildren() > 1) {
-            LOG.warn("The JEXL Expression created will be a reference"
-                + " to the first expression from the supplied script: \""
-                + expression + "\" ");
+            logger.warn("The JEXL Expression created will be a reference"
+                     + " to the first expression from the supplied script: \"" + expression + "\" ");
         }
         SimpleNode node = (SimpleNode) tree.jjtGetChild(0);
         return new ExpressionImpl(this, expression, node);
@@ -303,8 +304,7 @@
             throw new NullPointerException("scriptFile is null");
         }
         if (!scriptFile.canRead()) {
-            throw new IOException("Can't read scriptFile ("
-                + scriptFile.getCanonicalPath() + ")");
+            throw new IOException("Can't read scriptFile (" + scriptFile.getCanonicalPath() + ")");
         }
         BufferedReader reader = new BufferedReader(new FileReader(scriptFile));
         return createScript(readerToString(reader));
@@ -329,18 +329,18 @@
         URLConnection connection = scriptUrl.openConnection();
 
         BufferedReader reader = new BufferedReader(
-            new InputStreamReader(connection.getInputStream()));
+                new InputStreamReader(connection.getInputStream()));
         return createScript(readerToString(reader));
     }
 
     /**
-     * Access properties of a bean using an expression.
+     * Accesses properties of a bean using an expression.
      * <p>
      * jexl.get(myobject, "foo.bar"); should equate to
      * myobject.getFoo().getBar(); (or myobject.getFoo().get("bar"))
      * </p>
      * <p>
-     * If the JEXL engine is silent, errors will be logged through its logger as info.
+     * If the JEXL engine is silent, errors will be logged through its logger as warning.
      * </p>
      * @param bean the bean to get properties from
      * @param expr the property expression
@@ -348,14 +348,31 @@
      * @throws JexlException if there is an error parsing the expression or during evaluation
      */
     public Object getProperty(Object bean, String expr) {
-        return getProperty(EMPTY_CONTEXT, bean, expr);
+        return getProperty(null, bean, expr);
     }
+
+    /**
+     * Accesses properties of a bean using an expression.
+     * <p>
+     * If the JEXL engine is silent, errors will be logged through its logger as warning.
+     * </p>
+     * @param context the evaluation context
+     * @param bean the bean to get properties from
+     * @param expr the property expression
+     * @return the value of the property
+     * @throws JexlException if there is an error parsing the expression or during evaluation
+     */
     public Object getProperty(JexlContext context, Object bean, String expr) {
+        if (context == null) {
+            context = EMPTY_CONTEXT;
+        }
         Map<String, Object> vars = context.getVars();
         // lets build 1 unique & unused identifiers wrt context
         String r0 = "$0";
-        for(int s = 0; vars.containsKey(r0); ++s) r0 = r0 + s;
-        expr = r0 + (expr.charAt(0) =='['? "" : "." )+ expr +";";
+        for (int s = 0; vars.containsKey(r0); ++s) {
+            r0 = r0 + s;
+        }
+        expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
         try {
             SimpleNode tree = parse(expr);
             SimpleNode node = (SimpleNode) tree.jjtGetChild(0).jjtGetChild(0);
@@ -364,17 +381,15 @@
             Object[] r = {r0, bean, r0, bean};
             interpreter.setRegisters(r);
             return node.jjtAccept(interpreter, null);
-        }
-        catch(JexlException xjexl) {
+        } catch (JexlException xjexl) {
             if (silent) {
-                LOG.warn(xjexl.getMessage(), xjexl.getCause());
+                logger.warn(xjexl.getMessage(), xjexl.getCause());
                 return null;
             }
             throw xjexl;
-        }
-        catch(ParseException xparse) {
+        } catch (ParseException xparse) {
             if (silent) {
-                LOG.warn(xparse.getMessage(), xparse.getCause());
+                logger.warn(xparse.getMessage(), xparse.getCause());
                 return null;
             }
             throw new JexlException(null, "parsing error", xparse);
@@ -388,7 +403,7 @@
      * myobject.getFoo().setBar(10); (or myobject.getFoo().put("bar", 10) )
      * </p>
      * <p>
-     * If the JEXL engine is silent, errors will be logged through its logger as info.
+     * If the JEXL engine is silent, errors will be logged through its logger as warning.
      * </p>
      * @param bean the bean to set properties in
      * @param expr the property expression
@@ -396,16 +411,34 @@
      * @throws JexlException if there is an error parsing the expression or during evaluation
      */
     public void setProperty(Object bean, String expr, Object value) {
-       setProperty(EMPTY_CONTEXT, bean, expr, value);
+        setProperty(null, bean, expr, value);
     }
+
+    /**
+     * Assign properties of a bean using an expression.
+     * <p>
+     * If the JEXL engine is silent, errors will be logged through its logger as warning.
+     * </p>
+     * @param bean the bean to set properties in
+     * @param expr the property expression
+     * @param value the value of the property
+     * @throws JexlException if there is an error parsing the expression or during evaluation
+     */
     public void setProperty(JexlContext context, Object bean, String expr, Object value) {
+        if (context == null) {
+            context = EMPTY_CONTEXT;
+        }
         Map<String, Object> vars = context.getVars();
         // lets build 2 unique & unused identifiers wrt context
         String r0 = "$0", r1 = "$1";
-        for(int s = 0; vars.containsKey(r0); ++s) r0 = r0 + s;
-        for(int s = 0; vars.containsKey(r1); ++s) r1 = r1 + s;
+        for (int s = 0; vars.containsKey(r0); ++s) {
+            r0 = r0 + s;
+        }
+        for (int s = 0; vars.containsKey(r1); ++s) {
+            r1 = r1 + s;
+        }
         // synthetize expr
-        expr = r0 + (expr.charAt(0) =='['? "" : "." )+ expr +"=" + r1 +";";
+        expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + "=" + r1 + ";";
         try {
             SimpleNode tree = parse(expr);
             SimpleNode node = (SimpleNode) tree.jjtGetChild(0).jjtGetChild(0);
@@ -414,40 +447,40 @@
             Object[] r = {r0, bean, r1, value};
             interpreter.setRegisters(r);
             node.jjtAccept(interpreter, null);
-        }
-        catch(JexlException xjexl) {
+        } catch (JexlException xjexl) {
             if (silent) {
-                LOG.warn(xjexl.getMessage(), xjexl.getCause());
+                logger.warn(xjexl.getMessage(), xjexl.getCause());
                 return;
             }
             throw xjexl;
-        }
-        catch(ParseException xparse) {
+        } catch (ParseException xparse) {
             if (silent) {
-                LOG.warn(xparse.getMessage(), xparse.getCause());
+                logger.warn(xparse.getMessage(), xparse.getCause());
                 return;
             }
             throw new JexlException(null, "parsing error", xparse);
         }
     }
-    
+
     /**
      * Creates an interpreter.
      * @param context a JexlContext; if null, the EMPTY_CONTEXT is used instead.
      * @return an Interpreter
      */
     protected Interpreter createInterpreter(JexlContext context) {
-        if (context == null) context = EMPTY_CONTEXT;
+        if (context == null) {
+            context = EMPTY_CONTEXT;
+        }
         return new Interpreter(this, context);
     }
-    
+
     /**
      * Creates a SimpleNode cache.
      * @param cacheSize the cache size, must be > 0
      * @return a Map usable as a cache bounded to the given size
      */
-    protected Map<String,SimpleNode> createCache(final int cacheSize) {
-        return new java.util.LinkedHashMap<String,SimpleNode>(cacheSize, 0.75f, true) {
+    protected Map<String, SimpleNode> createCache(final int cacheSize) {
+        return new java.util.LinkedHashMap<String, SimpleNode>(cacheSize, LOAD_FACTOR, true) {
             @Override
             protected boolean removeEldestEntry(Map.Entry eldest) {
                 return size() > cacheSize;
@@ -457,7 +490,7 @@
 
     /**
      * Parses an expression.
-     * @param expression
+     * @param expression the expression to parse
      * @return the parsed tree
      * @throws ParseException if any error occured during parsing
      */
@@ -465,7 +498,7 @@
         String expr = cleanExpression(expression);
         SimpleNode tree = null;
         synchronized (parser) {
-            LOG.debug("Parsing expression: " + expression);
+            logger.debug("Parsing expression: " + expression);
             if (cache != null) {
                 tree = cache.get(expr);
                 if (tree != null) {
@@ -473,9 +506,7 @@
                 }
             }
             try {
-                Reader reader = expr.endsWith(";")?
-                            new StringReader(expr) :
-                            new StringReader(expr + ";");
+                Reader reader = expr.endsWith(";") ? new StringReader(expr) : new StringReader(expr + ";");
                 tree = parser.parse(reader);
                 if (cache != null) {
                     cache.put(expr, tree);
@@ -499,15 +530,15 @@
             int start = 0;
             int end = str.length();
             if (end > 0) {
-                for(start = 0; start < end && str.charAt(start) == ' '; ++start) {} // trim front spaces
-                for(;end > 0 && str.charAt(end - 1) == ' '; --end) {} // trim ending spaces
+                for (start = 0; start < end && str.charAt(start) == ' '; ++start); // trim front spaces
+                for (; end > 0 && str.charAt(end - 1) == ' '; --end); // trim ending spaces
                 return str.subSequence(start, end).toString();
             }
             return "";
         }
         return null;
     }
-    
+
     /**
      * Read a buffered reader into a StringBuffer and return a String with
      * the contents of the reader.
@@ -516,7 +547,7 @@
      * @throws IOException on any error reading the reader.
      */
     protected static String readerToString(BufferedReader reader)
-        throws IOException {
+            throws IOException {
         StringBuilder buffer = new StringBuilder();
         try {
             String line;
@@ -529,13 +560,14 @@
         }
 
     }
-
+    
     /**
      * ExpressionFactory & ScriptFactory need a singleton and this is the package
      * instance fulfilling that pattern.
      */
     @Deprecated
     private static volatile JexlEngine DEFAULT = null;
+
     /**
      * Retrieves a default JEXL engine.
      * @return the singleton
@@ -545,7 +577,7 @@
         // java 5 allows the lazy singleton initialization
         // using a double-check locking pattern
         if (DEFAULT == null) {
-            synchronized(JexlEngine.class) {
+            synchronized (JexlEngine.class) {
                 if (DEFAULT == null) {
                     DEFAULT = new JexlEngine();
                 }

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java Sat Jul 18 19:26:02 2009
@@ -26,12 +26,12 @@
     protected Node mark;
     /** A marker to use in NPEs stating a null operand error. */
     public static final String NULL_OPERAND = "jexl.null";
-
+    /** {@inheritDoc} */
     public JexlException(Node node, String msg) {
         super(msg);
         mark = node;
     }
-
+    /** {@inheritDoc} */
     public JexlException(Node node, String msg, Throwable cause) {
         super(msg, cause);
         mark = node;
@@ -39,8 +39,11 @@
     
     /**
      * Gets information about the cause of this error.
+     * <p>
      * The returned string represents the outermost expression in error.
-     * The info parameter, an int[2] optionally provided by the caller, will be filled with the begin/end offset characters of the precise error's trigger.
+     * The info parameter, an int[2] optionally provided by the caller, will be filled with the begin/end offset
+     * characters of the precise error's trigger.
+     * </p>
      * @param info character offset interval of the precise node triggering the error
      * @return a string representation of the offending expression, the empty string if it could not be determined
      */

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/UnifiedJEXL.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/UnifiedJEXL.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/UnifiedJEXL.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/UnifiedJEXL.java Sat Jul 18 19:26:02 2009
@@ -75,27 +75,30 @@
  * </p>
  * @since 2.0
  */
-public class UnifiedJEXL {
+public final class UnifiedJEXL {
     /** The JEXL engine instance. */
     private final JexlEngine jexl;
     /** The expression cache. */
     private final Map<String, Expression> cache;
-
+    /** The default cache size. */
+    private static final int CACHE_SIZE = 512;
+    /** The default cache load-factor. */
+    private static final float LOAD_FACTOR = 0.75f;
     /**
      * Creates a new instance of UnifiedJEXL with a default size cache.
-     * @param jexl the JexlEngine to use.
+     * @param aJexl the JexlEngine to use.
      */
-    public UnifiedJEXL(JexlEngine jexl) {
-        this(jexl, 512);
+    public UnifiedJEXL(JexlEngine aJexl) {
+        this(aJexl, CACHE_SIZE);
     }
 
     /**
      * Creates a new instance of UnifiedJEXL creating a local cache.
-     * @param jexl the JexlEngine to use.
+     * @param aJexl the JexlEngine to use.
      * @param cacheSize the number of expressions in this cache
      */
-    public UnifiedJEXL(JexlEngine jexl, int cacheSize) {
-        this.jexl = jexl;
+    public UnifiedJEXL(JexlEngine aJexl, int cacheSize) {
+        this.jexl = aJexl;
         this.cache = cacheSize > 0 ? createCache(cacheSize) : null;
     }
 
@@ -105,7 +108,7 @@
      * @return a LinkedHashMap
      */
     private static Map<String, Expression> createCache(final int cacheSize) {
-        return new LinkedHashMap<String, Expression>(cacheSize, 0.75f, true) {
+        return new LinkedHashMap<String, Expression>(cacheSize, LOAD_FACTOR, true) {
             @Override
             protected boolean removeEldestEntry(Map.Entry eldest) {
                 return size() > cacheSize;
@@ -126,6 +129,10 @@
         COMPOSITE(-1); // composite are not counted
         /** the index in arrays of expression counters for composite expressions. */
         private final int index;
+        /**
+         * Creates an ExpressionType.
+         * @param index the index for this type in counters arrays.
+         */
         ExpressionType(int index) {
             this.index = index;
         }
@@ -139,9 +146,13 @@
         private final int[] counts;
         private final ArrayList<Expression> expressions;
 
+        /**
+         * Creates a builder.
+         * @param size the initial expression array size
+         */
         ExpressionBuilder(int size) {
-           counts = new int[]{0, 0, 0};
-           expressions = new ArrayList<Expression>(size <= 0? 3 : size);
+            counts = new int[]{0, 0, 0};
+            expressions = new ArrayList<Expression>(size <= 0 ? 3 : size);
         }
 
         /**
@@ -161,24 +172,29 @@
          */
         Expression build(UnifiedJEXL el, Expression source) {
             int sum = 0;
-            for(int count : counts) {
+            for (int count : counts) {
                 sum += count;
             }
             if (expressions.size() != sum) {
-                String error = "parsing algorithm error, exprs: " + expressions.size() +
-                   ", constant:" + counts[ExpressionType.CONSTANT.index] +
-                   ", immediate:" + counts[ExpressionType.IMMEDIATE.index] +
-                   ", deferred:" + counts[ExpressionType.DEFERRED.index];
-                throw new IllegalStateException(error);
+                StringBuilder error = new StringBuilder("parsing algorithm error, exprs: ");
+                error.append(expressions.size());
+                error.append(", constant:");
+                error.append(counts[ExpressionType.CONSTANT.index]);
+                error.append(", immediate:");
+                error.append(counts[ExpressionType.IMMEDIATE.index]);
+                error.append(", deferred:");
+                error.append(counts[ExpressionType.DEFERRED.index]);
+                throw new IllegalStateException(error.toString());
             }
             // if only one sub-expr, no need to create a composite
-            return (expressions.size() == 1)?
-                    expressions.get(0) :
-                    el.new CompositeExpression(counts, expressions, source);
+            if (expressions.size() == 1) {
+                return expressions.get(0);
+            } else {
+                return el.new CompositeExpression(counts, expressions, source);
+            }
         }
     }
 
-
     /**
      * Gets the JexlEngine underlying the UnifiedJEXL.
      * @return the JexlEngine
@@ -191,6 +207,7 @@
      * The sole type of (runtime) exception the UnifiedJEXL can throw.
      */
     public class Exception extends RuntimeException {
+        /** {@inheritDoc} */
         public Exception(String msg, Throwable cause) {
             super(msg, cause);
         }
@@ -201,7 +218,10 @@
      */
     public abstract class Expression {
         protected final Expression source;
-
+        /**
+         * Creates an expression.
+         * @param source the source expression if any
+         */
         Expression(Expression source) {
             this.source = source != null ? source : this;
         }
@@ -219,6 +239,7 @@
             }
             return strb.toString();
         }
+
         /**
          * Generates this expression's string representation.
          * @return the string representation
@@ -258,7 +279,8 @@
          * If the underlying JEXL engine is silent, errors will be logged through its logger as warning.
          * </p>
          * @param context the variable context
-         * @return the result of this expression evaluation or null if an error occurs and the {@link JexlEngine} is silent
+         * @return the result of this expression evaluation or null if an error occurs and the {@link JexlEngine} is
+         * silent
          * @throws {@link UnifiedJEXL.Exception} if an error occurs and the {@link JexlEngine} is not silent
          */
         public abstract Object evaluate(JexlContext context);
@@ -317,7 +339,11 @@
     /** A constant expression. */
     private class ConstantExpression extends Expression {
         private final Object value;
-
+        /**
+         * Creates a constant expression.
+         * @param value the constant value
+         * @param source the source expression if any
+         */
         ConstantExpression(Object value, Expression source) {
             super(source);
             if (value == null) {
@@ -349,14 +375,12 @@
             if (value instanceof String || value instanceof CharSequence) {
                 for (int i = 0, size = str.length(); i < size; ++i) {
                     char c = str.charAt(i);
-                    if (c == '"')
+                    if (c == '"' || c == '\\') {
                         strb.append('\\');
-                    else if (c == '\\')
-                        strb.append("\\\\");
+                    }
                     strb.append(c);
                 }
-            }
-            else {
+            } else {
                 strb.append(str);
             }
         }
@@ -380,16 +404,20 @@
         Object evaluate(Interpreter interpreter) throws ParseException {
             return value;
         }
-
     }
 
 
     /** The base for Jexl based expressions. */
-    abstract private class JexlBasedExpression extends Expression {
+    private abstract class JexlBasedExpression extends Expression {
         protected final CharSequence expr;
         protected final SimpleNode node;
-
-        JexlBasedExpression(CharSequence expr, SimpleNode node, Expression source) {
+        /**
+         * Creates a JEXL interpretable expression.
+         * @param expr the expression as a string
+         * @param node the expression as an AST
+         * @param source the source expression if any
+         */
+        protected JexlBasedExpression(CharSequence expr, SimpleNode node, Expression source) {
             super(source);
             this.expr = expr;
             this.node = node;
@@ -402,7 +430,7 @@
                 strb.append(source.toString());
                 strb.append(" /*= ");
             }
-            strb.append(isImmediate()? '$' : '#');
+            strb.append(isImmediate() ? '$' : '#');
             strb.append("{");
             strb.append(expr);
             strb.append("}");
@@ -414,7 +442,7 @@
 
         @Override
         public void asString(StringBuilder strb) {
-            strb.append(isImmediate()? '$' : '#');
+            strb.append(isImmediate() ? '$' : '#');
             strb.append("{");
             strb.append(expr);
             strb.append("}");
@@ -439,11 +467,17 @@
         Object evaluate(Interpreter interpreter) throws ParseException {
             return interpreter.interpret(node);
         }
-
     }
 
+
     /** An immediate expression: ${jexl}. */
     private class ImmediateExpression extends JexlBasedExpression {
+        /**
+         * Creates an immediate expression.
+         * @param expr the expression as a string
+         * @param node the expression as an AST
+         * @param source the source expression if any
+         */
         ImmediateExpression(CharSequence expr, SimpleNode node, Expression source) {
             super(expr, node, source);
         }
@@ -461,6 +495,12 @@
 
     /** An immediate expression: ${jexl}. */
     private class DeferredExpression extends JexlBasedExpression {
+        /**
+         * Creates a deferred expression.
+         * @param expr the expression as a string
+         * @param node the expression as an AST
+         * @param source the source expression if any
+         */
         DeferredExpression(CharSequence expr, SimpleNode node, Expression source) {
             super(expr, node, source);
         }
@@ -482,13 +522,19 @@
      * Note that the deferred syntax is JEXL's, not UnifiedJEXL.
      */
     private class NestedExpression extends DeferredExpression {
+        /**
+         * Creates a nested expression.
+         * @param expr the expression as a string
+         * @param node the expression as an AST
+         * @param source the source expression if any
+         */
         NestedExpression(CharSequence expr, SimpleNode node, Expression source) {
             super(expr, node, source);
             if (this.source != this) {
                 throw new IllegalArgumentException("Nested expression can not have a source");
             }
         }
-        
+
         @Override
         ExpressionType getType() {
             return ExpressionType.NESTED;
@@ -521,21 +567,23 @@
     /** A composite expression: "... ${...} ... #{...} ...". */
     private class CompositeExpression extends Expression {
         // bit encoded (deferred count > 0) bit 1, (immediate count > 0) bit 0
-        final int meta;
+        private final int meta;
         // the list of expression resulting from parsing
-        final Expression[] exprs;
-
+        private final Expression[] exprs;
+        /**
+         * Creates a composite expression.
+         * @param counts counters of expression per type
+         * @param exprs the sub-expressions
+         * @param source the source for this expresion if any
+         */
         CompositeExpression(int[] counts, ArrayList<Expression> exprs, Expression source) {
             super(source);
             this.exprs = exprs.toArray(new Expression[exprs.size()]);
-            this.meta = (counts[ExpressionType.DEFERRED.index] > 0? 2 : 0) |
-                        (counts[ExpressionType.IMMEDIATE.index] > 0? 1 : 0);
-        }
-
-        int size() {
-            return exprs.length;
+            this.meta = (counts[ExpressionType.DEFERRED.index] > 0 ? 2 : 0) |
+                        (counts[ExpressionType.IMMEDIATE.index] > 0 ? 1 : 0);
         }
 
+        @Override
         ExpressionType getType() {
             return ExpressionType.COMPOSITE;
         }
@@ -561,21 +609,23 @@
         @Override
         Expression prepare(Interpreter interpreter) throws ParseException {
             // if this composite is not its own source, it is already prepared
-            if (source != this) return this;
+            if (source != this) {
+                return this;
+            }
             // we need to eval immediate expressions if there are some deferred/nested
             // ie both immediate & deferred counts > 0, bits 1 & 0 set, (1 << 1) & 1 == 3
             final boolean evalImmediate = meta == 3;
-            final int size = size();
+            final int size = exprs.length;
             final ExpressionBuilder builder = new ExpressionBuilder(size);
             // tracking whether prepare will return a different expression
             boolean eq = true;
-            for(int e = 0; e < size; ++e) {
+            for (int e = 0; e < size; ++e) {
                 Expression expr = exprs[e];
                 Expression prepared = expr.prepare(interpreter);
                 if (evalImmediate && prepared instanceof ImmediateExpression) {
                     // evaluate immediate as constant
                     Object value = prepared.evaluate(interpreter);
-                    prepared = value == null? null : new ConstantExpression(value, prepared);
+                    prepared = value == null ? null : new ConstantExpression(value, prepared);
                 }
                 // add it if not null
                 if (prepared != null) {
@@ -584,11 +634,10 @@
                 // keep track of expression equivalence
                 eq &= expr == prepared;
             }
-            Expression ready = eq? this : builder.build(UnifiedJEXL.this, this);
+            Expression ready = eq ? this : builder.build(UnifiedJEXL.this, this);
             return ready;
         }
 
-
         @Override
         public Object evaluate(JexlContext context) {
             return UnifiedJEXL.this.evaluate(context, this);
@@ -596,7 +645,7 @@
 
         @Override
         Object evaluate(Interpreter interpreter) throws ParseException {
-            final int size = size();
+            final int size = exprs.length;
             Object value = null;
             // common case: evaluate all expressions & concatenate them as a string
             StringBuilder strb = new StringBuilder();
@@ -624,8 +673,7 @@
         try {
             if (cache == null) {
                 return parseExpression(expression);
-            }
-            else synchronized (cache) {
+            } else synchronized (cache) {
                 Expression stmt = cache.get(expression);
                 if (stmt == null) {
                     stmt = parseExpression(expression);
@@ -633,19 +681,17 @@
                 }
                 return stmt;
             }
-        }
-        catch(JexlException xjexl) {
+        } catch (JexlException xjexl) {
             Exception xuel = new Exception("failed to parse '" + expression + "'", xjexl);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
-        }
-        catch(ParseException xparse) {
+        } catch (ParseException xparse) {
             Exception xuel = new Exception("failed to parse '" + expression + "'", xparse);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
@@ -665,19 +711,17 @@
             Interpreter interpreter = jexl.createInterpreter(context);
             interpreter.setSilent(false);
             return expr.prepare(interpreter);
-        }
-        catch (JexlException xjexl) {
-            Exception xuel = createException("prepare" , expr, xjexl);
+        } catch (JexlException xjexl) {
+            Exception xuel = createException("prepare", expr, xjexl);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
-        }
-        catch (ParseException xparse) {
-            Exception xuel = createException("prepare" , expr, xparse);
+        } catch (ParseException xparse) {
+            Exception xuel = createException("prepare", expr, xparse);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
@@ -697,19 +741,17 @@
             Interpreter interpreter = jexl.createInterpreter(context);
             interpreter.setSilent(false);
             return expr.evaluate(interpreter);
-        }
-        catch (JexlException xjexl) {
-            Exception xuel = createException("evaluate" , expr, xjexl);
+        } catch (JexlException xjexl) {
+            Exception xuel = createException("evaluate", expr, xjexl);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
-        }
-        catch (ParseException xparse) {
-            Exception xuel = createException("evaluate" , expr, xparse);
+        } catch (ParseException xparse) {
+            Exception xuel = createException("evaluate", expr, xparse);
             if (jexl.isSilent()) {
-                jexl.LOG.warn(xuel.getMessage(), xuel.getCause());
+                jexl.logger.warn(xuel.getMessage(), xuel.getCause());
                 return null;
             }
             throw xuel;
@@ -729,8 +771,8 @@
      * Creates a UnifiedJEXL.Exception from a JexlException.
      * @param action parse, prepare, evaluate
      * @param expr the expression
-     * @param xjexl the exception
-     * @return a "meaningfull" error message
+     * @param xany the exception
+     * @return an exception contained an explicit error message
      */
     private Exception createException(String action, Expression expr, java.lang.Exception xany) {
         StringBuilder strb = new StringBuilder("failed to ");
@@ -744,11 +786,12 @@
             if (causeMsg != null) {
                 strb.append(", ");
                 strb.append(causeMsg);
-             }
+            }
         }
         return new Exception(strb.toString(), xany);
     }
 
+
     /** The different parsing states. */
     private static enum ParseState {
         CONST, // parsing a constant string
@@ -760,7 +803,7 @@
     }
 
     /**
-     * Parses a unified expression
+     * Parses a unified expression.
      * @param expr the expression
      * @param counts the expression type counters
      * @return the list of expressions
@@ -777,7 +820,9 @@
         for (int i = 0; i < size; ++i) {
             char c = expr.charAt(i);
             switch (state) {
-                case CONST: {
+                default: // in case we ever add new expression type
+                    throw new UnsupportedOperationException("unexpected expression type");
+                case CONST:
                     if (c == '$') {
                         state = ParseState.IMMEDIATE0;
                     } else if (c == '#') {
@@ -790,8 +835,7 @@
                         strb.append(c);
                     }
                     break;
-                }
-                case IMMEDIATE0: { // $
+                case IMMEDIATE0: // $
                     if (c == '{') {
                         state = ParseState.IMMEDIATE1;
                         // if chars in buffer, create constant
@@ -807,8 +851,7 @@
                         state = ParseState.CONST;
                     }
                     break;
-                }
-                case DEFERRED0: { // #
+                case DEFERRED0: // #
                     if (c == '{') {
                         state = ParseState.DEFERRED1;
                         // if chars in buffer, create constant
@@ -824,8 +867,7 @@
                         state = ParseState.CONST;
                     }
                     break;
-                }
-                case IMMEDIATE1: { // ${...
+                case IMMEDIATE1: // ${...
                     if (c == '}') {
                         // materialize the immediate expr
                         //Expression iexpr = createExpression(ExpressionType.IMMEDIATE, strb, null);
@@ -838,8 +880,7 @@
                         strb.append(c);
                     }
                     break;
-                }
-                case DEFERRED1: { // #{...
+                case DEFERRED1: // #{...
                     // skip inner strings (for '}')
                     if (c == '"' || c == '\'') {
                         strb.append(c);
@@ -862,9 +903,12 @@
                             inner -= 1;
                         } else {
                             // materialize the nested/deferred expr
-                            Expression dexpr = nested?
-                                               new NestedExpression(expr.substring(inested, i+1), toNode(strb), null) :
-                                               new DeferredExpression(strb.toString(), toNode(strb), null);
+                            Expression dexpr = null;
+                            if (nested) {
+                                dexpr = new NestedExpression(expr.substring(inested, i + 1), toNode(strb), null);
+                            } else {
+                                dexpr = new DeferredExpression(strb.toString(), toNode(strb), null);
+                            }
                             builder.add(dexpr);
                             strb.delete(0, Integer.MAX_VALUE);
                             nested = false;
@@ -875,8 +919,7 @@
                         strb.append(c);
                     }
                     break;
-                }
-                case ESCAPE: {
+                case ESCAPE:
                     if (c == '#') {
                         strb.append('#');
                     } else {
@@ -884,13 +927,12 @@
                         strb.append(c);
                     }
                     state = ParseState.CONST;
-                }
-
             }
         }
         // we should be in that state
-        if (state != ParseState.CONST)
+        if (state != ParseState.CONST) {
             throw new ParseException("malformed expression: " + expr);
+        }
         // if any chars were buffered, add them as a constant
         if (strb.length() > 0) {
             Expression cexpr = new ConstantExpression(strb.toString(), null);

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/EnumerationIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/EnumerationIterator.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/EnumerationIterator.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/EnumerationIterator.java Sat Jul 18 19:26:02 2009
@@ -68,5 +68,4 @@
     public void remove() {
         // not implemented
     }
-   
 }
\ No newline at end of file

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java?rev=795421&r1=795420&r2=795421&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java Sat Jul 18 19:26:02 2009
@@ -76,6 +76,6 @@
      * @return o.get(property)
      */
     public Object execute(final Object o) {
-        return ((Map<?,?>) o).get(property);
+        return ((Map<String,?>) o).get(property);
     }
 }
\ No newline at end of file



Mime
View raw message