Search in sources :

Example 1 with ExpressionContext

use of io.atlasmap.expression.ExpressionContext in project atlasmap by atlasmap.

the class ISEMPTY method create.

@Override
public Expression create(List<Expression> args) throws ParseException {
    if (args.size() != 1) {
        throw new ParseException("ISEMPTY expects 1 argument.");
    }
    final Expression arg = args.get(0);
    return new BooleanExpression() {

        public Field evaluate(ExpressionContext ctx) throws ExpressionException {
            Field f = arg.evaluate(ctx);
            Object value = f == null ? null : f.getValue();
            if (value == null || value.toString().isEmpty()) {
                return wrapWithField(Boolean.TRUE);
            }
            return wrapWithField(Boolean.FALSE);
        }

        public boolean matches(ExpressionContext ctx) throws ExpressionException {
            Object answer = evaluate(ctx).getValue();
            return answer != null && answer == Boolean.TRUE;
        }
    };
}
Also used : Field(io.atlasmap.v2.Field) AtlasModelFactory.wrapWithField(io.atlasmap.v2.AtlasModelFactory.wrapWithField) BooleanExpression(io.atlasmap.expression.internal.BooleanExpression) Expression(io.atlasmap.expression.Expression) BooleanExpression(io.atlasmap.expression.internal.BooleanExpression) ExpressionContext(io.atlasmap.expression.ExpressionContext) ParseException(io.atlasmap.expression.parser.ParseException)

Aggregations

Expression (io.atlasmap.expression.Expression)1 ExpressionContext (io.atlasmap.expression.ExpressionContext)1 BooleanExpression (io.atlasmap.expression.internal.BooleanExpression)1 ParseException (io.atlasmap.expression.parser.ParseException)1 AtlasModelFactory.wrapWithField (io.atlasmap.v2.AtlasModelFactory.wrapWithField)1 Field (io.atlasmap.v2.Field)1