Author: gertv
Date: Sun Oct 12 22:11:28 2008
New Revision: 703916

URL: http://svn.apache.org/viewvc?rev=703916&view=rev
Log:
CAMEL-463: Adding setbody to the DSL

Added:
    
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala
    
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
Modified:
    activemq/camel/trunk/components/camel-scala/pom.xml
    
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
    
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
    
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
    
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Person.scala

Modified: activemq/camel/trunk/components/camel-scala/pom.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/pom.xml?rev=703916&r1=703915&r2=703916&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/pom.xml (original)
+++ activemq/camel/trunk/components/camel-scala/pom.xml Sun Oct 12 22:11:28 2008
@@ -88,6 +88,12 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-juel</artifactId>
+      <type>jar</type>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-jxpath</artifactId>
       <type>jar</type>
       <scope>test</scope>

Modified: 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=703916&r1=703915&r2=703916&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
 (original)
+++ 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
 Sun Oct 12 22:11:28 2008
@@ -37,6 +37,7 @@
   def loadbalance : SLoadBalanceType
   def delay(delay: Period) : SDelayerType
   def resequence(expression: Exchange => Any) : SResequencerType
+  def setbody(expression: Exchange => Any) : DSL
   def aggregate(expression: Exchange => Any) : SAggregatorType
   def idempotentconsumer(expression: Exchange => Any): SIdempotentConsumerType
 

Modified: 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala?rev=703916&r1=703915&r2=703916&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
 (original)
+++ 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractType.scala
 Sun Oct 12 22:11:28 2008
@@ -90,6 +90,8 @@
   
   def resequence(expression: Exchange => Any) = new 
SResequencerType(target.resequencer(expression))
   
+  def setbody(expression: Exchange => Any) = new 
SProcessorType(target.setBody(expression).asInstanceOf[ProcessorType[P] forSome 
{type P}])
+  
   def aggregate(expression: Exchange => Any) = new 
SAggregatorType(target.aggregator(expression))
 
 }

Modified: 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=703916&r1=703915&r2=703916&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
 (original)
+++ 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
 Sun Oct 12 22:11:28 2008
@@ -37,6 +37,7 @@
 
   implicit def stringToRoute(target: String) : SRouteType = new 
SRouteType(builder.from(target), this)  
   implicit def unwrap[W](wrapper: Wrapper[W]) = wrapper.unwrap
+  implicit def constantToExpression(value: Any) : (Exchange => Any) = 
(exchange: Exchange) => value 
 
   def print() = {
     println(builder)
@@ -72,6 +73,7 @@
   def loadbalance = stack.top.loadbalance
   def delay(delay: Period) = stack.top.delay(delay)
   def resequence(expression: Exchange => Any) = 
stack.top.resequence(expression)
+  def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
   def aggregate(expression: Exchange => Any) = stack.top.aggregate(expression)
 
 }

Added: 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala?rev=703916&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala
 (added)
+++ 
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala
 Sun Oct 12 22:11:28 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.camel.scala.dsl.languages;
+
+import org.apache.camel.builder.xml.XPathBuilder
+
+/**
+ * Trait to improve expression language support for Scala DSL
+ */
+trait El {
+  
+  implicit def exchangeToEl(exchange: Exchange) = new RichElExchange(exchange)
+  
+  def language(exchange: Exchange) = 
exchange.getContext().resolveLanguage("el")
+  def el(el: String)(exchange: Exchange) : Any = 
+    language(exchange).createExpression(el).evaluate(exchange)
+  
+  class RichElExchange(val exchange: Exchange) {
+    
+    def el(el: String) : Any = El.this.el(el)(exchange)
+    
+  }
+  
+}

Added: 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala?rev=703916&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
 (added)
+++ 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
 Sun Oct 12 22:11:28 2008
@@ -0,0 +1,69 @@
+/**
+ * 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.camel.scala.dsl;
+ 
+import scala.dsl.builder.RouteBuilder
+import org.apache.camel.scala.test.{Adult, Toddler}
+
+/**
+ * Test for setting the message body from the Scala DSL
+ */
+class SetBodyTest extends ScalaTestSupport {
+
+  def testSimpleSetBody() = doTestConstant("direct:a", "mock:a")
+  def testBlockSetBody() = doTestConstant("direct:b", "mock:b")
+  
+  def testSimpleExpression() = doTestExpression("direct:c", "mock:c")
+  def testBodyExpression() = doTestExpression("direct:d", "mock:d")
+  
+  
+  def doTestConstant(from: String, mock: String) = {
+    mock expect {_.received("pong")}
+    test {
+      from ! ("ping")
+    }    
+  }
+  
+  def doTestExpression(from: String, mock: String) = {
+    mock expect {_.received("Duchess", "Toulouse")}
+    test {
+      from ! (new Adult("Duchess"), new Toddler("Toulouse"))
+    }    
+  }
+    
+  val builder = new RouteBuilder with languages.El {
+     //START SNIPPET: simple
+     "direct:a" setbody "pong" to "mock:a"
+     "direct:c" setbody el("${in.body.name}") to "mock:c"
+     //END SNIPPET: simple
+     
+     //START SNIPPET: block
+     "direct:b" ==> {
+       setbody("pong")
+       to ("mock:b")
+     }
+     
+     "direct:d" ==> {
+       setbody(el("${in.body.name}"))
+       to ("mock:d")
+     }
+     //END SNIPPET: block
+     
+   }
+}
+
+

Modified: 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Person.scala
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Person.scala?rev=703916&r1=703915&r2=703916&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Person.scala
 (original)
+++ 
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/test/Person.scala
 Sun Oct 12 22:11:28 2008
@@ -16,15 +16,17 @@
  */
 package org.apache.camel.scala.test;
 
+import _root_.scala.reflect.BeanProperty
+
 /**
  * Just a simple Person test class
  */
 abstract class Person {
   def canVote : Boolean
 }
-case class Adult(name: String) extends Person {
+case class Adult(@BeanProperty name: String) extends Person {
   def canVote = true
 }
-case class Toddler(name: String) extends Person {
+case class Toddler(@BeanProperty name: String) extends Person {
   def canVote = false
 }


Reply via email to