Example usage for org.apache.commons.ognl Ognl createDefaultContext

List of usage examples for org.apache.commons.ognl Ognl createDefaultContext

Introduction

In this page you can find the example usage for org.apache.commons.ognl Ognl createDefaultContext.

Prototype

public static Map<String, Object> createDefaultContext(Object root, ClassResolver classResolver,
        TypeConverter converter) 

Source Link

Document

Creates and returns a new standard naming context for evaluating an OGNL expression.

Usage

From source file:it.d4nguard.rgrpg.util.dynacast.DynaManipulator.java

/**
 * Evaluates the given OGNL expression to insert a value into the object
 * graph rooted at the given root object.
 * /*from   w ww . j  a v  a2  s  .c  om*/
 * @param exp
 *            the OGNL expression to be parsed
 * @param root
 *            the root object for the OGNL expression
 * @param value
 *            the value to insert into the object graph
 * @throws DynaManipulatorException
 *             if something fails below.
 */
public static void setValue(String exp, Object root, String value) throws DynaManipulatorException {
    assert root != null;
    assert value != null;
    try {
        Map<String, Object> context = Ognl.createDefaultContext(root, null, new AdapterTypeConverter());
        Ognl.setValue(exp, context, root, value);
    } catch (Exception e) {
        throw new DynaManipulatorException(e);
    }
}

From source file:it.d4nguard.rgrpg.util.dynacast.DynaManipulator.java

/**
 * Evaluates the given OGNL expression tree to extract a value from the
 * given root object.//from   w ww  . j  av a 2 s  . co  m
 * 
 * @see Ognl#parseExpression(String)
 * @param exp
 *            the OGNL expression to be parsed
 * @param root
 *            the root object for the OGNL expression
 * @return
 * @throws DynaManipulatorException
 */
public static Object getValue(String exp, Object root) throws DynaManipulatorException {
    assert root != null;
    Object ret = root;
    try {
        Object expression = Ognl.parseExpression(exp);
        Map<String, Object> context = Ognl.createDefaultContext(root, null, new AdapterTypeConverter());
        ret = Ognl.getValue(expression, context, root);
    } catch (Exception e) {
        throw new DynaManipulatorException(e);
    }
    return ret;
}