Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 86170 invoked from network); 4 Jun 2008 07:37:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jun 2008 07:37:10 -0000 Received: (qmail 48354 invoked by uid 500); 4 Jun 2008 07:37:13 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 48343 invoked by uid 500); 4 Jun 2008 07:37:13 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 48334 invoked by uid 99); 4 Jun 2008 07:37:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jun 2008 00:37:13 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jun 2008 07:36:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 699B923889F1; Wed, 4 Jun 2008 00:36:46 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: camel-commits@activemq.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080604073646.699B923889F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 implements Predicate { + + private final Expression left; + private final Expression right; + + protected BinaryPredicateSupport(Expression left, Expression 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() { 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 Predicate not(final Predicate 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 implements Predicate { + + 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; + } }