Home » Source Code » » groovy_1/ExprSupport.java

groovy_1/ExprSupport.java ( File view )

From:
Description:...
  • By ophelia_fupx 2016-12-09
  • View(s):0
  • Download(s):0
  • Point(s): 1
			package com.yusys.approvalflow.afutil;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
 
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
 
import org.codehaus.groovy.control.CompilerConfiguration;
 
public class ExprSupport {

	
    private static final Object lock = new Object();
    private static final GroovyShell shell;
    private static Hashtable<String, Script> cache = new Hashtable<String, Script>();
    
    static {

        CompilerConfiguration cfg = new CompilerConfiguration();
        cfg.setScriptBaseClass(MyBasicScript.class.getName());
        shell = new GroovyShell(cfg);
    
}
 
    public static Object parseExpr(String expr) {

        Script s = getScriptFromCache(expr);
        return s.run();
    
}
 
    public static Object parseExpr(String expr, Map<?, ?> map) {

        Binding binding = new Binding(map);
        Script script = getScriptFromCache(expr);
        script.setBinding(binding);
        return script.run();
    
}
 
    private static Script getScriptFromCache(String expr) {

        if (cache.contains(expr)) {

            return cache.get(expr);
        
}
        synchronized (lock) {

            if (cache.contains(expr)) {

                return cache.get(expr);
            
}
            Script script = shell.parse(expr);
            cache.put(expr, 
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
ExprSupport.java2.07 kB2016-11-28 21:27
MyBasicScript.java608.00 B2016-11-28 10:12
groovy_10.00 B2016-12-09 17:53
...
Sponsored links

groovy_1/ExprSupport.java (1.31 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D