commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r884650 [1/2] - in /commons/proper/jexl/trunk: ./ src/main/java/org/apache/commons/jexl2/ src/main/java/org/apache/commons/jexl2/context/ src/main/java/org/apache/commons/jexl2/scripting/ src/test/java/org/apache/commons/jexl2/ src/test/jav...
Date Thu, 26 Nov 2009 17:17:44 GMT
Author: henrib
Date: Thu Nov 26 17:17:42 2009
New Revision: 884650

URL: http://svn.apache.org/viewvc?rev=884650&view=rev
Log:
JEXL-92: refactored JexlContext, removed JexlHelper & HashMapContext

Removed:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlHelper.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/context/HashMapContext.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/context/package.html
Modified:
    commons/proper/jexl/trunk/pom.xml
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlContext.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Main.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/package.html
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/scripting/JexlScriptEngine.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArrayLiteralTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/BlockTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MapLiteralTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/WhileTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/ArrayTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/examples/MethodPropertyTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java
    commons/proper/jexl/trunk/xdocs/index.xml
    commons/proper/jexl/trunk/xdocs/reference/examples.xml

Modified: commons/proper/jexl/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/pom.xml?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/pom.xml (original)
+++ commons/proper/jexl/trunk/pom.xml Thu Nov 26 17:17:42 2009
@@ -222,7 +222,7 @@
                 <version>2.3</version>
                 <configuration>
                     <configLocation>${basedir}/src/main/config/checkstyle.xml</configLocation>
-                    <excludes>org/apache/commons/jexl/parser/*.java</excludes>
+                    <excludes>org/apache/commons/jexl2/parser/*.java</excludes>
                     <headerFile>${basedir}/src/main/config/header.txt</headerFile>
                     <enableRulesSummary>false</enableRulesSummary>
                 </configuration>
@@ -234,8 +234,8 @@
                 <configuration>
                     <instrumentation>
                         <excludes>
-                            <exclude>org/apache/commons/jexl/parser/*.class</exclude>
-                            <exclude>apache/commons/jexl/**/*Test.class</exclude>
+                            <exclude>org/apache/commons/jexl2/parser/*.class</exclude>
+                            <exclude>apache/commons/jexl2/**/*Test.class</exclude>
                         </excludes>
                     </instrumentation>
                 </configuration>

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java Thu Nov 26 17:17:42 2009
@@ -360,7 +360,7 @@
                     variableName.append('.');
                     variableName.append(left.jjtGetChild(v).image);
                 }
-                object = context.getVars().get(variableName.toString());
+                object = context.getJexlVariable(variableName.toString());
                 // disallow mixing ant & bean with same root; avoid ambiguity
                 if (object != null) {
                     isVariable = false;
@@ -382,7 +382,7 @@
                     variableName.append(property);
                     property = variableName.toString();
                 }
-                context.getVars().put(String.valueOf(property), right);
+                context.setJexlVariable(String.valueOf(property), right);
                 return right;
             }
         } else if (propertyNode instanceof ASTIntegerLiteral) {
@@ -396,7 +396,7 @@
                     variableName.append(property);
                     property = variableName.toString();
                 }
-                context.getVars().put(String.valueOf(property), right);
+                context.setJexlVariable(String.valueOf(property), right);
                 return right;
             }
         } else if (propertyNode instanceof ASTArrayAccess) {
@@ -584,7 +584,7 @@
             while (itemsIterator.hasNext()) {
                 // set loopVariable to value of iterator
                 Object value = itemsIterator.next();
-                context.getVars().put(loopVariable.image, value);
+                context.setJexlVariable(loopVariable.image, value);
                 // execute statement
                 result = statement.jjtAccept(this, data);
             }
@@ -626,10 +626,10 @@
                     return registers[3];
                 }
             }
-            Object value = context.getVars().get(name);
+            Object value = context.getJexlVariable(name);
             if (value == null
                 && !(node.jjtGetParent() instanceof ASTReference)
-                && !context.getVars().containsKey(name)) {
+                && JexlEngine.isVariableUndefined(context, name)) {
                 JexlException xjexl = new JexlException(node, "undefined variable " + name);
                 return unknownVariable(xjexl);
             }
@@ -975,7 +975,6 @@
         // pass first piece of data in and loop through children
         Object result = null;
         StringBuilder variableName = null;
-        Map<String, ?> vars = context.getVars();
         boolean isVariable = true;
         int v = 0;
         for (int c = 0; c < numChildren; c++) {
@@ -992,18 +991,15 @@
                     variableName.append('.');
                     variableName.append(node.jjtGetChild(v).image);
                 }
-                result = vars.get(variableName.toString());
+                result = context.getJexlVariable(variableName.toString());
             }
         }
         if (result == null) {
             if (isVariable
                 && !(node.jjtGetParent() instanceof ASTTernaryNode)
-                && !vars.containsKey(variableName.toString())) {
+                && JexlEngine.isVariableUndefined(context, variableName.toString())) {
                 JexlException xjexl = new JexlException(node, "undefined variable " + variableName.toString());
-                if (strict) {
-                    throw xjexl;
-                }
-                logger.warn(xjexl.getMessage());
+                return unknownVariable(xjexl);
             }
         }
         return result;

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlContext.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlContext.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlContext.java Thu Nov 26 17:17:42 2009
@@ -16,33 +16,84 @@
  */
 package org.apache.commons.jexl2;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Holds a Map of variables which are referenced in a JEXL expression.
+ * Manages variables which can be referenced in a JEXL expression.
  *
  *  @since 1.0
- *  @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
  *  @version $Id$
  */
 public interface JexlContext {
     /**
-     * Replaces variables in a JexlContext with the variables contained
-     * in the supplied Map.  When setVars() is called on a JexlContext,
-     * it clears the current Map and puts each entry of the
-     * supplied Map into the current variable Map. 
-     * 
-     * @param vars Contents of vars will be replaced with the content 
-     *      of this Map
+     * Gets the value of a variable.
+     * @param name the variable's name
+     * @return the value
      */
-    void setVars(Map<String,Object> vars);
-    
+    Object getJexlVariable(String name);
+
+    /**
+     * Sets the value of a variable.
+     * @param name the variable's name
+     * @param value the variable's value
+     */
+    void setJexlVariable(String name, Object value);
+
     /**
-     * Retrives the Map of variables associated with this JexlContext.  The
-     * keys of this map correspond to variable names referenced in a
-     * JEXL expression.
-     * 
-     * @return A reference to the variable Map associated with this JexlContext.
+     * A context that differentiates null valued variables and undefined ones.
+     * <p>A non-nullable context does not allow differentiating a variable whose
+     * value is null and an undefined one; thus the Nullable name for this kind of context.</p>
      */
-    Map<String,Object> getVars();
+    public interface Nullable extends JexlContext {
+        /**
+         * Checks whether a variable is defined in this context.
+         * <p>A variable may be defined with a null value; this method checks whether the
+         * value is null or if the variable is undefined.</p>
+         * @param name the variable's name
+         * @return true if it exists, false otherwise
+         */
+        boolean definesJexlVariable(String name);
+    }
+
+    /**
+     * Wraps a map in a context.
+     * <p>Each entry in the map is considered a variable name, value pair.</p>
+     */
+    public static class Mapped implements Nullable {
+        /**
+         * The wrapped variable map.
+         */
+        protected final Map<Object,Object> map;
+        /**
+         * Creates an instance using an HashMap as the underlying variable storage.
+         */
+        public Mapped() {
+            this(null);
+        }
+        /**
+         * Creates an instance using a provided map as the underlying variable storage.
+         * @param vars the variables map
+         */
+        @SuppressWarnings("unchecked")
+        public Mapped(Map<?, ?> vars) {
+            map = (Map<Object,Object>) (vars == null? new HashMap<String,Object>() : vars);
+        }
+
+        /** {@inheritDoc} */
+        public boolean definesJexlVariable(String name) {
+            return map.containsKey(name);
+        }
+
+        /** {@inheritDoc} */
+        public Object getJexlVariable(String name) {
+            return map.get(name);
+        }
+
+        /** {@inheritDoc} */
+        public void setJexlVariable(String name, Object value) {
+            map.put(name, value);
+        }
+    }
+
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java Thu Nov 26 17:17:42 2009
@@ -87,7 +87,39 @@
  * </p>
  * @since 2.0
  */
-public class JexlEngine {
+public class JexlEngine {    
+
+    /**
+     * Checks whether a variable is defined in a context.
+     * @param context the context
+     * @param name the variable's name
+     * @return true if the variable is defined, false otherwise
+     */
+    protected static boolean isVariableUndefined(JexlContext context, String name) {
+        if (context instanceof JexlContext.Nullable) {
+            return !((JexlContext.Nullable) context).definesJexlVariable(name);
+        }
+        return context.getJexlVariable(name) == null;
+    }
+    
+    /**
+     * An empty/static/non-mutable JexlContext used instead of null context.
+     */
+    protected static final JexlContext EMPTY_CONTEXT = new JexlContext.Nullable() {
+        /** {@inheritDoc} */
+        public Object getJexlVariable(String name) {
+            return null;
+        }
+        /** {@inheritDoc} */
+        public boolean definesJexlVariable(String name) {
+            return false;
+        }
+        /** {@inheritDoc} */
+        public void setJexlVariable(String name, Object value) {
+            throw new UnsupportedOperationException("Not supported in void context.");
+        }
+    };
+
     /**
      * The Uberspect instance.
      */
@@ -124,19 +156,6 @@
      */
     protected SoftCache<String, ASTJexlScript> cache = null;
     /**
-     * An empty/static/non-mutable JexlContext used instead of null context.
-     */
-    protected static final JexlContext EMPTY_CONTEXT = new JexlContext() {
-        /** {@inheritDoc} */
-        public void setVars(Map<String, Object> vars) {
-            throw new UnsupportedOperationException("Immutable JexlContext");
-        }
-        /** {@inheritDoc} */
-        public Map<String, Object> getVars() {
-            return Collections.emptyMap();
-        }
-    };
-    /**
      * The default cache load factor.
      */
     private static final float LOAD_FACTOR = 0.75f;
@@ -447,10 +466,9 @@
         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) {
+        for (int s = 0; !isVariableUndefined(context, r0); ++s) {
             r0 = r0 + s;
         }
         expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
@@ -504,13 +522,12 @@
         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) {
+        for (int s = 0; !isVariableUndefined(context, r0); ++s) {
             r0 = r0 + s;
         }
-        for (int s = 0; vars.containsKey(r1); ++s) {
+        for (int s = 0; !isVariableUndefined(context, r1); ++s) {
             r1 = r1 + s;
         }
         // synthetize expr
@@ -753,9 +770,9 @@
                     cache.put(expr, tree);
                 }
             } catch (TokenMgrError xtme) {
-                throw new JexlException(info, "parsing failed", xtme);
+                throw new JexlException(info, "tokenization failed", xtme);
             } catch (ParseException xparse) {
-                throw new JexlException(info, "pasing failed", xparse);
+                throw new JexlException(info, "parsing failed", xparse);
             }
         }
         return tree;

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Main.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Main.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Main.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Main.java Thu Nov 26 17:17:42 2009
@@ -21,8 +21,6 @@
 import java.io.File;
 import java.io.InputStreamReader;
 
-import org.apache.commons.jexl2.context.HashMapContext;
-
 /**
  * Test application for JEXL.
  *
@@ -45,8 +43,8 @@
      */
     public static void main(String[] args) throws Exception {
         JexlEngine engine = new JexlEngine();
-        JexlContext context = new HashMapContext();
-        context.getVars().put("args", args);
+        JexlContext context = new JexlContext.Mapped();
+        context.setJexlVariable("args", args);
         if (args.length == 1) {
             Script script = engine.createScript(new File(args[0]));
             Object value = script.execute(context);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/package.html
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/package.html?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/package.html (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/package.html Thu Nov 26 17:17:42 2009
@@ -58,8 +58,8 @@
             Expression e = jexl.createExpression( jexlExp );
 
             // Create a context and add data
-            JexlContext jc = JexlHelper.createContext();
-            jc.getVars().put("foo", new Foo() );
+            JexlContext jc = new JexlContext.Mapped();
+            jc.setJexlVariable("foo", new Foo() );
 
             // Now evaluate the expression, getting the result
             Object o = e.evaluate(jc);
@@ -134,8 +134,8 @@
         <pre>
             JexlEngine jexl = nex JexlEngine();
 
-            JexlContext jc = JexlHelper.createContext();
-            jc.getVars().put("quuxClass", quux.class);
+            JexlContext jc = new JexlContext.Mapped();
+            jc.setJexlVariable("quuxClass", quux.class);
 
             Expression create = jexl.createExpression("quux = new(quuxClass, 'xuuq', 100)");
             Expression assign = jexl.createExpression("quux.froboz.value = 10");
@@ -219,8 +219,8 @@
             JexlEngine jexl = new JexlEngine();
             jexl.setFunctions(funcs);
 
-            JexlContext jc = JexlHelper.createContext();
-            jc.getVars().put("pi", Math.PI);
+            JexlContext jc = new JexlContext.Mapped();
+            jc.setJexlVariable("pi", Math.PI);
 
             e = JEXL.createExpression("math:cos(pi)");
             o = e.evaluate(jc);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/scripting/JexlScriptEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/scripting/JexlScriptEngine.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/scripting/JexlScriptEngine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/scripting/JexlScriptEngine.java Thu Nov 26 17:17:42 2009
@@ -20,9 +20,6 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.Reader;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
 
 import javax.script.AbstractScriptEngine;
 import javax.script.Bindings;
@@ -137,16 +134,7 @@
         
         try {
             Script script = jexlEngine.createScript(scriptText);
-            JexlContext ctxt = new JexlContext(){
-                @SuppressWarnings("unchecked")
-                public void setVars(Map vars) {
-                    context.setBindings(new SimpleBindings(vars), ScriptContext.ENGINE_SCOPE);
-                }
-
-                public Map<String,Object> getVars() {
-                    return new JexlContextWrapper(context);
-                }
-            };
+            JexlContext ctxt = new JexlContextWrapper(context);
             return script.execute(ctxt);
         } catch (Exception e) {
             throw new ScriptException(e.toString());
@@ -168,18 +156,16 @@
 
     /**
      * Wrapper to help convert a JSR-223 ScriptContext into a JexlContext.
-     * 
+     *
      * Current implementation only gives access to ENGINE_SCOPE binding.
      */
     @SuppressWarnings("unchecked")
-    private static class JexlContextWrapper implements Map<String,Object> {
-        
+    private static class JexlContextWrapper implements JexlContext.Nullable {
         /** The engine context. */
         private final ScriptContext engineContext;
-
         /**
          * Create the class.
-         * 
+         *
          * @param context the engine context.
          */
         private JexlContextWrapper (final ScriptContext  context){
@@ -187,88 +173,23 @@
         }
 
         /** {@inheritDoc} */
-        public void clear() {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            bnd.clear();
-        }
-
-        /** {@inheritDoc} */
-        public boolean containsKey(final Object key) {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.containsKey(key);
-        }
-
-        /** {@inheritDoc} */
-        public boolean containsValue(final Object value) {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.containsValue(value);
-        }
-
-        /** {@inheritDoc} */
-        public Set entrySet() {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.entrySet();
-        }
-
-        // Fetch first match of key, either engine or global
-        /** {@inheritDoc} */
-        public Object get(final Object key) {
-            if (key instanceof String) {
-                return engineContext.getAttribute((String) key);
-            }
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        public boolean isEmpty() {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.isEmpty();
+        public Object getJexlVariable(String name) {
+            return engineContext.getAttribute(name);
         }
 
         /** {@inheritDoc} */
-        public Set keySet() {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.keySet();
-        }
-
-        // Update existing key if found, else create new engine key
-        /** {@inheritDoc} */
-        public Object put(final String key, final Object value) {
-            int scope = engineContext.getAttributesScope(key);
+        public void setJexlVariable(String name, Object value) {
+            int scope = engineContext.getAttributesScope(name);
             if (scope == -1) { // not found, default to engine
                 scope = ScriptContext.ENGINE_SCOPE;
             }
-            return engineContext.getBindings(scope).put(key , value);
-        }
-
-        /** {@inheritDoc} */
-        public void putAll(Map t) {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            bnd.putAll(t); // N.B. SimpleBindings checks for valid keys
-        }
-
-        // N.B. if there is more than one copy of the key, only the nearest will be removed.
-        /** {@inheritDoc} */
-        public Object remove(Object key) {
-            if (key instanceof String){
-                int scope = engineContext.getAttributesScope((String) key);
-                if (scope != -1) { // found an entry
-                    return engineContext.removeAttribute((String)key, scope);
-                }
-            }
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        public int size() {
-            Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.size();
+            engineContext.getBindings(scope).put(name , value);
         }
 
         /** {@inheritDoc} */
-        public Collection values() {
+        public boolean definesJexlVariable(String name) {
             Bindings bnd = engineContext.getBindings(ScriptContext.ENGINE_SCOPE);
-            return bnd.values();
+            return bnd.containsKey(name);
         }
 
     }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java Thu Nov 26 17:17:42 2009
@@ -20,6 +20,7 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 
+import java.util.HashMap;
 import org.apache.commons.jexl2.junit.Asserter;
 
 
@@ -158,8 +159,8 @@
      * @throws Exception
      */
     public void testDivideByZero() throws Exception {
-        JexlContext context = JexlHelper.createContext();
-        Map<String, Object> vars = context.getVars();
+        Map<String,Object> vars = new HashMap<String,Object>();
+        JexlContext context = new JexlContext.Mapped(vars);
         vars.put("aByte", new Byte((byte) 1));
         vars.put("aShort", new Short((short) 2));
         vars.put("aInteger", new Integer(3));

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArrayLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArrayLiteralTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArrayLiteralTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArrayLiteralTest.java Thu Nov 26 17:17:42 2009
@@ -26,7 +26,7 @@
 
     public void testLiteralWithStrings() throws Exception {
         Expression e = JEXL.createExpression( "[ 'foo' , 'bar' ]" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         Object[] check = { "foo", "bar" };
@@ -35,7 +35,7 @@
 
     public void testLiteralWithOneEntry() throws Exception {
         Expression e = JEXL.createExpression( "[ 'foo' ]" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         Object[] check = { "foo" };
@@ -44,7 +44,7 @@
 
     public void testLiteralWithNumbers() throws Exception {
         Expression e = JEXL.createExpression( "[ 5.0 , 10 ]" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         Object[] check = { new Float(5), new Integer(10) };
@@ -53,7 +53,7 @@
 
     public void testLiteralWithIntegers() throws Exception {
         Expression e = JEXL.createExpression( "[ 5 , 10 ]" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         int[] check = { 5, 10 };
@@ -62,7 +62,7 @@
 
     public void testSizeOfSimpleArrayLiteral() throws Exception {
         Expression e = JEXL.createExpression( "size([ 'foo' , 'bar' ])" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         assertEquals( new Integer( 2 ), o );
@@ -70,7 +70,7 @@
 
     public void notestCallingMethodsOnNewMapLiteral() throws Exception {
         Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         assertEquals( new Integer( 1 ), o );
@@ -78,7 +78,7 @@
 
     public void testNotEmptySimpleArrayLiteral() throws Exception {
         Expression e = JEXL.createExpression( "empty([ 'foo' , 'bar' ])" );
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate( jc );
         assertFalse( ( (Boolean) o ).booleanValue() );

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java Thu Nov 26 17:17:42 2009
@@ -79,7 +79,7 @@
     public void testAntish() throws Exception {
         Expression assign = ENGINE.createExpression("froboz.value = 10");
         Expression check = ENGINE.createExpression("froboz.value");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = assign.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
         o = check.evaluate(jc);
@@ -89,9 +89,9 @@
     public void testBeanish() throws Exception {
         Expression assign = ENGINE.createExpression("froboz.value = 10");
         Expression check = ENGINE.createExpression("froboz.value");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Froboz froboz = new Froboz(-169);
-        jc.getVars().put("froboz", froboz);
+        jc.setJexlVariable("froboz", froboz);
         Object o = assign.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
         o = check.evaluate(jc);
@@ -100,9 +100,9 @@
     
     public void testAmbiguous() throws Exception {
         Expression assign = ENGINE.createExpression("froboz.nosuchbean = 10");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Froboz froboz = new Froboz(-169);
-        jc.getVars().put("froboz", froboz);
+        jc.setJexlVariable("froboz", froboz);
         Object o = null;
         try {
             o = assign.evaluate(jc);
@@ -120,9 +120,9 @@
     public void testArray() throws Exception {
         Expression assign = ENGINE.createExpression("froboz[\"value\"] = 10");
         Expression check = ENGINE.createExpression("froboz[\"value\"]");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Froboz froboz = new Froboz(0);
-        jc.getVars().put("froboz", froboz);
+        jc.setJexlVariable("froboz", froboz);
         Object o = assign.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
         o = check.evaluate(jc);
@@ -130,8 +130,8 @@
     }
     
     public void testMore() throws Exception {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("quuxClass", Quux.class);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("quuxClass", Quux.class);
         Expression create = ENGINE.createExpression("quux = new(quuxClass, 'xuuq', 100)");
         Expression assign = ENGINE.createExpression("quux.froboz.value = 10");
         Expression check = ENGINE.createExpression("quux[\"froboz\"].value");

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/BlockTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/BlockTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/BlockTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/BlockTest.java Thu Nov 26 17:17:42 2009
@@ -33,44 +33,44 @@
 
     public void testBlockSimple() throws Exception {
         Expression e = JEXL.createExpression("if (true) { 'hello'; }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
         assertEquals("Result is wrong", "hello", o);
     }
 
     public void testBlockExecutesAll() throws Exception {
         Expression e = JEXL.createExpression("if (true) { x = 'Hello'; y = 'World';}");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
-        assertEquals("First result is wrong", "Hello", jc.getVars().get("x"));
-        assertEquals("Second result is wrong", "World", jc.getVars().get("y"));
+        assertEquals("First result is wrong", "Hello", jc.getJexlVariable("x"));
+        assertEquals("Second result is wrong", "World", jc.getJexlVariable("y"));
         assertEquals("Block result is wrong", "World", o);
     }
 
     public void testEmptyBlock() throws Exception {
         Expression e = JEXL.createExpression("if (true) { }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
         assertNull("Result is wrong", o);
     }
 
     public void testBlockLastExecuted01() throws Exception {
         Expression e = JEXL.createExpression("if (true) { x = 1; } else { x = 2; }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
         assertEquals("Block result is wrong", new Integer(1), o);
     }
 
     public void testBlockLastExecuted02() throws Exception {
         Expression e = JEXL.createExpression("if (false) { x = 1; } else { x = 2; }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
         assertEquals("Block result is wrong", new Integer(2), o);
     }
 
     public void testNestedBlock() throws Exception {
         Expression e = JEXL.createExpression("if (true) { x = 'hello'; y = 'world';" + " if (true) { x; } y; }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Object o = e.evaluate(jc);
         assertEquals("Block result is wrong", "world", o);
     }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java Thu Nov 26 17:17:42 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.jexl2;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -257,8 +258,8 @@
         } else {
             jexl.setCache(0);
         }
-        JexlContext jc = JexlHelper.createContext();
-        Map<String, Object> vars = jc.getVars();
+        Map<String, Object> vars = new HashMap<String,Object>();
+        JexlContext jc = new JexlContext.Mapped(vars);
         Expression cacheGetValue = jexl.createExpression("cache.value");
         Expression cacheSetValue = jexl.createExpression("cache.value = value");
         Object result;
@@ -316,8 +317,8 @@
         } else {
             jexl.setCache(0);
         }
-        JexlContext jc = JexlHelper.createContext();
-        Map<String, Object> vars = jc.getVars();
+        Map<String, Object> vars = new HashMap<String,Object>();
+        JexlContext jc = new JexlContext.Mapped(vars);
         Expression cacheGetValue = jexl.createExpression("cache.flag");
         Expression cacheSetValue = jexl.createExpression("cache.flag = value");
         Object result;
@@ -357,8 +358,8 @@
         } else {
             jexl.setCache(0);
         }
-        JexlContext jc = JexlHelper.createContext();
-        Map<String, Object> vars = jc.getVars();
+        Map<String, Object> vars = new HashMap<String,Object>();
+        JexlContext jc = new JexlContext.Mapped(vars);
         Expression cacheGetValue = jexl.createExpression("cache.0");
         Expression cacheSetValue = jexl.createExpression("cache[0] = value");
         Object result;
@@ -412,8 +413,8 @@
         } else {
             jexl.setCache(0);
         }
-        JexlContext jc = JexlHelper.createContext();
-        Map<String, Object> vars = jc.getVars();
+        Map<String, Object> vars = new HashMap<String,Object>();
+        JexlContext jc = new JexlContext.Mapped(vars);
         jexl.setDebug(true);
         Expression compute2 = jexl.createExpression("cache.compute(a0, a1)");
         Expression compute1 = jexl.createExpression("cache.compute(a0)");
@@ -511,8 +512,8 @@
         } else {
             jexl.setCache(0);
         }
-        JexlContext jc = JexlHelper.createContext();
-        Map<String, Object> vars = jc.getVars();
+        Map<String, Object> vars = new HashMap<String,Object>();
+        JexlContext jc = new JexlContext.Mapped(vars);
         java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
         jexl.setFunctions(funcs);
         Expression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ClassCreatorTest.java Thu Nov 26 17:17:42 2009
@@ -112,7 +112,7 @@
 //        List<Object> mm = new ArrayList<Object>();
         Expression expr = jexl.createExpression("foo.value");
         Expression newx = jexl.createExpression("foo = new(clazz)");
-        JexlContext context = JexlHelper.createContext();
+        JexlContext context = new JexlContext.Mapped();
 
         ClassCreator cctor = new ClassCreator(jexl, base);
         for (int i = 0; i < LOOPS && gced < 0; ++i) {
@@ -132,12 +132,12 @@
 //          Method m = clazz.getDeclaredMethod("getValue", new Class<?>[0]);
 //          mm.add(m);
             // we should not be able to create foox since it is unknown to the Jexl classloader
-            context.getVars().put("clazz", cctor.getClassName());
-            context.getVars().put("foo", null);
+            context.setJexlVariable("clazz", cctor.getClassName());
+            context.setJexlVariable("foo", null);
             Object z = newx.evaluate(context);
             assertNull(z);
             // check with the class itself
-            context.getVars().put("clazz", clazz);
+            context.setJexlVariable("clazz", clazz);
             z = newx.evaluate(context);
             assertNotNull(clazz + ": class " + i + " could not be instantiated on pass " + pass, z);
             assertEquals(new Integer(i), expr.evaluate(context));

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ForEachTest.java Thu Nov 26 17:17:42 2009
@@ -37,7 +37,7 @@
 
     public void testForEachWithEmptyStatement() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) ;");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertNull("Result is not null", o);
@@ -45,7 +45,7 @@
 
     public void testForEachWithEmptyList() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) 1+1");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertNull("Result is not null", o);
@@ -53,78 +53,78 @@
 
     public void testForEachWithArray() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", new Object[] {"Hello", "World"});
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", new Object[] {"Hello", "World"});
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "World", o);
     }
 
     public void testForEachWithCollection() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", Arrays.asList(new Object[] {"Hello", "World"}));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", Arrays.asList(new Object[] {"Hello", "World"}));
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "World", o);
     }
 
     public void testForEachWithEnumeration() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", new StringTokenizer("Hello,World", ","));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", new StringTokenizer("Hello,World", ","));
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "World", o);
     }
 
     public void testForEachWithIterator() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "World", o);
     }
 
     public void testForEachWithMap() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) item");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Map<?, ?> map = System.getProperties();
         String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
-        jc.getVars().put("list", map);
+        jc.setJexlVariable("list", map);
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", lastProperty, o);
     }
 
     public void testForEachWithBlock() throws Exception {
         Expression e = JEXL.createExpression("for(item : list) { x = x + item; }");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", new Object[] {"1", "1"});
-        jc.getVars().put("x", new Integer(0));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", new Object[] {"1", "1"});
+        jc.setJexlVariable("x", new Integer(0));
         Object o = e.evaluate(jc);
         assertEquals("Result is wrong", new Integer(2), o);
-        assertEquals("x is wrong", new Integer(2), jc.getVars().get("x"));
+        assertEquals("x is wrong", new Integer(2), jc.getJexlVariable("x"));
     }
 
     public void testForEachWithListExpression() throws Exception {
         Expression e = JEXL.createExpression("for(item : list.keySet()) item");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Map<?, ?> map = System.getProperties();
         String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
-        jc.getVars().put("list", map);
+        jc.setJexlVariable("list", map);
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", lastKey, o);
     }
     
     public void testForEachWithProperty() throws Exception {
         Expression e = JEXL.createExpression("for(item : list.cheeseList) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", new Foo());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", new Foo());
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "brie", o);
     }
     
     public void testForEachWithIteratorMethod() throws Exception {
         Expression e = JEXL.createExpression("for(item : list.cheezy) item");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("list", new Foo());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("list", new Foo());
         Object o = e.evaluate(jc);
         assertEquals("Result is not last evaluated expression", "brie", o);
     }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java Thu Nov 26 17:17:42 2009
@@ -37,7 +37,7 @@
      */
     public void testSimpleIfTrue() throws Exception {
         Expression e = JEXL.createExpression("if (true) 1");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertEquals("Result is not 1", new Integer(1), o);
@@ -50,7 +50,7 @@
      */
     public void testSimpleIfFalse() throws Exception {
         Expression e = JEXL.createExpression("if (false) 1");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertNull("Return value is not empty", o);
@@ -64,7 +64,7 @@
     public void testSimpleElse() throws Exception {
         Expression e = JEXL
                 .createExpression("if (false) 1 else 2;");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertEquals("Result is not 2", new Integer(2), o);
@@ -78,7 +78,7 @@
     public void testBlockIfTrue() throws Exception {
         Expression e = JEXL
                 .createExpression("if (true) { 'hello'; }");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertEquals("Result is wrong", "hello", o);
@@ -92,7 +92,7 @@
     public void testBlockElse() throws Exception {
         Expression e = JEXL
                 .createExpression("if (false) {1} else {2 ; 3}");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Object o = e.evaluate(jc);
         assertEquals("Result is wrong", new Integer(3), o);
@@ -106,8 +106,8 @@
     public void testIfWithSimpleExpression() throws Exception {
         Expression e = JEXL
                 .createExpression("if (x == 1) true;");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(1));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("x", new Integer(1));
 
         Object o = e.evaluate(jc);
         assertEquals("Result is not true", Boolean.TRUE, o);
@@ -121,8 +121,8 @@
     public void testIfWithArithmeticExpression() throws Exception {
         Expression e = JEXL
                 .createExpression("if ((x * 2) + 1 == 5) true;");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Integer(2));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("x", new Integer(2));
 
         Object o = e.evaluate(jc);
         assertEquals("Result is not true", Boolean.TRUE, o);
@@ -136,8 +136,8 @@
     public void testIfWithDecimalArithmeticExpression() throws Exception {
         Expression e = JEXL
                 .createExpression("if ((x * 2) == 5) true");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Float(2.5f));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("x", new Float(2.5f));
 
         Object o = e.evaluate(jc);
         assertEquals("Result is not true", Boolean.TRUE, o);
@@ -151,11 +151,11 @@
     public void testIfWithAssignment() throws Exception {
         Expression e = JEXL
                 .createExpression("if ((x * 2) == 5) {y = 1} else {y = 2;}");
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("x", new Float(2.5f));
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("x", new Float(2.5f));
 
         e.evaluate(jc);
-        Object result = jc.getVars().get("y");
+        Object result = jc.getJexlVariable("y");
         assertEquals("y has the wrong value", new Integer(1), result);
     }
 
@@ -167,7 +167,7 @@
     public void testTernary() throws Exception {
         JexlEngine jexl = new JexlEngine();
         jexl.setCache(64);
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Expression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
         Object o;
 
@@ -178,40 +178,40 @@
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo", null);
+        jc.setJexlVariable("foo", null);
 
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo",Boolean.FALSE);
+        jc.setJexlVariable("foo",Boolean.FALSE);
 
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo",Boolean.TRUE);
+        jc.setJexlVariable("foo",Boolean.TRUE);
 
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be bar", "bar", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be bar", "bar", o);
         }
 
@@ -226,7 +226,7 @@
     public void testTernaryShorthand() throws Exception {
         JexlEngine jexl = new JexlEngine();
         jexl.setCache(64);
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Expression e = JEXL.createExpression("x.y.z = foo?:'quux'");
         Object o;
 
@@ -237,40 +237,40 @@
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo", null);
+        jc.setJexlVariable("foo", null);
 
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo", Boolean.FALSE);
+        jc.setJexlVariable("foo", Boolean.FALSE);
 
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be quux", "quux", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
 
-        jc.getVars().put("foo","bar");
+        jc.setJexlVariable("foo","bar");
         
         for(int l = 0; l < 4; ++l) {
             jexl.setLenient((l & 1) != 0);
             jexl.setSilent((l & 2) != 0);
             o = e.evaluate(jc);
             assertEquals("Should be bar", "bar", o);
-            o = jc.getVars().get("x.y.z");
+            o = jc.getJexlVariable("x.y.z");
             assertEquals("Should be bar", "bar", o);
         }
 

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java Thu Nov 26 17:17:42 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.jexl2;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -30,11 +31,11 @@
 
     // JEXL-49: blocks not parsed (fixed)
     public void test49() throws Exception {
-        JexlContext ctxt = JexlHelper.createContext();
+        Map<String,Object> vars = new HashMap<String,Object>();
+        JexlContext ctxt = new JexlContext.Mapped(vars);
         String stmt = "{a = 'b'; c = 'd';}";
         Script expr = JEXL.createScript(stmt);
         /* Object value = */ expr.execute(ctxt);
-        Map<String, Object> vars = ctxt.getVars();
         assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d"));
     }
 
@@ -69,8 +70,8 @@
         jexl.setSilent(false);
         String jexlExp = "(foo.getInner().foo() eq true) and (foo.getInner().goo() = (foo.getInner().goo()+1-1))";
         Expression e = jexl.createExpression(jexlExp);
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", new Foo());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", new Foo());
 
         try {
             /* Object o = */ e.evaluate(jc);
@@ -86,7 +87,7 @@
         JexlEngine jexl = new JexlEngine();
         // ensure errors will throw
         jexl.setSilent(false);
-        JexlContext ctxt = JexlHelper.createContext();
+        JexlContext ctxt = new JexlContext.Mapped();
 
         Expression expr = jexl.createExpression("true//false\n");
         Object value = expr.evaluate(ctxt);
@@ -108,8 +109,8 @@
         UnifiedJEXL uel = new UnifiedJEXL(jexl);
         // ensure errors will throw
         //jexl.setSilent(false);
-        JexlContext ctxt = JexlHelper.createContext();
-        ctxt.getVars().put("ax", "ok");
+        JexlContext ctxt = new JexlContext.Mapped();
+        ctxt.setJexlVariable("ax", "ok");
 
         UnifiedJEXL.Expression expr = uel.parse("${ax+(bx)}");
         Object value = expr.evaluate(ctxt);
@@ -133,8 +134,8 @@
         JexlEngine jexl = new JexlEngine();
         // ensure errors will throw
         jexl.setSilent(false);
-        JexlContext ctxt = JexlHelper.createContext();
-        ctxt.getVars().put("derived", new Derived());
+        JexlContext ctxt = new JexlContext.Mapped();
+        ctxt.setJexlVariable("derived", new Derived());
 
         Expression expr = jexl.createExpression("derived.foo()");
         Object value = expr.evaluate(ctxt);
@@ -162,15 +163,15 @@
         // ensure errors will throw
         jexl.setSilent(false);
         jexl.setLenient(false);
-        JexlContext ctxt = JexlHelper.createContext();
-        ctxt.getVars().put("a", null);
+        JexlContext ctxt = new JexlContext.Mapped();
+        ctxt.setJexlVariable("a", null);
 
         String[] exprs = {
-            "10 + null",
-            "a - 10",
-            "b * 10",
-            "a % b",
-            "1000 / a"
+            //"10 + null",
+            //"a - 10",
+            //"b * 10",
+            "a % b"//,
+            //"1000 / a"
         };
         for (int e = 0; e < exprs.length; ++e) {
             try {
@@ -191,11 +192,11 @@
 
         Script jscript;
 
-        ctxt = JexlHelper.createContext();
+        ctxt = new JexlContext.Mapped();
         jscript = jexl.createScript("dummy.hashCode()");
         assertEquals(jscript.getText(), null, jscript.execute(ctxt)); // OK
 
-        ctxt.getVars().put("dummy", "abcd");
+        ctxt.setJexlVariable("dummy", "abcd");
         assertEquals(jscript.getText(), Integer.valueOf("abcd".hashCode()), jscript.execute(ctxt)); // OK
 
         jscript = jexl.createScript("dummy.hashCode");
@@ -203,11 +204,11 @@
 
         Expression jexpr;
 
-        ctxt = JexlHelper.createContext();
+        ctxt = new JexlContext.Mapped();
         jexpr = jexl.createExpression("dummy.hashCode()");
         assertEquals(jexpr.getExpression(), null, jexpr.evaluate(ctxt)); // OK
 
-        ctxt.getVars().put("dummy", "abcd");
+        ctxt.setJexlVariable("dummy", "abcd");
         assertEquals(jexpr.getExpression(), Integer.valueOf("abcd".hashCode()), jexpr.evaluate(ctxt)); // OK
 
         jexpr = jexl.createExpression("dummy.hashCode");
@@ -216,7 +217,7 @@
 
     // JEXL-73
     public void test73() throws Exception {
-        JexlContext ctxt = JexlHelper.createContext();
+        JexlContext ctxt = new JexlContext.Mapped();
         JexlEngine jexl = new JexlEngine();
         jexl.setSilent(false);
         jexl.setLenient(false);
@@ -229,8 +230,8 @@
             assertTrue(msg.indexOf("variable c.e") > 0);
         }
 
-        ctxt.getVars().put("c", "{ 'a' : 3, 'b' : 5}");
-        ctxt.getVars().put("e", Integer.valueOf(2));
+        ctxt.setJexlVariable("c", "{ 'a' : 3, 'b' : 5}");
+        ctxt.setJexlVariable("e", Integer.valueOf(2));
         try {
             /* Object o = */ e.evaluate(ctxt);
         } catch (JexlException xjexl) {
@@ -242,27 +243,27 @@
 
     // JEXL-87
     public void test87() throws Exception {
-        JexlContext ctxt = JexlHelper.createContext();
+        JexlContext ctxt = new JexlContext.Mapped();
         JexlEngine jexl = new JexlEngine();
         jexl.setSilent(false);
         jexl.setLenient(false);
         Expression divide = jexl.createExpression("l / r");
         Expression modulo = jexl.createExpression("l % r");
 
-        ctxt.getVars().put("l", java.math.BigInteger.valueOf(7));
-        ctxt.getVars().put("r", java.math.BigInteger.valueOf(2));
+        ctxt.setJexlVariable("l", java.math.BigInteger.valueOf(7));
+        ctxt.setJexlVariable("r", java.math.BigInteger.valueOf(2));
         assertEquals("3", divide.evaluate(ctxt).toString());
         assertEquals("1", modulo.evaluate(ctxt).toString());
 
-        ctxt.getVars().put("l", java.math.BigDecimal.valueOf(7));
-        ctxt.getVars().put("r", java.math.BigDecimal.valueOf(2));
+        ctxt.setJexlVariable("l", java.math.BigDecimal.valueOf(7));
+        ctxt.setJexlVariable("r", java.math.BigDecimal.valueOf(2));
         assertEquals("3.5", divide.evaluate(ctxt).toString());
         assertEquals("1", modulo.evaluate(ctxt).toString());
     }
 
     // JEXL-90
     public void test90() throws Exception {
-        JexlContext ctxt = JexlHelper.createContext();
+        JexlContext ctxt = new JexlContext.Mapped();
         JexlEngine jexl = new JexlEngine();
         jexl.setSilent(false);
         jexl.setLenient(false);
@@ -291,8 +292,8 @@
             "for(z : [3, 4, 5]) { z } y ? 2 : 1",
             "for(z : [3, 4, 5]) { z } if (y) 2 else 1"
         };
-        ctxt.getVars().put("x", Boolean.FALSE);
-        ctxt.getVars().put("y", Boolean.TRUE);
+        ctxt.setJexlVariable("x", Boolean.FALSE);
+        ctxt.setJexlVariable("y", Boolean.TRUE);
         for (int e = 0; e < exprs.length; ++e) {
             Script s = jexl.createScript(exprs[e]);
             assertEquals(Integer.valueOf(2), s.execute(ctxt));
@@ -302,7 +303,7 @@
 
     // JEXL-44
     public void test44() throws Exception {
-        JexlContext ctxt = JexlHelper.createContext();
+        JexlContext ctxt = new JexlContext.Mapped();
         JexlEngine jexl = new JexlEngine();
         jexl.setSilent(false);
         jexl.setLenient(false);
@@ -316,4 +317,8 @@
         script = jexl.createScript("'hello world!';## commented\n'bye...'");
         assertEquals("bye...", script.execute(ctxt));
     }
+
+    public static void main(String[] args) throws Exception {
+        runTest("IssuesTest", "test11");
+    }
 }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/Jexl.java Thu Nov 26 17:17:42 2009
@@ -28,12 +28,9 @@
 
     public static void main(String[] args) {
         final JexlEngine JEXL = new JexlEngine();
+        Map m = System.getProperties();
         // dummy context to get variables
-        JexlContext context = new JexlContext() {
-            @SuppressWarnings("unchecked")
-            public Map getVars() { return System.getProperties(); }
-            public void setVars(Map<String,Object> map) { }
-        };
+        JexlContext context = new JexlContext.Mapped(System.getProperties());
         try {
             for (int i = 0; i < args.length; i++) {
                 Expression e = JEXL.createExpression(args[i]);

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java?rev=884650&r1=884649&r2=884650&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTest.java Thu Nov 26 17:17:42 2009
@@ -61,9 +61,9 @@
          */
 
         Expression e = JEXL.createExpression("foo.bar");
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
-        jc.getVars().put("foo", new Foo() );
+        jc.setJexlVariable("foo", new Foo() );
         Object o = e.evaluate(jc);
 
         assertTrue("o not instanceof String", o instanceof String);
@@ -73,10 +73,10 @@
     public void testBoolean()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", new Foo() );
-        jc.getVars().put("a", Boolean.TRUE);
-        jc.getVars().put("b", Boolean.FALSE);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", new Foo() );
+        jc.setJexlVariable("a", Boolean.TRUE);
+        jc.setJexlVariable("b", Boolean.FALSE);
 
         assertExpression(jc, "foo.convertBoolean(a==b)", "Boolean : false");
         assertExpression(jc, "foo.convertBoolean(a==true)", "Boolean : true");
@@ -92,24 +92,24 @@
         /*
          *  tests a simple property expression
          */
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", new Foo() );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", new Foo() );
         assertExpression(jc, "foo.get(\"woogie\")", "Repeat : woogie");
     }
 
     public void testExpression()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", new Foo() );
-        jc.getVars().put("a", Boolean.TRUE);
-        jc.getVars().put("b", Boolean.FALSE);
-        jc.getVars().put("num", new Integer(5));
-        jc.getVars().put("now", Calendar.getInstance().getTime());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", new Foo() );
+        jc.setJexlVariable("a", Boolean.TRUE);
+        jc.setJexlVariable("b", Boolean.FALSE);
+        jc.setJexlVariable("num", new Integer(5));
+        jc.setJexlVariable("now", Calendar.getInstance().getTime());
         GregorianCalendar gc = new GregorianCalendar(5000, 11, 20);
-        jc.getVars().put("now2", gc.getTime());
-        jc.getVars().put("bdec", new BigDecimal("7"));
-        jc.getVars().put("bint", new BigInteger("7"));
+        jc.setJexlVariable("now2", gc.getTime());
+        jc.setJexlVariable("bdec", new BigDecimal("7"));
+        jc.setJexlVariable("bint", new BigInteger("7"));
 
         assertExpression(jc, "a == b", Boolean.FALSE);
         assertExpression(jc, "a==true", Boolean.TRUE);
@@ -161,13 +161,13 @@
     public void testEmpty()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("string", "");
-        jc.getVars().put("array", new Object[0]);
-        jc.getVars().put("map", new HashMap<Object, Object>());
-        jc.getVars().put("list", new ArrayList<Object>());
-        jc.getVars().put("set", (new HashMap<Object, Object>()).keySet());
-        jc.getVars().put("longstring", "thingthing");
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("string", "");
+        jc.setJexlVariable("array", new Object[0]);
+        jc.setJexlVariable("map", new HashMap<Object, Object>());
+        jc.setJexlVariable("list", new ArrayList<Object>());
+        jc.setJexlVariable("set", (new HashMap<Object, Object>()).keySet());
+        jc.setJexlVariable("longstring", "thingthing");
 
         /*
          *  I can't believe anyone thinks this is a syntax.. :)
@@ -185,9 +185,9 @@
     public void testSize()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("s", "five!");
-        jc.getVars().put("array", new Object[5]);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("s", "five!");
+        jc.setJexlVariable("array", new Object[5]);
 
         Map<String, Integer> map = new HashMap<String, Integer>();
 
@@ -197,7 +197,7 @@
         map.put("4", new Integer(4));
         map.put("5", new Integer(5));
 
-        jc.getVars().put("map", map);
+        jc.setJexlVariable("map", map);
 
         List<String> list = new ArrayList<String>();
 
@@ -207,18 +207,18 @@
         list.add("4");
         list.add("5");
 
-        jc.getVars().put("list", list);
+        jc.setJexlVariable("list", list);
 
         // 30652 - support for set
         Set<String> set = new HashSet<String>();
         set.addAll(list);
         set.add("1");
         
-        jc.getVars().put("set", set);
+        jc.setJexlVariable("set", set);
         
         // support generic int size() method
         BitSet bitset = new BitSet(5);
-        jc.getVars().put("bitset", bitset);
+        jc.setJexlVariable("bitset", bitset);
 
         assertExpression(jc, "size(s)", new Integer(5));
         assertExpression(jc, "size(array)", new Integer(5));
@@ -238,11 +238,11 @@
 
     public void testSizeAsProperty() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("size", "cheese");
-        jc.getVars().put("map", map);
-        jc.getVars().put("foo", new Foo());
+        jc.setJexlVariable("map", map);
+        jc.setJexlVariable("foo", new Foo());
 
         assertExpression(jc, "map['size']", "cheese");
 // PR - unsure whether or not we should support map.size or force usage of the above 'escaped' version        
@@ -256,9 +256,9 @@
       *  test the new function e.g constructor invocation
       */
     public void testNew() throws Exception {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("double", Double.class);
-        jc.getVars().put("foo", "org.apache.commons.jexl2.Foo");
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("double", Double.class);
+        jc.setJexlVariable("foo", "org.apache.commons.jexl2.Foo");
         Expression expr;
         Object value;
         expr = JEXL.createExpression("new(double, 1)");
@@ -278,23 +278,23 @@
     public void testCalculations()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         /*
          * test to ensure new string cat works
          */
-        jc.getVars().put("stringy", "thingy" );
+        jc.setJexlVariable("stringy", "thingy" );
         assertExpression(jc, "stringy + 2", "thingy2");
 
         /*
          * test new null coersion
          */
-        jc.getVars().put("imanull", null );
+        jc.setJexlVariable("imanull", null );
         assertExpression(jc, "imanull + 2", new Integer(2));
         assertExpression(jc, "imanull + imanull", new Integer(0));
         
         /* test for bugzilla 31577 */
-        jc.getVars().put("n", new Integer(0));
+        jc.setJexlVariable("n", new Integer(0));
         assertExpression(jc, "n != null && n != 0", Boolean.FALSE);
     }
 
@@ -304,18 +304,18 @@
     public void testConditions()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", new Integer(2) );
-        jc.getVars().put("aFloat", new Float(1));
-        jc.getVars().put("aDouble", new Double(2));
-        jc.getVars().put("aChar", new Character('A'));
-        jc.getVars().put("aBool", Boolean.TRUE);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", new Integer(2) );
+        jc.setJexlVariable("aFloat", new Float(1));
+        jc.setJexlVariable("aDouble", new Double(2));
+        jc.setJexlVariable("aChar", new Character('A'));
+        jc.setJexlVariable("aBool", Boolean.TRUE);
         StringBuffer buffer = new StringBuffer("abc");
         List<Object> list = new ArrayList<Object>();
         List<Object> list2 = new LinkedList<Object>();
-        jc.getVars().put("aBuffer", buffer);
-        jc.getVars().put("aList", list);
-        jc.getVars().put("bList", list2);
+        jc.setJexlVariable("aBuffer", buffer);
+        jc.setJexlVariable("aList", list);
+        jc.setJexlVariable("bList", list2);
         
         assertExpression(jc, "foo == 2", Boolean.TRUE);
         assertExpression(jc, "2 == 3", Boolean.FALSE);
@@ -351,12 +351,12 @@
     public void testNotConditions()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         Foo foo = new Foo();
-        jc.getVars().put("x", Boolean.TRUE );
-        jc.getVars().put("foo", foo );
-        jc.getVars().put("bar", "true" );
+        jc.setJexlVariable("x", Boolean.TRUE );
+        jc.setJexlVariable("foo", foo );
+        jc.setJexlVariable("bar", "true" );
 
         assertExpression(jc, "!x", Boolean.FALSE);
         assertExpression(jc, "x", Boolean.TRUE);
@@ -368,7 +368,7 @@
         assertExpression(jc, "foo.getCheeseList().size() == 3", Boolean.TRUE);
         assertExpression(jc, "foo.cheeseList.size() == 3", Boolean.TRUE);
 
-        jc.getVars().put("string", "");
+        jc.setJexlVariable("string", "");
         assertExpression(jc, "not empty string", Boolean.FALSE);
         assertExpression(jc, "not(empty string)", Boolean.FALSE);
         assertExpression(jc, "not empty(string)", Boolean.FALSE);
@@ -385,10 +385,10 @@
     public void testNotConditionsWithDots()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
-        jc.getVars().put("x.a", Boolean.TRUE );
-        jc.getVars().put("x.b", Boolean.FALSE );
+        jc.setJexlVariable("x.a", Boolean.TRUE );
+        jc.setJexlVariable("x.b", Boolean.FALSE );
 
         assertExpression(jc, "x.a", Boolean.TRUE);
         assertExpression(jc, "!x.a", Boolean.FALSE);
@@ -401,8 +401,8 @@
     public void testComparisons()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", "the quick and lazy fox" );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", "the quick and lazy fox" );
 
         assertExpression(jc, "foo.indexOf('quick') > 0", Boolean.TRUE);
         assertExpression(jc, "foo.indexOf('bar') >= 0", Boolean.FALSE);
@@ -415,8 +415,8 @@
     public void testNull()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("bar", new Integer(2) );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("bar", new Integer(2) );
 
         assertExpression(jc, "empty foo", Boolean.TRUE);
         assertExpression(jc, "bar == null", Boolean.FALSE);
@@ -431,7 +431,7 @@
      * test quoting in strings 
      */
     public void testStringQuoting() throws Exception {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         assertExpression(jc, "'\"Hello\"'", "\"Hello\"");
         assertExpression(jc, "\"I'm testing\"", "I'm testing");
     }
@@ -442,8 +442,8 @@
     public void testBlankStrings()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("bar", "" );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("bar", "" );
 
         assertExpression(jc, "foo == ''", Boolean.FALSE);
         assertExpression(jc, "bar == ''", Boolean.TRUE);
@@ -459,9 +459,9 @@
     public void testLogicExpressions()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", "abc" );
-        jc.getVars().put("bar", "def" );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", "abc" );
+        jc.setJexlVariable("bar", "def" );
 
         assertExpression(jc, "foo == 'abc' || bar == 'abc'", Boolean.TRUE);
         assertExpression(jc, "foo == 'abc' or bar == 'abc'", Boolean.TRUE);
@@ -481,8 +481,8 @@
     public void testVariableNames()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo_bar", "123" );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo_bar", "123" );
         
         assertExpression(jc, "foo_bar", "123");
     }
@@ -496,8 +496,8 @@
         Map<String, String> foo = new HashMap<String, String>();
         foo.put( "bar", "123" );
 
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", foo );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", foo );
         
         assertExpression(jc, "foo.bar", "123");
     }
@@ -508,8 +508,8 @@
     public void testStringLiterals()
         throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", "bar" );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", "bar" );
 
         assertExpression(jc, "foo == \"bar\"", Boolean.TRUE);
         assertExpression(jc, "foo == 'bar'", Boolean.TRUE);
@@ -527,8 +527,8 @@
         assertEquals(4, foo.square(2));
         assertEquals(4, foo.square(-2));
 
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("foo", foo );
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("foo", foo );
 
         assertExpression(jc, "foo.count", new Integer(5));
         assertExpression(jc, "foo.square(2)", new Integer(4));
@@ -541,9 +541,9 @@
     public void testNegativeIntComparison()
          throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Foo foo = new Foo();
-        jc.getVars().put("foo", foo );
+        jc.setJexlVariable("foo", foo );
 
         assertExpression(jc, "foo.count != -1", Boolean.TRUE);
         assertExpression(jc, "foo.count == 5", Boolean.TRUE);
@@ -556,9 +556,9 @@
     public void testCharAtBug()
         throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
-        jc.getVars().put("foo", "abcdef");
+        jc.setJexlVariable("foo", "abcdef");
 
         assertExpression(jc, "foo.substring(2,4)", "cd");
         assertExpression(jc, "foo.charAt(2)", new Character('c'));
@@ -568,20 +568,20 @@
 
     public void testEmptyDottedVariableName() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
-        jc.getVars().put( "this.is.a.test", "");
+        jc.setJexlVariable( "this.is.a.test", "");
 
         assertExpression(jc, "empty(this.is.a.test)", Boolean.TRUE);
     }
 
     public void testEmptySubListOfMap() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>();
         m.put("aList", new ArrayList<Object>());
 
-        jc.getVars().put( "aMap", m );
+        jc.setJexlVariable( "aMap", m );
 
         assertExpression( jc, "empty( aMap.aList )", Boolean.TRUE );
     }
@@ -589,7 +589,7 @@
     public void testCoercionWithComparisionOperators()
         throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
 
         assertExpression(jc, "'2' > 1", Boolean.TRUE);
         assertExpression(jc, "'2' >= 1", Boolean.TRUE);
@@ -614,16 +614,16 @@
     {
         // handle false for the left arg of 'and'
         Foo tester = new Foo();
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("first", Boolean.FALSE);
-        jc.getVars().put("foo", tester);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("first", Boolean.FALSE);
+        jc.setJexlVariable("foo", tester);
         Expression expr = JEXL.createExpression("first and foo.trueAndModify");
         expr.evaluate(jc);
         assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified());
         // handle true for the left arg of 'and' 
         tester = new Foo();
-        jc.getVars().put("first", Boolean.TRUE);
-        jc.getVars().put("foo", tester);
+        jc.setJexlVariable("first", Boolean.TRUE);
+        jc.setJexlVariable("foo", tester);
         expr.evaluate(jc);
         assertTrue("Short circuit failure: rhs not evaluated when lhs TRUE", tester.getModified());
     }
@@ -636,16 +636,16 @@
     {
         // handle false for the left arg of 'or'
         Foo tester = new Foo();
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("first", Boolean.FALSE);
-        jc.getVars().put("foo", tester);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("first", Boolean.FALSE);
+        jc.setJexlVariable("foo", tester);
         Expression expr = JEXL.createExpression("first or foo.trueAndModify");
         expr.evaluate(jc);
         assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified());
         // handle true for the left arg of 'or' 
         tester = new Foo();
-        jc.getVars().put("first", Boolean.TRUE);
-        jc.getVars().put("foo", tester);
+        jc.setJexlVariable("first", Boolean.TRUE);
+        jc.setJexlVariable("foo", tester);
         expr.evaluate(jc);
         assertTrue("Short circuit failure: rhs evaluated when lhs TRUE", !tester.getModified());
     }
@@ -656,9 +656,9 @@
      */
     public void testStringConcatenation() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("first", "Hello");
-        jc.getVars().put("second", "World");
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("first", "Hello");
+        jc.setJexlVariable("second", "World");
         assertExpression(jc, "first + ' ' + second", "Hello World");
     }
 
@@ -676,7 +676,7 @@
     {
         try
         {
-            assertExpression(JexlHelper.createContext(), "empty()", null);
+            assertExpression(new JexlContext.Mapped(), "empty()", null);
             fail("Bad expression didn't throw ParseException");
         }
         catch (JexlException pe)
@@ -691,7 +691,7 @@
      */
     public void testComment() throws Exception
     {
-        assertExpression(JexlHelper.createContext(), "## double or nothing\n 1 + 1", Integer.valueOf("2"));
+        assertExpression(new JexlContext.Mapped(), "## double or nothing\n 1 + 1", Integer.valueOf("2"));
     }
     
     /**
@@ -700,17 +700,17 @@
      */
     public void testAssignment() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("aString", "Hello");
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("aString", "Hello");
         Foo foo = new Foo();
-        jc.getVars().put("foo", foo);
+        jc.setJexlVariable("foo", foo);
         Parser parser = new Parser(new StringReader(";"));
         parser.parse(new StringReader("aString = 'World';"), null);
         
         assertExpression(jc, "hello = 'world'", "world");
-        assertEquals("hello variable not changed", "world", jc.getVars().get("hello"));
+        assertEquals("hello variable not changed", "world", jc.getJexlVariable("hello"));
         assertExpression(jc, "result = 1 + 1", new Integer(2));
-        assertEquals("result variable not changed", new Integer(2), jc.getVars().get("result"));
+        assertEquals("result variable not changed", new Integer(2), jc.getJexlVariable("result"));
         // todo: make sure properties can be assigned to, fall back to flat var if no property
         // assertExpression(jc, "foo.property1 = '99'", "99");
         // assertEquals("property not set", "99", foo.getProperty1());
@@ -718,9 +718,9 @@
     
     public void testAntPropertiesWithMethods() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         String value = "Stinky Cheese";
-        jc.getVars().put("maven.bob.food", value);
+        jc.setJexlVariable("maven.bob.food", value);
         assertExpression(jc, "maven.bob.food.length()", new Integer(value.length()));
         assertExpression(jc, "empty(maven.bob.food)", Boolean.FALSE);
         assertExpression(jc, "size(maven.bob.food)", new Integer(value.length()));
@@ -728,13 +728,13 @@
 
         // DG: Note the following ant properties don't work
 //        String version = "1.0.3";
-//        jc.getVars().put("commons-logging", version);
+//        jc.setJexlVariable("commons-logging", version);
 //        assertExpression(jc, "commons-logging", version);
     }
 
     public void testUnicodeSupport() throws Exception
     {
-        JexlContext jc = JexlHelper.createContext();
+        JexlContext jc = new JexlContext.Mapped();
         assertExpression(jc, "myvar == 'Użytkownik'", Boolean.FALSE);
         assertExpression(jc, "'c:\\some\\windows\\path'", "c:\\some\\windows\\path");
         assertExpression(jc, "'foo\\u0020bar'", "foo\u0020bar");
@@ -770,8 +770,8 @@
     @SuppressWarnings("boxing")
     public void testDuck() throws Exception {
         JexlEngine jexl = JEXL;
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("duck", new Duck());
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("duck", new Duck());
         Expression expr;
         Object result;
         expr = jexl.createExpression("duck.zero");
@@ -797,8 +797,8 @@
     public void testArray() throws Exception {
         int[] array = { 100, 101 , 102 };
         JexlEngine jexl = JEXL;
-        JexlContext jc = JexlHelper.createContext();
-        jc.getVars().put("array", array);
+        JexlContext jc = new JexlContext.Mapped();
+        jc.setJexlVariable("array", array);
         Expression expr;
         Object result;
         expr = jexl.createExpression("array.1");



Mime
View raw message