Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 93919 invoked from network); 7 Aug 2009 17:51:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Aug 2009 17:51:41 -0000 Received: (qmail 15726 invoked by uid 500); 7 Aug 2009 17:51:48 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 15618 invoked by uid 500); 7 Aug 2009 17:51:48 -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 15609 invoked by uid 99); 7 Aug 2009 17:51:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2009 17:51:48 +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; Fri, 07 Aug 2009 17:51:46 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 00F0823888AD; Fri, 7 Aug 2009 17:51:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r802105 - in /commons/proper/jexl/branches/2.0/src: main/java/org/apache/commons/jexl/util/Introspector.java test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java Date: Fri, 07 Aug 2009 17:51:25 -0000 To: commits@commons.apache.org From: rahul@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090807175126.00F0823888AD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rahul Date: Fri Aug 7 17:51:25 2009 New Revision: 802105 URL: http://svn.apache.org/viewvc?rev=802105&view=rev Log: Try list executors before duck. JEXL-81 Added: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java (with props) Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java?rev=802105&r1=802104&r2=802105&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java (original) +++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/util/Introspector.java Fri Aug 7 17:51:25 2009 @@ -198,11 +198,6 @@ if (executor.isAlive()) { return executor; } - // if that didn't work, look for get("foo") - executor = new DuckGetExecutor(this, 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); @@ -212,7 +207,11 @@ return executor; } } - + // if that didn't work, look for get("foo") + executor = new DuckGetExecutor(this, claz, identifier); + if (executor.isAlive()) { + return executor; + } return null; } @@ -239,11 +238,6 @@ if (executor.isAlive()) { return executor; } - // if that didn't work, look for get("foo") - executor = new DuckSetExecutor(this, claz, property, 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); @@ -253,6 +247,11 @@ return executor; } } + // if that didn't work, look for get("foo") + executor = new DuckSetExecutor(this, claz, property, arg); + if (executor.isAlive()) { + return executor; + } return null; } Added: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java?rev=802105&view=auto ============================================================================== --- commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java (added) +++ commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java Fri Aug 7 17:51:25 2009 @@ -0,0 +1,63 @@ +/* + * 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.jexl.util.introspection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.commons.jexl.util.Introspector; +import org.apache.commons.jexl.util.ListGetExecutor; +import org.apache.commons.jexl.util.ListSetExecutor; +import org.apache.commons.jexl.util.MapGetExecutor; +import org.apache.commons.jexl.util.MapSetExecutor; + +/** + * Tests for checking introspection discovery. + * + * @since 2.0 + */ +public class DiscoveryTest extends TestCase { + + public void testListIntrospection() throws Exception { + Uberspect uber = Introspector.getUberspect(); + Introspector intro = (Introspector) uber; + List list = new ArrayList(); + + assertTrue(intro.getGetExecutor(list, "1") instanceof ListGetExecutor); + assertTrue(intro.getSetExecutor(list, "1", "foo") instanceof ListSetExecutor); + + assertTrue(uber.getPropertyGet(list, "1", null) instanceof ListGetExecutor); + assertTrue(uber.getPropertySet(list, "1", "foo", null) instanceof ListSetExecutor); + } + + public void testMapIntrospection() throws Exception { + Uberspect uber = Introspector.getUberspect(); + Introspector intro = (Introspector) uber; + Map list = new HashMap(); + + assertTrue(intro.getGetExecutor(list, "foo") instanceof MapGetExecutor); + assertTrue(intro.getSetExecutor(list, "foo", "bar") instanceof MapSetExecutor); + + assertTrue(uber.getPropertyGet(list, "foo", null) instanceof MapGetExecutor); + assertTrue(uber.getPropertySet(list, "foo", "bar", null) instanceof MapSetExecutor); + } + +} Propchange: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/util/introspection/DiscoveryTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL