camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r749299 - in /camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/builder/ main/scala/org/apache/camel/scala/dsl/languages/ test/scala/org/apache/camel/scala/dsl/
Date Mon, 02 Mar 2009 13:24:56 GMT
Author: gertv
Date: Mon Mar  2 13:24:55 2009
New Revision: 749299

URL: http://svn.apache.org/viewvc?rev=749299&view=rev
Log:
CAMEL-463: Adding support for the other languages in a single trait

Added:
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/Languages.scala
Removed:
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/El.scala
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/JXPath.scala
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/XPath.scala
Modified:
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RecipientListRouteTest.scala
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala

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=749299&r1=749298&r2=749299&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 Mar  2 13:24:55 2009
@@ -25,10 +25,12 @@
 
 import org.apache.camel.scala.dsl._
 
+import org.apache.camel.scala.dsl.languages.Languages
+
 /**
  * Scala RouteBuilder implementation
  */
-class RouteBuilder extends Preamble with DSL with Routes {
+class RouteBuilder extends Preamble with DSL with Routes with Languages {
 
   val builder = new org.apache.camel.builder.RouteBuilder {
     override def configure() =  {}

Added: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/Languages.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/Languages.scala?rev=749299&view=auto
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/Languages.scala
(added)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/languages/Languages.scala
Mon Mar  2 13:24:55 2009
@@ -0,0 +1,68 @@
+/**
+ * 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
+
+/**
+ * Trait to support the different expression languages available in Camel 
+ */
+trait Languages {
+  
+  /**
+   * Implicitly make a method for every language available on the Camel Exchange
+   */
+  implicit def addLanguageMethodsToExchange(exchange: Exchange) = new {
+    def el(expression: String) =     Languages.this.el(expression)(exchange)
+    def groovy(expression: String) = Languages.this.groovy(expression)(exchange)
+    def jxpath(expression: String) = Languages.this.jxpath(expression)(exchange)
+    def mvel(expression: String) =   Languages.this.mvel(expression)(exchange)
+    def ognl(expression: String) =   Languages.this.ognl(expression)(exchange) 
+    def php(expression: String) =    Languages.this.php(expression)(exchange)
+    def python(expression: String) = Languages.this.python(expression)(exchange)
+    def ruby(expression: String) =   Languages.this.ruby(expression)(exchange)
+    def simple(expression: String) = Languages.this.simple(expression)(exchange)
+    def sql(expression: String) =    Languages.this.sql(expression)(exchange)
+    def xpath(expression: String) =  Languages.this.xpath(expression)(exchange)
+    def xquery(expression: String) = Languages.this.xquery(expression)(exchange)
+  }
+  
+  // a set of methods to allow direct use of the language as an expression
+  def el(expression: String)(exchange: Exchange) =         Languages.evaluate(expression)(exchange)("el")
+  def groovy(expression: String)(exchange: Exchange) =     Languages.evaluate(expression)(exchange)("groovy")
+  def javascript(expression: String)(exchange: Exchange) = Languages.evaluate(expression)(exchange)("javascript")
+  def jxpath(expression: String)(exchange: Exchange) =     Languages.evaluate(expression)(exchange)("jxpath")
+  def mvel(expression: String)(exchange: Exchange) =       Languages.evaluate(expression)(exchange)("mvel")
+  def ognl(expression: String)(exchange: Exchange) =       Languages.evaluate(expression)(exchange)("ognl")
+  def php(expression: String)(exchange: Exchange) =        Languages.evaluate(expression)(exchange)("php")
+  def python(expression: String)(exchange: Exchange) =     Languages.evaluate(expression)(exchange)("python")
+  def ruby(expression: String)(exchange: Exchange) =       Languages.evaluate(expression)(exchange)("ruby")
+  def simple(expression: String)(exchange: Exchange) =     Languages.evaluate(expression)(exchange)("simply")
+  def sql(expression: String)(exchange: Exchange) =        Languages.evaluate(expression)(exchange)("sql")
+  def xpath(expression: String)(exchange: Exchange) =      Languages.evaluate(expression)(exchange)("xpath")
+  def xquery(expression: String)(exchange: Exchange) =     Languages.evaluate(expression)(exchange)("xquery")
+  
+}
+
+/**
+ * Companion object with the static template method for language support 
+ */
+object Languages {
+
+  def evaluate(expression: String)(exchange: Exchange)(lang: String) : Any = { 
+    val language = exchange.getContext().resolveLanguage(lang)
+    language.createExpression(expression).evaluate(exchange)
+  }
+}

Modified: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RecipientListRouteTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RecipientListRouteTest.scala?rev=749299&r1=749298&r2=749299&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RecipientListRouteTest.scala
(original)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RecipientListRouteTest.scala
Mon Mar  2 13:24:55 2009
@@ -41,7 +41,7 @@
     "mock:d" assert()
   }
    
-  val builder = new RouteBuilder with languages.JXPath {
+  val builder = new RouteBuilder {
     //START SNIPPET: simple
     "direct:a" recipients(_.in(classOf[String]).substring(21))
     //END SNIPPET: simple

Modified: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala?rev=749299&r1=749298&r2=749299&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
(original)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetBodyTest.scala
Mon Mar  2 13:24:55 2009
@@ -45,7 +45,7 @@
     }    
   }
     
-  val builder = new RouteBuilder with languages.El {
+  val builder = new RouteBuilder {
      //START SNIPPET: simple
      "direct:a" setbody "pong" to "mock:a"
      "direct:c" setbody el("${in.body.name}") to "mock:c"

Modified: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala?rev=749299&r1=749298&r2=749299&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
(original)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SetHeaderTest.scala
Mon Mar  2 13:24:55 2009
@@ -45,7 +45,7 @@
     }    
   }
     
-  val builder = new RouteBuilder with languages.El {
+  val builder = new RouteBuilder {
      //START SNIPPET: simple
      "direct:a" setheader("response", "pong?") to "mock:a"
      "direct:c" setheader("genus",el("${in.body.genus}")) to "mock:c"

Modified: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala?rev=749299&r1=749298&r2=749299&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
(original)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/SplitterRouteBuilderTest.scala
Mon Mar  2 13:24:55 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.scala.dsl;
  
 import org.w3c.dom.Document
-import languages.XPath
 import scala.dsl.builder.RouteBuilder
 
 /**
@@ -41,7 +40,7 @@
 
   val builder =
     //START SNIPPET: xpath
-    new RouteBuilder with XPath {
+    new RouteBuilder {
     //END SNIPPET: xpath
        //START SNIPPET: simple
        "direct:a" as(classOf[Document]) splitter(xpath("/persons/person")) to "mock:a"



Mime
View raw message