You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/05/15 17:35:48 UTC

svn commit: r775194 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/language/ camel-core/src/test/java/org/apache/camel/processor/

Author: ningjiang
Date: Fri May 15 15:35:47 2009
New Revision: 775194

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

........
  r775155 | ningjiang | 2009-05-15 22:32:44 +0800 (Fri, 15 May 2009) | 1 line
  
  CAMEL-1618 Also updated the method DSL in the ExpressionClause
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionTest.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May 15 15:35:47 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,775123
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,775123,775155

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

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?rev=775194&r1=775193&r2=775194&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java Fri May 15 15:35:47 2009
@@ -147,7 +147,18 @@
      * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a>
      * value builder
      *
-     * @param beanType  the bean's class
+     * @param beanType the Class of the bean which we want to invoke
+     * @return the builder
+     */
+    public ValueBuilder bean(Class<?> beanType) {
+        return Builder.bean(beanType, null);
+    }
+    
+    /**
+     * Returns a <a href="http://camel.apache.org/bean-language.html">bean expression</a>
+     * value builder
+     *
+     * @param beanType the Class of the bean which we want to invoke
      * @param methodName  the method name that will be invoked
      * @return the builder
      */

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java?rev=775194&r1=775193&r2=775194&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java Fri May 15 15:35:47 2009
@@ -172,6 +172,21 @@
         setExpressionType(expression);
         return result;
     }
+    
+    /**
+     * Evaluates an expression using the <a
+     * href="http://camel.apache.org/bean-language.html>bean language</a>
+     * which basically means the bean is invoked to determine the expression
+     * value.
+     * 
+     * @param beanType the Class of the bean which we want to invoke
+     * @return the builder to continue processing the DSL
+     */
+    public T method(Class beanType) {
+        MethodCallExpression expression = new MethodCallExpression(beanType);
+        setExpressionType(expression);
+        return result;
+    }
 
     /**
      * Evaluates an expression using the
@@ -187,6 +202,22 @@
         setExpressionType(expression);
         return result;
     }
+    
+    /**
+     * Evaluates an expression using the <a
+     * href="http://camel.apache.org/bean-language.html>bean language</a>
+     * which basically means the bean is invoked to determine the expression
+     * value.
+     * 
+     * @param beanType the Class of the bean which we want to invoke
+     * @param method the name of the method to invoke on the bean
+     * @return the builder to continue processing the DSL
+     */
+    public T method(Class beanType, String method) {
+        MethodCallExpression expression = new MethodCallExpression(beanType, method);
+        setExpressionType(expression);
+        return result;
+    }
 
     /**
      * Evaluates a <a href="http://activemq.apache.org/camel/beanshell.html">BeanShell expression</a>

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java?rev=775194&r1=775193&r2=775194&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/model/language/MethodCallExpression.java Fri May 15 15:35:47 2009
@@ -20,12 +20,14 @@
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
 import org.apache.camel.language.bean.BeanExpression;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * For expressions and predicates using the
@@ -40,6 +42,10 @@
     private String bean;
     @XmlAttribute(required = false)
     private String method;
+    @XmlTransient
+    // we don't need to support the beanType class in Spring
+    private Class beanType;
+    
 
     public MethodCallExpression() {
     }
@@ -52,6 +58,17 @@
         super(beanName);
         this.method = method;
     }
+    
+    public MethodCallExpression(Class type) {
+        super(type.toString());
+        this.beanType = type;        
+    }
+    
+    public MethodCallExpression(Class type, String method) {
+        super(type.toString());
+        this.beanType = type;
+        this.method = method;
+    }
 
     public String getLanguage() {
         return "bean";
@@ -65,14 +82,24 @@
         this.method = method;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public Expression createExpression(RouteContext routeContext) {
-        return new BeanExpression(beanName(), getMethod());
+        if (beanType != null) {            
+            return new BeanExpression(ObjectHelper.newInstance(beanType), getMethod());
+        } else {
+            return new BeanExpression(beanName(), getMethod());   
+        }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
-    public Predicate<Exchange> createPredicate(RouteContext routeContext) {
-        return new BeanExpression<Exchange>(beanName(), getMethod());
+    public Predicate createPredicate(RouteContext routeContext) {
+        if (beanType != null) {
+            return new BeanExpression(ObjectHelper.newInstance(beanType), getMethod());
+        } else {
+            return new BeanExpression(beanName(), getMethod());
+        }
     }
 
     protected String beanName() {

Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionTest.java?rev=775194&r1=775193&r2=775194&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionTest.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/ChoiceWhenBeanExpressionTest.java Fri May 15 15:35:47 2009
@@ -25,20 +25,34 @@
     private MockEndpoint gradeA;
     private MockEndpoint otherGrade;
     
-    public void testGradeA() throws Exception {       
+    protected void verifyGradeA(String endpointUri) throws Exception {       
+        gradeA.reset();
+        otherGrade.reset();
         gradeA.expectedMessageCount(1);
         otherGrade.expectedMessageCount(0);
-        template.sendBody("direct:start", new Student(95));
+        template.sendBody(endpointUri, new Student(95));
         assertMockEndpointsSatisfied();
     }
     
-    public void testOtherGrade() throws Exception {       
+    public void verifyOtherGrade(String endpointUri) throws Exception {
+        gradeA.reset();
+        otherGrade.reset();
         gradeA.expectedMessageCount(0);
         otherGrade.expectedMessageCount(1);
-        template.sendBody("direct:start", new Student(60));
+        template.sendBody(endpointUri, new Student(60));
         assertMockEndpointsSatisfied();
     }
     
+    public void testBeanExpression() throws Exception {
+        verifyGradeA("direct:expression");
+        verifyOtherGrade("direct:expression");
+    }
+    
+    public void testMethod() throws Exception {
+        verifyGradeA("direct:method");
+        verifyOtherGrade("direct:method");
+    }
+    
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -50,11 +64,17 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {                
-                from("direct:start")
+                from("direct:expression")
                     .choice()
                         .when().expression(bean(MyBean.class, "isGradeA")).to("mock:gradeA")
                         .otherwise().to("mock:otherGrade")
                     .end();
+                
+                from("direct:method")
+                    .choice()
+                        .when().method(MyBean.class).to("mock:gradeA")
+                        .otherwise().to("mock:otherGrade")
+                    .end();
             }
         };
     }