camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r663018 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: builder/ impl/ util/
Date Wed, 04 Jun 2008 07:36:45 GMT
Author: ningjiang
Date: Wed Jun  4 00:36:45 2008
New Revision: 663018

URL: http://svn.apache.org/viewvc?rev=663018&view=rev
Log:
CAMEL-573 applied patch with thanks to Christian

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BinaryPredicateSupport.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NoRouteBuilder.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateSupport.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExpressionSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BinaryPredicateSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BinaryPredicateSupport.java?rev=663018&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BinaryPredicateSupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BinaryPredicateSupport.java
Wed Jun  4 00:36:45 2008
@@ -0,0 +1,69 @@
+/**
+ * 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;
+import static org.apache.camel.util.ObjectHelper.notNull;
+
+/**
+ * A useful base class for {@link Predicate} implementations
+ * 
+ * @version $Revision$
+ */
+public abstract class BinaryPredicateSupport<E extends Exchange> implements Predicate<E>
{
+
+    private final Expression<E> left;
+    private final Expression<E> right;
+
+    protected BinaryPredicateSupport(Expression<E> left, Expression<E> right)
{
+        notNull(left, "left");
+        notNull(right, "right");
+
+        this.left = left;
+        this.right = right;
+    }
+
+    @Override
+    public String toString() {
+        return left + " " + getOperationText() + " " + right;
+    }
+
+    public boolean matches(E exchange) {
+        Object leftValue = left.evaluate(exchange);
+        Object rightValue = right.evaluate(exchange);
+        return matches(exchange, leftValue, rightValue);
+    }
+
+    public void assertMatches(String text, E exchange) {
+        Object leftValue = left.evaluate(exchange);
+        Object rightValue = right.evaluate(exchange);
+        if (!matches(exchange, leftValue, rightValue)) {
+            throw new AssertionError(text + assertionFailureMessage(exchange, leftValue,
rightValue));
+        }
+    }
+
+    protected abstract boolean matches(E exchange, Object leftValue, Object rightValue);
+
+    protected abstract String getOperationText();
+
+    protected String assertionFailureMessage(E exchange, Object leftValue, Object rightValue)
{
+        return this + " failed on " + exchange + " with left value <" + leftValue + ">
right value <"
+               + rightValue + ">";
+    }
+}

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

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

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NoRouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NoRouteBuilder.java?rev=663018&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NoRouteBuilder.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NoRouteBuilder.java
Wed Jun  4 00:36:45 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.builder;
+
+
+/**
+ * A helper class, usually used for testing which does not create any routes.
+ *
+ * @version $Revision$
+ */
+public class NoRouteBuilder extends RouteBuilder {
+    private static final NoRouteBuilder INSTANCE = new NoRouteBuilder();
+
+    public static NoRouteBuilder getInstance() {
+        return INSTANCE;
+    }
+
+    public void configure() throws Exception {
+    }
+}

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

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java?rev=663018&r1=663017&r2=663018&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
Wed Jun  4 00:36:45 2008
@@ -16,19 +16,17 @@
  */
 package org.apache.camel.builder;
 
+import static org.apache.camel.util.ObjectHelper.compare;
+import static org.apache.camel.util.ObjectHelper.notNull;
+
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
-import org.apache.camel.impl.BinaryPredicateSupport;
-import org.apache.camel.impl.PredicateSupport;
 import org.apache.camel.util.ObjectHelper;
 
-import static org.apache.camel.util.ObjectHelper.compare;
-import static org.apache.camel.util.ObjectHelper.notNull;
-
 /**
  * A helper class for working with predicates
  *
@@ -49,7 +47,7 @@
         return new PredicateSupport<E>() {
             public boolean matches(E exchange) {
                 Object value = expression.evaluate(exchange);
-                return evaluateValuePredicate(value);
+                return ObjectHelper.evaluateValuePredicate(value);
             }
 
             @Override
@@ -60,18 +58,6 @@
     }
 
     /**
-     * Evaluate the value as a predicate which attempts to convert the value to
-     * a boolean otherwise true is returned if the value is not null
-     */
-    public static boolean evaluateValuePredicate(Object value) {
-        if (value instanceof Boolean) {
-            Boolean aBoolean = (Boolean)value;
-            return aBoolean.booleanValue();
-        }
-        return value != null;
-    }
-
-    /**
      * A helper method to return the logical not of the given predicate
      */
     public static <E extends Exchange> Predicate<E> not(final Predicate<E>
predicate) {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateSupport.java?rev=663018&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateSupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateSupport.java
Wed Jun  4 00:36:45 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.Predicate;
+
+/**
+ * A useful base class for {@link Predicate} implementations
+ *
+ * @version $Revision$
+ */
+public abstract class PredicateSupport<E extends Exchange> implements Predicate<E>
{
+
+    public void assertMatches(String text, E exchange) {
+        if (!matches(exchange)) {
+            throw new AssertionError(assertionFailureMessage(exchange)  + " on " + exchange);
+        }
+    }
+
+    protected String assertionFailureMessage(E exchange) {
+        return toString();
+    }
+}

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

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

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExpressionSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExpressionSupport.java?rev=663018&r1=663017&r2=663018&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExpressionSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ExpressionSupport.java
Wed Jun  4 00:36:45 2008
@@ -19,7 +19,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Predicate;
-import static org.apache.camel.builder.PredicateBuilder.evaluateValuePredicate;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * A useful base class for {@link Predicate} and {@link Expression} implementations
@@ -30,7 +30,7 @@
 
     public boolean matches(E exchange) {
         Object value = evaluate(exchange);
-        return evaluateValuePredicate(value);
+        return ObjectHelper.evaluateValuePredicate(value);
     }
 
     public void assertMatches(String text, E exchange) {
@@ -40,4 +40,4 @@
     }
 
     protected abstract String assertionFailureMessage(E exchange);
-}
\ No newline at end of file
+}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=663018&r1=663017&r2=663018&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Wed Jun  4 00:36:45 2008
@@ -617,4 +617,16 @@
     public static Object type(Object bean) {
         return bean != null ? bean.getClass() : null;
     }
+
+	/**
+	 * Evaluate the value as a predicate which attempts to convert the value to
+	 * a boolean otherwise true is returned if the value is not null
+	 */
+	public static boolean evaluateValuePredicate(Object value) {
+	    if (value instanceof Boolean) {
+	        Boolean aBoolean = (Boolean)value;
+	        return aBoolean.booleanValue();
+	    }
+	    return value != null;
+	}
 }



Mime
View raw message