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

org.yelong.support.ognl.OgnlWrapper Maven / Gradle / Ivy

Go to download

对各种开源框架的包装、支持、拓展。这里也包含的yelong-core与orm框架的整合。 默认对所有依赖为 scope 为 provided 。您需要针对自己的需要进行再次依赖

There is a newer version: 2.2.0
Show newest version
/**
 * 
 */
package org.yelong.support.ognl;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;

/**
 * Ognl包装器
 * 
 * @author PengFei
 */
public class OgnlWrapper {

	private OgnlContext ognlContext = new OgnlContext();

	public OgnlWrapper() {
	}

	public OgnlWrapper(Object root) {
		setRoot(root);
	}

	/**
	 * 添加对象
	 * 
	 * @param key   对象对应的key
	 * @param value 对象
	 */
	public void put(String key, Object value) {
		ognlContext.put(key, value);
	}

	/**
	 * 获取表达式的值
	 * 
	 * @param expression 表达式
	 * @return value
	 * @throws OgnlException
	 */
	public Object getValue(String expression) throws OgnlException {
		return Ognl.getValue(expression, ognlContext, ognlContext.getRoot());
	}

	/**
	 * 设置表达式的属性值
	 * 
	 * @param expression 表达式
	 * @param value      值
	 * @throws OgnlException
	 */
	public void setValue(String expression, Object value) throws OgnlException {
		Ognl.setValue(expression, ognlContext, ognlContext.getRoot(), value);
	}

	/**
	 * @param root 根对象
	 */
	public void setRoot(Object root) {
		ognlContext.setRoot(root);
	}

	/**
	 * @return 根对象
	 */
	public Object getRoot() {
		return ognlContext.getRoot();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy