yangys
2024-04-23 cacfe3693e552724a07ff65ee620cee91787da76
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.qianwen.core.tool.script.engine;
 
import java.util.HashMap;
import java.util.Map;
import com.qianwen.core.tool.script.engine.SpEL.SpElEngine;
import com.qianwen.core.tool.script.engine.groovy.GroovyEngine;
import com.qianwen.core.tool.script.engine.js.JavaScriptEngine;
import com.qianwen.core.tool.script.engine.ognl.OgnlEngine;
import com.qianwen.core.tool.script.engine.python.PythonScriptEngine;
import com.qianwen.core.tool.script.engine.ruby.RubyScriptEngine;
 
 
public final class DynamicScriptEngineFactory {
    private static final Map<String, DynamicScriptEngine> map = new HashMap<>();
 
    static {
        JavaScriptEngine engine = new JavaScriptEngine();
        map.put("js", engine);
        map.put("javascript", engine);
        map.put("groovy", new GroovyEngine());
        map.put("ruby", new RubyScriptEngine());
        map.put("python", new PythonScriptEngine());
        try {
            Class.forName("org.springframework.expression.ExpressionParser");
            map.put("spel", new SpElEngine());
        } catch (ClassNotFoundException e) {
        }
        try {
            Class.forName("ognl.Ognl");
            map.put("ognl", new OgnlEngine());
        } catch (ClassNotFoundException e2) {
        }
    }
 
    public static final DynamicScriptEngine getEngine(String type) {
        return map.get(type);
    }
}