use of org.apache.camel.Predicate in project camel by apache.
the class BinaryExpression method createRegexExpression.
private Expression createRegexExpression(final Expression leftExp, final Expression rightExp) {
return new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
// reg ex should use String pattern, so we evaluate the right hand side as a String
Predicate predicate = PredicateBuilder.regex(leftExp, rightExp.evaluate(exchange, String.class));
if (operator == BinaryOperatorType.NOT_REGEX) {
predicate = PredicateBuilder.not(predicate);
}
boolean answer = predicate.matches(exchange);
return exchange.getContext().getTypeConverter().convertTo(type, answer);
}
@Override
public String toString() {
return left + " " + token.getText() + " " + right;
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class LogicalExpression method createOrExpression.
private Expression createOrExpression(final Expression leftExp, final Expression rightExp) {
return new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
Predicate predicate = ExpressionToPredicateAdapter.toPredicate(leftExp);
predicate = PredicateBuilder.or(predicate, ExpressionToPredicateAdapter.toPredicate(rightExp));
boolean answer = predicate.matches(exchange);
return exchange.getContext().getTypeConverter().convertTo(type, answer);
}
@Override
public String toString() {
return left + " " + token.getText() + " " + right;
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class LogicalExpression method createAndExpression.
private Expression createAndExpression(final Expression leftExp, final Expression rightExp) {
return new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
Predicate predicate = ExpressionToPredicateAdapter.toPredicate(leftExp);
predicate = PredicateBuilder.and(predicate, ExpressionToPredicateAdapter.toPredicate(rightExp));
boolean answer = predicate.matches(exchange);
return exchange.getContext().getTypeConverter().convertTo(type, answer);
}
@Override
public String toString() {
return left + " " + token.getText() + " " + right;
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class WhenSkipSendToEndpointDefinition method createPredicate.
@Override
protected Predicate createPredicate(RouteContext routeContext) {
// we need to keep track whether the when matches or not, so delegate
// the predicate and add the matches result as a property on the exchange
final Predicate delegate = super.createPredicate(routeContext);
return new Predicate() {
@Override
public boolean matches(Exchange exchange) {
boolean matches = delegate.matches(exchange);
exchange.setProperty(Exchange.INTERCEPT_SEND_TO_ENDPOINT_WHEN_MATCHED, matches);
return matches;
}
@Override
public String toString() {
return delegate.toString();
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class ExpressionDefinition method getLabel.
/**
* Returns some descriptive text to describe this node
*/
public String getLabel() {
Predicate predicate = getPredicate();
if (predicate != null) {
return predicate.toString();
}
Expression expressionValue = getExpressionValue();
if (expressionValue != null) {
return expressionValue.toString();
}
String exp = getExpression();
return exp != null ? exp : "";
}
Aggregations