camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r960448 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ test/java/org/apache/camel/builder/ test/java/org/apache/camel/processor/
Date Mon, 05 Jul 2010 05:19:33 GMT
Author: davsclaus
Date: Mon Jul  5 05:19:32 2010
New Revision: 960448

URL: http://svn.apache.org/viewvc?rev=960448&view=rev
Log:
CAMEL-2906: Introduced SimpleBuilder to make it easy to use simple language in Java DSL as
both Expression/Predicate.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java   (with
props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java 
 (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithSimpleExpressionTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?rev=960448&r1=960447&r2=960448&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java Mon
Jul  5 05:19:32 2010
@@ -132,8 +132,8 @@ public abstract class BuilderSupport {
     /**
      * Returns a simple expression value builder
      */
-    public ValueBuilder simple(String value) {
-        return Builder.simple(value);
+    public SimpleBuilder simple(String value) {
+        return SimpleBuilder.simple(value);
     }
     
     /**

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java?rev=960448&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java Mon Jul
 5 05:19:32 2010
@@ -0,0 +1,51 @@
+/**
+ * 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.builder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+
+/**
+ * Creates an {@link org.apache.camel.language.Simple} language builder.
+ * <p/>
+ * This builder is available in the Java DSL from the {@link RouteBuilder} which means that
using
+ * simple language for {@link Expression}s or {@link Predicate}s is very easy with the help
of this builder.
+ *
+ * @version $Revision$
+ */
+public class SimpleBuilder implements Predicate, Expression {
+
+    private final String text;
+
+    public SimpleBuilder(String text) {
+        this.text = text;
+    }
+
+    public static SimpleBuilder simple(String text) {
+        return new SimpleBuilder(text);
+    }
+
+    public boolean matches(Exchange exchange) {
+        return exchange.getContext().resolveLanguage("simple").createPredicate(text).matches(exchange);
+    }
+
+    public <T> T evaluate(Exchange exchange, Class<T> type) {
+        return exchange.getContext().resolveLanguage("simple").createExpression(text).evaluate(exchange,
type);
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java?rev=960448&r1=960447&r2=960448&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java Mon Jul
 5 05:19:32 2010
@@ -51,8 +51,7 @@ public class ValueBuilder implements Exp
 
     // Predicate builders
     // -------------------------------------------------------------------------
-    // this method will be removed , please use PredicateBuilder.toPredicate(Expression)

-    @Deprecated
+
     public Predicate matches(Expression expression) {
         return onNewPredicate(PredicateBuilder.toPredicate(expression));
     }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java?rev=960448&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java Mon
Jul  5 05:19:32 2010
@@ -0,0 +1,44 @@
+/**
+ * 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.builder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.TestSupport;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * @version $Revision$
+ */
+public class SimpleBuilderTest extends TestSupport {
+
+    protected Exchange exchange = new DefaultExchange(new DefaultCamelContext());
+
+    public void testPredicate() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        assertTrue(SimpleBuilder.simple("${body} == 'foo'").matches(exchange));
+        assertFalse(SimpleBuilder.simple("${body} == 'bar'").matches(exchange));
+    }
+
+    public void testExpression() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        assertEquals("foo", SimpleBuilder.simple("${body}").evaluate(exchange, String.class));
+        assertNull(SimpleBuilder.simple("${header.cheese}").evaluate(exchange, String.class));
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/SimpleBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithSimpleExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithSimpleExpressionTest.java?rev=960448&r1=960447&r2=960448&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithSimpleExpressionTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ChoiceWithSimpleExpressionTest.java
Mon Jul  5 05:19:32 2010
@@ -16,10 +16,7 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount;
 
 /**
  * @version $Revision$
@@ -30,8 +27,8 @@ public class ChoiceWithSimpleExpressionT
         return new RouteBuilder() {
             public void configure() {
                 from("direct:start").choice()
-                  .when(simple("${header.foo} == 'bar'").matches()).to("mock:x")
-                  .when(simple("${in.header.foo} == 'cheese'").matches()).to("mock:y")
+                  .when(simple("${header.foo} == 'bar'")).to("mock:x")
+                  .when(simple("${in.header.foo} == 'cheese'")).to("mock:y")
                   .otherwise().to("mock:z").end().to("mock:end");
             }
         };



Mime
View raw message