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

com.dexcoder.dal.batis.ognl.OgnlCache Maven / Gradle / Ivy

package com.dexcoder.dal.batis.ognl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import ognl.Ognl;
import ognl.OgnlException;

import com.dexcoder.dal.exceptions.JdbcAssistantException;

/**
 * Created by liyd on 2015-11-30.
 */
public final class OgnlCache {

    private static final Map expressionCache = new ConcurrentHashMap();

    private OgnlCache() {
        // Prevent Instantiation of Static Class
    }

    public static Object getValue(String expression, Object root) {
        try {
            return Ognl.getValue(parseExpression(expression), root);
        } catch (OgnlException e) {
            throw new JdbcAssistantException("Error evaluating expression '" + expression + "'. Cause: " + e, e);
        }
    }

    private static Object parseExpression(String expression) throws OgnlException {
        Object node = expressionCache.get(expression);
        if (node == null) {
            node = Ognl.parseExpression(expression);
            expressionCache.put(expression, node);
        }
        return node;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy