Package cambridge.mvel

Source Code of cambridge.mvel.MvelExpressionLanguage

package cambridge.mvel;

import java.io.Serializable;
import java.util.Locale;

import cambridge.parser.expressions.MapExpressionContext;
import cambridge.runtime.ExpressionContext;
import org.mvel2.MVEL;
import org.mvel2.ParserConfiguration;
import org.mvel2.ParserContext;

import cambridge.ExpressionLanguage;
import cambridge.ExpressionParsingException;
import cambridge.Expressions;
import cambridge.model.Expression;

/**
* @author Erdinc YILMAZEL
* @since 2/1/11
*/
public class MvelExpressionLanguage implements ExpressionLanguage {
    public static void register() {
        Expressions.registerExpressionLanguage("mvel", MvelExpressionLanguage.class);
    }

    ParserConfiguration configuration = new ParserConfiguration();

    public ParserConfiguration getParserConfiguration() {
        return configuration;
    }

    public Expression parse(String expressionString, int line, int column) throws ExpressionParsingException {
        ParserContext ctx = new ParserContext(configuration);

        Serializable compiledExpression = MVEL.compileExpression(expressionString, ctx);

        return new MVELExpression(compiledExpression, expressionString, line, column);
    }

    public String wrapExpressionAsList(String expr) {
        return "[" + expr + "]";
    }

    @Override
    public ExpressionContext createNewContext(Locale locale)
    {
        return new MapExpressionContext(locale);
    }

    @Override
    public ExpressionContext createNewContext()
    {
        return new MapExpressionContext();
    }
}
TOP

Related Classes of cambridge.mvel.MvelExpressionLanguage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.