Coverage Report - org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ImplicitObjectResolver
0%
0/109
0%
0/38
4.6
 
 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.ELContext;
 22  
 import javax.el.ELException;
 23  
 import javax.el.ELResolver;
 24  
 import javax.el.PropertyNotFoundException;
 25  
 import javax.el.PropertyNotWritableException;
 26  
 import java.beans.FeatureDescriptor;
 27  
 import java.util.ArrayList;
 28  
 import java.util.HashMap;
 29  
 import java.util.Iterator;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * See JSF 1.2 spec sections 5.6.1.1 and 5.6.2.1
 34  
  * 
 35  
  * @author Stan Silvert
 36  
  */
 37  
 public class ImplicitObjectResolver extends ELResolver
 38  
 {
 39  
 
 40  
     private Map<String, ImplicitObject> implicitObjects;
 41  
 
 42  
     /**
 43  
      * Static factory for an ELResolver for resolving implicit objects in JSPs. See JSF 1.2 spec section 5.6.1.1
 44  
      */
 45  
     public static ELResolver makeResolverForJSP()
 46  
     {
 47  0
         Map<String, ImplicitObject> forJSPList = new HashMap<String, ImplicitObject>(8);//4
 48  0
         ImplicitObject io1 = new FacesContextImplicitObject();
 49  0
         forJSPList.put(io1.getName(), io1);
 50  0
         ImplicitObject io2 = new ViewImplicitObject();
 51  0
         forJSPList.put(io2.getName(), io2);
 52  0
         ImplicitObject io3 = new ResourceImplicitObject();
 53  0
         forJSPList.put(io3.getName(), io3);
 54  0
         ImplicitObject io4 = new ViewScopeImplicitObject();
 55  0
         forJSPList.put(io4.getName(), io4);
 56  0
         return new ImplicitObjectResolver(forJSPList);
 57  
     }
 58  
 
 59  
     /**
 60  
      * Static factory for an ELResolver for resolving implicit objects in all of Faces. See JSF 1.2 spec section 5.6.1.2
 61  
      */
 62  
     public static ELResolver makeResolverForFaces()
 63  
     {
 64  0
         Map<String, ImplicitObject> forFacesList = new HashMap<String, ImplicitObject>(30);//14
 65  0
         ImplicitObject io1 = new ApplicationImplicitObject();
 66  0
         forFacesList.put(io1.getName(), io1);
 67  0
         ImplicitObject io2 = new ApplicationScopeImplicitObject();
 68  0
         forFacesList.put(io2.getName(), io2);
 69  0
         ImplicitObject io3 = new CookieImplicitObject();
 70  0
         forFacesList.put(io3.getName(), io3);
 71  0
         ImplicitObject io4 = new FacesContextImplicitObject();
 72  0
         forFacesList.put(io4.getName(), io4);
 73  0
         ImplicitObject io5 = new HeaderImplicitObject();
 74  0
         forFacesList.put(io5.getName(), io5);
 75  0
         ImplicitObject io6 = new HeaderValuesImplicitObject();
 76  0
         forFacesList.put(io6.getName(), io6);
 77  0
         ImplicitObject io7 = new InitParamImplicitObject();
 78  0
         forFacesList.put(io7.getName(), io7);
 79  0
         ImplicitObject io8 = new ParamImplicitObject();
 80  0
         forFacesList.put(io8.getName(), io8);
 81  0
         ImplicitObject io9 = new ParamValuesImplicitObject();
 82  0
         forFacesList.put(io9.getName(), io9);
 83  0
         ImplicitObject io10 = new RequestImplicitObject();
 84  0
         forFacesList.put(io10.getName(), io10);
 85  0
         ImplicitObject io11 = new RequestScopeImplicitObject();
 86  0
         forFacesList.put(io11.getName(), io11);
 87  0
         ImplicitObject io12 = new SessionImplicitObject();
 88  0
         forFacesList.put(io12.getName(), io12);
 89  0
         ImplicitObject io13 = new SessionScopeImplicitObject();
 90  0
         forFacesList.put(io13.getName(), io13);
 91  0
         ImplicitObject io14 = new ViewImplicitObject();
 92  0
         forFacesList.put(io14.getName(), io14);
 93  0
         ImplicitObject io15 = new ComponentImplicitObject();
 94  0
         forFacesList.put(io15.getName(), io15);
 95  0
         ImplicitObject io16 = new ResourceImplicitObject();
 96  0
         forFacesList.put(io16.getName(), io16);
 97  0
         ImplicitObject io17 = new ViewScopeImplicitObject();
 98  0
         forFacesList.put(io17.getName(), io17);
 99  0
         ImplicitObject io18 = new CompositeComponentImplicitObject();
 100  0
         forFacesList.put(io18.getName(), io18);
 101  0
         ImplicitObject io19 = new FlowScopeImplicitObject();
 102  0
         forFacesList.put(io19.getName(), io19);
 103  0
         return new ImplicitObjectResolver(forFacesList);
 104  
     }
 105  
 
 106  
     private ImplicitObjectResolver()
 107  
     {
 108  0
         super();
 109  0
         this.implicitObjects = new HashMap<String, ImplicitObject>();
 110  0
     }
 111  
 
 112  
     /** Creates a new instance of ImplicitObjectResolverForJSP */
 113  
     private ImplicitObjectResolver(Map<String, ImplicitObject> implicitObjects)
 114  
     {
 115  0
         this();
 116  0
         this.implicitObjects = implicitObjects;
 117  0
     }
 118  
 
 119  
     @Override
 120  
     public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException,
 121  
         PropertyNotFoundException, PropertyNotWritableException, ELException
 122  
     {
 123  
 
 124  0
         if (base != null)
 125  
         {
 126  0
             return;
 127  
         }
 128  0
         if (property == null)
 129  
         {
 130  0
             throw new PropertyNotFoundException();
 131  
         }
 132  0
         if (!(property instanceof String))
 133  
         {
 134  0
             return;
 135  
         }
 136  
 
 137  0
         String strProperty = property.toString();
 138  
 
 139  0
         if (implicitObjects.containsKey(strProperty))
 140  
         {
 141  0
             throw new PropertyNotWritableException();
 142  
         }
 143  0
     }
 144  
 
 145  
     @Override
 146  
     public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException,
 147  
         PropertyNotFoundException, ELException
 148  
     {
 149  
 
 150  0
         if (base != null)
 151  
         {
 152  0
             return false;
 153  
         }
 154  0
         if (property == null)
 155  
         {
 156  0
             throw new PropertyNotFoundException();
 157  
         }
 158  0
         if (!(property instanceof String))
 159  
         {
 160  0
             return false;
 161  
         }
 162  
 
 163  0
         String strProperty = property.toString();
 164  
 
 165  0
         if (implicitObjects.containsKey(strProperty))
 166  
         {
 167  0
             context.setPropertyResolved(true);
 168  0
             return true;
 169  
         }
 170  
 
 171  0
         return false;
 172  
     }
 173  
 
 174  
     @Override
 175  
     public Object getValue(ELContext context, Object base, Object property) throws NullPointerException,
 176  
         PropertyNotFoundException, ELException
 177  
     {
 178  
 
 179  0
         if (base != null)
 180  
         {
 181  0
             return null;
 182  
         }
 183  0
         if (property == null)
 184  
         {
 185  0
             throw new PropertyNotFoundException();
 186  
         }
 187  0
         if (!(property instanceof String))
 188  
         {
 189  0
             return null;
 190  
         }
 191  
 
 192  0
         String strProperty = property.toString();
 193  
 
 194  0
         ImplicitObject obj = implicitObjects.get(strProperty);
 195  0
         if (obj != null)
 196  
         {
 197  0
             context.setPropertyResolved(true);
 198  0
             return obj.getValue(context);
 199  
         }
 200  
 
 201  0
         return null;
 202  
     }
 203  
 
 204  
     @Override
 205  
     public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException,
 206  
         PropertyNotFoundException, ELException
 207  
     {
 208  
 
 209  0
         if (base != null)
 210  
         {
 211  0
             return null;
 212  
         }
 213  0
         if (property == null)
 214  
         {
 215  0
             throw new PropertyNotFoundException();
 216  
         }
 217  0
         if (!(property instanceof String))
 218  
         {
 219  0
             return null;
 220  
         }
 221  
 
 222  0
         String strProperty = property.toString();
 223  
 
 224  0
         if (implicitObjects.containsKey(strProperty))
 225  
         {
 226  0
             context.setPropertyResolved(true);
 227  
         }
 228  
 
 229  0
         return null;
 230  
     }
 231  
 
 232  
     @Override
 233  
     public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
 234  
     {
 235  0
         if (base != null)
 236  
         {
 237  0
             return null;
 238  
         }
 239  
 
 240  0
         ArrayList<FeatureDescriptor> descriptors = new ArrayList<FeatureDescriptor>(implicitObjects.size());
 241  
 
 242  0
         for (ImplicitObject obj : implicitObjects.values())
 243  
         {
 244  0
             descriptors.add(obj.getDescriptor());
 245  0
         }
 246  
 
 247  0
         return descriptors.iterator();
 248  
     }
 249  
 
 250  
     @Override
 251  
     public Class<?> getCommonPropertyType(ELContext context, Object base)
 252  
     {
 253  0
         if (base != null)
 254  
         {
 255  0
             return null;
 256  
         }
 257  
 
 258  0
         return String.class;
 259  
     }
 260  
 
 261  
 }