commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1211893 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/ main/java/org/apache/commons/jexl3/annotations/ main/java/org/apache/commons/jexl3/internal/ main/java/org/apache/commons/jexl3/internal/introspection/ main/j...
Date Thu, 08 Dec 2011 14:06:31 GMT
Author: henrib
Date: Thu Dec  8 14:06:30 2011
New Revision: 1211893

URL: http://svn.apache.org/viewvc?rev=1211893&view=rev
Log:
JEXL-123:
Revamped more documentation;
Renamed some classes (JexlSandbox, NamespaceResolver as sub-interface of JexlContext);
Switched SandboxUberspect to delegation rather than derivation;
Better segregation of static and dynamic configurability;

Added:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java
      - copied, changed from r1211427, commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Sandbox.java
Removed:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/NamespaceResolver.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Sandbox.java
Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlBuilder.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlContext.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEngine.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEvalContext.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ReadonlyContext.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/package.html
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/CacheTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlBuilder.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlBuilder.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlBuilder.java Thu Dec  8 14:06:30 2011
@@ -19,6 +19,7 @@ package org.apache.commons.jexl3;
 import org.apache.commons.jexl3.internal.Engine;
 import java.util.Map;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
 import org.apache.commons.logging.Log;
 
 /**
@@ -57,6 +58,10 @@ public class JexlBuilder {
      */
     protected JexlUberspect uberspect = null;
     /**
+     * The sandbox.
+     */
+    protected JexlSandbox sandbox = null;
+    /**
      * The Log to which all JexlEngine messages will be logged.
      */
     protected Log logger = null;
@@ -119,6 +124,21 @@ public class JexlBuilder {
     public JexlArithmetic arithmetic() {
         return this.arithmetic;
     }
+    
+    /**
+     * Sets the sandbox the engine will use.
+     * @param box the sandbox
+     * @return this builder
+     */
+    public JexlBuilder sandbox(JexlSandbox box) {
+        this.sandbox = box;
+        return this;
+    }
+    
+    /** @return the sandbox */
+    public JexlSandbox sandbox() {
+        return this.sandbox;
+    }
 
     /**
      * Sets the o.a.c.Log instance to use.
@@ -197,7 +217,7 @@ public class JexlBuilder {
     }
 
     /**
-     * Sets the map of function namespaces the engine will use.
+     * Sets the default namespaces map the engine will use.
      * <p>
      * Each entry key is used as a prefix, each entry value used as a bean implementing
      * methods; an expression like 'nsx:method(123)' will thus be solved by looking at

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlContext.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlContext.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlContext.java Thu Dec  8 14:06:30 2011
@@ -46,4 +46,28 @@ public interface JexlContext {
      * @return true if it exists, false otherwise
      */
     boolean has(String name);
+
+    /**
+     * 
+     * This interface declares how to resolve a namespace from its name; it is used by the interpreter during
+     * evalutation.
+     * <p>
+     * In JEXL, a namespace is an object that serves the purpose of encapsulating functions; for instance,
+     * the "math" namespace would be the proper object to expose functions like "log(...)", "sinus(...)", etc.
+     * </p>
+     * In expressions like "ns:function(...)", the resolver is called with resolveNamespace("ns").
+     * <p>
+     * JEXL itself reserves 'jexl' and 'ujexl' as namespaces for internal purpose; resolving those may lead to
+     * unexpected results.
+     * </p>
+     * @since 3.0
+     */
+    public interface NamespaceResolver {
+        /**
+         * Resolves a namespace by its name.
+         * @param name the name
+         * @return the namespace object
+         */
+        Object resolveNamespace(String name);
+    }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEngine.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEngine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEngine.java Thu Dec  8 14:06:30 2011
@@ -21,7 +21,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
 import java.net.URL;
-import java.util.Map;
 import java.math.MathContext;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
 
@@ -30,7 +29,7 @@ import org.apache.commons.jexl3.introspe
  * Creates and evaluates JexlExpression and JexlScript objects.
  * Determines the behavior of expressions & scripts during their evaluation with respect to:
  * <ul>
- *  <li>Introspection, see {@link Uberspect}</li>
+ *  <li>Introspection, see {@link JexlUberspect}</li>
  *  <li>Arithmetic & comparison, see {@link JexlArithmetic}</li>
  *  <li>Error reporting</li>
  *  <li>Logging</li>
@@ -62,12 +61,6 @@ public abstract class JexlEngine {
         Boolean isStrict();
         
         /**
-         * The namespaces to use for evaluation.
-         * @return the map of namespaces
-         */
-        Map<String, Object> getNamespaces();
-        
-        /**
          * Checks whether the arithmetic triggers errors during evaluation when null is used as an operand.
          * @return true if strict, false otherwise
          */
@@ -87,30 +80,18 @@ public abstract class JexlEngine {
     }
     
     /**
-     * Gets this engine underlying uberspect.
+     * Gets this engine underlying {@link JexlUberspect}.
      * @return the uberspect
      */
     public abstract JexlUberspect getUberspect();
     
     /**
-     * Gets this engine underlying arithmetic.
+     * Gets this engine underlying {@link JexlArithmetic}.
      * @return the arithmetic
      */
     public abstract JexlArithmetic getArithmetic();
     
     /**
-     * Gets a Jexl Template engine instance.
-     * @return a Jexl Template engine
-     */
-    public abstract JxltEngine jxlt();
-
-    /**
-     * Retrieves the map of function namespaces.
-     * @return the map passed in setFunctions or the empty map if the
-     * original was null.
-     */
-    public abstract Map<String, Object> getFunctions();
-    /**
      * Checks whether this engine is in debug mode.
      * @return true if debug is on, false otherwise
      */
@@ -137,6 +118,12 @@ public abstract class JexlEngine {
     public abstract void setClassLoader(ClassLoader loader);
     
     /**
+     * Creates a new {@link JxltEngine} instance using this engine.
+     * @return a Jexl Template engine
+     */
+    public abstract JxltEngine createJxltEngine();
+    
+    /**
      * Clears the expression cache.
      */
     public abstract void clearCache();
@@ -146,7 +133,7 @@ public abstract class JexlEngine {
      * JEXL syntax.  This method parses the expression which
      * must contain either a reference or an expression.
      * @param expression A String containing valid JEXL syntax
-     * @return An JexlExpression object which can be evaluated with a JexlContext
+     * @return An {@link JexlExpression} which can be evaluated using a {@link JexlContext}
      * @throws JexlException An exception can be thrown if there is a problem
      * parsing this expression, or if the expression is neither an
      * expression nor a reference.
@@ -158,7 +145,7 @@ public abstract class JexlEngine {
      * JEXL syntax.  This method parses the expression which
      * must contain either a reference or an expression.
      * @param expression A String containing valid JEXL syntax
-     * @return An JexlExpression object which can be evaluated with a JexlContext
+     * @return An {@link JexlExpression} which can be evaluated using a {@link JexlContext}
      * @param info An info structure to carry debugging information if needed
      * @throws JexlException An exception can be thrown if there is a problem
      * parsing this expression, or if the expression is neither an
@@ -171,7 +158,7 @@ public abstract class JexlEngine {
      * This method parses the script which validates the syntax.
      *
      * @param scriptText A String containing valid JEXL syntax
-     * @return A {@link Script} which can be executed using a {@link JexlContext}.
+     * @return A {@link JexlScript} which can be executed using a {@link JexlContext}
      * @throws JexlException if there is a problem parsing the script.
      */
     public abstract JexlScript createScript(String scriptText);
@@ -182,7 +169,7 @@ public abstract class JexlEngine {
      *
      * @param scriptText A String containing valid JEXL syntax
      * @param names the script parameter names
-     * @return A {@link Script} which can be executed using a {@link JexlContext}.
+     * @return A {@link JexlScript} which can be executed using a {@link JexlContext}
      * @throws JexlException if there is a problem parsing the script.
      */
     public abstract JexlScript createScript(String scriptText, String... names);
@@ -196,7 +183,7 @@ public abstract class JexlEngine {
      * @param scriptText A String containing valid JEXL syntax
      * @param info An info structure to carry debugging information if needed
      * @param names the script parameter names
-     * @return A {@link Script} which can be executed using a {@link JexlContext}.
+     * @return A {@link JexlScript} which can be executed using a {@link JexlContext}
      * @throws JexlException if there is a problem parsing the script.
      */
     public abstract JexlScript createScript(String scriptText, JexlInfo info, String[] names);
@@ -207,7 +194,7 @@ public abstract class JexlEngine {
      *
      * @param scriptFile A {@link File} containing valid JEXL syntax.
      * Must not be null. Must be a readable file.
-     * @return A {@link Script} which can be executed with a
+     * @return A {@link JexlScript} which can be executed with a
      * {@link JexlContext}.
      * @throws IOException if there is a problem reading the script.
      * @throws JexlException if there is a problem parsing the script.
@@ -220,7 +207,7 @@ public abstract class JexlEngine {
      *
      * @param scriptUrl A {@link URL} containing valid JEXL syntax.
      * Must not be null. Must be a readable file.
-     * @return A {@link Script} which can be executed with a
+     * @return A {@link JexlScript} which can be executed with a
      * {@link JexlContext}.
      * @throws IOException if there is a problem reading the script.
      * @throws JexlException if there is a problem parsing the script.

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEvalContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEvalContext.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEvalContext.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/JexlEvalContext.java Thu Dec  8 14:06:30 2011
@@ -176,16 +176,4 @@ public class JexlEvalContext implements 
         mathScale = scale;
     }
 
-    @Override
-    public Map<String, Object> getNamespaces() {
-        return namespaces;
-    }
-
-    /**
-     * Sets the namespaces vars to use during evaluation.
-     * @param funcs the namespaces
-     */
-    public void setNamespaces(Map<String, Object> funcs) {
-        namespaces = funcs;
-    }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ReadonlyContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ReadonlyContext.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ReadonlyContext.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/ReadonlyContext.java Thu Dec  8 14:06:30 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.jexl3;
 
 import java.math.MathContext;
-import java.util.Map;
 
 /**
  * A readonly context wrapper.
@@ -84,9 +83,4 @@ public final class ReadonlyContext imple
     public int getArithmeticMathScale() {
         return options == null? -1 : options.getArithmeticMathScale();
     }
-
-    @Override
-    public Map<String, Object> getNamespaces() {
-        return options == null? null : options.getNamespaces();
-    }
 }

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java Thu Dec  8 14:06:30 2011
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
  * This allows to completely hide a package, class, interface, constructor, method of field from 
  * JEXL; a NoJexl annotated element will not be usable through any kind of JEXL expression or script.
  * </p>
- * <p>See {@link org.apache.commons.jexl3.Sandbox} for another way to restrict JEXL access.
+ * <p>See {@link org.apache.commons.jexl3.JexlSandbox} for another way to restrict JEXL access.
  */
 @Documented
 @Retention(RetentionPolicy.RUNTIME)

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java Thu Dec  8 14:06:30 2011
@@ -26,9 +26,13 @@ import org.apache.commons.jexl3.JexlExpr
 import org.apache.commons.jexl3.JexlInfo;
 import org.apache.commons.jexl3.JexlInfoHandle;
 import org.apache.commons.jexl3.JexlScript;
+
+import org.apache.commons.jexl3.internal.introspection.SandboxUberspect;
 import org.apache.commons.jexl3.internal.introspection.Uberspect;
 import org.apache.commons.jexl3.introspection.JexlMethod;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
+
 import org.apache.commons.jexl3.parser.ASTArrayAccess;
 import org.apache.commons.jexl3.parser.ASTIdentifier;
 import org.apache.commons.jexl3.parser.ASTJexlScript;
@@ -59,6 +63,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import java.lang.ref.SoftReference;
+
 import java.net.URL;
 import java.net.URLConnection;
 
@@ -154,26 +159,20 @@ public class Engine extends JexlEngine {
     }
 
     /**
-     * Creates a JEXL engine using the provided {@link Uberspect}, (@link JexlArithmetic),
-     * a function map and logger.
-     * @param anUberspect to allow different introspection behaviour
-     * @param anArithmetic to allow different arithmetic behaviour
-     * @param theFunctions an optional map of namespaces (@link setFunctions)
-     * @param log the logger for various messages
-     */
-    public Engine(JexlUberspect anUberspect, JexlArithmetic anArithmetic, Map<String, Object> theFunctions, Log log) {
-        this(new JexlBuilder().uberspect(anUberspect).arithmetic(anArithmetic).namespaces(theFunctions).logger(log));
-    }
-
-    /**
      * Creates a JEXL engine using the provided {@link JexlBuilder}.
      * @param conf the builder
      */
     public Engine(JexlBuilder conf) {
-        this.uberspect = conf.uberspect() == null ? getUberspect(conf.logger()) : conf.uberspect();
+        JexlSandbox sandbox = conf.sandbox();
+        JexlUberspect uber = conf.uberspect() == null ? getUberspect(conf.logger()) : conf.uberspect();
         ClassLoader loader = conf.loader();
         if (loader != null) {
-            uberspect.setClassLoader(loader);
+            uber.setClassLoader(loader);
+        }
+        if (sandbox == null) {
+            this.uberspect = uber;
+        } else {
+            this.uberspect = new SandboxUberspect(uber, sandbox);
         }
         this.logger = conf.logger() == null ? LogFactory.getLog(JexlEngine.class) : conf.logger();
         this.functions = conf.namespaces() == null ? Collections.<String, Object>emptyMap() : conf.namespaces();
@@ -211,7 +210,7 @@ public class Engine extends JexlEngine {
     }
     
     @Override
-    public TemplateEngine jxlt() {
+    public TemplateEngine createJxltEngine() {
         return new TemplateEngine(this);
     }
 
@@ -256,17 +255,6 @@ public class Engine extends JexlEngine {
     }
 
     /**
-     * Retrieves the map of function namespaces.
-     *
-     * @return the map passed in setFunctions or the empty map if the
-     * original was null.
-     */
-    @Override
-    public Map<String, Object> getFunctions() {
-        return functions;
-    }
-
-    /**
      * An overridable through covariant return JexlExpression creator.
      * @param text the script text
      * @param tree the parse AST tree

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java Thu Dec  8 14:06:30 2011
@@ -16,23 +16,17 @@
  */
 package org.apache.commons.jexl3.internal;
 
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.commons.jexl3.JexlArithmetic;
 import org.apache.commons.jexl3.JexlContext;
 import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.JexlException;
 import org.apache.commons.jexl3.JexlScript;
-import org.apache.commons.jexl3.NamespaceResolver;
-import org.apache.commons.logging.Log;
 
-import org.apache.commons.jexl3.parser.JexlNode;
+import org.apache.commons.jexl3.introspection.JexlMethod;
+import org.apache.commons.jexl3.introspection.JexlPropertyGet;
+import org.apache.commons.jexl3.introspection.JexlPropertySet;
+import org.apache.commons.jexl3.introspection.JexlUberspect;
+
 import org.apache.commons.jexl3.parser.ASTAdditiveNode;
 import org.apache.commons.jexl3.parser.ASTAdditiveOperator;
 import org.apache.commons.jexl3.parser.ASTAndNode;
@@ -50,8 +44,8 @@ import org.apache.commons.jexl3.parser.A
 import org.apache.commons.jexl3.parser.ASTERNode;
 import org.apache.commons.jexl3.parser.ASTEmptyFunction;
 import org.apache.commons.jexl3.parser.ASTFalseNode;
-import org.apache.commons.jexl3.parser.ASTFunctionNode;
 import org.apache.commons.jexl3.parser.ASTForeachStatement;
+import org.apache.commons.jexl3.parser.ASTFunctionNode;
 import org.apache.commons.jexl3.parser.ASTGENode;
 import org.apache.commons.jexl3.parser.ASTGTNode;
 import org.apache.commons.jexl3.parser.ASTIdentifier;
@@ -79,15 +73,22 @@ import org.apache.commons.jexl3.parser.A
 import org.apache.commons.jexl3.parser.ASTTernaryNode;
 import org.apache.commons.jexl3.parser.ASTTrueNode;
 import org.apache.commons.jexl3.parser.ASTUnaryMinusNode;
+import org.apache.commons.jexl3.parser.ASTVar;
 import org.apache.commons.jexl3.parser.ASTWhileStatement;
+import org.apache.commons.jexl3.parser.JexlNode;
 import org.apache.commons.jexl3.parser.Node;
 import org.apache.commons.jexl3.parser.ParserVisitor;
 
-import org.apache.commons.jexl3.introspection.JexlUberspect;
-import org.apache.commons.jexl3.introspection.JexlMethod;
-import org.apache.commons.jexl3.introspection.JexlPropertyGet;
-import org.apache.commons.jexl3.introspection.JexlPropertySet;
-import org.apache.commons.jexl3.parser.ASTVar;
+import org.apache.commons.logging.Log;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * An interpreter of JEXL syntax.
@@ -138,17 +139,15 @@ public class Interpreter extends ParserV
             JexlEngine.Options opts = (JexlEngine.Options) context;
             Boolean ostrict = opts.isStrict();
             Boolean osilent = opts.isSilent();
-            Map<String,Object> ofunction = opts.getNamespaces();
             this.strictEngine = ostrict == null? jexl.isStrict() : ostrict.booleanValue();
             this.silent = osilent == null? jexl.isSilent() : osilent.booleanValue();
-            this.functions = ofunction == null? jexl.functions : ofunction;
             this.arithmetic = jexl.arithmetic.options(opts);
         } else {
             this.strictEngine = jexl.isStrict();
             this.silent = jexl.isSilent();
-            this.functions = jexl.functions;
             this.arithmetic = jexl.arithmetic;
         }
+        this.functions = jexl.functions;
         this.strictArithmetic = this.arithmetic.isStrict();
         this.cache = jexl.cache != null;
         if (frame != null) {
@@ -278,8 +277,8 @@ public class Interpreter extends ParserV
             }
         }
         // check if namespace if a resolver
-        if (context instanceof NamespaceResolver) {
-            namespace = ((NamespaceResolver) context).resolveNamespace(prefix);
+        if (context instanceof JexlContext.NamespaceResolver) {
+            namespace = ((JexlContext.NamespaceResolver) context).resolveNamespace(prefix);
         }
         if (namespace == null) {
             namespace = functions.get(prefix);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java Thu Dec  8 14:06:30 2011
@@ -20,7 +20,6 @@ import org.apache.commons.jexl3.JexlCont
 import org.apache.commons.jexl3.JexlEngine;
 import org.apache.commons.jexl3.JexlException;
 import org.apache.commons.jexl3.JxltEngine;
-import org.apache.commons.jexl3.NamespaceResolver;
 import org.apache.commons.jexl3.introspection.JexlMethod;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
 import org.apache.commons.jexl3.parser.ASTJexlScript;
@@ -1002,7 +1001,7 @@ public final class TemplateEngine extend
      * <p>This context exposes its writer as '$jexl' to the scripts.</p>
      * <p>public for introspection purpose.</p>
      */
-    public final class TemplateContext implements JexlContext, NamespaceResolver {
+    public final class TemplateContext implements JexlContext, JexlContext.NamespaceResolver {
         /** The wrapped context. */
         private final JexlContext wrap;
         /** The array of TemplateEngine expressions. */

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java Thu Dec  8 14:06:30 2011
@@ -16,40 +16,38 @@
  */
 package org.apache.commons.jexl3.internal.introspection;
 
+import java.util.Iterator;
 import org.apache.commons.jexl3.JexlInfoHandle;
 import org.apache.commons.jexl3.introspection.JexlMethod;
 import org.apache.commons.jexl3.introspection.JexlPropertyGet;
 import org.apache.commons.jexl3.introspection.JexlPropertySet;
-import org.apache.commons.jexl3.introspection.Sandbox;
-import org.apache.commons.logging.Log;
+import org.apache.commons.jexl3.introspection.JexlUberspect;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
 
 /**
  * An uberspect that controls usage of properties, methods and contructors through a sandbox.
  * @since 3.0
  */
-public final class SandboxUberspect extends Uberspect {
+public final class SandboxUberspect implements JexlUberspect {
+    /** The base uberspect. */
+    protected final JexlUberspect uberspect;
     /**  The sandbox. */
-    private final Sandbox sandbox;
+    protected final JexlSandbox sandbox;
 
     /**
-     * A constructor for Sandbox uberspect.
-     * @param runtimeLogger the logger to use or null to use default
-     * @param theSandbox the sandbox instance to use
+     * A constructor for JexlSandbox uberspect.
+     * @param theUberspect the JexlUberspect to sandbox
+     * @param theSandbox the sandbox which is copied to avoid changes at runtime
      */
-    public SandboxUberspect(Log runtimeLogger, Sandbox theSandbox) {
-        super(runtimeLogger);
+    public SandboxUberspect(JexlUberspect theUberspect, JexlSandbox theSandbox) {
         if (theSandbox == null) {
             throw new NullPointerException("sandbox can not be null");
         }
-        this.sandbox = theSandbox;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setLoader(ClassLoader cloader) {
-        base().setLoader(cloader);
+        if (theUberspect == null) {
+            throw new NullPointerException("uberspect can not be null");
+        }
+        this.uberspect = theUberspect;
+        this.sandbox = theSandbox.copy();
     }
 
     /**
@@ -67,7 +65,7 @@ public final class SandboxUberspect exte
             return null;
         }
         if (sandbox.execute(className, "") != null) {
-            return super.getConstructor(className, args, info);
+            return uberspect.getConstructor(className, args, info);
         }
         return null;
     }
@@ -80,7 +78,7 @@ public final class SandboxUberspect exte
         if (obj != null && method != null) {
             String actual = sandbox.execute(obj.getClass().getName(), method);
             if (actual != null) {
-                return getMethodExecutor(obj, actual, args);
+                return uberspect.getMethod(obj, actual, args, info);
             }
         }
         return null;
@@ -94,7 +92,7 @@ public final class SandboxUberspect exte
         if (obj != null && identifier != null) {
             String actual = sandbox.read(obj.getClass().getName(), identifier.toString());
             if (actual != null) {
-                return super.getPropertyGet(obj, actual, info);
+                return uberspect.getPropertyGet(obj, actual, info);
             }
         }
         return null;
@@ -108,10 +106,20 @@ public final class SandboxUberspect exte
         if (obj != null && identifier != null) {
             String actual = sandbox.write(obj.getClass().getName(), identifier.toString());
             if (actual != null) {
-                return super.getPropertySet(obj, actual, arg, info);
+                return uberspect.getPropertySet(obj, actual, arg, info);
             }
         }
         return null;
 
     }
+
+    @Override
+    public void setClassLoader(ClassLoader loader) {
+        uberspect.setClassLoader(loader);
+    }
+
+    @Override
+    public Iterator<?> getIterator(Object obj, JexlInfoHandle info) {
+        return uberspect.getIterator(obj, info);
+    }
 }

Copied: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java (from r1211427, commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Sandbox.java)
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java?p2=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java&p1=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Sandbox.java&r1=1211427&r2=1211893&rev=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Sandbox.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java Thu Dec  8 14:06:30 2011
@@ -53,10 +53,13 @@ import java.util.Set;
  * <li><b>execute</b> controls executable methods and constructor</li>
  * </ul>
  * </p>
- * 
+ * <p>
+ * Note that a JexlUberspect allways uses a copy of a JexlSandbox when built to avoid synchronization and/or
+ * concurrent modifications at runtime.
+ * </p>
  * @since 3.0
  */
-public final class Sandbox {
+public final class JexlSandbox {
     /**
      * The map from class names to permissions.
      */
@@ -65,7 +68,7 @@ public final class Sandbox {
     /**
      * Creates a new default sandbox.
      */
-    public Sandbox() {
+    public JexlSandbox() {
         this(new HashMap<String, Permissions>());
     }
 
@@ -73,11 +76,22 @@ public final class Sandbox {
      * Creates a sandbox based on an existing permissions map.
      * @param map the permissions map
      */
-    protected Sandbox(Map<String, Permissions> map) {
+    protected JexlSandbox(Map<String, Permissions> map) {
         sandbox = map;
     }
 
     /**
+     * @return a copy of this sandbox
+     */
+    public JexlSandbox copy() {
+        Map<String, Permissions> map = new HashMap<String, Permissions>();
+        for (Map.Entry<String, Permissions> entry : sandbox.entrySet()) {
+            map.put(entry.getKey(), entry.getValue().copy());
+        }
+        return new JexlSandbox(map);
+    }
+
+    /**
      * Gets the read permission value for a given property of a class.
      * @param clazz the class
      * @param name the property name
@@ -182,6 +196,13 @@ public final class Sandbox {
         public String get(String name) {
             return name;
         }
+
+        /**
+         * @return a copy of these Names
+         */
+        protected Names copy() {
+            return this;
+        }
     }
     /**
      * The pass-thru name set.
@@ -191,6 +212,11 @@ public final class Sandbox {
         public boolean add(String name) {
             return false;
         }
+
+        @Override
+        protected Names copy() {
+            return this;
+        }
     };
 
     /**
@@ -201,6 +227,13 @@ public final class Sandbox {
         private Map<String, String> names = null;
 
         @Override
+        protected Names copy() {
+            WhiteSet copy = new WhiteSet();
+            copy.names = names == null ? null : new HashMap<String, String>(names);
+            return copy;
+        }
+
+        @Override
         public boolean add(String name) {
             if (names == null) {
                 names = new HashMap<String, String>();
@@ -234,6 +267,13 @@ public final class Sandbox {
         private Set<String> names = null;
 
         @Override
+        protected Names copy() {
+            BlackSet copy = new BlackSet();
+            copy.names = names == null ? null : new HashSet<String>(names);
+            return copy;
+        }
+
+        @Override
         public boolean add(String name) {
             if (names == null) {
                 names = new HashSet<String>();
@@ -283,6 +323,13 @@ public final class Sandbox {
         }
 
         /**
+         * @return a copy of these permissions
+         */
+        Permissions copy() {
+            return new Permissions(read.copy(), write.copy(), execute.copy());
+        }
+
+        /**
          * Adds a list of readable property names to these permissions.
          * @param pnames the property names
          * @return this instance of permissions
@@ -343,7 +390,6 @@ public final class Sandbox {
             return execute;
         }
     }
-    
     /**
      * The pass-thru permissions.
      */

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/package.html
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/package.html?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/package.html (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/package.html Thu Dec  8 14:06:30 2011
@@ -93,7 +93,7 @@
             <li>org.apache.commons.jexl3.internal.introspection</li>
         </ul>
 
-        <h3><a name="usage_api">Dynamic invocation</a></h3>
+        <h3><a name="usage_api">Dynamic Invocation</a></h3>
         <p>
             These functionalities are close to the core level utilities found in
             <a href="http://commons.apache.org/beanutils/">BeanUtils</a>.
@@ -139,7 +139,7 @@
             assertEquals("Result is not 1000", new Integer(1000), o);
         </pre>
 
-        <h3><a name="usage_jexl">JEXL script expression</a></h3>
+        <h3><a name="usage_jexl">Expressions and Scripts</a></h3>
         <p>
             If your needs require simple expression evaluation capabilities, the core JEXL features
             will most likely fit.
@@ -189,53 +189,54 @@
             JxltEngine.UnifiedExpression expr = jxlt.createExpression("Hello ${user}");
             String hello = jxlt.evaluate(context, jxlt).toString();
         </pre>
-        <h3>JexlExpression, JexlScript, UnifiedExpression and Template: differences</h3>
+
+        <h3>JexlExpression, JexlScript, UnifiedExpression and Template: summary</h3>
         <h4>JexlExpression </h4>
         <p>
-        These are the most basic form of JexlEngine expressions and only allows for a single command
-        to be executed and its result returned. If you try to use multiple commands it ignores 
-        everything after the first semi-colon and just returns the result from 
-        the first command. 
+            These are the most basic form of JexlEngine expressions and only allow for a single command
+            to be executed and its result returned. If you try to use multiple commands, it ignores 
+            everything after the first semi-colon and just returns the result from 
+            the first command. 
         </p>
         <h4>JexlScript</h4>
         <p>
-        This allows you to put multiple commands in the expression and you can 
-        use variable assignments, loops, calculations, etc. More or less what can be achieved in Shell or
-        JavaScript at its basic level. The result from the last command is returned from the script.
+            This allows you to put multiple commands in the expression and you can 
+            use variable assignments, loops, calculations, etc. More or less what can be achieved in Shell or
+            JavaScript at its basic level. The result from the last command is returned from the script.
         </p>
         <h4>JxltEngine.UnifiedExpression</h4> 
         <p>
-        These are ideal to produce "one-liner" text, like a 'toString()' on steroids.
-        To get a calculation you use the EL-like syntax 
-        as in ${someVariable}. The expression that goes between the brackets 
-        behaves like a JexlScript, not an expression. You can use semi-colons to 
-        execute multiple commands and the result from the last command is 
-        returned from the script. You also have the ability to use a 2-pass evaluation using
-        the #{someScript} syntax.
+            These are ideal to produce "one-liner" text, like a 'toString()' on steroids.
+            To get a calculation you use the EL-like syntax 
+            as in ${someVariable}. The expression that goes between the brackets 
+            behaves like a JexlScript, not an expression. You can use semi-colons to 
+            execute multiple commands and the result from the last command is 
+            returned from the script. You also have the ability to use a 2-pass evaluation using
+            the #{someScript} syntax.
         </p>
         <h4>JxltEngine.Template</h4> 
         <p>
-        These produce text documents. Each line beginning with '$$' (as a default) is
-        considered JEXL code and all others considered as JxltEngine.UnifiedExpression.
-        Think of those as simple Velocity templates. A rewritten MudStore initial Velocity sample looks like this:
+            These produce text documents. Each line beginning with '$$' (as a default) is
+            considered JEXL code and all others considered as JxltEngine.UnifiedExpression.
+            Think of those as simple Velocity templates. A rewritten MudStore initial Velocity sample looks like this:
         </p>
         <pre><code>
         &lt;html&gt;
-&lt;body&gt;
-Hello ${customer.name}!
-&lt;table>
-$$for(var mud : mudsOnSpecial ) {
-$$   if (customer.hasPurchased(mud) ) {
-      &lt;tr&gt;
-        &lt;td&gt;
-          ${flogger.getPromo( mud )}
-        &lt;/td&gt;
-      &lt;/tr&gt;
-$$    }
-$$}
-&lt;/table&gt;
-&lt;/body&gt;
-&lt;/html&gt;
+            &lt;body&gt;
+                Hello ${customer.name}!
+                &lt;table&gt;
+        $$      for(var mud : mudsOnSpecial ) {
+        $$          if (customer.hasPurchased(mud) ) {
+                    &lt;tr&gt;
+                        &lt;td&gt;
+                            ${flogger.getPromo( mud )}
+                        &lt;/td&gt;
+                    &lt;/tr&gt;
+        $$          }
+        $$      }
+        &lt;/table&gt;
+        &lt;/body&gt;
+        &lt;/html&gt;
         </code></pre>
 
         <h2><a name="configuration">JEXL Configuration</a></h2>
@@ -243,43 +244,27 @@ $$}
             The JexlEngine can be configured through a few parameters that will drive how it reacts
             in case of errors.
             These configuration methods are embedded through a {@link org.apache.commons.jexl3.JexlBuilder}.
-        <p>
-            Most configuration options can be overriden during evaluation by using a {@link org.apache.commons.jexl3.JexlEvalContext}
-            which merges both a {@link org.apache.commons.jexl3.JexlContext} to expose variables and a
-{@link org.apache.commons.jexl3.JexlEngine$Options} to carry evaluation options.
         </p>
+        <h3><a name="static_configuration">Static Configuration</a></h3>
         <p>
-            {@link org.apache.commons.jexl3.JexlBuilder#strict} configures when JEXL considers 'null' as an error or not in various situations;
-            when facing an unreferenceable variable, using null as an argument to an arithmetic operator or failing to call
-            a method or constructor. The lenient mode is close to JEXL-1.1 behavior.
+            Both JexlEngine and JxltEngine are thread-safe, all their inner fields are final; the same instance can be shared between different
+            threads and proper synchronization is enforced in critical areas (introspection caches).
+            The following properties can only be set during JexlEngine creation.
         </p>
         <p>
-            {@link org.apache.commons.jexl3.JexlBuilder#silent} configures how JEXL reacts to errors; if silent, the engine will not throw exceptions
-            but will warn through loggers and return null in case of errors. Note that when non-silent, JEXL throws
-            JexlException which are unchecked exception.
+            {@link org.apache.commons.jexl3.JexlBuilder#loader} indicates to the JexlEngine being built which class loader
+            to use to solve a class name; this affects how JexlEngine.newInstance and the 'new' script method operates.
+            This is mostly useful in cases where you rely on JEXL to dynamically load and call plugins for your application.
         </p>
         <p>
-            {@link org.apache.commons.jexl3.JexlBuilder#debug} makes stacktraces carried by JExlException more meaningfull; in particular, these
-            traces will carry the exact caller location the Expression was created from.
-        </p>
-        <p>
-            {@link org.apache.commons.jexl3.JexlBuilder#loader} indicates to a JexlEngine which class loader to use to solve a class name; this affects
-            how JexlEngine.newInstance and the 'new' script method operates. This is mostly useful in cases where
-            you rely on JEXL to dynamically load and call plugins for your application.
+            You can state what can be manipulated through scripting by the {@link org.apache.commons.jexl3.annotations.NoJexl}
+            annotation that completely shield classes and methods from JEXL introspection.
+            The other configurable way to restrict JEXL is by using a
+            {@link org.apache.commons.jexl3.introspection.JexlSandbox} which allows finer control over what is exposed; the sandbox
+            can be set through {@link org.apache.commons.jexl3.JexlBuilder#sandbox}.
         </p>
         <p>
-            JexlEngine and JxltEngine expression caches can be configured as well. If you intend to use JEXL
-            repeatedly in your application, these are worth configuring since expression parsing is quite heavy.
-            Note that all caches created by JEXL are held through SoftReference; under high memory pressure, the GC will be able
-            to reclaim those caches and JEXL will rebuild them if needed. By default, a JexlEngine does not create a cache
-            whilst JxltEngine does.
-        </p>
-        <p>Both JexlEngine and JxltEngine are thread-safe, all their inner fields are final; the same instance can be shared between different
-            threads and proper synchronization is enforced in critical areas.</p>
-        <p>{@link org.apache.commons.jexl3.JexlBuilder#cache} will set how many expressions can be simultaneously cached by the
-            JEXL engine. UnifiedJEXL allows to define the cache size through its constructor.</p>
-        <p>
-            {@link org.apache.commons.jexl3.JexlEngine#namespaces} extends JEXL scripting by registering your own classes as
+            {@link org.apache.commons.jexl3.JexlBuilder#namespaces} extends JEXL scripting by registering your own classes as
             namespaces allowing your own functions to be exposed at will.
         </p>
         This can be used as in:
@@ -289,7 +274,7 @@ $$}
                     return Math.cos(x);
                 }
             }
-            Map&lt;String, Object> funcs = new HashMap&lt;String, Object>();
+            Map&lt;String, Object> funcs = new HashMap&lt;String, Object&gt;();
             funcs.put("math", new MyMath());
             JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
 
@@ -300,12 +285,53 @@ $$}
             o = e.evaluate(jc);
             assertEquals(Double.valueOf(-1),o);
         </code></pre>
-        If the <i>namespace</i> is a Class and that class declares a constructor that takes a JexlContext (or
-        a class extending JexlContext), one <i>namespace</i> instance is created on first usage in an
-        expression; this instance lifetime is limited to the expression evaluation.
+        <p>
+            If the <i>namespace</i> is a Class and that class declares a constructor that takes a JexlContext (or
+            a class extending JexlContext), one <i>namespace</i> instance is created on first usage in an
+            expression; this instance lifetime is limited to the expression evaluation.
+        </p>
+        <p>
+            JexlEngine and JxltEngine expression caches can be configured as well. If you intend to use JEXL
+            repeatedly in your application, these are worth configuring since expression parsing is quite heavy.
+            Note that all caches created by JEXL are held through SoftReference; under high memory pressure, the GC will be able
+            to reclaim those caches and JEXL will rebuild them if needed. By default, a JexlEngine does not create a cache
+            whilst JxltEngine does.
+        </p>
+        <p>{@link org.apache.commons.jexl3.JexlBuilder#cache} will set how many expressions can be simultaneously cached by the
+            JEXL engine. UnifiedJEXL allows to define the cache size through its constructor.
+        </p>
+        <p>
+            {@link org.apache.commons.jexl3.JexlBuilder#debug}
+            makes stacktraces carried by JExlException more meaningful; in particular, these
+            traces will carry the exact caller location the Expression was created from.
+        </p>
+
+        <h3><a name="dynamic_configuration">Dynamic Configuration</a></h3>
+        <p>
+            Those configuration options can be overriden during evaluation by using a {@link org.apache.commons.jexl3.JexlEvalContext}
+            which merges both a {@link org.apache.commons.jexl3.JexlContext} to expose variables and a
+            {@link org.apache.commons.jexl3.JexlEngine$Options} to carry evaluation options.
+        </p>
+        <p>
+            {@link org.apache.commons.jexl3.JexlBuilder#strict} or {@link org.apache.commons.jexl3.JexlEvalContext#setStrict}
+            configures when JEXL considers 'null' as an error or not in various situations;
+            when facing an unreferenceable variable, using null as an argument to an arithmetic operator or failing to call
+            a method or constructor. The lenient mode is close to JEXL-1.1 behavior.
+        </p>
+        <p>
+            {@link org.apache.commons.jexl3.JexlBuilder#silent} or {@link org.apache.commons.jexl3.JexlEvalContext#setSilent}
+            configures how JEXL reacts to errors; if silent, the engine will not throw exceptions
+            but will warn through loggers and return null in case of errors. Note that when non-silent, JEXL throws
+            JexlException which are unchecked exception.
+        </p>
+        <p>
+            Implementing a {@link org.apache.commons.jexl3.JexlContext$NamespaceResolver} through a JexlContext - by deriving
+            JexlEvalContext for instance - allows to override the namespace resolution and the default namespace map defined
+            through {@link org.apache.commons.jexl3.JexlBuilder#namespaces}.
+        </p>
+
 
         <h2><a name="customization">JEXL Customization</a></h2>
-        
         <p>
             The {@link org.apache.commons.jexl3.JexlContext}, {@link org.apache.commons.jexl3.JexlBuilder} and
             {@link org.apache.commons.jexl3.JexlEngine$Options} are
@@ -314,10 +340,6 @@ $$}
             and {@link org.apache.commons.jexl3.ObjectContext} which may already cover some of your needs.
         </p>
         <p>
-            The {@link org.apache.commons.jexl3.NamespaceResolver} may also be of interest since it allows resolving namespaces (sic)
-            without having to store them in a map.
-        </p>
-        <p>
             {@link org.apache.commons.jexl3.JexlArithmetic}
             is the class to derive if you need to change how operators behave or add types upon which they
             operate. For example, this would
@@ -326,7 +348,7 @@ $$}
             Note however that you can not change the operator precedence.
         </p>
 
-        <h2><a name="extension">JEXL Extending</a></h2>
+        <h2><a name="extension">Extending JEXL</a></h2>
         If you need to make JEXL treat some objects in a specialized manner or tweak how it
         reacts to some settings, you can derive most of its inner-workings. The classes and methods are rarely private or
         final - only when the inner contract really requires it. However, using the protected methods

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/CacheTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/CacheTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/CacheTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/CacheTest.java Thu Dec  8 14:06:30 2011
@@ -31,7 +31,9 @@ public class CacheTest extends JexlTestC
     public CacheTest() {
         super("CacheTest", null);
     }
-    private static final JexlEngine jexl = new JexlBuilder().cache(512).debug(true).strict(true).create();
+    private static final JexlEngine jexlCache = new JexlBuilder().cache(1024).debug(true).strict(true).create();
+    private static final JexlEngine jexlNoCache = new JexlBuilder().cache(0).debug(true).strict(true).create();
+    private static JexlEngine jexl = jexlCache;
 
     @Override
     public void setUp() throws Exception {
@@ -278,7 +280,9 @@ public class CacheTest extends JexlTestC
             loops = MIX.length;
         }
         if (!cache) {
-            jexl.clearCache();
+            jexl = jexlNoCache;
+        } else {
+            jexl = jexlCache;
         }
         java.util.concurrent.ExecutorService execs = java.util.concurrent.Executors.newFixedThreadPool(NTHREADS);
         List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>(NTHREADS);
@@ -584,6 +588,19 @@ public class CacheTest extends JexlTestC
     public void testComputeCache() throws Exception {
             runThreaded(ComputeTask.class, LOOPS, true);
     }
+    
+    public static class JexlContextNS extends JexlEvalContext implements JexlContext.NamespaceResolver {
+        final Map<String, Object> funcs;
+        JexlContextNS(Map<String, Object> vars, Map<String, Object> funcs) {
+            super(vars);
+            this.funcs = funcs;
+        }
+        @Override
+        public Object resolveNamespace(String name) {
+            return funcs.get(name);
+        }
+        
+    }
 
     /**
      * The remaining tests exercise the namespaced namespaces; not MT.
@@ -600,9 +617,8 @@ public class CacheTest extends JexlTestC
             jexl.clearCache();
         }
         Map<String, Object> vars = new HashMap<String, Object>();
-        JexlEvalContext jc = new JexlEvalContext(vars);
         java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
-        jc.setNamespaces(funcs);
+        JexlEvalContext jc = new JexlContextNS(vars, funcs);
         JexlExpression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
         JexlExpression compute1 = jexl.createExpression("cached:COMPUTE(a0)");
         Object result = null;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java Thu Dec  8 14:06:30 2011
@@ -29,11 +29,11 @@ import org.apache.commons.jexl3.junit.As
 public class MethodTest extends JexlTestCase {
     private Asserter asserter;
     private static final String METHOD_STRING = "Method string";
-    
+
     public MethodTest() {
         super("MethodTest");
     }
-    
+
     public static class VarArgs {
         public String callInts(Integer... args) {
             int result = 0;
@@ -94,8 +94,19 @@ public class MethodTest extends JexlTest
         }
     }
 
-    public static class EnhancedContext extends JexlEvalContext {
+    public static class EnhancedContext extends JexlEvalContext implements JexlContext.NamespaceResolver {
         int factor = 6;
+        final Map<String, Object> funcs;
+
+        EnhancedContext(Map<String, Object> funcs) {
+            super();
+            this.funcs = funcs;
+        }
+
+        @Override
+        public Object resolveNamespace(String name) {
+            return funcs.get(name);
+        }
     }
 
     public static class ContextualFunctor {
@@ -221,8 +232,7 @@ public class MethodTest extends JexlTest
         funcs.put("math", new MyMath());
         funcs.put("cx", ContextualFunctor.class);
 
-        EnhancedContext jc = new EnhancedContext();
-        jc.setNamespaces(funcs);
+        EnhancedContext jc = new EnhancedContext(funcs);
 
         JexlExpression e = JEXL.createExpression("ten()");
         Object o = e.evaluate(jc);
@@ -252,8 +262,8 @@ public class MethodTest extends JexlTest
         funcs.put("FUNC", Functor.class);
 
         JexlExpression e = JEXL.createExpression("func:ten()");
-        JexlEvalContext jc = new JexlEvalContext();
-        jc.setNamespaces(funcs);
+        JexlEvalContext jc = new EnhancedContext(funcs);
+        
         Object o = e.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
 
@@ -274,7 +284,7 @@ public class MethodTest extends JexlTest
         assertEquals("Result is not 40", new Integer(40), o);
     }
 
-    public static class ScriptContext extends MapContext implements NamespaceResolver {
+    public static class ScriptContext extends MapContext implements JexlContext.NamespaceResolver {
         Map<String, Object> nsScript;
 
         ScriptContext(Map<String, Object> ns) {
@@ -316,7 +326,7 @@ public class MethodTest extends JexlTest
         JexlMethod mplus = new JexlMethod() {
             @Override
             public Object invoke(Object obj, Object[] params) throws Exception {
-                if (obj instanceof Map<?,?>) {
+                if (obj instanceof Map<?, ?>) {
                     return ja.add(params[0], params[1]);
                 } else {
                     throw new Exception("not a script context");
@@ -351,12 +361,12 @@ public class MethodTest extends JexlTest
                 return Object.class;
             }
         };
-        
+
         foo.put("PLUS", mplus);
         forty2 = JEXL.createScript("script:PLUS(4, 2) * script:PLUS(4, 3)");
         o = forty2.execute(context);
         assertEquals("Result is not 42", new Integer(42), o);
-        
+
         context.set("foo.bar", foo);
         forty2 = JEXL.createScript("foo.'bar'.PLUS(4, 2) * foo.bar.PLUS(4, 3)");
         o = forty2.execute(context);

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java Thu Dec  8 14:06:30 2011
@@ -17,9 +17,7 @@
 package org.apache.commons.jexl3;
 
 import org.apache.commons.jexl3.annotations.NoJexl;
-import org.apache.commons.jexl3.internal.introspection.SandboxUberspect;
-import org.apache.commons.jexl3.introspection.JexlUberspect;
-import org.apache.commons.jexl3.introspection.Sandbox;
+import org.apache.commons.jexl3.introspection.JexlSandbox;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -102,10 +100,9 @@ public class SandboxTest extends JexlTes
         result = script.execute(null);
         assertEquals("42", ((Foo) result).getName());
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.black(Foo.class.getName()).execute("");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr);
         try {
@@ -125,10 +122,9 @@ public class SandboxTest extends JexlTes
         result = script.execute(null, foo);
         assertEquals(foo.Quux(), result);
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.black(Foo.class.getName()).execute("Quux");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo");
         try {
@@ -148,10 +144,9 @@ public class SandboxTest extends JexlTes
         result = script.execute(null, foo);
         assertEquals(foo.alias, result);
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.black(Foo.class.getName()).read("alias");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo");
         try {
@@ -171,10 +166,9 @@ public class SandboxTest extends JexlTes
         result = script.execute(null, foo, "43");
         assertEquals("43", result);
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.black(Foo.class.getName()).write("alias");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo", "$0");
         try {
@@ -191,10 +185,9 @@ public class SandboxTest extends JexlTes
         JexlScript script;
         Object result;
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.white(Foo.class.getName()).execute("");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr);
         result = script.execute(null);
@@ -207,10 +200,9 @@ public class SandboxTest extends JexlTes
         JexlScript script;
         Object result;
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.white(Foo.class.getName()).execute("Quux");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo");
         result = script.execute(null, foo);
@@ -230,7 +222,7 @@ public class SandboxTest extends JexlTes
         JexlScript script;
         Object result;
 
-        JexlEngine sjexl = new JexlBuilder().loader(Foo.class.getClassLoader()).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().strict(true).create();
         for (String expr : exprs) {
             script = sjexl.createScript(expr, "foo");
             try {
@@ -252,11 +244,10 @@ public class SandboxTest extends JexlTes
         JexlScript script;
         Object result;
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.white(Foo.class.getName()).read("alias");
         sandbox.get(Foo.class.getName()).read().alias("alias", "ALIAS");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo");
         result = script.execute(null, foo);
@@ -273,10 +264,9 @@ public class SandboxTest extends JexlTes
         JexlScript script;
         Object result;
 
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         sandbox.white(Foo.class.getName()).write("alias");
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         script = sjexl.createScript(expr, "foo", "$0");
         result = script.execute(null, foo, "43");
@@ -287,14 +277,13 @@ public class SandboxTest extends JexlTes
     public void testRestrict() throws Exception {
         JexlContext context = new MapContext();
         context.set("System", System.class);
-        Sandbox sandbox = new Sandbox();
+        JexlSandbox sandbox = new JexlSandbox();
         // only allow call to currentTimeMillis (avoid exit, gc, loadLibrary, etc)
         sandbox.white(System.class.getName()).execute("currentTimeMillis");
         // can not create a new file
         sandbox.black(java.io.File.class.getName()).execute("");
 
-        JexlUberspect uber = new SandboxUberspect(null, sandbox);
-        JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
+        JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).create();
 
         String expr;
         JexlScript script;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java Thu Dec  8 14:06:30 2011
@@ -67,7 +67,7 @@ public class ScriptCallableTest extends 
         assertTrue(future.isCancelled());
     }
 
-    public static class TestContext extends MapContext implements NamespaceResolver {
+    public static class TestContext extends MapContext implements JexlContext.NamespaceResolver {
         public Object resolveNamespace(String name) {
             return name == null ? this : null;
         }

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/UnifiedJEXLTest.java Thu Dec  8 14:06:30 2011
@@ -34,7 +34,7 @@ import java.util.Set;
 public class UnifiedJEXLTest extends JexlTestCase {
     private static final JexlEngine ENGINE = new JexlBuilder().silent(false).cache(128).strict(true).create();
 
-    private static final JxltEngine JXLT = ENGINE.jxlt();
+    private static final JxltEngine JXLT = ENGINE.createJxltEngine();
     private static final Log LOG = LogFactory.getLog(JxltEngine.class);
     private JexlEvalContext context = null;
 

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java?rev=1211893&r1=1211892&r2=1211893&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/VarTest.java Thu Dec  8 14:06:30 2011
@@ -85,7 +85,7 @@ public class VarTest extends JexlTestCas
         assertEquals("Result is not 42", new Integer(42), o);
     }
 
-    public static class NumbersContext extends MapContext implements NamespaceResolver {
+    public static class NumbersContext extends MapContext implements JexlContext.NamespaceResolver {
         @Override
         public Object resolveNamespace(String name) {
             return name == null ? this : null;



Mime
View raw message