You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/04/10 08:06:04 UTC

svn commit: r1311582 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/BeanInfo.java test/java/org/apache/camel/language/simple/SimpleTest.java

Author: davsclaus
Date: Tue Apr 10 06:06:04 2012
New Revision: 1311582

URL: http://svn.apache.org/viewvc?rev=1311582&view=rev
Log:
CAMEL-5154: Simple language - OGNL - Invoking explicit method with no parameters should not cause ambiguous exception for overloaded methods

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1311582&r1=1311581&r2=1311582&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Tue Apr 10 06:06:04 2012
@@ -71,6 +71,7 @@ public class BeanInfo {
     // shared state with details of operations introspected from the bean, created during the constructor
     private Map<String, List<MethodInfo>> operations = new HashMap<String, List<MethodInfo>>();
     private List<MethodInfo> operationsWithBody = new ArrayList<MethodInfo>();
+    private List<MethodInfo> operationsWithNoBody = new ArrayList<MethodInfo>();
     private List<MethodInfo> operationsWithCustomAnnotation = new ArrayList<MethodInfo>();
     private List<MethodInfo> operationsWithHandlerAnnotation = new ArrayList<MethodInfo>();
     private Map<Method, MethodInfo> methodMap = new HashMap<Method, MethodInfo>();
@@ -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);
@@ -311,6 +313,8 @@ public class BeanInfo {
             operationsWithCustomAnnotation.add(methodInfo);
         } else if (methodInfo.hasBodyParameter()) {
             operationsWithBody.add(methodInfo);
+        } else {
+            operationsWithNoBody.add(methodInfo);
         }
 
         if (methodInfo.hasHandlerAnnotation()) {
@@ -442,6 +446,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<MethodInfo> localOperationsWithBody = new ArrayList<MethodInfo>(operationsWithBody);
+        final List<MethodInfo> localOperationsWithNoBody = new ArrayList<MethodInfo>(operationsWithNoBody);
         final List<MethodInfo> localOperationsWithCustomAnnotation = new ArrayList<MethodInfo>(operationsWithCustomAnnotation);
         final List<MethodInfo> localOperationsWithHandlerAnnotation = new ArrayList<MethodInfo>(operationsWithHandlerAnnotation);
 
@@ -450,11 +455,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) {
@@ -468,6 +475,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/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java?rev=1311582&r1=1311581&r2=1311582&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java Tue Apr 10 06:06:04 2012
@@ -1045,6 +1045,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);