Author: gertv
Date: Mon Jul 28 14:01:53 2008
New Revision: 680490
URL: http://svn.apache.org/viewvc?rev=680490&view=rev
Log:
CAMEL-463: Adding support for beans in simple Scala DSL routes
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SimpleBeanTest.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=680490&r1=680489&r2=680490&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
Mon Jul 28 14:01:53 2008
@@ -21,6 +21,7 @@
*/
trait DSL {
+ def bean(bean: Any) : DSL
def choice : SChoiceType
def -->(uris: String*) : DSL
def to(uris: String*) : DSL
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=680490&r1=680489&r2=680490&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
Mon Jul 28 14:01:53 2008
@@ -59,6 +59,12 @@
this
}
+ def bean(bean: Any) = bean match {
+ case cls: Class[Any] => new
SProcessorType(target.bean(cls).asInstanceOf[ProcessorType[P] forSome {type P}])
+ case ref: String => new
SProcessorType(target.beanRef(ref).asInstanceOf[ProcessorType[P] forSome {type
P}])
+ case obj: Any => new
SProcessorType(target.bean(obj).asInstanceOf[ProcessorType[P] forSome {type P}])
+ }
+
def choice = new SChoiceType(target.choice)
def otherwise : SChoiceType =
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=680490&r1=680489&r2=680490&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
Mon Jul 28 14:01:53 2008
@@ -50,6 +50,7 @@
def from(uri: String) = new SRouteType(builder.from(uri), this)
+ def bean(bean: Any) = stack.top.bean(bean)
def choice = stack.top.choice
def -->(uris: String*) = stack.top.to(uris: _*)
def to(uris: String*) = stack.top.to(uris: _*)
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SimpleBeanTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SimpleBeanTest.scala?rev=680490&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SimpleBeanTest.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SimpleBeanTest.scala
Mon Jul 28 14:01:53 2008
@@ -0,0 +1,80 @@
+/**
+ * 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
+
+/**
+ * Test for bean support in simple Scala DSL expressions
+ */
+class SimpleBeanTest extends ScalaTestSupport {
+
+ def testSimpleObject() = {
+ "mock:a" expect {_.received("Lucky Luke rides Jolly Jumper")}
+ test {
+ "direct:a" ! ("Lucky Luke")
+ }
+ }
+
+ def testSimpleClass() = {
+ "mock:b" expect {_.received("Batman drives the batmobile")}
+ test {
+ "direct:b" ! ("Batman")
+ }
+ }
+
+ def testSimpleRef() = {
+ "mock:c" expect {_.received("Aladin flies a carpet")}
+ test {
+ "direct:c" ! ("Aladin")
+ }
+ }
+
+ val builder = new RouteBuilder {
+ //START SNIPPET: object
+ "direct:a" bean(new CartoonService()) to("mock:a")
+ //END SNIPPET: object
+
+ //START SNIPPET: class
+ "direct:b" bean(classOf[CartoonService]) to("mock:b")
+ //END SNIPPET: class
+
+ //START SNIPPET: ref
+ "direct:c" bean("CartoonService") to("mock:c")
+ //END SNIPPET: ref
+ }
+
+ override def createRegistry() = {
+ val registry = super.createRegistry()
+ registry.bind("CartoonService", new CartoonService())
+ registry
+ }
+}
+
+/**
+ * A simple CartoonService
+ */
+class CartoonService {
+
+ def determineAppropriateTransport(person: String) = person match {
+ case "Lucky Luke" => person + " rides Jolly Jumper"
+ case "Batman" => person + " drives the batmobile"
+ case "Aladin" => person + " flies a carpet"
+ }
+}
+
+