Search in sources :

Example 1 with ELException

use of javax.el.ELException in project spring-framework by spring-projects.

the class WebApplicationContextFacesELResolver method getType.

@Override
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
    if (base != null) {
        if (base instanceof WebApplicationContext) {
            WebApplicationContext wac = (WebApplicationContext) base;
            String beanName = property.toString();
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
            }
            if (wac.containsBean(beanName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
                }
                elContext.setPropertyResolved(true);
                try {
                    return wac.getType(beanName);
                } catch (BeansException ex) {
                    throw new ELException(ex);
                }
            } else {
                // Mimic standard JSF/JSP behavior when base is a Map by returning null.
                return null;
            }
        }
    } else {
        if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
            elContext.setPropertyResolved(true);
            return WebApplicationContext.class;
        }
    }
    return null;
}
Also used : ELException(javax.el.ELException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) BeansException(org.springframework.beans.BeansException)

Example 2 with ELException

use of javax.el.ELException in project spring-framework by spring-projects.

the class WebApplicationContextFacesELResolver method getValue.

@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
    if (base != null) {
        if (base instanceof WebApplicationContext) {
            WebApplicationContext wac = (WebApplicationContext) base;
            String beanName = property.toString();
            if (logger.isTraceEnabled()) {
                logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
            }
            if (wac.containsBean(beanName)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
                }
                elContext.setPropertyResolved(true);
                try {
                    return wac.getBean(beanName);
                } catch (BeansException ex) {
                    throw new ELException(ex);
                }
            } else {
                // Mimic standard JSF/JSP behavior when base is a Map by returning null.
                return null;
            }
        }
    } else {
        if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
            elContext.setPropertyResolved(true);
            return getWebApplicationContext(elContext);
        }
    }
    return null;
}
Also used : ELException(javax.el.ELException) WebApplicationContext(org.springframework.web.context.WebApplicationContext) BeansException(org.springframework.beans.BeansException)

Example 3 with ELException

use of javax.el.ELException in project camunda-engine-dmn by camunda.

the class FeelEngineImpl method evaluateSimpleUnaryTests.

public boolean evaluateSimpleUnaryTests(String simpleUnaryTests, String inputName, VariableContext variableContext) {
    try {
        ELContext elContext = createContext(variableContext);
        ValueExpression valueExpression = transformSimpleUnaryTests(simpleUnaryTests, inputName, elContext);
        return (Boolean) valueExpression.getValue(elContext);
    } catch (FeelMissingFunctionException e) {
        throw LOG.unknownFunction(simpleUnaryTests, e);
    } catch (FeelMissingVariableException e) {
        if (inputName.equals(e.getVariable())) {
            throw LOG.unableToEvaluateExpressionAsNotInputIsSet(simpleUnaryTests, e);
        } else {
            throw LOG.unknownVariable(simpleUnaryTests, e);
        }
    } catch (FeelConvertException e) {
        throw LOG.unableToConvertValue(simpleUnaryTests, e);
    } catch (ELException e) {
        if (e.getCause() instanceof FeelMethodInvocationException) {
            throw LOG.unableToInvokeMethod(simpleUnaryTests, (FeelMethodInvocationException) e.getCause());
        } else {
            throw LOG.unableToEvaluateExpression(simpleUnaryTests, e);
        }
    }
}
Also used : ELContext(javax.el.ELContext) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException)

Example 4 with ELException

use of javax.el.ELException in project sonar-web by SonarSource.

the class UnifiedExpressionCheck method validateExpression.

private void validateExpression(TagNode element, Attribute attribute) {
    ExpressionLanguageContext context = new ExpressionLanguageContext(element);
    ExpressionBuilder builder = new ExpressionBuilder(attribute.getValue(), context);
    try {
        builder.createValueExpression(Object.class);
    } catch (ELException e) {
        if (e.getMessage().startsWith("Error")) {
            createViolation(element.getStartLinePosition(), "Fix this expression: " + (e.getMessage() == null ? "" : e.getMessage()));
        }
    }
}
Also used : ELException(javax.el.ELException) ExpressionBuilder(org.jboss.el.lang.ExpressionBuilder)

Example 5 with ELException

use of javax.el.ELException in project tomcat70 by apache.

the class ExpressionBuilder method visit.

/*
     * (non-Javadoc)
     *
     * @see com.sun.el.parser.NodeVisitor#visit(com.sun.el.parser.Node)
     */
@Override
public void visit(Node node) throws ELException {
    if (node instanceof AstFunction) {
        AstFunction funcNode = (AstFunction) node;
        if (this.fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }
        Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode.getLocalName());
        if (m == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.method", funcNode.getOutputName()));
        }
        int methodParameterCount = m.getParameterTypes().length;
        int inputParameterCount = node.jjtGetNumChildren();
        if (m.isVarArgs() && inputParameterCount < methodParameterCount - 1 || !m.isVarArgs() && inputParameterCount != methodParameterCount) {
            throw new ELException(MessageFactory.get("error.fnMapper.paramcount", funcNode.getOutputName(), "" + methodParameterCount, "" + node.jjtGetNumChildren()));
        }
    } else if (node instanceof AstIdentifier && this.varMapper != null) {
        String variable = ((AstIdentifier) node).getImage();
        // simply capture it
        this.varMapper.resolveVariable(variable);
    }
}
Also used : AstFunction(org.apache.el.parser.AstFunction) AstIdentifier(org.apache.el.parser.AstIdentifier) ELException(javax.el.ELException) Method(java.lang.reflect.Method)

Aggregations

ELException (javax.el.ELException)23 ValueExpression (javax.el.ValueExpression)6 Method (java.lang.reflect.Method)5 ELContext (javax.el.ELContext)4 Test (org.junit.Test)4 ExpressionFactory (javax.el.ExpressionFactory)3 ELContextImpl (org.apache.jasper.el.ELContextImpl)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 FunctionMapper (javax.el.FunctionMapper)2 ExpressionBuilder (org.jboss.el.lang.ExpressionBuilder)2 BeansException (org.springframework.beans.BeansException)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 AuthorizationException (fi.otavanopisto.security.AuthorizationException)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Properties (java.util.Properties)1 EJBException (javax.ejb.EJBException)1