Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 023959125 for ; Tue, 10 Apr 2012 06:07:47 +0000 (UTC) Received: (qmail 18827 invoked by uid 500); 10 Apr 2012 06:07:46 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 18795 invoked by uid 500); 10 Apr 2012 06:07:46 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 18788 invoked by uid 99); 10 Apr 2012 06:07:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2012 06:07:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Tue, 10 Apr 2012 06:07:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 231A623888FE; Tue, 10 Apr 2012 06:07:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1311584 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java Date: Tue, 10 Apr 2012 06:07:24 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120410060725.231A623888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Tue Apr 10 06:07:24 2012 New Revision: 1311584 URL: http://svn.apache.org/viewvc?rev=1311584&view=rev Log: CAMEL-5154: Simple language - OGNL - Invoking explicit method with no parameters should not cause ambiguous exception for overloaded methods Modified: camel/branches/camel-2.9.x/ (props changed) camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1311582 Propchange: camel/branches/camel-2.9.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1311584&r1=1311583&r2=1311584&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Tue Apr 10 06:07:24 2012 @@ -71,6 +71,7 @@ public class BeanInfo { // shared state with details of operations introspected from the bean, created during the constructor private Map> operations = new HashMap>(); private List operationsWithBody = new ArrayList(); + private List operationsWithNoBody = new ArrayList(); private List operationsWithCustomAnnotation = new ArrayList(); private List operationsWithHandlerAnnotation = new ArrayList(); private Map methodMap = new HashMap(); @@ -130,6 +131,7 @@ public class BeanInfo { // to keep this code thread safe operations = Collections.unmodifiableMap(operations); operationsWithBody = Collections.unmodifiableList(operationsWithBody); + operationsWithNoBody = Collections.unmodifiableList(operationsWithNoBody); operationsWithCustomAnnotation = Collections.unmodifiableList(operationsWithCustomAnnotation); operationsWithHandlerAnnotation = Collections.unmodifiableList(operationsWithHandlerAnnotation); methodMap = Collections.unmodifiableMap(methodMap); @@ -312,6 +314,8 @@ public class BeanInfo { operationsWithCustomAnnotation.add(methodInfo); } else if (methodInfo.hasBodyParameter()) { operationsWithBody.add(methodInfo); + } else { + operationsWithNoBody.add(methodInfo); } if (methodInfo.hasHandlerAnnotation()) { @@ -443,6 +447,7 @@ public class BeanInfo { // must use defensive copy, to avoid altering the shared lists // and we want to remove unwanted operations from these local lists final List localOperationsWithBody = new ArrayList(operationsWithBody); + final List localOperationsWithNoBody = new ArrayList(operationsWithNoBody); final List localOperationsWithCustomAnnotation = new ArrayList(operationsWithCustomAnnotation); final List localOperationsWithHandlerAnnotation = new ArrayList(operationsWithHandlerAnnotation); @@ -451,11 +456,13 @@ public class BeanInfo { removeNonMatchingMethods(localOperationsWithHandlerAnnotation, name); removeNonMatchingMethods(localOperationsWithCustomAnnotation, name); removeNonMatchingMethods(localOperationsWithBody, name); + removeNonMatchingMethods(localOperationsWithNoBody, name); } else { // remove all getter/setter as we do not want to consider these methods removeAllSetterOrGetterMethods(localOperationsWithHandlerAnnotation); removeAllSetterOrGetterMethods(localOperationsWithCustomAnnotation); removeAllSetterOrGetterMethods(localOperationsWithBody); + removeAllSetterOrGetterMethods(localOperationsWithNoBody); } if (localOperationsWithHandlerAnnotation.size() > 1) { @@ -469,6 +476,13 @@ public class BeanInfo { } else if (localOperationsWithCustomAnnotation.size() == 1) { // if there is one method with an annotation then use that one return localOperationsWithCustomAnnotation.get(0); + } + + // named method and with no parameters + boolean noParameters = name != null && name.endsWith("()"); + if (noParameters && localOperationsWithNoBody.size() == 1) { + // if there was a method name configured and it has no parameters, then use the method with no body (eg no parameters) + return localOperationsWithNoBody.get(0); } else if (localOperationsWithBody.size() == 1) { // if there is one method with body then use that one return localOperationsWithBody.get(0); Modified: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java?rev=1311584&r1=1311583&r2=1311584&view=diff ============================================================================== --- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java (original) +++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java Tue Apr 10 06:07:24 2012 @@ -1041,6 +1041,18 @@ public class SimpleTest extends Language assertExpression("${body.dangerous}", "false"); } + public void testBodyOgnlOnString() throws Exception { + exchange.getIn().setBody("Camel"); + + assertExpression("${body.substring(2)}", "mel"); + assertExpression("${body.substring(2, 4)}", "me"); + assertExpression("${body.length()}", 5); + assertExpression("${body.toUpperCase()}", "CAMEL"); + assertExpression("${body.toUpperCase()}", "CAMEL"); + assertExpression("${body.toUpperCase().substring(2)}", "MEL"); + assertExpression("${body.toLowerCase().length()}", 5); + } + public void testClassSimpleName() throws Exception { Animal tiger = new Animal("Tony the Tiger", 13); exchange.getIn().setBody(tiger);