use of org.apache.camel.Predicate in project camel by apache.
the class AssertionClause method applyAssertionOn.
/**
* Performs any assertions on the given exchange
*/
protected void applyAssertionOn(MockEndpoint endpoint, int index, Exchange exchange) {
for (Predicate predicate : predicates) {
currentIndex = index;
PredicateAssertHelper.assertMatches(predicate, "Assertion error at index " + index + " on mock " + endpoint.getEndpointUri() + " with predicate: ", exchange);
}
}
use of org.apache.camel.Predicate in project camel by apache.
the class RefLanguage method createExpression.
public Expression createExpression(final String expression) {
final Expression exp = RefLanguage.ref(expression);
return new ExpressionAdapter() {
public Object evaluate(Exchange exchange) {
Expression target = null;
Object lookup = exp.evaluate(exchange, Object.class);
// must favor expression over predicate
if (lookup != null && lookup instanceof Expression) {
target = (Expression) lookup;
} else if (lookup != null && lookup instanceof Predicate) {
target = PredicateToExpressionAdapter.toExpression((Predicate) lookup);
}
if (target != null) {
return target.evaluate(exchange, Object.class);
} else {
throw new IllegalArgumentException("Cannot find expression or predicate in registry with ref: " + expression);
}
}
public String toString() {
return exp.toString();
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class BinaryExpression method createInExpression.
private Expression createInExpression(final Expression leftExp, final Expression rightExp) {
return new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
// okay the in operator is a bit more complex as we need to build a list of values
// from the right hand side expression.
// each element on the right hand side must be separated by comma (default for create iterator)
Iterator<Object> it = ObjectHelper.createIterator(rightExp.evaluate(exchange, Object.class));
List<Object> values = new ArrayList<Object>();
while (it.hasNext()) {
values.add(it.next());
}
// then reuse value builder to create the in predicate with the list of values
ValueBuilder vb = new ValueBuilder(leftExp);
Predicate predicate = vb.in(values.toArray());
if (operator == BinaryOperatorType.NOT_IN) {
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 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;
}
};
}
Aggregations