View Javadoc

    1   /*
    2    * Copyright 1999-2004 The Apache Software Foundation
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *     http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.jxpath.ri.compiler;
    17
    18  import org.apache.commons.jxpath.ri.QName;
    19  import org.apache.commons.jxpath.ri.EvalContext;
    20
    21  /***
    22   * An element of the compile tree holding a variable reference.
    23   *
    24   * @author Dmitri Plotnikov
    25   * @version $Revision: 1.9 $ $Date: 2004/02/29 14:17:38 $
    26   */
    27  public class VariableReference extends Expression {
    28
    29      private QName varName;
    30
    31      public VariableReference(QName varName) {
    32          this.varName = varName;
    33      }
    34
    35      public QName getVariableName() {
    36          return varName;
    37      }
    38
    39      public String toString() {
    40          return "$" + varName;
    41      }
    42
    43      public boolean isContextDependent() {
    44          return false;
    45      }
    46
    47      public boolean computeContextDependent() {
    48          return false;
    49      }
    50
    51      public Object compute(EvalContext context) {
    52          return computeValue(context);
    53      }
    54
    55      /***
    56       * Returns the value of the variable.
    57       */
    58      public Object computeValue(EvalContext context) {
    59          return context.getRootContext().getVariableContext(varName);
    60      }
    61  }