commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r890409 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl2/ main/java/org/apache/commons/jexl2/internal/introspection/ test/java/org/apache/commons/jexl2/
Date Mon, 14 Dec 2009 18:53:22 GMT
On 14/12/2009, henrib@apache.org <henrib@apache.org> wrote:
> Author: henrib
>  Date: Mon Dec 14 17:38:45 2009
>  New Revision: 890409
>
>  URL: http://svn.apache.org/viewvc?rev=890409&view=rev
>  Log:
>  fixed JEXL-94; modified test accordingly. Also fixed a bug in MethodKey#isApplicable
that surfaced through test.
>
>  Modified:
>     commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
>     commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
>     commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java
>     commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/MethodTest.java
>
>  Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
>  URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=890409&r1=890408&r2=890409&view=diff
>  ==============================================================================
>  --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
(original)
>  +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
Mon Dec 14 17:38:45 2009
>  @@ -97,6 +97,8 @@
>      protected final JexlArithmetic arithmetic;
>      /** The map of registered functions. */
>      protected final Map<String, Object> functions;
>  +    /** The map of registered functions. */
>  +    protected Map<String, Object> functors;

Could/should be private.

Indeed so should all the other instance variables...

>      /** The context to store/retrieve variables. */
>      protected final JexlContext context;
>      /** Strict interpreter flag. */
>  @@ -124,6 +126,7 @@
>          this.silent = jexl.silent;
>          this.cache = jexl.cache != null;
>          this.context = aContext;
>  +        this.functors = null;

Why not allocate an empty HashMap here?

It would save a lot of null checking later, and the variable could
then be final.

>      }
>
>      /**
>  @@ -231,6 +234,46 @@
>          return null;
>      }
>
>  +    /**
>  +     * Resolves a namespace, eventually allocating an instance using context as constructor
argument.
>  +     * The lifetime of such instances span the current expression or script evaluation.
>  +     *
>  +     * @param prefix the prefix name (may be null for global namespace)
>  +     * @param node the AST node
>  +     * @return the namespace instance
>  +     */
>  +    protected Object resolveNamespace(String prefix, JexlNode node) {
>  +        Object namespace;
>  +        // check whether this namespace is a functor
>  +        if (functors != null) {
>  +            namespace = functors.get(prefix);
>  +            if (namespace != null) {
>  +                return namespace;
>  +            }
>  +        }
>  +        namespace = functions.get(prefix);
>  +        if (namespace == null) {
>  +            throw new JexlException(node, "no such function namespace " + prefix);
>  +        }
>  +        // allow namespace to be instantiated as functor with context
>  +        if (namespace instanceof Class<?>) {
>  +            Object[] args = new Object[]{context};
>  +            Constructor<?> ctor = uberspect.getConstructor(namespace,args, node);
>  +            if (ctor != null) {
>  +                try {
>  +                    namespace = ctor.newInstance(args);
>  +                    if (functors == null) {
>  +                        functors = new HashMap<String, Object>();
>  +                    }
>  +                    functors.put(prefix, namespace);
>  +                } catch (Exception xinst) {
>  +                    throw new JexlException(node, "unable to instantiate namespace
" + prefix, xinst);
>  +                }
>  +            }
>  +        }
>  +        return namespace;
>  +    }
>  +

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


Mime
View raw message