You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ge...@apache.org on 2008/11/20 23:12:30 UTC

svn commit: r719399 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/ main/scala/org/apache/camel/scala/dsl/builder/ test/scala/org/apache/camel/scala/dsl/

Author: gertv
Date: Thu Nov 20 14:12:29 2008
New Revision: 719399

URL: http://svn.apache.org/viewvc?rev=719399&view=rev
Log:
CAMEL-463: A first stab at adding support for DataFormats

Added:
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DataFormatTest.scala
Modified:
    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

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=719399&r1=719398&r2=719399&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 Thu Nov 20 14:12:29 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.scala.dsl 
 
+import org.apache.camel.model.dataformat.DataFormatType
+
 /**
  * Defines the 'keywords' in our Scala DSL
  */
@@ -31,6 +33,7 @@
   def recipients(expression: Exchange => Any) : DSL
   def splitter(expression: Exchange => Any) : SSplitterType
   def otherwise : DSL
+  def marshal(format : DataFormatType) : DSL
   def multicast : SMulticastType
   def process(function: Exchange => Unit) : DSL
   def throttle(frequency: Frequency) : SThrottlerType
@@ -39,6 +42,7 @@
   def resequence(expression: Exchange => Any) : SResequencerType
   def setbody(expression: Exchange => Any) : DSL
   def setheader(header: String, expression: Exchange => Any) : DSL
+  def unmarshal(format: DataFormatType) : 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=719399&r1=719398&r2=719399&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 Thu Nov 20 14:12:29 2008
@@ -21,6 +21,8 @@
 import org.apache.camel.model.ChoiceType
 import org.apache.camel.model.IdempotentConsumerType
 
+import org.apache.camel.model.dataformat.DataFormatType
+
 import org.apache.camel.scala.dsl.builder.RouteBuilder
 
 abstract class SAbstractType extends DSL {
@@ -74,6 +76,11 @@
     throw new Exception("otherwise is only supported in a choice block or after a when statement")
   
   def idempotentconsumer(expression: Exchange => Any) = new SIdempotentConsumerType(target.idempotentConsumer(expression, null))
+ 
+  def marshal(format: DataFormatType) = {
+    target.marshal(format)
+    this
+  }
   
   def multicast = new SMulticastType(target.multicast)
   
@@ -81,6 +88,7 @@
     target.process(new ScalaProcessor(function))
     this
   }
+ 
   
   def throttle(frequency: Frequency) = new SThrottlerType(target.throttler(frequency.count).timePeriodMillis(frequency.period.milliseconds))
   
@@ -94,6 +102,11 @@
   
   def setheader(name: String, expression: Exchange => Any) = new SProcessorType(target.setHeader(name, expression).asInstanceOf[ProcessorType[P] forSome {type P}])
   
+  def unmarshal(format: DataFormatType) = {
+    target.unmarshal(format)
+    this
+  }
+  
   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=719399&r1=719398&r2=719399&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 Thu Nov 20 14:12:29 2008
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.scala.dsl.builder;
 
-import org.apache.camel.model.ProcessorType
-import org.apache.camel.model.ChoiceType
+import org.apache.camel.model.{ChoiceType, ProcessorType}
+import org.apache.camel.model.dataformat.DataFormatType
 import org.apache.camel.Routes
 
 import collection.mutable.Stack
@@ -68,6 +68,7 @@
   def idempotentconsumer(expression: Exchange => Any) = stack.top.idempotentconsumer(expression)
   def splitter(expression: Exchange => Any) = stack.top.splitter(expression)
   def otherwise = stack.top.otherwise
+  def marshal(format: DataFormatType) = stack.top.marshal(format)
   def multicast = stack.top.multicast
   def process(function: Exchange => Unit) = stack.top.process(function)
   def throttle(frequency: Frequency) = stack.top.throttle(frequency)
@@ -76,6 +77,7 @@
   def resequence(expression: Exchange => Any) = stack.top.resequence(expression)
   def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
   def setheader(name: String, expression: Exchange => Any) = stack.top.setheader(name, expression)
+  def unmarshal(format: DataFormatType) = stack.top.unmarshal(format)
   def aggregate(expression: Exchange => Any) = stack.top.aggregate(expression)
 
   // implementing the Routes interface to allow RouteBuilder to be discovered by Spring
@@ -83,4 +85,5 @@
   def getContext = builder.getContext()
   def setContext(context: CamelContext) = builder.setContext(context)
   
+  val serialization = new org.apache.camel.model.dataformat.SerializationDataFormat
 }

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DataFormatTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DataFormatTest.scala?rev=719399&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DataFormatTest.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/DataFormatTest.scala Thu Nov 20 14:12:29 2008
@@ -0,0 +1,48 @@
+/**
+ * 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 org.w3c.dom.Document
+import scala.dsl.builder.RouteBuilder
+import scala.test.Adult
+
+/**
+ * Test case for working with data formats
+ */
+class DataFormatTest extends ScalaTestSupport {
+  
+  def testSimpleTrottler = {
+    val person = new Adult("Captain Nemo")
+    "mock:a" expect { _.received(person) } 
+	test {
+	  "direct:a" ! person
+	}
+  }
+    
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: dataformat
+       "direct:a" marshal(serialization) to "direct:serial"
+       
+       "direct:serial" ==> {
+         unmarshal(serialization)
+         to ("mock:a") 
+       }
+       //END SNIPPET: dataformat
+    }
+
+}