Example usage for org.apache.commons.el Constants NULL_EXPRESSION_STRING

List of usage examples for org.apache.commons.el Constants NULL_EXPRESSION_STRING

Introduction

In this page you can find the example usage for org.apache.commons.el Constants NULL_EXPRESSION_STRING.

Prototype

String NULL_EXPRESSION_STRING

To view the source code for org.apache.commons.el Constants NULL_EXPRESSION_STRING.

Click Source Link

Usage

From source file:it.cilea.osd.jdyna.web.tag.ExpressionEvaluatorImpl.java

/**
 * //from  w ww .ja va2s. co m
 * Evaluates the given expression String
 * 
 * @param pExpressionString
 *            The expression to be evaluated.
 * @param pExpectedType
 *            The expected type of the result of the evaluation
 * @param pResolver
 *            A VariableResolver instance that can be used at runtime to
 *            resolve the name of implicit objects into Objects.
 * @param functions
 *            A FunctionMapper to resolve functions found in the expression.
 *            It can be null, in which case no functions are supported for
 *            this invocation.
 * @return the expression String evaluated to the given expected type
 **/
public Object evaluate(String pExpressionString, Class pExpectedType, VariableResolver pResolver,
        FunctionMapper functions) throws ELException {
    // Check for null expression strings
    if (pExpressionString == null) {
        throw new ELException(Constants.NULL_EXPRESSION_STRING);
    }

    // Get the parsed version of the expression string
    Object parsedValue = parseExpressionString(pExpressionString);

    // Evaluate differently based on the parsed type
    if (parsedValue instanceof String) {
        // Convert the String, and cache the conversion
        String strValue = (String) parsedValue;
        return convertStaticValueToExpectedType(strValue, pExpectedType, pLogger);
    }

    else if (parsedValue instanceof Expression) {
        // Evaluate the expression and convert
        Object value = ((Expression) parsedValue).evaluate(pResolver, functions, pLogger);
        return convertToExpectedType(value, pExpectedType, pLogger);
    }

    else if (parsedValue instanceof ExpressionString) {
        // Evaluate the expression/string list and convert
        String strValue = ((ExpressionString) parsedValue).evaluate(pResolver, functions, pLogger);
        return convertToExpectedType(strValue, pExpectedType, pLogger);
    }

    else {
        // This should never be reached
        return null;
    }
}