Author: hadrian
Date: Tue Apr 22 07:56:21 2008
New Revision: 650538
URL: http://svn.apache.org/viewvc?rev=650538&view=rev
Log:
CAMEL-463. Patch applied with thanks!
Added:
activemq/camel/trunk/components/camel-scala/src/main/resources/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/ScalaTypeConverter.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaExpression.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RouteBuilder.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/PipelineAndMulticastTest.scala
Added:
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.scala
\ No newline at end of file
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/ScalaTypeConverter.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/ScalaTypeConverter.scala?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/ScalaTypeConverter.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/converters/ScalaTypeConverter.scala
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,34 @@
+/**
+ * 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.converters;
+
+import _root_.scala.xml.Elem
+
+import org.apache.camel.Converter
+import org.apache.camel.converter.jaxp.XmlConverter
+
+/**
+ * Converter implementation for supporting some common Scala types within
Apache Camel
+ */
[EMAIL PROTECTED] object ScalaTypeConverter {
+
+ val converter = new XmlConverter()
+
+ @Converter
+ def convertToDocument(xml: Elem) = converter.toDOMDocument(xml.toString)
+
+}
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichProcessor.scala
Tue Apr 22 07:56:21 2008
@@ -18,8 +18,14 @@
import org.apache.camel.model.ProcessorType
-class RichProcessor(processor : ProcessorType[T] forSome {type T}) {
+class RichProcessor(processor : ProcessorType[T] forSome {type T}, builder:
RouteBuilder) {
def -->(uri: String) = processor.to(uri)
+
+ def splitter(expression: Exchange => Any) = processor.splitter(new
ScalaExpression(expression))
+
+ def as(target: Class[T] forSome {type T}) =
processor.convertBodyTo(target).asInstanceOf[ProcessorType[T] forSome {type T}]
+
+ def apply(block: => Unit) = builder.build(processor, block)
}
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RichUriString.scala
Tue Apr 22 07:56:21 2008
@@ -17,6 +17,7 @@
package org.apache.camel.scala.dsl;
import org.apache.camel.model.FilterType
+import org.apache.camel.model.SplitterType
import org.apache.camel.model.ProcessorType
class RichUriString(uri:String, builder:RouteBuilder) {
@@ -41,6 +42,11 @@
def when(filter: Exchange => Boolean) : FilterType =
builder.from(uri).filter(new WhenPredicate(filter))
+ def splitter(expression: Exchange => Any) : SplitterType = {
+ println("configuring splitter with " + expression)
+ builder.from(uri).splitter(new ScalaExpression(expression))
+ }
-
+ def as(target: Class[T] forSome {type T}) =
builder.from(uri).convertBodyTo(target)
+
}
Modified:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RouteBuilder.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RouteBuilder.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RouteBuilder.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/RouteBuilder.scala
Tue Apr 22 07:56:21 2008
@@ -34,7 +34,7 @@
implicit def stringToUri(uri:String) : RichUriString = new
RichUriString(uri, this)
implicit def choiceWrapper(choice: ChoiceType) = new RichChoiceType(choice,
this);
- implicit def processorWrapper(processor: ProcessorType[T] forSome {type T})
= new RichProcessor(processor)
+ implicit def processorWrapper(processor: ProcessorType[T] forSome {type T})
= new RichProcessor(processor, this)
def print() = {
println(builder)
@@ -79,6 +79,10 @@
case _ => throw new Exception("otherwise is only supported in a choice
block or after a when statement")
}
}
+
+ def splitter(expression: Exchange => Any) = stack.top.splitter(new
ScalaExpression(expression))
+
+ def as[T](toType: Class[T]) = stack.top.convertBodyTo(toType)
}
object RouteBuilder {
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaExpression.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaExpression.scala?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaExpression.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaExpression.scala
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+/**
+ * Scala implementation for an Apache Camel Expression
+ */
+class ScalaExpression(val expression: Exchange => Any) extends
Expression[Exchange] {
+
+ def evaluate(exchange: Exchange) = expression(exchange).asInstanceOf[Object]
+
+}
Added:
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,39 @@
+/**
+ * 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 XPath support for Scala DSL
+ */
+trait XPath {
+
+ def xpath(path: String) = XPathBuilder.xpath(path)
+
+ implicit def exchangeToXpath(exchange: Exchange) = new
RichXPathExchange(exchange)
+
+ class RichXPathExchange(exchange: Exchange) {
+
+ def xpath(xpath: String) : Any = {
+ val builder = new XPathBuilder[Exchange](xpath)
+ builder.evaluate(exchange)
+ }
+
+ }
+
+}
Modified:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/RichMockEndpoint.scala
Tue Apr 22 07:56:21 2008
@@ -26,5 +26,8 @@
endpoint.expectedBodiesReceived(list)
}
+ def count : Int = endpoint.getExpectedCount
+
+ def count_=(count: Int) = endpoint.expectedMessageCount(count)
}
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTypeConverterTest.scala
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+import junit.framework.TestCase
+import junit.framework.Assert._
+
+import org.apache.camel.impl.ReflectionInjector
+import org.apache.camel.impl.converter.DefaultTypeConverter
+
+import org.w3c.dom.Document
+
+/**
+ * Test case for ScalaTypeConverter
+ */
+class ScalaTypeConverterTest extends TestCase {
+
+ val converter = new DefaultTypeConverter(new ReflectionInjector())
+
+ def testDocumentConverter = {
+ val result = converter.convertTo(classOf[Document], <persons/>)
+ assertNotNull(result)
+ assertNotNull(result.getElementsByTagName("persons"))
+ }
+
+}
Modified:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala
Tue Apr 22 07:56:21 2008
@@ -19,27 +19,34 @@
class ContentBasedRouterTest extends ScalaTestSupport {
def testSimpleContentBasedRouter = {
- "mock:a" expect {_.expectedMessageCount(3)}
- "mock:b" expect {_.received("<hello/>")}
- "mock:c" expect {_.received("<hallo/>")}
- "mock:d" expect {_.received("<hellos/>")}
+ "mock:polyglot" expect {_.expectedMessageCount(3)}
+ "mock:english" expect {_.received("<hello/>")}
+ "mock:dutch" expect {_.received("<hallo/>")}
+ "mock:german" expect {_.received("<hallo/>")}
+ "mock:french" expect {_.received("<hellos/>")}
"direct:a" ! ("<hello/>", "<hallo/>", "<hellos/>")
- "mock:a" assert()
- "mock:b" assert()
- "mock:c" assert()
- "mock:d" assert()
+ "mock:polyglot" assert()
+ "mock:english" assert()
+ "mock:dutch" assert()
+ "mock:german" assert()
+ "mock:french" assert()
}
override protected def createRouteBuilder() =
new RouteBuilder {
+ //START SNIPPET: cbr
"direct:a" ==> {
- to ("mock:a")
+ to ("mock:polyglot")
choice {
- when (_.in == "<hello/>") to ("mock:b")
- when (_.in == "<hallo/>") to ("mock:c")
- otherwise to ("mock:d")
+ when (_.in == "<hello/>") to ("mock:english")
+ when (_.in == "<hallo/>") {
+ to ("mock:dutch")
+ to ("mock:german")
+ }
+ otherwise to ("mock:french")
}
}
+ //END SNIPPET: cbr
}.print
}
Modified:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/PipelineAndMulticastTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/PipelineAndMulticastTest.scala?rev=650538&r1=650537&r2=650538&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/PipelineAndMulticastTest.scala
(original)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/PipelineAndMulticastTest.scala
Tue Apr 22 07:56:21 2008
@@ -38,12 +38,12 @@
override protected def createRouteBuilder() =
new RouteBuilder {
- //START SNIPPET: simple
+ // START SNIPPET: simple
"direct:a" --> ("mock:a", "mock:b") --> "mock:c"
"direct:d" to ("mock:d", "mock:e") to "mock:f"
- //END SNIPPET: simple
+ // END SNIPPET: simple
- //START SNIPPET: block
+ // START SNIPPET: block
"direct:g" ==> {
--> ("mock:g", "mock:h")
--> ("mock:i")
@@ -52,7 +52,7 @@
to ("mock:j", "mock:k")
to ("mock:l")
}
- //START SNIPPET: block
+ // END SNIPPET: block
}.print
}
Added:
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala?rev=650538&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
(added)
+++
activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
Tue Apr 22 07:56:21 2008
@@ -0,0 +1,60 @@
+/**
+ * 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 languages.XPath
+
+/**
+ * Test case for Splitter
+ */
+class SplitterRouteBuilderTest extends ScalaTestSupport {
+
+ def testSimpleSplitter = {
+ "mock:a" expect { _.count = 3}
+ "direct:a" ! <persons><person id="1"/><person id="2"/><person
id="3"/></persons>
+ "mock:a" assert()
+ }
+
+ def testBlockSplitter = {
+ "mock:b" expect { _.count = 3}
+ "mock:c" expect { _.count = 3}
+ "direct:b" ! <persons><person id="1"/><person id="2"/><person
id="3"/></persons>
+ "mock:b" assert()
+ "mock:c" assert()
+ }
+
+ override protected def createRouteBuilder() =
+ //START SNIPPET: xpath
+ new RouteBuilder with XPath {
+ //END SNIPPET: xpath
+ //START SNIPPET: simple
+ "direct:a" as(classOf[Document]) splitter(xpath("/persons/person")) to
"mock:a"
+ //END SNIPPET: simple
+
+ //START SNIPPET: block
+ "direct:b" ==> {
+ as(classOf[Document])
+ splitter(_.xpath("/persons/person")) {
+ to("mock:b")
+ to("mock:c")
+ }
+ }
+ //END SNIPPET: block
+ }.print
+
+}