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();
}
Aggregations