Search in sources :

Example 1 with DefaultValidationResult

use of org.mule.runtime.api.el.DefaultValidationResult in project mule by mulesoft.

the class DefaultExpressionManager method validate.

@Override
public ValidationResult validate(String expression) {
    if (!muleContext.getConfiguration().isValidateExpressions()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Validate expressions is turned off, no checking done for: " + expression);
        }
        return new DefaultValidationResult(true, null);
    }
    final StringBuilder message = new StringBuilder();
    try {
        parser.validate(expression);
        final AtomicBoolean valid = new AtomicBoolean(true);
        if (expression.contains(DEFAULT_EXPRESSION_PREFIX)) {
            parser.parse(token -> {
                if (valid.get()) {
                    ValidationResult result = expressionLanguage.validate(token);
                    if (!result.isSuccess()) {
                        valid.compareAndSet(true, false);
                        message.append(token).append(" is invalid\n");
                        message.append(result.errorMessage().orElse(""));
                    }
                }
                return null;
            }, expression);
        } else {
            return expressionLanguage.validate(expression);
        }
    } catch (IllegalArgumentException e) {
        return failure(e.getMessage(), expression);
    }
    if (message.length() > 0) {
        return failure(message.toString());
    }
    return success();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultValidationResult(org.mule.runtime.api.el.DefaultValidationResult) DefaultValidationResult(org.mule.runtime.api.el.DefaultValidationResult) ValidationResult(org.mule.runtime.api.el.ValidationResult)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DefaultValidationResult (org.mule.runtime.api.el.DefaultValidationResult)1 ValidationResult (org.mule.runtime.api.el.ValidationResult)1