2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.test.el.FacesVariableResolverChainWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
FacesVariableResolverChainWrapper
100%
3/3
N/A
3.5
 
 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  
 
 18  
 package org.apache.shale.test.el;
 19  
 
 20  
 import java.util.Iterator;
 21  
 
 22  
 import javax.el.ELContext;
 23  
 import javax.el.ELException;
 24  
 import javax.el.PropertyNotFoundException;
 25  
 import javax.faces.context.ExternalContext;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.el.VariableResolver;
 28  
 
 29  
 /**
 30  
  * <p><code>ELResolver</code> implementation that wraps the legacy (JSF 1.1)
 31  
  * <code>VariableResolver</code> chain.  See the JSF 1.2 Specification, section
 32  
  * 5.6.1.5, for requirements implemented by this class.</p>
 33  
  *
 34  
  * @since 1.0.4
 35  
  */
 36  1
 public class FacesVariableResolverChainWrapper extends AbstractELResolver {
 37  
     
 38  
 
 39  
     /**
 40  
      * <p>Return the most general type this resolver accepts for the
 41  
      * <code>property</code> argument.</p>
 42  
      */
 43  
     public Class getCommonPropertyType(ELContext context, Object base) {
 44  
 
 45  
         if (base != null) {
 46  
             return null;
 47  
         } else {
 48  
             return String.class;
 49  
         }
 50  
 
 51  
     }
 52  
 
 53  
 
 54  
     /**
 55  
      * <p>Return an <code>Iterator</code> over the attributes that this
 56  
      * resolver knows how to deal with.</p>
 57  
      *
 58  
      * @param context <code>ELContext</code> for evaluating this value
 59  
      * @param base Base object against which this evaluation occurs
 60  
      */
 61  
     public Iterator getFeatureDescriptors(ELContext context, Object base) {
 62  
 
 63  
         return null;
 64  
 
 65  
     }
 66  
 
 67  
 
 68  
 
 69  
     /**
 70  
      * <p>Return the Java type of the specified property.</p>
 71  
      *
 72  
      * @param context <code>ELContext</code> for evaluating this value
 73  
      * @param base Base object against which this evaluation occurs
 74  
      *  (must be null because we are evaluating a top level variable)
 75  
      * @param property Property name to be accessed
 76  
      */
 77  
     public Class getType(ELContext context, Object base, Object property) {
 78  
 
 79  
         if ((base == null) && (property == null)) {
 80  
             throw new PropertyNotFoundException("No property specified");
 81  
         }
 82  
         return null;
 83  
 
 84  
     }
 85  
 
 86  
 
 87  
     /**
 88  
      * <p>Evaluate with the legacy variable resolver chain and return
 89  
      * the value.</p>
 90  
      *
 91  
      * @param context <code>ELContext</code> for evaluating this value
 92  
      * @param base Base object against which this evaluation occurs
 93  
      *  (must be null because we are evaluating a top level variable)
 94  
      * @param property Property name to be accessed
 95  
      */
 96  
     public Object getValue(ELContext context, Object base, Object property) {
 97  
 
 98  1
         if (base != null) {
 99  1
             return null;
 100  
         }
 101  
         if (property == null) {
 102  
             throw new PropertyNotFoundException("No property specified");
 103  
         }
 104  
 
 105  
         FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class);
 106  
         ExternalContext econtext = fcontext.getExternalContext();
 107  
         String name = property.toString();
 108  
 
 109  
         context.setPropertyResolved(true);
 110  
         ELContext elContext = fcontext.getELContext();
 111  
         VariableResolver vr = fcontext.getApplication().getVariableResolver();
 112  
         try {
 113  
             return vr.resolveVariable(fcontext, name);
 114  
         } catch (Exception e) {
 115  
             context.setPropertyResolved(false);
 116  
             throw new ELException(e);
 117  
         }
 118  
 
 119  
     }
 120  
 
 121  
 
 122  
     /**
 123  
      * <p>Return <code>true</code> if the specified property is read only.</p>
 124  
      *
 125  
      * @param context <code>ELContext</code> for evaluating this value
 126  
      * @param base Base object against which this evaluation occurs
 127  
      *  (must be null because we are evaluating a top level variable)
 128  
      * @param property Property name to be accessed
 129  
      */
 130  
     public boolean isReadOnly(ELContext context, Object base, Object property) {
 131  
 
 132  
         if ((base == null) && (property == null)) {
 133  
             throw new PropertyNotFoundException("No property specified");
 134  
         }
 135  
         return false;
 136  
 
 137  
     }
 138  
 
 139  
 
 140  
 
 141  
     /**
 142  
      * <p>Set the value of a scoped object for the specified name.</p>
 143  
      *
 144  
      * @param context <code>ELContext</code> for evaluating this value
 145  
      * @param base Base object against which this evaluation occurs
 146  
      *  (must be null because we are evaluating a top level variable)
 147  
      * @param property Property name to be accessed
 148  
      * @param value New value to be set
 149  
      */
 150  
     public void setValue(ELContext context, Object base, Object property, Object value) {
 151  
 
 152  
         if ((base == null) && (property == null)) {
 153  
             throw new PropertyNotFoundException("No property specified");
 154  
         }
 155  
 
 156  
     }
 157  
 
 158  
 
 159  
 }