Updated Branches: refs/heads/camel-2.10.x d475a37fc -> 0db45d083
CAMEL-6743: Bean parameter binding with boolean types should eval as predicates. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0db45d08 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0db45d08 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0db45d08 Branch: refs/heads/camel-2.10.x Commit: 0db45d08310d3d101f9fd409b5f79c52f90b4672 Parents: d475a37 Author: Claus Ibsen <[email protected]> Authored: Fri Sep 13 11:00:08 2013 +0200 Committer: Claus Ibsen <[email protected]> Committed: Fri Sep 13 11:00:08 2013 +0200 ---------------------------------------------------------------------- .../util/PredicateToExpressionAdapter.java | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0db45d08/camel-core/src/main/java/org/apache/camel/util/PredicateToExpressionAdapter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/PredicateToExpressionAdapter.java b/camel-core/src/main/java/org/apache/camel/util/PredicateToExpressionAdapter.java new file mode 100644 index 0000000..b2df0a1 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/util/PredicateToExpressionAdapter.java @@ -0,0 +1,48 @@ +/** + * 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.util; + +import org.apache.camel.Exchange; +import org.apache.camel.Expression; +import org.apache.camel.Predicate; + +public final class PredicateToExpressionAdapter implements Expression { + private final Predicate predicate; + + public PredicateToExpressionAdapter(Predicate predicate) { + this.predicate = predicate; + } + + @Override + public <T> T evaluate(Exchange exchange, Class<T> type) { + boolean matches = predicate.matches(exchange); + return exchange.getContext().getTypeConverter().convertTo(type, exchange, matches); + } + + @Override + public String toString() { + return predicate.toString(); + } + + /** + * Converts the given predicate into an {@link org.apache.camel.Expression} + */ + public static Expression toExpression(final Predicate predicate) { + return new PredicateToExpressionAdapter(predicate); + } + +} \ No newline at end of file
