Search in sources :

Example 1 with ExpressionToPredicateAdapter

use of org.apache.camel.util.ExpressionToPredicateAdapter in project camel by apache.

the class ExpressionDefinition method createPredicate.

public Predicate createPredicate(CamelContext camelContext) {
    if (predicate == null) {
        if (getExpressionType() != null) {
            predicate = getExpressionType().createPredicate(camelContext);
        } else if (getExpressionValue() != null) {
            predicate = new ExpressionToPredicateAdapter(getExpressionValue());
        } else if (getExpression() != null) {
            ObjectHelper.notNull("language", getLanguage());
            Language language = camelContext.resolveLanguage(getLanguage());
            if (language == null) {
                throw new NoSuchLanguageException(getLanguage());
            }
            String exp = getExpression();
            // should be true by default
            boolean isTrim = getTrim() == null || getTrim();
            // trim if configured to trim
            if (exp != null && isTrim) {
                exp = exp.trim();
            }
            // resolve the expression as it may be an external script from the classpath/file etc
            exp = ResourceHelper.resolveOptionalExternalScript(camelContext, exp);
            predicate = language.createPredicate(exp);
            configurePredicate(camelContext, predicate);
        }
    }
    return predicate;
}
Also used : Language(org.apache.camel.spi.Language) ExpressionToPredicateAdapter(org.apache.camel.util.ExpressionToPredicateAdapter) NoSuchLanguageException(org.apache.camel.NoSuchLanguageException)

Aggregations

NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 Language (org.apache.camel.spi.Language)1 ExpressionToPredicateAdapter (org.apache.camel.util.ExpressionToPredicateAdapter)1