All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mvel2.jsr223.MvelScriptEngineFactory Maven / Gradle / Ivy

Go to download

TBEL is a powerful expression language for ThingsBoard platform user-defined functions. Original implementation is based on MVEL.

There is a newer version: 1.2.4
Show newest version
package org.mvel2.jsr223;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;

import org.mvel2.MVEL;

public class MvelScriptEngineFactory implements ScriptEngineFactory {
    private static final String           ENGINE_NAME        = MVEL.NAME;
    private static final String           ENGINE_VERSION     = MVEL.VERSION;
    private static final String           LANGUAGE_NAME      = "mvel";
    private static final String           LANGUAGE_VERSION   = MVEL.VERSION;

    private static final List NAMES;
    private static final List EXTENSIONS;
    private static final List MIME_TYPES;

    static {
        List n = new ArrayList(1);
        n.add(LANGUAGE_NAME);
        NAMES = Collections.unmodifiableList(n);

        EXTENSIONS = NAMES;

        n = new ArrayList(1);
        n.add("application/x-"+LANGUAGE_NAME);
        MIME_TYPES = Collections.unmodifiableList(n);
    }

    private static final MvelScriptEngine MVEL_SCRIPT_ENGINE = new MvelScriptEngine();

    public MvelScriptEngineFactory() {
    }

    @Override
    public String getEngineName() {
        return ENGINE_NAME;
    }

    @Override
    public String getEngineVersion() {
        return ENGINE_VERSION;
    }

    @Override
    public List getExtensions() {
        return EXTENSIONS;
    }

    @Override
    public List getMimeTypes() {
        return MIME_TYPES;
    }

    @Override
    public List getNames() {
        return NAMES;
    }

    @Override
    public String getLanguageName() {
        return LANGUAGE_NAME;
    }

    @Override
    public String getLanguageVersion() {
        return LANGUAGE_VERSION;
    }

    @Override
    public Object getParameter(String key) {
        if (key.equals(ScriptEngine.NAME)) {
            return getLanguageName();
        } else if (key.equals(ScriptEngine.ENGINE)) {
            return getEngineName();
        } else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
            return getEngineVersion();
        } else if (key.equals(ScriptEngine.LANGUAGE)) {
            return getLanguageName();
        } else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
            return getLanguageVersion();
        } else if (key.equals("THREADING")) {
            return "THREAD-ISOLATED";
        } else {
            return null;
        }
    }

    @Override
    public String getMethodCallSyntax(String obj, String m, String... args) {
        return null;
    }

    @Override
    public String getOutputStatement(String toDisplay) {
        return null;
    }

    @Override
    public String getProgram(String... statements) {
        return null;
    }

    @Override
    public ScriptEngine getScriptEngine() {
        return MVEL_SCRIPT_ENGINE;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy