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 2010/10/11 13:14:58 UTC
svn commit: r1021306 - in /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: Mon Oct 11 11:14:57 2010
New Revision: 1021306
URL: http://svn.apache.org/viewvc?rev=1021306&view=rev
Log:
CAMEL-463: Adding support for sort() DSL method (incl. sortBody())
Added:
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/Functions.scala
camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SSortTest.scala
Modified:
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
Modified: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala?rev=1021306&r1=1021305&r2=1021306&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala (original)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/DSL.scala Mon Oct 11 11:14:57 2010
@@ -19,7 +19,8 @@ package scala
package dsl
import org.apache.camel.model.DataFormatDefinition
-import reflect.Manifest;
+import reflect.Manifest
+import java.util.Comparator;
import org.apache.camel.processor.aggregate.AggregationStrategy
import org.apache.camel.spi.Policy
@@ -75,6 +76,7 @@ trait DSL {
def setfaultbody(expression: Exchange => Any) : DSL
def setheader(header: String, expression: Exchange => Any) : DSL
+ def sort[T](expression: Exchange => Any, comparator: Comparator[T] = null) : DSL
def split(expression: Exchange => Any) : SSplitDefinition
def stop : DSL
Added: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/Functions.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/Functions.scala?rev=1021306&view=auto
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/Functions.scala (added)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/Functions.scala Mon Oct 11 11:14:57 2010
@@ -0,0 +1,33 @@
+/**
+ * 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.apache.camel.Exchange
+
+/**
+ * A set of convenience functions for use in RouteBuilders and other Scala code interacting with Camel
+ */
+trait Functions {
+
+ /**
+ * Convenience function for extracting the 'in' message body from a Camel org.apache.camel.Exchange
+ *
+ * Can also be used as a partially applied function where the DSL requires Exchange => Any
+ */
+ def body(exchange: Exchange) = exchange.getIn.getBody
+
+}
\ No newline at end of file
Modified: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala?rev=1021306&r1=1021305&r2=1021306&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala (original)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SAbstractDefinition.scala Mon Oct 11 11:14:57 2010
@@ -31,6 +31,7 @@ import org.apache.camel.processor.aggreg
import org.apache.camel.scala.dsl.builder.RouteBuilder
import reflect.Manifest
import java.lang.String
+import java.util.Comparator
abstract class SAbstractDefinition[P <: ProcessorDefinition[_]] extends DSL with Wrapper[P] with Block {
@@ -135,7 +136,9 @@ abstract class SAbstractDefinition[P <:
def routingSlip(header: String) = wrap(target.routingSlip(header))
def routingSlip(header: String, separator: String) = wrap(target.routingSlip(header, separator))
def routingSlip(expression: Exchange => Any) = wrap(target.routingSlip(expression))
-
+
+ def sort[T](expression: (Exchange) => Any, comparator: Comparator[T] = null) = wrap(target.sort(expression, comparator))
+
def dynamicRouter(expression: Exchange => Any) = wrap(target.dynamicRouter(expression))
def setbody(expression: Exchange => Any) = wrap(target.setBody(expression))
Modified: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=1021306&r1=1021305&r2=1021306&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala (original)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala Mon Oct 11 11:14:57 2010
@@ -32,11 +32,12 @@ import org.apache.camel.scala.dsl._
import org.apache.camel.scala.dsl.languages.Languages
import java.lang.String
+import java.util.Comparator
/**
* Scala RouteBuilder implementation
*/
-class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages {
+class RouteBuilder extends Preamble with DSL with RoutesBuilder with Languages with Functions {
val builder = new org.apache.camel.builder.RouteBuilder {
override def configure() = {
@@ -130,6 +131,7 @@ class RouteBuilder extends Preamble with
def setbody(expression : Exchange => Any) = stack.top.setbody(expression)
def setfaultbody(expression: Exchange => Any) = stack.top.setfaultbody(expression)
def setheader(name: String, expression: Exchange => Any) = stack.top.setheader(name, expression)
+ def sort[T](expression: (Exchange) => Any, comparator: Comparator[T] = null) = stack.top.sort(expression, comparator)
def stop = stack.top.stop
def threads = stack.top.threads
def throwException(exception: Exception) = stack.top.throwException(exception)
Added: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SSortTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SSortTest.scala?rev=1021306&view=auto
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SSortTest.scala (added)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SSortTest.scala Mon Oct 11 11:14:57 2010
@@ -0,0 +1,47 @@
+/**
+ * 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 builder.{RouteBuilder, RouteBuilderSupport}
+import org.apache.camel.processor.SortExpressionTest.MyReverseComparator
+import org.apache.camel.processor.{SortBodyTest, SortExpressionTest}
+
+/**
+ * Scala DSL equivalent for the SortExpressionTest, using simple one-line Scala DSL syntax
+ */
+class SSortExpressionTest extends SortExpressionTest with RouteBuilderSupport {
+
+ override def createRouteBuilder = new RouteBuilder {
+ "direct:start" sort(_.in[String].split(",")) to("mock:result")
+ "direct:reverse" sort(_.in[String].split(","), new MyReverseComparator()) to("mock:result")
+ }
+
+}
+
+/**
+ * Scala DSL equivalent for the SortBodyTest, using the Scala DSL block syntax
+ */
+class SSortBodyTest extends SortBodyTest with RouteBuilderSupport {
+
+ override def createRouteBuilder = new RouteBuilder {
+ "direct:start" ==> {
+ sort(body)
+ to("mock:result")
+ }
+ }
+
+}
\ No newline at end of file