Example usage for org.apache.commons.el ComplexValue getSuffixes

List of usage examples for org.apache.commons.el ComplexValue getSuffixes

Introduction

In this page you can find the example usage for org.apache.commons.el ComplexValue getSuffixes.

Prototype

public List getSuffixes() 

Source Link

Usage

From source file:org.apache.myfaces.el.ELParserHelper.java

private static void replaceSuffixes(ComplexValue complexValue) {
    Application application = FacesContext.getCurrentInstance().getApplication();

    List suffixes = complexValue.getSuffixes();
    for (int i = 0, len = suffixes.size(); i < len; i++) {
        ValueSuffix suffix = (ValueSuffix) suffixes.get(i);
        if (suffix instanceof PropertySuffix) {
            if (suffix instanceof MyPropertySuffix) {
                throw new IllegalStateException("Suffix is MyPropertySuffix and must not be");
            }//from   w  w  w.ja v  a  2  s .  c o  m

            suffixes.set(i, new MyPropertySuffix((PropertySuffix) suffix, application));
        } else if (suffix instanceof ArraySuffix) {
            if (suffix instanceof MyArraySuffix) {
                throw new IllegalStateException("Suffix is MyArraySuffix and must not be");
            }

            suffixes.set(i, new MyArraySuffix((ArraySuffix) suffix, application));
        } else {
            throw new IllegalStateException("Unknown suffix class: " + suffix.getClass().getName());
        }
    }
}

From source file:org.apache.myfaces.el.ValueBindingImpl.java

protected Object resolveToBaseAndProperty(FacesContext facesContext)
        throws ELException, NotVariableReferenceException {
    if (facesContext == null) {
        throw new NullPointerException("facesContext");
    }//from w  w  w .java  2  s. c o  m

    VariableResolver variableResolver = new ELVariableResolver(facesContext);
    Object expression = _expression;

    while (expression instanceof ConditionalExpression) {
        ConditionalExpression conditionalExpression = ((ConditionalExpression) expression);
        // first, evaluate the condition (and coerce the result to a
        // boolean value)
        boolean condition = Coercions.coerceToBoolean(conditionalExpression.getCondition()
                .evaluate(variableResolver, s_functionMapper, ELParserHelper.LOGGER), ELParserHelper.LOGGER)
                .booleanValue();

        // then, use this boolean to branch appropriately
        expression = condition ? conditionalExpression.getTrueBranch() : conditionalExpression.getFalseBranch();
    }

    if (expression instanceof NamedValue) {
        return ((NamedValue) expression).getName();
    }

    if (!(expression instanceof ComplexValue)) {
        // all other cases are not variable references
        throw new NotVariableReferenceException(
                "Parsed Expression of unsupported type for this operation. Expression class: "
                        + _expression.getClass().getName() + ". Expression: '" + _expressionString + "'");
    }

    ComplexValue complexValue = (ComplexValue) expression;

    // resolve the prefix
    Object base = complexValue.getPrefix().evaluate(variableResolver, s_functionMapper, ELParserHelper.LOGGER);
    if (base == null) {
        throw new PropertyNotFoundException("Base is null: " + complexValue.getPrefix().getExpressionString());
    }

    // Resolve and apply the suffixes
    List suffixes = complexValue.getSuffixes();
    int max = suffixes.size() - 1;
    for (int i = 0; i < max; i++) {
        ValueSuffix suffix = (ValueSuffix) suffixes.get(i);
        base = suffix.evaluate(base, variableResolver, s_functionMapper, ELParserHelper.LOGGER);
        if (base == null) {
            throw new PropertyNotFoundException("Base is null: " + suffix.getExpressionString());
        }
    }

    // Resolve the last suffix
    ArraySuffix arraySuffix = (ArraySuffix) suffixes.get(max);
    Expression arraySuffixIndex = arraySuffix.getIndex();

    Object index;
    if (arraySuffixIndex != null) {
        index = arraySuffixIndex.evaluate(variableResolver, s_functionMapper, ELParserHelper.LOGGER);
        if (index == null) {
            throw new PropertyNotFoundException("Index is null: " + arraySuffixIndex.getExpressionString());
        }
    } else {
        index = ((PropertySuffix) arraySuffix).getName();
    }

    return new Object[] { base, index };
}

From source file:org.seasar.teeda.core.el.impl.commons.CommonsExpressionProcessorImpl.java

public Object resolveBase(FacesContext context, Object expression)
        throws ReferenceSyntaxException, PropertyNotFoundException {
    while (expression instanceof ConditionalExpression) {
        ConditionalExpression conditionalExpression = ((ConditionalExpression) expression);
        Object value = evaluate(context, conditionalExpression.getCondition());
        boolean condition = CoercionsUtil.coerceToPrimitiveBoolean(value);
        expression = (condition) ? conditionalExpression.getTrueBranch()
                : conditionalExpression.getFalseBranch();
    }/*from   w  ww.j  a  va 2  s  .  c  om*/
    if (expression instanceof NamedValue) {
        return ((NamedValue) expression).getName();
    }
    if (!(expression instanceof ComplexValue)) {
        return null;
    }
    ComplexValue complexValue = (ComplexValue) expression;
    Object base = evaluate(context, complexValue.getPrefix());
    VariableResolver resolver = new ELVariableResolver(context);
    if (base == null) {
        throw new PropertyNotFoundException("Base is null: " + complexValue.getPrefix().getExpressionString());
    }

    List suffixes = complexValue.getSuffixes();
    int max = suffixes.size() - 1;
    for (int i = 0; i < max; i++) {
        ValueSuffix suffix = (ValueSuffix) suffixes.get(i);
        try {
            base = suffix.evaluate(base, resolver, mapper_, CommonsElLogger.getLogger());
        } catch (ELException e) {
            throw new EvaluationException(e);
        }
        if (base == null) {
            throw new PropertyNotFoundException("Base is null: " + suffix.getExpressionString());
        }
    }
    ArraySuffix arraySuffix = (ArraySuffix) suffixes.get(max);
    Expression arraySuffixIndex = arraySuffix.getIndex();
    Object index;
    if (arraySuffixIndex != null) {
        index = evaluate(context, arraySuffixIndex);
        if (index == null) {
            throw new PropertyNotFoundException("Index is null: " + arraySuffixIndex.getExpressionString());
        }
    } else {
        index = ((PropertySuffix) arraySuffix).getName();
    }
    return new Object[] { base, index };
}

From source file:org.seasar.teeda.core.el.impl.commons.ComplexValueReplacer.java

public void replace(Object expression) {
    ComplexValue complexValue = (ComplexValue) expression;
    Application application = ApplicationUtil.getApplicationFromContext();
    List suffixes = complexValue.getSuffixes();
    for (int i = 0; i < suffixes.size(); i++) {
        ValueSuffix valueSuffix = (ValueSuffix) suffixes.get(i);
        if (isSuitablePropertySuffix(valueSuffix)) {
            PropertySuffix propertySuffix = (PropertySuffix) valueSuffix;
            suffixes.set(i, new JsfPropertySuffix(propertySuffix, application, processor_));
        } else if (isSuitableArraySuffix(valueSuffix)) {
            ArraySuffix arraySuffix = (ArraySuffix) valueSuffix;
            suffixes.set(i, new JsfArraySuffix(arraySuffix, application, processor_));
        } else {/*from w  ww  .  j  a v  a2  s  .  c om*/
            throw new IllegalStateException();
        }
    }
}