Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » el » parser » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   /* Generated By:JJTree: Do not edit this line. AstIdentifier.java */
   18   
   19   package org.apache.el.parser;
   20   
   21   import javax.el.ELException;
   22   import javax.el.MethodExpression;
   23   import javax.el.MethodInfo;
   24   import javax.el.MethodNotFoundException;
   25   import javax.el.ValueExpression;
   26   import javax.el.VariableMapper;
   27   
   28   import org.apache.el.lang.EvaluationContext;
   29   
   30   
   31   /**
   32    * @author Jacob Hookom [jacob@hookom.net]
   33    * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: markt $
   34    */
   35   public final class AstIdentifier extends SimpleNode {
   36       public AstIdentifier(int id) {
   37           super(id);
   38       }
   39   
   40       public Class getType(EvaluationContext ctx) throws ELException {
   41           VariableMapper varMapper = ctx.getVariableMapper();
   42           if (varMapper != null) {
   43               ValueExpression expr = varMapper.resolveVariable(this.image);
   44               if (expr != null) {
   45                   return expr.getType(ctx.getELContext());
   46               }
   47           }
   48           ctx.setPropertyResolved(false);
   49           return ctx.getELResolver().getType(ctx, null, this.image);
   50       }
   51   
   52       public Object getValue(EvaluationContext ctx) throws ELException {
   53           VariableMapper varMapper = ctx.getVariableMapper();
   54           if (varMapper != null) {
   55               ValueExpression expr = varMapper.resolveVariable(this.image);
   56               if (expr != null) {
   57                   return expr.getValue(ctx.getELContext());
   58               }
   59           }
   60           ctx.setPropertyResolved(false);
   61           return ctx.getELResolver().getValue(ctx, null, this.image);
   62       }
   63   
   64       public boolean isReadOnly(EvaluationContext ctx) throws ELException {
   65           VariableMapper varMapper = ctx.getVariableMapper();
   66           if (varMapper != null) {
   67               ValueExpression expr = varMapper.resolveVariable(this.image);
   68               if (expr != null) {
   69                   return expr.isReadOnly(ctx.getELContext());
   70               }
   71           }
   72           ctx.setPropertyResolved(false);
   73           return ctx.getELResolver().isReadOnly(ctx, null, this.image);
   74       }
   75   
   76       public void setValue(EvaluationContext ctx, Object value)
   77               throws ELException {
   78           VariableMapper varMapper = ctx.getVariableMapper();
   79           if (varMapper != null) {
   80               ValueExpression expr = varMapper.resolveVariable(this.image);
   81               if (expr != null) {
   82                   expr.setValue(ctx.getELContext(), value);
   83                   return;
   84               }
   85           }
   86           ctx.setPropertyResolved(false);
   87           ctx.getELResolver().setValue(ctx, null, this.image, value);
   88       }
   89   
   90       private final Object invokeTarget(EvaluationContext ctx, Object target,
   91               Object[] paramValues) throws ELException {
   92           if (target instanceof MethodExpression) {
   93               MethodExpression me = (MethodExpression) target;
   94               return me.invoke(ctx.getELContext(), paramValues);
   95           } else if (target == null) {
   96               throw new MethodNotFoundException("Identity '" + this.image
   97                       + "' was null and was unable to invoke");
   98           } else {
   99               throw new ELException(
  100                       "Identity '"
  101                               + this.image
  102                               + "' does not reference a MethodExpression instance, returned type: "
  103                               + target.getClass().getName());
  104           }
  105       }
  106   
  107       public Object invoke(EvaluationContext ctx, Class[] paramTypes,
  108               Object[] paramValues) throws ELException {
  109           return this.getMethodExpression(ctx).invoke(ctx.getELContext(), paramValues);
  110       }
  111       
  112   
  113       public MethodInfo getMethodInfo(EvaluationContext ctx, Class[] paramTypes)
  114               throws ELException {
  115           return this.getMethodExpression(ctx).getMethodInfo(ctx.getELContext());
  116       }
  117   
  118       private final MethodExpression getMethodExpression(EvaluationContext ctx)
  119               throws ELException {
  120           Object obj = null;
  121   
  122           // case A: ValueExpression exists, getValue which must
  123           // be a MethodExpression
  124           VariableMapper varMapper = ctx.getVariableMapper();
  125           ValueExpression ve = null;
  126           if (varMapper != null) {
  127               ve = varMapper.resolveVariable(this.image);
  128               if (ve != null) {
  129                   obj = ve.getValue(ctx);
  130               }
  131           }
  132   
  133           // case B: evaluate the identity against the ELResolver, again, must be
  134           // a MethodExpression to be able to invoke
  135           if (ve == null) {
  136               ctx.setPropertyResolved(false);
  137               obj = ctx.getELResolver().getValue(ctx, null, this.image);
  138           }
  139   
  140           // finally provide helpful hints
  141           if (obj instanceof MethodExpression) {
  142               return (MethodExpression) obj;
  143           } else if (obj == null) {
  144               throw new MethodNotFoundException("Identity '" + this.image
  145                       + "' was null and was unable to invoke");
  146           } else {
  147               throw new ELException(
  148                       "Identity '"
  149                               + this.image
  150                               + "' does not reference a MethodExpression instance, returned type: "
  151                               + obj.getClass().getName());
  152           }
  153       }
  154   }

Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » el » parser » [javadoc | source]