Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 24634 invoked from network); 14 Dec 2009 18:53:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Dec 2009 18:53:47 -0000 Received: (qmail 26786 invoked by uid 500); 14 Dec 2009 18:53:46 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 26656 invoked by uid 500); 14 Dec 2009 18:53:46 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 26646 invoked by uid 99); 14 Dec 2009 18:53:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 18:53:46 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebbaz@gmail.com designates 209.85.220.220 as permitted sender) Received: from [209.85.220.220] (HELO mail-fx0-f220.google.com) (209.85.220.220) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 18:53:44 +0000 Received: by fxm20 with SMTP id 20so5847620fxm.35 for ; Mon, 14 Dec 2009 10:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=TVbMghvLK/5PNVMPO05jAdg3bp6NgveAeLKi0miheDY=; b=KjmEgIT8ffs5/8bsmfhc9iq5miT5k5bqVTH1lkKYgBzgRsqXA6iDXgiMv+ujxet0rD L3hXtFA+qI+8pIsYOw1nTdgnzu5sILVlOzepwqXHyr6nrJ0qvM+p2oBur8nUwI/pyMUI XKrocs1Ri1CbVN8ax4SXFsrnYoLslWd7bnRKE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=cJMF7qNnjkVelzXa/GoI+M0lZc3O9B9TZXy4ikfcemwVDZl/jU2WhwyD/EiVwlgvEq kDPov8ynGxcdQdH4sQek/NNlSr/Dy0YmtvfJELOBFhEjXiTwPSYKA72/3v/NgzNXY/PW 1/IkWsf0o5oiB3a6NQ3flbJtzzju0hcPIPt4I= MIME-Version: 1.0 Received: by 10.239.139.221 with SMTP id u29mr514852hbu.35.1260816802609; Mon, 14 Dec 2009 10:53:22 -0800 (PST) In-Reply-To: <20091214173845.DEC6023889D1@eris.apache.org> References: <20091214173845.DEC6023889D1@eris.apache.org> Date: Mon, 14 Dec 2009 18:53:22 +0000 Message-ID: <25aac9fc0912141053q77508bf0x2c3fd7e11760a5af@mail.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/ From: sebb To: dev@commons.apache.org Content-Type: text/plain; charset=ISO-8859-1 On 14/12/2009, 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 functions; > + /** The map of registered functions. */ > + protected Map 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(); > + } > + 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