Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 50124 invoked from network); 1 Aug 2009 03:58:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Aug 2009 03:58:50 -0000 Received: (qmail 78561 invoked by uid 500); 1 Aug 2009 03:58:54 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 78446 invoked by uid 500); 1 Aug 2009 03:58:53 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 78436 invoked by uid 99); 1 Aug 2009 03:58:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Aug 2009 03:58:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Aug 2009 03:58:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 354BD23888DD; Sat, 1 Aug 2009 03:58:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r799796 - /commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java Date: Sat, 01 Aug 2009 03:58:31 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090801035831.354BD23888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Sat Aug 1 03:58:30 2009 New Revision: 799796 URL: http://svn.apache.org/viewvc?rev=799796&view=rev Log: Allow Read/write of both local and global scopes TODO how to create global keys? Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java?rev=799796&r1=799795&r2=799796&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java (original) +++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java Sat Aug 1 03:58:30 2009 @@ -141,6 +141,13 @@ context = _context; } + /* + * TODO how to handle clear, containsKey() etc.? + * Should they be restricted to engine scope, or should they apply to the + * union of the two scopes? + * Are they actually used by Jexl? + */ + public void clear() { Bindings bnd = context.getBindings(ScriptContext.ENGINE_SCOPE); bnd.clear(); @@ -161,9 +168,12 @@ return bnd.entrySet(); } + // Fetch first match of key, either engine or global public Object get(final Object key) { - Bindings bnd = context.getBindings(ScriptContext.ENGINE_SCOPE); - return bnd.get(key); + if (key instanceof String) { + return context.getAttribute((String) key); + } + return null; } public boolean isEmpty() { @@ -176,9 +186,14 @@ return bnd.keySet(); } + // Update existing key if found, else create new engine key + // TODO - how do we create global keys? public Object put(final String key, final Object value) { - Bindings bnd = context.getBindings(ScriptContext.ENGINE_SCOPE); - return bnd.put(key, value); + int scope = context.getAttributesScope(key); + if (scope == -1) { // not found, default to engine + scope = ScriptContext.ENGINE_SCOPE; + } + return context.getBindings(scope).put(key , value); } public void putAll(Map t) { @@ -186,9 +201,15 @@ bnd.putAll(t); // N.B. SimpleBindings checks for valid keys } + // N.B. if there is more than one copy of the key, only the nearest will be removed. public Object remove(Object key) { - Bindings bnd = context.getBindings(ScriptContext.ENGINE_SCOPE); - return bnd.remove(key); + if (key instanceof String){ + int scope = context.getAttributesScope((String) key); + if (scope != -1) { // found an entry + return context.removeAttribute((String)key, scope); + } + } + return null; } public int size() {