You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/10/03 20:07:37 UTC

svn commit: r1178481 - in /camel/branches/camel-2.8.x: ./ camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java camel-core/src/test/java/org/apache/camel/language/SimpleTest.java

Author: dkulp
Date: Mon Oct  3 18:07:36 2011
New Revision: 1178481

URL: http://svn.apache.org/viewvc?rev=1178481&view=rev
Log:
Merged revisions 1177213 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1177213 | davsclaus | 2011-09-29 04:29:48 -0400 (Thu, 29 Sep 2011) | 1 line
  
  CAMEL-4492: Bean component can access getClass in case user want to eg log the class type etc.
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1178481&r1=1178480&r2=1178481&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Mon Oct  3 18:07:36 2011
@@ -140,6 +140,7 @@ public class BeanInfo {
         return null;
     }
 
+    @SuppressWarnings("unchecked")
     public MethodInvocation createInvocation(Object pojo, Exchange exchange)
         throws AmbiguousMethodCallException, MethodNotFoundException {
         MethodInfo methodInfo = null;
@@ -153,25 +154,37 @@ public class BeanInfo {
                 name = ObjectHelper.before(methodName, "(");
             }
 
-            List<MethodInfo> methods = getOperations(name);
-            if (methods != null && methods.size() == 1) {
-                // only one method then choose it
-                methodInfo = methods.get(0);
-            } else if (methods != null) {
-                // there are more methods with that name so we cannot decide which to use
-
-                // but first lets try to choose a method and see if that comply with the name
-                // must use the method name which may have qualifiers
-                methodInfo = chooseMethod(pojo, exchange, methodName);
-
-                if (methodInfo == null || !name.equals(methodInfo.getMethod().getName())) {
-                    throw new AmbiguousMethodCallException(exchange, methods);
+            // special for getClass, as we want the user to be able to invoke this method
+            // for example to log the class type or the likes
+            if ("class".equals(name) || "getClass".equals(name)) {
+                try {
+                    Method method = pojo.getClass().getMethod("getClass");
+                    methodInfo = new MethodInfo(exchange.getContext(), pojo.getClass(), method, Collections.EMPTY_LIST, Collections.EMPTY_LIST, false, false);
+                } catch (NoSuchMethodException e) {
+                    throw new MethodNotFoundException(exchange, pojo, "getClass");
                 }
             } else {
-                // a specific method was given to invoke but not found
-                throw new MethodNotFoundException(exchange, pojo, methodName);
+                List<MethodInfo> methods = getOperations(name);
+                if (methods != null && methods.size() == 1) {
+                    // only one method then choose it
+                    methodInfo = methods.get(0);
+                } else if (methods != null) {
+                    // there are more methods with that name so we cannot decide which to use
+
+                    // but first lets try to choose a method and see if that comply with the name
+                    // must use the method name which may have qualifiers
+                    methodInfo = chooseMethod(pojo, exchange, methodName);
+
+                    if (methodInfo == null || !name.equals(methodInfo.getMethod().getName())) {
+                        throw new AmbiguousMethodCallException(exchange, methods);
+                    }
+                } else {
+                    // a specific method was given to invoke but not found
+                    throw new MethodNotFoundException(exchange, pojo, methodName);
+                }
             }
         }
+
         if (methodInfo == null) {
             // no name or type
             methodInfo = chooseMethod(pojo, exchange, null);
@@ -203,7 +216,7 @@ public class BeanInfo {
         Method[] methods = clazz.getDeclaredMethods();
         for (Method method : methods) {
             boolean valid = isValidMethod(clazz, method);
-            LOG.trace("Method:  {} is valid: {}", method, valid);
+            LOG.trace("Method: {} is valid: {}", method, valid);
             if (valid) {
                 introspect(clazz, method);
             }

Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java?rev=1178481&r1=1178480&r2=1178481&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java Mon Oct  3 18:07:36 2011
@@ -973,6 +973,15 @@ public class SimpleTest extends Language
         assertExpression("${body.dangerous}", "false");
     }
 
+    public void testClassSimpleName() throws Exception {
+        Animal tiger = new Animal("Tony the Tiger", 13);
+        exchange.getIn().setBody(tiger);
+
+        assertExpression("${body.getClass().getSimpleName()}", "Animal");
+        assertExpression("${body.getClass.getSimpleName}", "Animal");
+        assertExpression("${body.class.simpleName}", "Animal");
+    }
+
     protected String getLanguageName() {
         return "simple";
     }