Coverage Report - org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ImplicitObjectResolver
0%
0/82
0%
0/38
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.el.unified.resolver.implicitobject;
 20  
 
 21  
 import javax.el.*;
 22  
 import java.beans.FeatureDescriptor;
 23  
 import java.util.ArrayList;
 24  
 import java.util.HashMap;
 25  
 import java.util.Iterator;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * See JSF 1.2 spec sections 5.6.1.1 and 5.6.2.1
 30  
  *
 31  
  * @author Stan Silvert
 32  
  */
 33  
 public class ImplicitObjectResolver extends ELResolver {
 34  
     
 35  
     private Map<String, ImplicitObject> implicitObjects;
 36  
     
 37  
     /**
 38  
      * Static factory for an ELResolver for resolving implicit objects in JSPs. 
 39  
      * See JSF 1.2 spec section 5.6.1.1
 40  
      */
 41  
     public static ELResolver makeResolverForJSP() {
 42  0
         Map<String, ImplicitObject> forJSPList = new HashMap<String, ImplicitObject>(2);
 43  0
         ImplicitObject io1 = new FacesContextImplicitObject();
 44  0
         forJSPList.put(io1.getName(), io1);
 45  0
         ImplicitObject io2 = new ViewImplicitObject();
 46  0
         forJSPList.put(io2.getName(), io2);
 47  0
         return new ImplicitObjectResolver(forJSPList);
 48  
     }
 49  
     
 50  
     /**
 51  
      * Static factory for an ELResolver for resolving implicit objects in all of Faces. 
 52  
      * See JSF 1.2 spec section 5.6.1.2
 53  
      */
 54  
     public static ELResolver makeResolverForFaces() {
 55  0
         Map<String, ImplicitObject> forFacesList = new HashMap<String, ImplicitObject>(14);
 56  0
         ImplicitObject io1 = new ApplicationImplicitObject();
 57  0
         forFacesList.put(io1.getName(), io1);
 58  0
         ImplicitObject io2 = new ApplicationScopeImplicitObject();
 59  0
         forFacesList.put(io2.getName(), io2);
 60  0
         ImplicitObject io3 = new CookieImplicitObject();
 61  0
         forFacesList.put(io3.getName(), io3);
 62  0
         ImplicitObject io4 = new FacesContextImplicitObject();
 63  0
         forFacesList.put(io4.getName(), io4);
 64  0
         ImplicitObject io5 = new HeaderImplicitObject();
 65  0
         forFacesList.put(io5.getName(), io5);
 66  0
         ImplicitObject io6 = new HeaderValuesImplicitObject();
 67  0
         forFacesList.put(io6.getName(), io6);
 68  0
         ImplicitObject io7 = new InitParamImplicitObject();
 69  0
         forFacesList.put(io7.getName(), io7);
 70  0
         ImplicitObject io8 = new ParamImplicitObject();
 71  0
         forFacesList.put(io8.getName(), io8);
 72  0
         ImplicitObject io9 = new ParamValuesImplicitObject();
 73  0
         forFacesList.put(io9.getName(), io9);
 74  0
         ImplicitObject io10 = new RequestImplicitObject();
 75  0
         forFacesList.put(io10.getName(), io10);
 76  0
         ImplicitObject io11 = new RequestScopeImplicitObject();
 77  0
         forFacesList.put(io11.getName(), io11);
 78  0
         ImplicitObject io12 = new SessionImplicitObject();
 79  0
         forFacesList.put(io12.getName(), io12);
 80  0
         ImplicitObject io13 = new SessionScopeImplicitObject();
 81  0
         forFacesList.put(io13.getName(), io13);
 82  0
         ImplicitObject io14 = new ViewImplicitObject();
 83  0
         forFacesList.put(io14.getName(), io14);
 84  0
         return new ImplicitObjectResolver(forFacesList);        
 85  
     }
 86  
     
 87  
     
 88  
     private ImplicitObjectResolver() {
 89  0
         super();
 90  0
         this.implicitObjects = new HashMap<String, ImplicitObject>();
 91  0
     }
 92  
     
 93  
     /** Creates a new instance of ImplicitObjectResolverForJSP */
 94  
     private ImplicitObjectResolver(Map<String, ImplicitObject> implicitObjects) {
 95  0
         this();
 96  0
         this.implicitObjects = implicitObjects;
 97  0
     }
 98  
 
 99  
     public void setValue(ELContext context, Object base, Object property, Object value) 
 100  
         throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
 101  
         
 102  0
         if (base != null) return;
 103  0
         if (property == null) throw new PropertyNotFoundException();
 104  0
         if (!(property instanceof String)) return;
 105  
         
 106  0
         String strProperty = castAndIntern(property);
 107  
         
 108  0
         if (implicitObjects.containsKey(strProperty)) {
 109  0
             throw new PropertyNotWritableException();
 110  
         }
 111  0
     }
 112  
     
 113  
     public boolean isReadOnly(ELContext context, Object base, Object property) 
 114  
         throws NullPointerException, PropertyNotFoundException, ELException {
 115  
         
 116  0
         if (base != null) return false;
 117  0
         if (property == null) throw new PropertyNotFoundException();
 118  0
         if (!(property instanceof String)) return false;
 119  
         
 120  0
         String strProperty = castAndIntern(property);
 121  
         
 122  0
         if (implicitObjects.containsKey(strProperty)) {
 123  0
             context.setPropertyResolved(true);
 124  0
             return true;
 125  
         }
 126  
         
 127  0
         return false;
 128  
     }
 129  
 
 130  
     public Object getValue(ELContext context, Object base, Object property) 
 131  
         throws NullPointerException, PropertyNotFoundException, ELException {
 132  
 
 133  0
         if (base != null) return null;
 134  0
         if (property == null) throw new PropertyNotFoundException();      
 135  0
         if (!(property instanceof String)) return null;
 136  
             
 137  0
         String strProperty = castAndIntern(property);
 138  
 
 139  0
         ImplicitObject obj = implicitObjects.get(strProperty);
 140  0
         if (obj != null) {
 141  0
             context.setPropertyResolved(true);
 142  0
             return obj.getValue(context);
 143  
         }
 144  
         
 145  0
         return null;
 146  
     }
 147  
 
 148  
     public Class<?> getType(ELContext context, Object base, Object property) 
 149  
         throws NullPointerException, PropertyNotFoundException, ELException {
 150  
         
 151  0
         if (base != null) return null;
 152  0
         if (property == null) throw new PropertyNotFoundException();
 153  0
         if (!(property instanceof String)) return null;
 154  
         
 155  0
         String strProperty = castAndIntern(property);
 156  
         
 157  0
         if (implicitObjects.containsKey(strProperty)) {
 158  0
             context.setPropertyResolved(true);
 159  
         }
 160  
         
 161  0
         return null;
 162  
     }
 163  
 
 164  
     public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
 165  0
         if (base != null) return null;
 166  
 
 167  0
         ArrayList<FeatureDescriptor> descriptors = new ArrayList<FeatureDescriptor>(implicitObjects.size());
 168  
         
 169  0
         for (ImplicitObject obj: implicitObjects.values()) {
 170  0
             descriptors.add(obj.getDescriptor());
 171  
          }
 172  
         
 173  0
         return descriptors.iterator();
 174  
     }
 175  
 
 176  
     public Class<?> getCommonPropertyType(ELContext context, Object base) {
 177  0
         if (base != null) return null;
 178  
         
 179  0
         return String.class;
 180  
     }
 181  
     
 182  
     protected String castAndIntern(Object o) {
 183  0
         String s = (String)o;
 184  0
         return s.intern();
 185  
     }
 186  
     
 187  
 }