commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1210927 [5/7] - in /commons/proper/jexl/trunk: ./ src/main/java/org/apache/commons/jexl3/ src/main/java/org/apache/commons/jexl3/internal/ src/main/java/org/apache/commons/jexl3/internal/introspection/ src/main/java/org/apache/commons/jexl...
Date Tue, 06 Dec 2011 14:19:36 GMT
Added: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java?rev=1210927&view=auto
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java (added)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java Tue Dec  6 14:19:33 2011
@@ -0,0 +1,774 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl3.internal.introspection;
+
+import java.beans.IntrospectionException;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.jexl3.JexlInfo;
+import org.apache.commons.jexl3.JexlException;
+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.JexlUberspect;
+import org.apache.commons.logging.Log;
+
+/**
+ * Implementation of Uberspect to provide the default introspective
+ * functionality of JEXL.
+ * <p>This is the class to derive to customize introspection.</p>
+ *
+ * @since 1.0
+ */
+public class Uberspect implements JexlUberspect {
+    /**
+     * Publicly exposed special failure object returned by tryInvoke.
+     */
+    public static final Object TRY_FAILED = AbstractExecutor.TRY_FAILED;
+/** The logger to use for all warnings & errors. */
+    protected final Log rlog;
+    /** The soft reference to the introspector currently in use. */
+    private volatile SoftReference<Introspector> ref;
+
+    /**
+     * Coerce an Object  to an Integer.
+     * @param arg the Object to coerce
+     * @return an Integer if it can be converted, null otherwise
+     */
+    protected Integer toInteger(Object arg) {
+        if (arg == null) {
+            return null;
+        }
+        if (arg instanceof Number) {
+            return Integer.valueOf(((Number) arg).intValue());
+        }
+        try {
+            return Integer.valueOf(arg.toString());
+        } catch (NumberFormatException xnumber) {
+            return null;
+        }
+    }
+
+    /**
+     * Coerce an Object to a String.
+     * @param arg the Object to coerce
+     * @return a String if it can be converted, null otherwise
+     */
+    protected String toString(Object arg) {
+        return arg == null ? null : arg.toString();
+    }
+
+    /**
+     * Gets the current introspector base.
+     * <p>If the reference has been collected, this method will recreate the underlying introspector.</p>
+     * @return the introspector
+     */
+    // CSOFF: DoubleCheckedLocking
+    protected final Introspector base() {
+        Introspector intro = ref.get();
+        if (intro == null) {
+            // double checked locking is ok (fixed by Java 5 memory model).
+            synchronized(this) {
+                intro = ref.get();
+                if (intro == null) {
+                    intro = new Introspector(rlog);
+                    ref = new SoftReference<Introspector>(intro);
+                }
+            }
+        }
+        return intro;
+    }
+    // CSON: DoubleCheckedLocking
+
+    @Override
+    public void setClassLoader(ClassLoader loader) {
+        base().setLoader(loader);
+    }
+
+    /**
+     * Gets a class by name through this introspector class loader.
+     * @param className the class name
+     * @return the class instance or null if it could not be found
+     */
+    public final Class<?> getClassByName(String className) {
+        return base().getClassByName(className);
+    }
+    
+    /**
+     * Gets the field named by <code>key</code> for the class <code>c</code>.
+     *
+     * @param c     Class in which the field search is taking place
+     * @param key   Name of the field being searched for
+     * @return a {@link java.lang.reflect.Field} or null if it does not exist or is not accessible
+     * */
+    public final Field getField(Class<?> c, String key) {
+        return base().getField(c, key);
+    }
+
+    /**
+     * Gets the accessible field names known for a given class.
+     * @param c the class
+     * @return the class field names
+     */
+    public final String[] getFieldNames(Class<?> c) {
+        return base().getFieldNames(c);
+    }
+
+    /**
+     * Gets the method defined by <code>name</code> and
+     * <code>params</code> for the Class <code>c</code>.
+     *
+     * @param c Class in which the method search is taking place
+     * @param name Name of the method being searched for
+     * @param params An array of Objects (not Classes) that describe the
+     *               the parameters
+     *
+     * @return a {@link java.lang.reflect.Method}
+     *  or null if no unambiguous method could be found through introspection.
+     */
+    public final Method getMethod(Class<?> c, String name, Object[] params) {
+        return base().getMethod(c, new MethodKey(name, params));
+    }
+
+    /**
+     * Gets the method defined by <code>key</code> and for the Class <code>c</code>.
+     *
+     * @param c Class in which the method search is taking place
+     * @param key MethodKey of the method being searched for
+     *
+     * @return a {@link java.lang.reflect.Method}
+     *  or null if no unambiguous method could be found through introspection.
+     */
+    public final Method getMethod(Class<?> c, MethodKey key) {
+        return base().getMethod(c, key);
+    }
+
+
+    /**
+     * Gets the accessible methods names known for a given class.
+     * @param c the class
+     * @return the class method names
+     */
+    public final String[] getMethodNames(Class<?> c) {
+        return base().getMethodNames(c);
+    }
+            
+    /**
+     * Gets all the methods with a given name from this map.
+     * @param c the class
+     * @param methodName the seeked methods name
+     * @return the array of methods
+     */
+    public final Method[] getMethods(Class<?> c, final String methodName) {
+        return base().getMethods(c, methodName);
+    }
+    /**
+     * Creates a new UberspectImpl.
+     * @param runtimeLogger the logger used for all logging needs
+     */
+    public Uberspect(Log runtimeLogger) {
+        rlog = runtimeLogger;
+        ref = new SoftReference<Introspector>(null);
+    }
+
+    /**
+     * Resets this Uberspect class loader.
+     * @param cloader the class loader to use
+     */
+    public void setLoader(ClassLoader cloader) {
+        base().setLoader(cloader);
+    }
+
+
+    /**
+     * Returns a general constructor.
+     * @param ctorHandle the object
+     * @param args contructor arguments
+     * @return a {@link java.lang.reflect.Constructor}
+     *  or null if no unambiguous contructor could be found through introspection.
+     */
+    protected final Constructor<?> getConstructor(Object ctorHandle, Object[] args) {
+        String className = null;
+        Class<?> clazz = null;
+        if (ctorHandle instanceof Class<?>) {
+            clazz = (Class<?>) ctorHandle;
+            className = clazz.getName();
+        } else if (ctorHandle != null) {
+            className = ctorHandle.toString();
+        } else {
+            return null;
+        }
+        return base().getConstructor(clazz, new MethodKey(className, args));
+    }
+
+    /**
+     * Returns a general method.
+     * @param obj the object
+     * @param name the method name
+     * @param args method arguments
+     * @return a {@link AbstractExecutor.Method}.
+     */
+    protected final AbstractExecutor.Method getMethodExecutor(Object obj, String name, Object[] args) {
+        AbstractExecutor.Method me = new MethodExecutor(base(), obj, name, args);
+        return me.isAlive() ? me : null;
+    }
+
+    /**
+     * Return a property getter.
+     * @param obj the object to base the property from.
+     * @param identifier property name
+     * @return a {@link AbstractExecutor.Get}.
+     */
+    protected final AbstractExecutor.Get getGetExecutor(Object obj, Object identifier) {
+        final Class<?> claz = obj.getClass();
+        final String property = toString(identifier);
+        final Introspector is = base();
+        AbstractExecutor.Get executor;
+        // first try for a getFoo() type of property (also getfoo() )
+        if (property != null) {
+            executor = new PropertyGetExecutor(is, claz, property);
+            if (executor.isAlive()) {
+                return executor;
+            }
+        //}
+        // look for boolean isFoo()
+        //if (property != null) {
+            executor = new BooleanGetExecutor(is, claz, property);
+            if (executor.isAlive()) {
+                return executor;
+            }
+        }
+        // let's see if we are a map...
+        executor = new MapGetExecutor(is, claz, identifier);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        // let's see if we can convert the identifier to an int,
+        // if obj is an array or a list, we can still do something
+        Integer index = toInteger(identifier);
+        if (index != null) {
+            executor = new ListGetExecutor(is, claz, index);
+            if (executor.isAlive()) {
+                return executor;
+            }
+        }
+        // if that didn't work, look for set("foo")
+        executor = new DuckGetExecutor(is, claz, identifier);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        // if that didn't work, look for set("foo")
+        executor = new DuckGetExecutor(is, claz, property);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        return null;
+    }
+
+    /**
+     * Return a property setter.
+     * @param obj the object to base the property from.
+     * @param identifier property name (or identifier)
+     * @param arg value to set
+     * @return a {@link AbstractExecutor.Set}.
+     */
+    public final AbstractExecutor.Set getSetExecutor(final Object obj, final Object identifier, Object arg) {
+        final Class<?> claz = obj.getClass();
+        final String property = toString(identifier);
+        final Introspector is = base();
+        AbstractExecutor.Set executor;
+        // first try for a setFoo() type of property (also setfoo() )
+        if (property != null) {
+            executor = new PropertySetExecutor(is, claz, property, arg);
+            if (executor.isAlive()) {
+                return executor;
+            }
+        }
+        // let's see if we are a map...
+        executor = new MapSetExecutor(is, claz, identifier, arg);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        // let's see if we can convert the identifier to an int,
+        // if obj is an array or a list, we can still do something
+        Integer index = toInteger(identifier);
+        if (index != null) {
+            executor = new ListSetExecutor(is, claz, index, arg);
+            if (executor.isAlive()) {
+                return executor;
+            }
+        }
+        // if that didn't work, look for set(foo)
+        executor = new DuckSetExecutor(is, claz, identifier, arg);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        // if that didn't work, look for set("foo")
+        executor = new DuckSetExecutor(is, claz, property, arg);
+        if (executor.isAlive()) {
+            return executor;
+        }
+        return null;
+    }
+    
+    @Override
+    @SuppressWarnings("unchecked")
+    public Iterator<?> getIterator(Object obj, JexlInfoHandle info) {
+        if (obj instanceof Iterator<?>) {
+            return ((Iterator<?>) obj);
+        }
+        if (obj.getClass().isArray()) {
+            return new ArrayIterator(obj);
+        }
+        if (obj instanceof Map<?, ?>) {
+            return ((Map<?, ?>) obj).values().iterator();
+        }
+        if (obj instanceof Enumeration<?>) {
+            return new EnumerationIterator<Object>((Enumeration<Object>) obj);
+        }
+        if (obj instanceof Iterable<?>) {
+            return ((Iterable<?>) obj).iterator();
+        }
+        try {
+            // look for an iterator() method to support the JDK5 Iterable
+            // interface or any user tools/DTOs that want to work in
+            // foreach without implementing the Collection interface
+            AbstractExecutor.Method it = getMethodExecutor(obj, "iterator", null);
+            if (it != null && Iterator.class.isAssignableFrom(it.getReturnType())) {
+                return (Iterator<Object>) it.execute(obj, null);
+            }
+        } catch (Exception xany) {
+            throw new JexlException(info.jexlInfo(), "unable to generate iterator()", xany);
+        }
+        return null;
+    }
+    
+    @Override
+    public JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfoHandle info) {
+        return getMethodExecutor(obj, method, args);
+    }
+
+    @Override
+    public JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfoHandle info) {
+        final Constructor<?> ctor = getConstructor(ctorHandle, args);
+        if (ctor != null) {
+            return new ConstructorMethod(ctor);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfoHandle info) {
+        JexlPropertyGet get = getGetExecutor(obj, identifier);
+        if (get == null && obj != null && identifier != null) {
+            get = getIndexedGet(obj, identifier.toString());
+            if (get == null) {
+                Field field = getField(obj, identifier.toString(), info.jexlInfo());
+                if (field != null) {
+                    return new FieldPropertyGet(field);
+                }
+            }
+        }
+        return get;
+    }
+
+    @Override
+    public JexlPropertySet getPropertySet(final Object obj, final Object identifier, Object arg, JexlInfoHandle info) {
+        JexlPropertySet set = getSetExecutor(obj, identifier, arg);
+        if (set == null && obj != null && identifier != null) {
+            Field field = getField(obj, identifier.toString(), info.jexlInfo());
+            if (field != null
+                    && !Modifier.isFinal(field.getModifiers())
+                    && (arg == null || MethodKey.isInvocationConvertible(field.getType(), arg.getClass(), false))) {
+                return new FieldPropertySet(field);
+            }
+        }
+        return set;
+    }
+
+    /**
+     * Returns a class field.
+     * @param obj the object
+     * @param name the field name
+     * @param info debug info
+     * @return a {@link Field}.
+     */
+    protected Field getField(Object obj, String name, JexlInfo info) {
+        final Class<?> clazz = obj instanceof Class<?> ? (Class<?>) obj : obj.getClass();
+        return getField(clazz, name);
+    }
+
+    /**
+     * Attempts to find an indexed-property getter in an object.
+     * The code attempts to find the list of methods getXXX() and setXXX().
+     * Note that this is not equivalent to the strict bean definition of indexed properties; the type of the key
+     * is not necessarily an int and the set/get arrays are not resolved.
+     * @param object the object
+     * @param name the container name
+     * @return a JexlPropertyGet is successfull, null otherwise
+     */
+    protected JexlPropertyGet getIndexedGet(Object object, String name) {
+        if (object != null && name != null) {
+            String base = name.substring(0, 1).toUpperCase() + name.substring(1);
+            final String container = name;
+            final Class<?> clazz = object.getClass();
+            final Method[] getters = getMethods(object.getClass(), "get" + base);
+            final Method[] setters = getMethods(object.getClass(), "set" + base);
+            if (getters != null) {
+                return new IndexedType(container, clazz, getters, setters);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Abstract an indexed property container.
+     * This stores the container name and owning class as well as the list of available getter and setter methods.
+     * It implements JexlPropertyGet since such a container can only be accessed from its owning instance (not set).
+     */
+    protected static final class IndexedType implements JexlPropertyGet {
+        /** The container name. */
+        private final String container;
+        /** The owning class. */
+        private final Class<?> clazz;
+        /** The array of getter methods. */
+        private final Method[] getters;
+        /** The array of setter methods. */
+        private final Method[] setters;
+
+        /**
+         * Creates a new indexed type.
+         * @param name the container name
+         * @param c the owning class
+         * @param gets the array of getter methods
+         * @param sets the array of setter methods
+         */
+        protected IndexedType(String name, Class<?> c, Method[] gets, Method[] sets) {
+            this.container = name;
+            this.clazz = c;
+            this.getters = gets;
+            this.setters = sets;
+        }
+
+        @Override
+        public Object invoke(Object obj) throws Exception {
+            if (obj != null && clazz.equals(obj.getClass())) {
+                return new IndexedContainer(this, obj);
+            } else {
+                throw new IntrospectionException("property resolution error");
+            }
+        }
+
+        @Override
+        public Object tryInvoke(Object obj, Object key) {
+            if (obj != null && key != null && clazz.equals(obj.getClass()) && container.equals(key.toString())) {
+                return new IndexedContainer(this, obj);
+            } else {
+                return TRY_FAILED;
+            }
+        }
+
+        @Override
+        public boolean tryFailed(Object rval) {
+            return rval == TRY_FAILED;
+        }
+
+        @Override
+        public boolean isCacheable() {
+            return true;
+        }
+
+        /**
+         * Gets the value of a property from a container.
+         * @param object the instance owning the container (not null)
+         * @param key the property key (not null)
+         * @return the property value
+         * @throws Exception if invocation failed; IntrospectionException if a property getter could not be found
+         */
+        public Object invokeGet(Object object, Object key) throws Exception {
+            if (getters != null) {
+                final Object[] args = {key};
+                final Method jm;
+                if (getters.length == 1) {
+                    jm = getters[0];
+                } else {
+                    jm = new MethodKey(getters[0].getName(), args).getMostSpecificMethod(Arrays.asList(getters));
+                }
+                if (jm != null) {
+                    return jm.invoke(object, args);
+                }
+            }
+            throw new IntrospectionException("property get error: "
+                    + object.getClass().toString() + "@" + key.toString());
+        }
+
+        /**
+         * Sets the value of a property in a container.
+         * @param object the instance owning the container (not null)
+         * @param key the property key (not null)
+         * @param value the property value (not null)
+         * @return the result of the method invocation (frequently null)
+         * @throws Exception if invocation failed; IntrospectionException if a property setter could not be found
+         */
+        public Object invokeSet(Object object, Object key, Object value) throws Exception {
+            if (setters != null) {
+                final Object[] args = {key, value};
+                final Method jm;
+                if (setters.length == 1) {
+                    jm = setters[0];
+                } else {
+                    jm = new MethodKey(setters[0].getName(), args).getMostSpecificMethod(Arrays.asList(setters));
+                }
+                if (jm != null) {
+                    return jm.invoke(object, args);
+                }
+            }
+            throw new IntrospectionException("property set error: "
+                    + object.getClass().toString() + "@" + key.toString());
+        }
+    }
+
+    /**
+     * A generic indexed property container, exposes get(key) and set(key, value) and solves method call dynamically
+     * based on arguments.
+     * <p>Must remain public for introspection purpose.</p>
+     */
+    public static final class IndexedContainer {
+        /** The instance owning the container. */
+        private final Object object;
+        /** The container type instance. */
+        private final IndexedType type;
+
+        /**
+         * Creates a new duck container.
+         * @param theType the container type
+         * @param theObject the instance owning the container
+         */
+        private IndexedContainer(IndexedType theType, Object theObject) {
+            this.type = theType;
+            this.object = theObject;
+        }
+
+        /**
+         * Gets a property from a container.
+         * @param key the property key
+         * @return the property value
+         * @throws Exception if inner invocation fails
+         */
+        public Object get(Object key) throws Exception {
+            return type.invokeGet(object, key);
+        }
+
+        /**
+         * Sets a property in a container.
+         * @param key the property key
+         * @param value the property value
+         * @return the invocation result (frequently null)
+         * @throws Exception if inner invocation fails
+         */
+        public Object set(Object key, Object value) throws Exception {
+            return type.invokeSet(object, key, value);
+        }
+    }
+
+    /**
+     * A JexlMethod that wraps constructor.
+     */
+    protected final class ConstructorMethod implements JexlMethod {
+        /** The wrapped constructor. */
+        private final Constructor<?> ctor;
+
+        /**
+         * Creates a constructor method.
+         * @param theCtor the constructor to wrap
+         */
+        protected ConstructorMethod(Constructor<?> theCtor) {
+            this.ctor = theCtor;
+        }
+
+        @Override
+        public Object invoke(Object obj, Object[] params) throws Exception {
+            Class<?> clazz = null;
+            if (obj instanceof Class<?>) {
+                clazz = (Class<?>) obj;
+            } else if (obj != null) {
+                clazz = getClassByName(obj.toString());
+            } else {
+                clazz = ctor.getDeclaringClass();
+            }
+            if (clazz.equals(ctor.getDeclaringClass())) {
+                return ctor.newInstance(params);
+            } else {
+                throw new IntrospectionException("constructor resolution error");
+            }
+        }
+
+        @Override
+        public Object tryInvoke(String name, Object obj, Object[] params) {
+            Class<?> clazz = null;
+            if (obj instanceof Class<?>) {
+                clazz = (Class<?>) obj;
+            } else if (obj != null) {
+                clazz = getClassByName(obj.toString());
+            } else {
+                clazz = ctor.getDeclaringClass();
+            }
+            if (clazz.equals(ctor.getDeclaringClass())
+                    && (name == null || name.equals(clazz.getName()))) {
+                try {
+                    return ctor.newInstance(params);
+                } catch (InstantiationException xinstance) {
+                    return TRY_FAILED;
+                } catch (IllegalAccessException xaccess) {
+                    return TRY_FAILED;
+                } catch (IllegalArgumentException xargument) {
+                    return TRY_FAILED;
+                } catch (InvocationTargetException xinvoke) {
+                    return TRY_FAILED;
+                }
+            }
+            return TRY_FAILED;
+        }
+
+        @Override
+        public boolean tryFailed(Object rval) {
+            return rval == TRY_FAILED;
+        }
+
+        @Override
+        public boolean isCacheable() {
+            return true;
+        }
+
+        @Override
+        public Class<?> getReturnType() {
+            return ctor.getDeclaringClass();
+        }
+    }
+
+    /**
+     * A JexlPropertyGet for public fields.
+     */
+    protected static final class FieldPropertyGet implements JexlPropertyGet {
+        /**
+         * The public field.
+         */
+        private final Field field;
+
+        /**
+         * Creates a new instance of FieldPropertyGet.
+         * @param theField the class public field
+         */
+        protected FieldPropertyGet(Field theField) {
+            field = theField;
+        }
+
+        @Override
+        public Object invoke(Object obj) throws Exception {
+            return field.get(obj);
+        }
+
+        @Override
+        public Object tryInvoke(Object obj, Object key) {
+            if (obj.getClass().equals(field.getDeclaringClass()) && key.equals(field.getName())) {
+                try {
+                    return field.get(obj);
+                } catch (IllegalAccessException xill) {
+                    return TRY_FAILED;
+                }
+            }
+            return TRY_FAILED;
+        }
+
+        @Override
+        public boolean tryFailed(Object rval) {
+            return rval == TRY_FAILED;
+        }
+
+        @Override
+        public boolean isCacheable() {
+            return true;
+        }
+    }
+
+    /**
+     * A JexlPropertySet for public fields.
+     */
+    protected static final class FieldPropertySet implements JexlPropertySet {
+        /**
+         * The public field.
+         */
+        private final Field field;
+
+        /**
+         * Creates a new instance of FieldPropertySet.
+         * @param theField the class public field
+         */
+        protected FieldPropertySet(Field theField) {
+            field = theField;
+        }
+
+        @Override
+        public Object invoke(Object obj, Object arg) throws Exception {
+            field.set(obj, arg);
+            return arg;
+        }
+
+        @Override
+        public Object tryInvoke(Object obj, Object key, Object value) {
+            if (obj.getClass().equals(field.getDeclaringClass())
+                    && key.equals(field.getName())
+                    && (value == null || MethodKey.isInvocationConvertible(field.getType(), value.getClass(), false))) {
+                try {
+                    field.set(obj, value);
+                    return value;
+                } catch (IllegalAccessException xill) {
+                    return TRY_FAILED;
+                }
+            }
+            return TRY_FAILED;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean tryFailed(Object rval) {
+            return rval == TRY_FAILED;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public boolean isCacheable() {
+            return true;
+        }
+    }
+}

Copied: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java (from r1209060, commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Uberspect.java)
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java?p2=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java&p1=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Uberspect.java&r1=1209060&r2=1210927&rev=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/Uberspect.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java Tue Dec  6 14:19:33 2011
@@ -18,7 +18,7 @@
 package org.apache.commons.jexl3.introspection;
 
 import java.util.Iterator;
-import org.apache.commons.jexl3.JexlInfo;
+import org.apache.commons.jexl3.JexlInfoHandle;
 
 /**
  * 'Federated' introspection/reflection interface to allow the introspection
@@ -26,7 +26,7 @@ import org.apache.commons.jexl3.JexlInfo
  * 
  * @since 1.0
  */
-public interface Uberspect {
+public interface JexlUberspect {
     /** Sets the class loader to use when getting a constructor with
      * a class name parameter.
      * @param loader the class loader
@@ -41,7 +41,7 @@ public interface Uberspect {
      * @return a {@link JexlMethod}
      * @since 3.0
      */
-    JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfo.Handle info);
+    JexlMethod getConstructor(Object ctorHandle, Object[] args, JexlInfoHandle info);
     /**
      * Returns a JexlMethod.
      * @param obj the object
@@ -50,7 +50,7 @@ public interface Uberspect {
      * @param info contextual information
      * @return a {@link JexlMethod}
      */
-    JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfo.Handle info);
+    JexlMethod getMethod(Object obj, String method, Object[] args, JexlInfoHandle info);
 
     /**
      * Property getter.
@@ -60,7 +60,7 @@ public interface Uberspect {
      * @param info contextual information
      * @return a {@link JexlPropertyGet}
      */
-    JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfo.Handle info);
+    JexlPropertyGet getPropertyGet(Object obj, Object identifier, JexlInfoHandle info);
 
     /**
      * Property setter.
@@ -71,7 +71,7 @@ public interface Uberspect {
      * @param info contextual information
      * @return a {@link JexlPropertySet}.
      */
-    JexlPropertySet getPropertySet(Object obj, Object identifier, Object arg, JexlInfo.Handle info);
+    JexlPropertySet getPropertySet(Object obj, Object identifier, Object arg, JexlInfoHandle info);
 
     /**
      * Gets an iterator from an object.
@@ -79,6 +79,6 @@ public interface Uberspect {
      * @param info contextual information
      * @return an iterator over obj
      */
-    Iterator<?> getIterator(Object obj, JexlInfo.Handle info);
+    Iterator<?> getIterator(Object obj, JexlInfoHandle info);
 
 }
\ No newline at end of file

Modified: 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/Sandbox.java?rev=1210927&r1=1210926&r2=1210927&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/Sandbox.java Tue Dec  6 14:19:33 2011
@@ -198,7 +198,7 @@ public final class Sandbox {
      */
     public static final class WhiteSet extends Names {
         /** The map of controlled names and aliases. */
-        protected Map<String, String> names = null;
+        private Map<String, String> names = null;
 
         @Override
         public boolean add(String name) {
@@ -231,7 +231,7 @@ public final class Sandbox {
      */
     public static final class BlackSet extends Names {
         /** The set of controlled names. */
-        protected Set<String> names = null;
+        private Set<String> names = null;
 
         @Override
         public boolean add(String name) {

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java Tue Dec  6 14:19:33 2011
@@ -16,14 +16,14 @@
  */
 package org.apache.commons.jexl3.parser;
 
-import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.internal.Engine;
 
 /**
  * Enhanced script to allow parameters declaration.
  */
 public class ASTJexlScript extends JexlNode {
     /** The script scope. */
-    private JexlEngine.Scope scope = null;
+    private Engine.Scope scope = null;
 
     public ASTJexlScript(int id) {
         super(id);
@@ -42,14 +42,14 @@ public class ASTJexlScript extends JexlN
      * Sets the parameters and registers
      * @param theScope the scope
      */
-    public void setScope(JexlEngine.Scope theScope) {
+    public void setScope(Engine.Scope theScope) {
         this.scope = theScope;
     }
     
     /**
      * Gets this script scope.
      */
-    public JexlEngine.Scope getScope() {
+    public Engine.Scope getScope() {
         return scope;
     }
     
@@ -58,7 +58,7 @@ public class ASTJexlScript extends JexlN
      * @param values the argument values
      * @return the arguments array
      */
-    public JexlEngine.Frame createFrame(Object... values) {
+    public Engine.Frame createFrame(Object... values) {
         return scope != null? scope.createFrame(values) : null;
     }
     

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java Tue Dec  6 14:19:33 2011
@@ -17,13 +17,14 @@
 package org.apache.commons.jexl3.parser;
 
 import org.apache.commons.jexl3.JexlInfo;
+import org.apache.commons.jexl3.JexlInfoHandle;
 
 /**
  * Base class for parser nodes - holds an 'image' of the token for later use.
  *
  * @since 2.0
  */
-public abstract class JexlNode extends SimpleNode implements JexlInfo.Handle {
+public abstract class JexlNode extends SimpleNode implements JexlInfoHandle {
     /** A marker interface for literals.
      * @param <T> the literal type
      */

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java Tue Dec  6 14:19:33 2011
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.jexl3.parser;
 
-import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.internal.Engine;
 import org.apache.commons.jexl3.JexlException;
 import org.apache.commons.jexl3.JexlInfo;
 
@@ -30,7 +30,7 @@ public class JexlParser extends StringPa
      * Each parameter is associated to a register and is materialized as an offset in the registers array used
      * during evaluation.
      */
-    protected JexlEngine.Scope frame;
+    protected Engine.Scope frame;
 
     /**
      * Sets the frame to use bythis parser.
@@ -39,7 +39,7 @@ public class JexlParser extends StringPa
      * </p>
      * @param theFrame the register map
      */
-    public void setFrame(JexlEngine.Scope theFrame) {
+    public void setFrame(Engine.Scope theFrame) {
         frame = theFrame;
     }
     
@@ -51,7 +51,7 @@ public class JexlParser extends StringPa
      * </p>
      * @return the named register map
      */
-    public JexlEngine.Scope getFrame() {
+    public Engine.Scope getFrame() {
         return frame;
     }
     
@@ -82,7 +82,7 @@ public class JexlParser extends StringPa
      */
     public void declareVariable(ASTVar identifier, String image) {
         if (frame == null) {
-            frame = new JexlEngine.Scope((String[])null);
+            frame = new Engine.Scope((String[])null);
         }
         Integer register = frame.declareVariable(image);
         identifier.setRegister(register.intValue());

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java Tue Dec  6 14:19:33 2011
@@ -19,14 +19,30 @@ package org.apache.commons.jexl3.parser;
  * Fully abstract to avoid public interface exposition.
  */
 public abstract class ParserVisitor {
-    protected abstract Object visit(SimpleNode node, Object data);
+    /**
+     * Unused, satisfy ParserVisitor interface.
+     * @param node a node
+     * @param data the data
+     * @return does not return
+     */
+    protected final Object visit(SimpleNode node, Object data) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    /**
+     * Unused, should throw in Parser.
+     * @param node a node
+     * @param data the data
+     * @return does not return
+     */
+    protected final Object visit(ASTAmbiguous node, Object data) {
+        throw new UnsupportedOperationException("unexpected type of node");
+    }
 
     protected abstract Object visit(ASTJexlScript node, Object data);
 
     protected abstract Object visit(ASTBlock node, Object data);
 
-    protected abstract Object visit(ASTAmbiguous node, Object data);
-
     protected abstract Object visit(ASTIfStatement node, Object data);
 
     protected abstract Object visit(ASTWhileStatement node, Object data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java Tue Dec  6 14:19:33 2011
@@ -32,9 +32,11 @@ import javax.script.ScriptEngineFactory;
 import javax.script.ScriptException;
 import javax.script.SimpleBindings;
 
+import org.apache.commons.jexl3.internal.Engine;
+import org.apache.commons.jexl3.JexlBuilder;
 import org.apache.commons.jexl3.JexlContext;
 import org.apache.commons.jexl3.JexlEngine;
-import org.apache.commons.jexl3.Script;
+import org.apache.commons.jexl3.JexlScript;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -188,12 +190,12 @@ public class JexlScriptEngine extends Ab
         jexlObject = new JexlScriptObject();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public Bindings createBindings() {
         return new SimpleBindings();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public Object eval(final Reader reader, final ScriptContext context) throws ScriptException {
         // This is mandated by JSR-223 (see SCR.5.5.2   Methods)
         if (reader == null || context == null) {
@@ -202,16 +204,16 @@ public class JexlScriptEngine extends Ab
         return eval(readerToString(reader), context);
     }
 
-    /** {@inheritDoc} */
+    @Override
     public Object eval(final String script, final ScriptContext context) throws ScriptException {
         // This is mandated by JSR-223 (see SCR.5.5.2   Methods)
         if (script == null || context == null) {
             throw new NullPointerException("script and context must be non-null");
         }
-        // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
+        // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - JexlScript Execution)
         context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
         try {
-            Script jexlScript = jexlEngine.createScript(script);
+            JexlScript jexlScript = jexlEngine.createScript(script);
             JexlContext ctxt = new JexlContextWrapper(context);
             return jexlScript.execute(ctxt);
         } catch (Exception e) {
@@ -224,21 +226,21 @@ public class JexlScriptEngine extends Ab
         return parentFactory;
     }
 
-    /** {@inheritDoc} */
+    @Override
     public CompiledScript compile(final String script) throws ScriptException {
         // This is mandated by JSR-223
         if (script == null) {
             throw new NullPointerException("script must be non-null");
         }
         try {
-            Script jexlScript = jexlEngine.createScript(script);
+            JexlScript jexlScript = jexlEngine.createScript(script);
             return new JexlCompiledScript(jexlScript);
         } catch (Exception e) {
             throw new ScriptException(e.toString());
         }
     }
 
-    /** {@inheritDoc} */
+    @Override
     public CompiledScript compile(final Reader script) throws ScriptException {
         // This is mandated by JSR-223
         if (script == null) {
@@ -255,7 +257,7 @@ public class JexlScriptEngine extends Ab
      */
     private String readerToString(final Reader script) throws ScriptException {
         try {
-           return JexlEngine.readerToString(script);
+           return Engine.readerToString(script);
         } catch (IOException e) {
             throw new ScriptException(e);
         }
@@ -273,17 +275,13 @@ public class JexlScriptEngine extends Ab
 
     /**
      * Holds singleton JexlScriptEngine (IODH).
-     * <p>A single JEXL engine and Uberspect is shared by all instances of JexlScriptEngine.</p>
+     * <p>A single JEXL engine and JexlUberspect is shared by all instances of JexlScriptEngine.</p>
      */
     private static class EngineSingletonHolder {
         /** non instantiable. */
         private EngineSingletonHolder() {}
         /** The JEXL engine singleton instance. */
-        private static final JexlEngine DEFAULT_ENGINE = new JexlEngine(null, null, null, LOG) {
-            {
-                this.setCache(CACHE_SIZE);
-            }
-        };
+        private static final JexlEngine DEFAULT_ENGINE = new JexlBuilder().logger(LOG).cache(CACHE_SIZE).create();
     }
 
     /**
@@ -302,7 +300,7 @@ public class JexlScriptEngine extends Ab
             scriptContext = theContext;
         }
 
-        /** {@inheritDoc} */
+        @Override
         public Object get(final String name) {
             final Object o = scriptContext.getAttribute(name);
             if (JEXL_OBJECT_KEY.equals(name)) {
@@ -314,7 +312,7 @@ public class JexlScriptEngine extends Ab
             return o;
         }
 
-        /** {@inheritDoc} */
+        @Override
         public void set(final String name, final Object value) {
             int scope = scriptContext.getAttributesScope(name);
             if (scope == -1) { // not found, default to engine
@@ -323,7 +321,7 @@ public class JexlScriptEngine extends Ab
             scriptContext.getBindings(scope).put(name , value);
         }
 
-        /** {@inheritDoc} */
+        @Override
         public boolean has(final String name) {
             Bindings bnd = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
             return bnd.containsKey(name);
@@ -332,17 +330,17 @@ public class JexlScriptEngine extends Ab
     }
 
     /**
-     * Wrapper to help convert a Jexl Script into a JSR-223 CompiledScript.
+     * Wrapper to help convert a Jexl JexlScript into a JSR-223 CompiledScript.
      */
     private final class JexlCompiledScript extends CompiledScript {
         /** The underlying Jexl expression instance. */
-        private final Script script;
+        private final JexlScript script;
 
         /**
          * Creates an instance.
          * @param theScript to wrap
          */
-        private JexlCompiledScript(final Script theScript) {
+        private JexlCompiledScript(final JexlScript theScript) {
             script = theScript;
         }
 
@@ -355,7 +353,7 @@ public class JexlScriptEngine extends Ab
         /** {@inheritDoc} */
         @Override
         public Object eval(final ScriptContext context) throws ScriptException {
-            // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
+            // This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - JexlScript Execution)
             context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
             try {
                 JexlContext ctxt = new JexlContextWrapper(context);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java Tue Dec  6 14:19:33 2011
@@ -23,7 +23,7 @@ import java.util.List;
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineFactory;
-import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.internal.Engine;
 import org.apache.commons.jexl3.parser.StringParser;
 
 /**
@@ -42,28 +42,28 @@ import org.apache.commons.jexl3.parser.S
  */
 public class JexlScriptEngineFactory implements ScriptEngineFactory {
 
-    /** {@inheritDoc} */
+    @Override
     public String getEngineName() {
         return "JEXL Engine";
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getEngineVersion() {
         return "3.0"; // ensure this is updated if function changes are made to this class
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getLanguageName() {
         return "JEXL";
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getLanguageVersion() {
         return "3.0"; // TODO this should be derived from the actual version
     }
 
-    /** {@inheritDoc} */
-    public String getMethodCallSyntax(String obj, String m, String[] args) {
+    @Override
+    public String getMethodCallSyntax(String obj, String m, String... args) {
         StringBuilder sb = new StringBuilder();
         sb.append(obj);
         sb.append('.');
@@ -81,26 +81,26 @@ public class JexlScriptEngineFactory imp
         return sb.toString();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public List<String> getExtensions() {
         return Collections.unmodifiableList(Arrays.asList("jexl", "jexl2", "jexl3"));
     }
 
-    /** {@inheritDoc} */
+    @Override
     public List<String> getMimeTypes() {
         return Collections.unmodifiableList(Arrays.asList("application/x-jexl",
                                                           "application/x-jexl2",
                                                           "application/x-jexl3"));
     }
 
-    /** {@inheritDoc} */
+    @Override
     public List<String> getNames() {
         return Collections.unmodifiableList(Arrays.asList("JEXL", "Jexl", "jexl",
                                                           "JEXL2", "Jexl2", "jexl2",
                                                           "JEXL3", "Jexl3", "jexl3"));
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getOutputStatement(String toDisplay) {
         if (toDisplay == null) {
             return "JEXL.out.print(null)";
@@ -109,7 +109,7 @@ public class JexlScriptEngineFactory imp
         }
     }
 
-    /** {@inheritDoc} */
+    @Override
     public Object getParameter(String key) {
         if (key.equals(ScriptEngine.ENGINE)) {
             return getEngineName();
@@ -133,11 +133,11 @@ public class JexlScriptEngineFactory imp
         return null;
     }
 
-    /** {@inheritDoc} */
-    public String getProgram(String[] statements) {
+    @Override
+    public String getProgram(String... statements) {
         StringBuilder sb = new StringBuilder();
         for(String statement : statements){
-            sb.append(JexlEngine.cleanExpression(statement));
+            sb.append(Engine.cleanExpression(statement));
             if (!statement.endsWith(";")){
                 sb.append(';');
             }
@@ -145,7 +145,7 @@ public class JexlScriptEngineFactory imp
         return sb.toString();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public ScriptEngine getScriptEngine() {
         JexlScriptEngine engine = new JexlScriptEngine(this);
         return engine;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java Tue Dec  6 14:19:33 2011
@@ -31,12 +31,12 @@ public class ArithmeticTest extends Jexl
     private Asserter asserter;
 
     public ArithmeticTest() {
-        super(createThreadedArithmeticEngine(true));
+        super("ArithmeticTest");
+        asserter = new Asserter(JEXL);
     }
 
     @Override
     public void setUp() {
-        asserter = new Asserter(JEXL);
     }
 
     public void testUndefinedVar() throws Exception {
@@ -46,6 +46,7 @@ public class ArithmeticTest extends Jexl
     public void testLeftNullOperand() throws Exception {
         asserter.setVariable("left", null);
         asserter.setVariable("right", Integer.valueOf(8));
+        asserter.setStrict(true);
         asserter.failExpression("left + right", ".*null.*");
         asserter.failExpression("left - right", ".*null.*");
         asserter.failExpression("left * right", ".*null.*");
@@ -137,7 +138,13 @@ public class ArithmeticTest extends Jexl
      * test some simple mathematical calculations
      */
     public void testCalculations() throws Exception {
-
+        asserter.setStrict(true, false);
+        /*
+         * test new null coersion
+         */
+        asserter.setVariable("imanull", null);
+        asserter.assertExpression("imanull + 2", new Integer(2));
+        asserter.assertExpression("imanull + imanull", new Integer(0));
         asserter.setVariable("foo", new Integer(2));
 
         asserter.assertExpression("foo + 2", new Integer(4));
@@ -162,6 +169,7 @@ public class ArithmeticTest extends Jexl
         /*
          * test / and %
          */
+        asserter.setStrict(false, false);
         asserter.assertExpression("6 / 3", new Integer(6 / 3));
         asserter.assertExpression("6.4 / 3", new Double(6.4 / 3));
         asserter.assertExpression("0 / 3", new Integer(0 / 3));
@@ -169,17 +177,11 @@ public class ArithmeticTest extends Jexl
         asserter.assertExpression("4 % 3", new Integer(1));
         asserter.assertExpression("4.8 % 3", new Double(4.8 % 3));
 
-        /*
-         * test new null coersion
-         */
-        asserter.setVariable("imanull", null);
-        asserter.assertExpression("imanull + 2", new Integer(2));
-        asserter.assertExpression("imanull + imanull", new Integer(0));
     }
 
     public void testCoercions() throws Exception {
         asserter.assertExpression("1", new Integer(1)); // numerics default to Integer
-//        asserter.assertExpression("5L", new Long(5)); // TODO when implemented
+        asserter.assertExpression("5L", new Long(5)); 
 
         asserter.setVariable("I2", new Integer(2));
         asserter.setVariable("L2", new Long(2));
@@ -279,7 +281,7 @@ public class ArithmeticTest extends Jexl
      */
     public void testDivideByZero() throws Exception {
         Map<String, Object> vars = new HashMap<String, Object>();
-        JexlContext context = new MapContext(vars);
+        JexlEvalContext context = new JexlEvalContext(vars);
         vars.put("aByte", new Byte((byte) 1));
         vars.put("aShort", new Short((short) 2));
         vars.put("aInteger", new Integer(3));
@@ -307,12 +309,11 @@ public class ArithmeticTest extends Jexl
         // number of permutations this will generate
         final int PERMS = tnames.length * tnames.length;
 
-        JexlEngine jexl = createThreadedArithmeticEngine(true);
-        jexl.setCache(128);
-        jexl.setSilent(false);
+        JexlEngine jexl = JEXL;
         // for non-silent, silent...
         for (int s = 0; s < 2; ++s) {
-            JexlThreadedArithmetic.setLenient(Boolean.valueOf(s == 0));
+            boolean strict = Boolean.valueOf(s != 0);
+            context.setStrict(true, strict);
             int zthrow = 0;
             int zeval = 0;
             // for vars of all types...
@@ -322,7 +323,7 @@ public class ArithmeticTest extends Jexl
                     // divide var by zero
                     String expr = "a" + vname + " / " + "z" + zname;
                     try {
-                        Expression zexpr = jexl.createExpression(expr);
+                        JexlExpression zexpr = jexl.createExpression(expr);
                         Object nan = zexpr.evaluate(context);
                         // check we have a zero & incremement zero count
                         if (nan instanceof Number) {
@@ -337,7 +338,7 @@ public class ArithmeticTest extends Jexl
                     }
                 }
             }
-            if (!jexl.isLenient()) {
+            if (strict) {
                 assertTrue("All expressions should have thrown " + zthrow + "/" + PERMS,
                         zthrow == PERMS);
             } else {

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java Tue Dec  6 14:19:33 2011
@@ -44,6 +44,10 @@ public class ArrayAccessTest extends Jex
     static final String[][] GET_METHOD_ARRAY2 =
         new String[][] { {"One", "Two", "Three"},{"Four", "Five", "Six"} };
 
+    public ArrayAccessTest() {
+        super("ArrayAccessTest");
+    }
+    
     @Override
     public void setUp() {
         asserter = new Asserter(JEXL);

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java Tue Dec  6 14:19:33 2011
@@ -24,8 +24,12 @@ import java.util.Arrays;
  */
 public class ArrayLiteralTest extends JexlTestCase {
 
+    public ArrayLiteralTest() {
+        super("ArrayLiteralTest");
+    }
+    
     public void testLiteralWithStrings() throws Exception {
-        Expression e = JEXL.createExpression( "[ 'foo' , 'bar' ]" );
+        JexlExpression e = JEXL.createExpression( "[ 'foo' , 'bar' ]" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -34,7 +38,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void testLiteralWithOneEntry() throws Exception {
-        Expression e = JEXL.createExpression( "[ 'foo' ]" );
+        JexlExpression e = JEXL.createExpression( "[ 'foo' ]" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -43,7 +47,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void testLiteralWithNumbers() throws Exception {
-        Expression e = JEXL.createExpression( "[ 5.0 , 10 ]" );
+        JexlExpression e = JEXL.createExpression( "[ 5.0 , 10 ]" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -69,7 +73,7 @@ public class ArrayLiteralTest extends Je
         };
         JexlContext jc = new MapContext();
         for(int t = 0; t < exprs.length; ++t) {
-            Expression e = JEXL.createExpression( exprs[t] );
+            JexlExpression e = JEXL.createExpression( exprs[t] );
             Object o = e.evaluate( jc );
             assertTrue(exprs[t], Arrays.equals(checks[t], (Object[])o) );
         }
@@ -77,7 +81,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void testLiteralWithIntegers() throws Exception {
-        Expression e = JEXL.createExpression( "[ 5 , 10 ]" );
+        JexlExpression e = JEXL.createExpression( "[ 5 , 10 ]" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -86,7 +90,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void testSizeOfSimpleArrayLiteral() throws Exception {
-        Expression e = JEXL.createExpression( "size([ 'foo' , 'bar' ])" );
+        JexlExpression e = JEXL.createExpression( "size([ 'foo' , 'bar' ])" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -94,7 +98,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void notestCallingMethodsOnNewMapLiteral() throws Exception {
-        Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
+        JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );
@@ -102,7 +106,7 @@ public class ArrayLiteralTest extends Je
     }
 
     public void testNotEmptySimpleArrayLiteral() throws Exception {
-        Expression e = JEXL.createExpression( "empty([ 'foo' , 'bar' ])" );
+        JexlExpression e = JEXL.createExpression( "empty([ 'foo' , 'bar' ])" );
         JexlContext jc = new MapContext();
 
         Object o = e.evaluate( jc );

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/AssignTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/AssignTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/AssignTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/AssignTest.java Tue Dec  6 14:19:33 2011
@@ -22,12 +22,7 @@ package org.apache.commons.jexl3;
  * @since 1.1
  */
 public class AssignTest extends JexlTestCase {
-    private static final JexlArithmetic ARITH = new JexlArithmetic(false);
-    private static final JexlEngine ENGINE = new JexlEngine(null, ARITH, null, null);
-    static {
-        ENGINE.setSilent(false);
-    }
-    
+
     public static class Froboz {
         int value;
         public Froboz(int v) {
@@ -67,7 +62,7 @@ public class AssignTest extends JexlTest
     }
 
     public AssignTest(String testName) {
-        super(testName);
+        super(testName, new JexlBuilder().cache(512).strict(true).silent(false).create());
     }
 
     /**
@@ -76,8 +71,8 @@ public class AssignTest extends JexlTest
      * @throws Exception on any error
      */
     public void testAntish() throws Exception {
-        Expression assign = ENGINE.createExpression("froboz.value = 10");
-        Expression check = ENGINE.createExpression("froboz.value");
+        JexlExpression assign = JEXL.createExpression("froboz.value = 10");
+        JexlExpression check = JEXL.createExpression("froboz.value");
         JexlContext jc = new MapContext();
         Object o = assign.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
@@ -86,8 +81,8 @@ public class AssignTest extends JexlTest
     }
 
     public void testAntishInteger() throws Exception {
-        Expression assign = ENGINE.createExpression("froboz.0 = 10");
-        Expression check = ENGINE.createExpression("froboz.0");
+        JexlExpression assign = JEXL.createExpression("froboz.0 = 10");
+        JexlExpression check = JEXL.createExpression("froboz.0");
         JexlContext jc = new MapContext();
         Object o = assign.evaluate(jc);
         assertEquals("Result is not 10", new Integer(10), o);
@@ -96,8 +91,8 @@ public class AssignTest extends JexlTest
     }
     
     public void testBeanish() throws Exception {
-        Expression assign = ENGINE.createExpression("froboz.value = 10");
-        Expression check = ENGINE.createExpression("froboz.value");
+        JexlExpression assign = JEXL.createExpression("froboz.value = 10");
+        JexlExpression check = JEXL.createExpression("froboz.value");
         JexlContext jc = new MapContext();
         Froboz froboz = new Froboz(-169);
         jc.set("froboz", froboz);
@@ -108,7 +103,7 @@ public class AssignTest extends JexlTest
     }
     
     public void testAmbiguous() throws Exception {
-        Expression assign = ENGINE.createExpression("froboz.nosuchbean = 10");
+        JexlExpression assign = JEXL.createExpression("froboz.nosuchbean = 10");
         JexlContext jc = new MapContext();
         Froboz froboz = new Froboz(-169);
         jc.set("froboz", froboz);
@@ -127,8 +122,8 @@ public class AssignTest extends JexlTest
     }
         
     public void testArray() throws Exception {
-        Expression assign = ENGINE.createExpression("froboz[\"value\"] = 10");
-        Expression check = ENGINE.createExpression("froboz[\"value\"]");
+        JexlExpression assign = JEXL.createExpression("froboz[\"value\"] = 10");
+        JexlExpression check = JEXL.createExpression("froboz[\"value\"]");
         JexlContext jc = new MapContext();
         Froboz froboz = new Froboz(0);
         jc.set("froboz", froboz);
@@ -141,9 +136,9 @@ public class AssignTest extends JexlTest
     public void testMore() throws Exception {
         JexlContext jc = new MapContext();
         jc.set("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");
+        JexlExpression create = JEXL.createExpression("quux = new(quuxClass, 'xuuq', 100)");
+        JexlExpression assign = JEXL.createExpression("quux.froboz.value = 10");
+        JexlExpression check = JEXL.createExpression("quux[\"froboz\"].value");
 
         Quux quux = (Quux) create.evaluate(jc);
         assertNotNull("quux is null", quux);
@@ -154,12 +149,12 @@ public class AssignTest extends JexlTest
     }
 
     public void testUtil() throws Exception {
-        Quux quux = ENGINE.newInstance(Quux.class, "xuuq", Integer.valueOf(100));
-        ENGINE.setProperty(quux, "froboz.value", Integer.valueOf(100));
-        Object o = ENGINE.getProperty(quux, "froboz.value");
+        Quux quux = JEXL.newInstance(Quux.class, "xuuq", Integer.valueOf(100));
+        JEXL.setProperty(quux, "froboz.value", Integer.valueOf(100));
+        Object o = JEXL.getProperty(quux, "froboz.value");
         assertEquals("Result is not 100", new Integer(100), o);
-        ENGINE.setProperty(quux, "['froboz'].value", Integer.valueOf(1000));
-        o = ENGINE.getProperty(quux, "['froboz']['value']");
+        JEXL.setProperty(quux, "['froboz'].value", Integer.valueOf(1000));
+        o = JEXL.getProperty(quux, "['froboz']['value']");
         assertEquals("Result is not 1000", new Integer(1000), o);
     }
 

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BitwiseOperatorTest.java Tue Dec  6 14:19:33 2011
@@ -17,7 +17,6 @@
 
 package org.apache.commons.jexl3;
 import org.apache.commons.jexl3.junit.Asserter;
-import org.apache.commons.jexl3.junit.Asserter;
 
 /**
  * Tests for the bitwise operators.
@@ -29,6 +28,7 @@ public class BitwiseOperatorTest extends
     @Override
     public void setUp() {
         asserter = new Asserter(JEXL);
+        asserter.setStrict(false);
     }
 
     /**

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BlockTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BlockTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BlockTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/BlockTest.java Tue Dec  6 14:19:33 2011
@@ -16,10 +16,6 @@
  */
 package org.apache.commons.jexl3;
 
-import org.apache.commons.jexl3.Expression;
-import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.MapContext;
-
 /**
  * Tests for blocks
  * @since 1.1
@@ -36,14 +32,14 @@ public class BlockTest extends JexlTestC
     }
 
     public void testBlockSimple() throws Exception {
-        Expression e = JEXL.createExpression("if (true) { 'hello'; }");
+        JexlExpression e = JEXL.createExpression("if (true) { 'hello'; }");
         JexlContext jc = new MapContext();
         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';}");
+        JexlExpression e = JEXL.createExpression("if (true) { x = 'Hello'; y = 'World';}");
         JexlContext jc = new MapContext();
         Object o = e.evaluate(jc);
         assertEquals("First result is wrong", "Hello", jc.get("x"));
@@ -52,28 +48,28 @@ public class BlockTest extends JexlTestC
     }
 
     public void testEmptyBlock() throws Exception {
-        Expression e = JEXL.createExpression("if (true) { }");
+        JexlExpression e = JEXL.createExpression("if (true) { }");
         JexlContext jc = new MapContext();
         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; }");
+        JexlExpression e = JEXL.createExpression("if (true) { x = 1; } else { x = 2; }");
         JexlContext jc = new MapContext();
         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; }");
+        JexlExpression e = JEXL.createExpression("if (false) { x = 1; } else { x = 2; }");
         JexlContext jc = new MapContext();
         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; }");
+        JexlExpression e = JEXL.createExpression("if (true) { x = 'hello'; y = 'world';" + " if (true) { x; } y; }");
         JexlContext jc = new MapContext();
         Object o = e.evaluate(jc);
         assertEquals("Block result is wrong", "world", o);

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=1210927&r1=1210926&r2=1210927&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 Tue Dec  6 14:19:33 2011
@@ -28,15 +28,10 @@ import java.util.concurrent.TimeUnit;
  * Verifies cache & tryExecute
  */
 public class CacheTest extends JexlTestCase {
-    public CacheTest(String testName) {
-        super(testName);
-    }
-    private static final JexlEngine jexl = createEngine(false);
-
-    static {
-        jexl.setCache(512);
-        jexl.setSilent(false);
+    public CacheTest() {
+        super("CacheTest", null);
     }
+    private static final JexlEngine jexl = new JexlBuilder().cache(512).debug(true).strict(true).create();
 
     @Override
     public void setUp() throws Exception {
@@ -210,7 +205,7 @@ public class CacheTest extends JexlTestC
         }
 
         @Override
-        public Object put(String key, Object arg) {
+        public final Object put(String key, Object arg) {
             if (arg == null) {
                 arg = "na";
             }
@@ -282,10 +277,8 @@ public class CacheTest extends JexlTestC
         if (loops == 0) {
             loops = MIX.length;
         }
-        if (cache) {
-            jexl.setCache(32);
-        } else {
-            jexl.setCache(0);
+        if (!cache) {
+            jexl.clearCache();
         }
         java.util.concurrent.ExecutorService execs = java.util.concurrent.Executors.newFixedThreadPool(NTHREADS);
         List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>(NTHREADS);
@@ -307,12 +300,13 @@ public class CacheTest extends JexlTestC
         final TestCacheArguments args = new TestCacheArguments();
         final int loops;
         final Map<String, Object> vars = new HashMap<String, Object>();
-        final JexlContext jc = new MapContext(vars);
+        final JexlEvalContext jc = new JexlEvalContext(vars);
 
         Task(int loops) {
             this.loops = loops;
         }
 
+        @Override
         public abstract Integer call() throws Exception;
 
         /**
@@ -333,8 +327,8 @@ public class CacheTest extends JexlTestC
             args.value = new Object[]{value};
             Object result;
 
-            Expression cacheGetValue = jexl.createExpression("cache.value");
-            Expression cacheSetValue = jexl.createExpression("cache.value = value");
+            JexlExpression cacheGetValue = jexl.createExpression("cache.value");
+            JexlExpression cacheSetValue = jexl.createExpression("cache.value = value");
             for (int l = 0; l < loops; ++l) {
                 int px = (int) Thread.currentThread().getId();
                 int mix = MIX[(l + px) % MIX.length];
@@ -402,8 +396,8 @@ public class CacheTest extends JexlTestC
         /** The actual test function. */
         private Integer runAssignBoolean(Boolean value) {
             args.value = new Object[]{value};
-            Expression cacheGetValue = jexl.createExpression("cache.flag");
-            Expression cacheSetValue = jexl.createExpression("cache.flag = value");
+            JexlExpression cacheGetValue = jexl.createExpression("cache.flag");
+            JexlExpression cacheSetValue = jexl.createExpression("cache.flag = value");
             Object result;
 
             for (int l = 0; l < loops; ++l) {
@@ -447,8 +441,8 @@ public class CacheTest extends JexlTestC
                         c1
                     };
 
-            Expression cacheGetValue = jexl.createExpression("cache.0");
-            Expression cacheSetValue = jexl.createExpression("cache[0] = value");
+            JexlExpression cacheGetValue = jexl.createExpression("cache.0");
+            JexlExpression cacheSetValue = jexl.createExpression("cache[0] = value");
             Object result;
 
             for (int l = 0; l < loops; ++l) {
@@ -514,10 +508,10 @@ public class CacheTest extends JexlTestC
             args.ca = new Object[]{args.c0, args.c1, args.c2};
             args.value = new Object[]{new Integer(2), "quux"};
             //jexl.setDebug(true);
-            Expression compute2 = jexl.createExpression("cache.compute(a0, a1)");
-            Expression compute1 = jexl.createExpression("cache.compute(a0)");
-            Expression compute1null = jexl.createExpression("cache.compute(a0)");
-            Expression ambiguous = jexl.createExpression("cache.ambiguous(a0, a1)");
+            JexlExpression compute2 = jexl.createExpression("cache.compute(a0, a1)");
+            JexlExpression compute1 = jexl.createExpression("cache.compute(a0)");
+            JexlExpression compute1null = jexl.createExpression("cache.compute(a0)");
+            JexlExpression ambiguous = jexl.createExpression("cache.ambiguous(a0, a1)");
             //jexl.setDebug(false);
 
             Object result = null;
@@ -584,25 +578,15 @@ public class CacheTest extends JexlTestC
     }
 
     public void testComputeNoCache() throws Exception {
-        try {
-            jexl.setDebug(true);
             runThreaded(ComputeTask.class, LOOPS, false);
-        } finally {
-            jexl.setDebug(false);
-        }
     }
 
     public void testComputeCache() throws Exception {
-        try {
-            jexl.setDebug(true);
             runThreaded(ComputeTask.class, LOOPS, true);
-        } finally {
-            jexl.setDebug(false);
-        }
     }
 
     /**
-     * The remaining tests exercise the namespaced functions; not MT.
+     * The remaining tests exercise the namespaced namespaces; not MT.
      * @param x
      * @param loops
      * @param cache
@@ -612,17 +596,15 @@ public class CacheTest extends JexlTestC
         if (loops == 0) {
             loops = MIX.length;
         }
-        if (cache) {
-            jexl.setCache(32);
-        } else {
-            jexl.setCache(0);
+        if (!cache) {
+            jexl.clearCache();
         }
         Map<String, Object> vars = new HashMap<String, Object>();
-        JexlContext jc = new MapContext(vars);
+        JexlEvalContext jc = new JexlEvalContext(vars);
         java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
-        jexl.setFunctions(funcs);
-        Expression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
-        Expression compute1 = jexl.createExpression("cached:COMPUTE(a0)");
+        jc.setNamespaces(funcs);
+        JexlExpression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
+        JexlExpression compute1 = jexl.createExpression("cached:COMPUTE(a0)");
         Object result = null;
         String expected = null;
         for (int l = 0; l < loops; ++l) {

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreator.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreator.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreator.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreator.java Tue Dec  6 14:19:33 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.jexl3;
 
-import org.apache.commons.jexl3.JexlEngine;
 
 import java.io.File;
 import java.io.FileWriter;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java Tue Dec  6 14:19:33 2011
@@ -24,10 +24,6 @@ import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.jexl3.Expression;
-import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.JexlEngine;
-import org.apache.commons.jexl3.MapContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -40,11 +36,14 @@ public class ClassCreatorTest extends Je
     private File base = null;
     private JexlEngine jexl = null;
 
+    public ClassCreatorTest() {
+        super("ClassCreatorTest");
+    }
+    
     @Override
     public void setUp() throws Exception {
         base = new File(System.getProperty("java.io.tmpdir") + File.pathSeparator + "jexl" + System.currentTimeMillis());
-        jexl = new JexlEngine();
-        jexl.setCache(512);
+        jexl = JEXL;
 
     }
 
@@ -116,9 +115,11 @@ public class ClassCreatorTest extends Je
         List<Reference<?>> stuff = new ArrayList<Reference<?>>();
         // keeping a reference on methods prevent classes from being GCed
 //        List<Object> mm = new ArrayList<Object>();
-        Expression expr = jexl.createExpression("foo.value");
-        Expression newx = jexl.createExpression("foo = new(clazz)");
-        JexlContext context = new MapContext();
+        JexlExpression expr = jexl.createExpression("foo.value");
+        JexlExpression newx = jexl.createExpression("foo = new(clazz)");
+        JexlEvalContext context = new JexlEvalContext();
+        context.setStrict(false);
+        context.setSilent(true);
 
         ClassCreator cctor = new ClassCreator(jexl, base);
         for (int i = 0; i < LOOPS && gced < 0; ++i) {

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ForEachTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ForEachTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ForEachTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ForEachTest.java Tue Dec  6 14:19:33 2011
@@ -19,6 +19,7 @@ package org.apache.commons.jexl3;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Map;
 import java.util.StringTokenizer;
 
@@ -35,23 +36,25 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithEmptyStatement() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) ;");
+        JexlExpression e = JEXL.createExpression("for(item : list) ;");
         JexlContext jc = new MapContext();
+        jc.set("list", Collections.emptyList());
 
         Object o = e.evaluate(jc);
         assertNull("Result is not null", o);
     }
 
     public void testForEachWithEmptyList() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) 1+1");
+        JexlExpression e = JEXL.createExpression("for(item : list) 1+1");
         JexlContext jc = new MapContext();
+        jc.set("list", Collections.emptyList());
 
         Object o = e.evaluate(jc);
         assertNull("Result is not null", o);
     }
 
     public void testForEachWithArray() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) item");
+        JexlExpression e = JEXL.createExpression("for(item : list) item");
         JexlContext jc = new MapContext();
         jc.set("list", new Object[] {"Hello", "World"});
         Object o = e.evaluate(jc);
@@ -59,7 +62,7 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithCollection() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) item");
+        JexlExpression e = JEXL.createExpression("for(item : list) item");
         JexlContext jc = new MapContext();
         jc.set("list", Arrays.asList(new Object[] {"Hello", "World"}));
         Object o = e.evaluate(jc);
@@ -67,7 +70,7 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithEnumeration() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) item");
+        JexlExpression e = JEXL.createExpression("for(item : list) item");
         JexlContext jc = new MapContext();
         jc.set("list", new StringTokenizer("Hello,World", ","));
         Object o = e.evaluate(jc);
@@ -75,7 +78,7 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithIterator() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) item");
+        JexlExpression e = JEXL.createExpression("for(item : list) item");
         JexlContext jc = new MapContext();
         jc.set("list", Arrays.asList(new Object[] {"Hello", "World"}).iterator());
         Object o = e.evaluate(jc);
@@ -83,7 +86,7 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithMap() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list) item");
+        JexlExpression e = JEXL.createExpression("for(item : list) item");
         JexlContext jc = new MapContext();
         Map<?, ?> map = System.getProperties();
         String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
@@ -93,9 +96,9 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithBlock() throws Exception {
-        Expression exs0 = JEXL.createExpression("for(in : list) { x = x + in; }");
-        Expression exs1 = JEXL.createExpression("foreach(item in list) { x = x + item; }");
-        Expression []exs = { exs0, exs1 };
+        JexlExpression exs0 = JEXL.createExpression("for(in : list) { x = x + in; }");
+        JexlExpression exs1 = JEXL.createExpression("foreach(item in list) { x = x + item; }");
+        JexlExpression []exs = { exs0, exs1 };
         JexlContext jc = new MapContext();
         jc.set("list", new Object[] {"2", "3"});
         for(int ex = 0; ex < exs.length; ++ex) {
@@ -107,7 +110,7 @@ public class ForEachTest extends JexlTes
     }
 
     public void testForEachWithListExpression() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list.keySet()) item");
+        JexlExpression e = JEXL.createExpression("for(item : list.keySet()) item");
         JexlContext jc = new MapContext();
         Map<?, ?> map = System.getProperties();
         String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
@@ -117,7 +120,7 @@ public class ForEachTest extends JexlTes
     }
     
     public void testForEachWithProperty() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list.cheeseList) item");
+        JexlExpression e = JEXL.createExpression("for(item : list.cheeseList) item");
         JexlContext jc = new MapContext();
         jc.set("list", new Foo());
         Object o = e.evaluate(jc);
@@ -125,7 +128,7 @@ public class ForEachTest extends JexlTes
     }
     
     public void testForEachWithIteratorMethod() throws Exception {
-        Expression e = JEXL.createExpression("for(item : list.cheezy) item");
+        JexlExpression e = JEXL.createExpression("for(item : list.cheezy) item");
         JexlContext jc = new MapContext();
         jc.set("list", new Foo());
         Object o = e.evaluate(jc);



Mime
View raw message