Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.el;
 
 
 
An Expression that can get or set a value.

In previous incarnations of this API, expressions could only be read. ValueExpression objects can now be used both to retrieve a value and to set a value. Expressions that can have a value set on them are referred to as l-value expressions. Those that cannot are referred to as r-value expressions. Not all r-value expressions can be used as l-value expressions (e.g. "${1+1}" or "${firstName} ${lastName}"). See the EL Specification for details. Expressions that cannot be used as l-values must always return true from isReadOnly().

The javax.el.ExpressionFactory.createValueExpression(java.lang.Object,java.lang.Class) method can be used to parse an expression string and return a concrete instance of ValueExpression that encapsulates the parsed expression. The javax.el.FunctionMapper is used at parse time, not evaluation time, so one is not needed to evaluate an expression using this class. However, the javax.el.ELContext is needed at evaluation time.

The getValue(javax.el.ELContext), setValue(javax.el.ELContext,java.lang.Object), isReadOnly(javax.el.ELContext) and getType(javax.el.ELContext) methods will evaluate the expression each time they are called. The javax.el.ELResolver in the ELContext is used to resolve the top-level variables and to determine the behavior of the . and [] operators. For any of the four methods, the javax.el.ELResolver.getValue(javax.el.ELContext,java.lang.Object,java.lang.Object) method is used to resolve all properties up to but excluding the last one. This provides the base object. At the last resolution, the ValueExpression will call the corresponding javax.el.ELResolver.getValue(javax.el.ELContext,java.lang.Object,java.lang.Object), javax.el.ELResolver.setValue(javax.el.ELContext,java.lang.Object,java.lang.Object,java.lang.Object), javax.el.ELResolver.isReadOnly(javax.el.ELContext,java.lang.Object,java.lang.Object) or javax.el.ELResolver.getType(javax.el.ELContext,java.lang.Object,java.lang.Object) method, depending on which was called on the ValueExpression.

See the notes about comparison, serialization and immutability in the javax.el.Expression javadocs.

Author(s):
Jacob Hookom [jacob@hookom.net]
Version:
$Id: ValueExpressionImpl.java 1882 2011-12-06 15:27:15Z remy.maucherat@jboss.com $
See also:
javax.el.ELResolver
javax.el.Expression
javax.el.ExpressionFactory
javax.el.ValueExpression
 
 public final class ValueExpressionImpl extends ValueExpression implements
         Externalizable {
 
     private Class<?> expectedType;
 
     private String expr;
 
     private FunctionMapper fnMapper;
 
     private VariableMapper varMapper;
    private transient Node node;
    public ValueExpressionImpl() {
        super();
    }

    
    public ValueExpressionImpl(String exprNode nodeFunctionMapper fnMapper,
            VariableMapper varMapperClass<?> expectedType) {
        this. = expr;
        this. = node;
        this. = fnMapper;
        this. = varMapper;
        this. = expectedType;
    }
    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        return (obj instanceof ValueExpressionImpl && obj.hashCode() == this
                .hashCode());
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#getExpectedType()
     */
    @Override
    public Class<?> getExpectedType() {
        return this.;
    }

    
Returns the type the result of the expression will be coerced to after evaluation.

Returns:
the expectedType passed to the ExpressionFactory.createValueExpression method that created this ValueExpression.
See also:
javax.el.Expression.getExpressionString()
    @Override
    public String getExpressionString() {
        return this.;
    }

    

Returns:
Throws:
javax.el.ELException
    private Node getNode() throws ELException {
        if (this. == null) {
            this. = ExpressionBuilder.createNode(this.);
        }
        return this.;
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#getType(javax.el.ELContext)
     */
    @Override
    public Class<?> getType(ELContext contextthrows PropertyNotFoundException,
            ELException {
        EvaluationContext ctx = new EvaluationContext(contextthis.,
                this.);
        return this.getNode().getType(ctx);
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
     */
    @Override
    public Object getValue(ELContext contextthrows PropertyNotFoundException,
            ELException {
        EvaluationContext ctx = new EvaluationContext(contextthis.,
                this.);
        Object value = this.getNode().getValue(ctx);
        if (this. != null) {
            return ELSupport.coerceToType(valuethis.);
        }
        return value;
    }
    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return this.getNode().hashCode();
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#isLiteralText()
     */
    @Override
    public boolean isLiteralText() {
        try {
            return this.getNode() instanceof AstLiteralExpression;
        } catch (ELException ele) {
            return false;
        }
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
     */
    @Override
    public boolean isReadOnly(ELContext context)
            throws PropertyNotFoundExceptionELException {
        EvaluationContext ctx = new EvaluationContext(contextthis.,
                this.);
        return this.getNode().isReadOnly(ctx);
    }
    @Override
    public void readExternal(ObjectInput inthrows IOException,
            ClassNotFoundException {
        this. = in.readUTF();
        String type = in.readUTF();
        if (!"".equals(type)) {
            this. = ReflectionUtil.forName(type);
        }
        this. = (FunctionMapperin.readObject();
        this. = (VariableMapperin.readObject();
    }
    /*
     * (non-Javadoc)
     *
     * @see javax.el.ValueExpression#setValue(javax.el.ELContext,
     *      java.lang.Object)
     */
    @Override
    public void setValue(ELContext contextObject value)
            ELException {
        EvaluationContext ctx = new EvaluationContext(contextthis.,
                this.);
        this.getNode().setValue(ctxvalue);
    }
    @Override
    public void writeExternal(ObjectOutput outthrows IOException {
        out.writeUTF(this.);
        out.writeUTF((this. != null) ? this..getName()
                : "");
        out.writeObject(this.);
        out.writeObject(this.);
    }
    @Override
    public String toString() {
        return "ValueExpression["+this.+"]";
    }

    

Since:
EL 2.2
    @Override
    public ValueReference getValueReference(ELContext context) {
        EvaluationContext ctx = new EvaluationContext(contextthis.,
                this.);
        return this.getNode().getValueReference(ctx);
    }
New to GrepCode? Check out our FAQ X