Search in sources :

Example 1 with Variables

use of org.apache.commons.jxpath.Variables in project collect by openforis.

the class AbstractSchemaExpression method evaluate.

public Object evaluate(NodeDefinition context, NodeDefinition thisNode) {
    if (!(Schema.class.isAssignableFrom(context.getClass()) || NodeDefinition.class.isAssignableFrom(context.getClass()))) {
        throw new IllegalArgumentException("Unable to evaluate expression with context class " + context.getClass().getName());
    }
    JXPathContext jxPathContext = JXPathContext.newContext(CONTEXT, context);
    Variables variables = jxPathContext.getVariables();
    variables.declareVariable(AbstractExpression.CONTEXT_NODE_VARIABLE_NAME, context);
    variables.declareVariable(AbstractExpression.THIS_VARIABLE_NAME, thisNode);
    String expr = Path.getNormalizedPath(expression);
    Object result = jxPathContext.getValue(expr);
    return result;
}
Also used : Variables(org.apache.commons.jxpath.Variables) JXPathContext(org.apache.commons.jxpath.JXPathContext) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition)

Example 2 with Variables

use of org.apache.commons.jxpath.Variables in project collect by openforis.

the class AbstractExpression method createJXPathContext.

/**
 * Creates a new JXPath context in order to evaluate the expression
 */
private JXPathContext createJXPathContext(Node<?> contextNode, Node<?> thisNode) {
    ModelJXPathContext jxPathContext = ModelJXPathContext.newContext(this.jxPathContext, contextNode);
    Variables variables = jxPathContext.getVariables();
    variables.declareVariable(CONTEXT_NODE_VARIABLE_NAME, contextNode);
    if (thisNode != null) {
        variables.declareVariable(THIS_VARIABLE_NAME, thisNode);
    }
    return jxPathContext;
}
Also used : Variables(org.apache.commons.jxpath.Variables) ModelJXPathContext(org.openforis.idm.model.expression.internal.ModelJXPathContext)

Aggregations

Variables (org.apache.commons.jxpath.Variables)2 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 ModelJXPathContext (org.openforis.idm.model.expression.internal.ModelJXPathContext)1