Coverage Report - javax.faces.component.UIViewRoot
 
Classes in this File Line Coverage Branch Coverage Complexity
UIViewRoot
29%
153/511
18%
62/330
3.959
UIViewRoot$1
N/A
N/A
3.959
UIViewRoot$ApplyRequestValuesPhaseProcessor
16%
1/6
0%
0/4
3.959
UIViewRoot$Events
100%
7/7
62%
5/8
3.959
UIViewRoot$PhaseProcessor
N/A
N/A
3.959
UIViewRoot$ProcessValidatorPhaseProcessor
16%
1/6
0%
0/4
3.959
UIViewRoot$PropertyKeys
100%
9/9
N/A
3.959
UIViewRoot$ResetValuesCallback
25%
1/4
0%
0/2
3.959
UIViewRoot$UpdateModelPhaseProcessor
16%
1/6
0%
0/4
3.959
UIViewRoot$ViewScope
0%
0/5
N/A
3.959
 
 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 javax.faces.component;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Arrays;
 24  
 import java.util.Collection;
 25  
 import java.util.Collections;
 26  
 import java.util.HashMap;
 27  
 import java.util.Iterator;
 28  
 import java.util.LinkedList;
 29  
 import java.util.List;
 30  
 import java.util.Locale;
 31  
 import java.util.Map;
 32  
 import java.util.logging.Level;
 33  
 import java.util.logging.Logger;
 34  
 
 35  
 import javax.el.MethodExpression;
 36  
 import javax.el.ValueExpression;
 37  
 import javax.faces.FactoryFinder;
 38  
 import javax.faces.application.ProjectStage;
 39  
 import javax.faces.component.visit.VisitCallback;
 40  
 import javax.faces.component.visit.VisitContext;
 41  
 import javax.faces.component.visit.VisitResult;
 42  
 import javax.faces.context.FacesContext;
 43  
 import javax.faces.context.PartialViewContext;
 44  
 import javax.faces.event.AbortProcessingException;
 45  
 import javax.faces.event.ExceptionQueuedEvent;
 46  
 import javax.faces.event.ExceptionQueuedEventContext;
 47  
 import javax.faces.event.FacesEvent;
 48  
 import javax.faces.event.PhaseEvent;
 49  
 import javax.faces.event.PhaseId;
 50  
 import javax.faces.event.PhaseListener;
 51  
 import javax.faces.event.PostConstructViewMapEvent;
 52  
 import javax.faces.event.PreDestroyViewMapEvent;
 53  
 import javax.faces.event.SystemEvent;
 54  
 import javax.faces.event.SystemEventListener;
 55  
 import javax.faces.lifecycle.Lifecycle;
 56  
 import javax.faces.lifecycle.LifecycleFactory;
 57  
 import javax.faces.view.ViewDeclarationLanguage;
 58  
 import javax.faces.view.ViewMetadata;
 59  
 import javax.faces.webapp.FacesServlet;
 60  
 
 61  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
 62  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
 63  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
 64  
 
 65  
 /**
 66  
  * Creates a JSF View, which is a container that holds all of the components that are part of the view.
 67  
  * <p>
 68  
  * Unless otherwise specified, all attributes accept static values or EL expressions.
 69  
  * </p>
 70  
  * <p>
 71  
  * See the javadoc for this class in the <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF
 72  
  * Specification</a> for further details.
 73  
  * </p>
 74  
  */
 75  2
 @JSFComponent(name = "f:view", bodyContent = "JSP", tagClass = "org.apache.myfaces.taglib.core.ViewTag")
 76  
 @JSFJspProperty(name = "binding", returnType = "java.lang.String", tagExcluded = true)
 77  0
 public class UIViewRoot extends UIComponentBase implements UniqueIdVendor
 78  
 {
 79  
     public static final String COMPONENT_FAMILY = "javax.faces.ViewRoot";
 80  
     public static final String COMPONENT_TYPE = "javax.faces.ViewRoot";
 81  
     public static final String METADATA_FACET_NAME = "javax_faces_metadata";
 82  
     public static final String UNIQUE_ID_PREFIX = "j_id";
 83  
     public static final String VIEW_PARAMETERS_KEY = "javax.faces.component.VIEW_PARAMETERS_KEY";
 84  
 
 85  568
     private transient Logger logger = null;
 86  
 
 87  2
     private static final PhaseProcessor APPLY_REQUEST_VALUES_PROCESSOR = new ApplyRequestValuesPhaseProcessor();
 88  2
     private static final PhaseProcessor PROCESS_VALIDATORS_PROCESSOR = new ProcessValidatorPhaseProcessor();
 89  2
     private static final PhaseProcessor UPDATE_MODEL_PROCESSOR = new UpdateModelPhaseProcessor();
 90  
 
 91  2
     private static final VisitCallback RESET_VALUES_CALLBACK = new ResetValuesCallback();
 92  
     
 93  
     /**
 94  
      * Class that is used to create the view scope map. This strategy
 95  
      * allows change the implementation of view scope map to use cdi or
 96  
      * whatever without change UIViewRoot implementation.
 97  
      */
 98  
     private static final Class<?> VIEW_SCOPE_PROXY_MAP_CLASS;
 99  
 
 100  
     static
 101  
     {
 102  2
         Class<?> viewMapClass = null;
 103  
         try
 104  
         {
 105  2
             viewMapClass = _ClassUtils.classForName(
 106  
                 "org.apache.myfaces.view.ViewScopeProxyMap");
 107  
         }
 108  2
         catch (Exception e)
 109  
         {
 110  
             // no op
 111  0
         }
 112  2
         VIEW_SCOPE_PROXY_MAP_CLASS = viewMapClass;
 113  2
     }
 114  
 
 115  
     /**
 116  
      * The counter which will ensure a unique component id for every component instance in the tree that doesn't have an
 117  
      * id attribute set.
 118  
      */
 119  
     //private long _uniqueIdCounter = 0;
 120  
 
 121  
     // todo: is it right to save the state of _events and _phaseListeners?
 122  
     private List<FacesEvent> _events;
 123  
 
 124  
     /**
 125  
      * Map containing view scope objects. 
 126  
      * 
 127  
      * It is not expected this map hold PartialStateHolder instances,
 128  
      * so we can use saveAttachedState and restoreAttachedState methods.
 129  
      */
 130  
     private Map<String, Object> _viewScope;
 131  568
     private transient boolean _restoreViewScopeStateCalled = false;
 132  
 
 133  568
     private transient Lifecycle _lifecycle = null;
 134  
     
 135  
     private HashMap<Class<? extends SystemEvent>, List<SystemEventListener>> _systemEventListeners;
 136  
     
 137  
     // Tracks success in the beforePhase. Listeners that threw an exception
 138  
     // in beforePhase or were never called, because a previous listener threw
 139  
     // an exception, should not have their afterPhase method called
 140  
     private transient Map<PhaseId, boolean[]> listenerSuccessMap;
 141  
     
 142  
     private static final String JAVAX_FACES_LOCATION_PREFIX = "javax_faces_location_";
 143  
     private static final String JAVAX_FACES_LOCATION_HEAD = "javax_faces_location_head";
 144  
     private static final String JAVAX_FACES_LOCATION_BODY = "javax_faces_location_body";
 145  
     private static final String JAVAX_FACES_LOCATION_FORM = "javax_faces_location_form";
 146  
     
 147  
     private static final String SKIP_VIEW_MAP_SAVE_STATE = "oam.viewPool.SKIP_VIEW_MAP_SAVE_STATE";
 148  
     
 149  568
     private transient int _resetSaveStateMode = 0;
 150  
     private transient boolean _resourceDependencyUniqueId;
 151  
     private transient Map<String,Object> _attributesMap;
 152  
     
 153  
     /**
 154  
      * Construct an instance of the UIViewRoot.
 155  
      */
 156  
     public UIViewRoot()
 157  568
     {
 158  568
         setRendererType(null);
 159  568
     }
 160  
 
 161  
     /**
 162  
      * @since 2.0
 163  
      */
 164  
     public void addComponentResource(FacesContext context, UIComponent componentResource)
 165  
     {
 166  0
         addComponentResource(context, componentResource, null);
 167  0
     }
 168  
 
 169  
     /**
 170  
      * @since 2.0
 171  
      */
 172  
     public void addComponentResource(FacesContext context, UIComponent componentResource, String target)
 173  
     {
 174  
         // If the target argument is null
 175  0
         if (target == null)
 176  
         {
 177  
             // Look for a target attribute on the component
 178  0
             target = (String)componentResource.getAttributes().get("target");
 179  
 
 180  
             // If there is no target attribute, set target to be the default value head
 181  0
             if (target == null)
 182  
             {
 183  0
                 target = "head";
 184  
             }
 185  
         }
 186  
 
 187  
         // Call getComponentResources to obtain the child list for the given target
 188  0
         List<UIComponent> componentResources = _getComponentResources(context, target);
 189  
 
 190  
         // If the component ID of componentResource matches the ID of a resource
 191  
         // that has already been added, remove the old resource.
 192  0
         String componentId = componentResource.getId();
 193  
         
 194  0
         if (componentId == null)
 195  
         {
 196  
             // componentResource can have no id - calling createUniqueId makes us sure that component will have one
 197  
             // https://issues.apache.org/jira/browse/MYFACES-2775
 198  0
             componentId = createUniqueId(context, null);
 199  0
             componentResource.setId(componentId);
 200  
         }
 201  
         
 202  
         // This var helps to handle the case when we try to add a component that already is
 203  
         // on the resource list, because PostAddToViewEvent also is sent to components 
 204  
         // backing resources. The problem start when a component is already inside
 205  
         // componentResources list and we try to relocate it again. This leads to a StackOverflowException
 206  
         // so we need to check if a component is and prevent remove and add it again. Note
 207  
         // that remove and then add a component trigger another PostAddToViewEvent. The right
 208  
         // point to prevent this StackOverflowException is here, because this method is 
 209  
         // responsible to traverse the componentResources list and add when necessary.
 210  0
         boolean alreadyAdded = false;
 211  
 
 212  
         //The check is only necessary if the component resource is part of the tree.
 213  0
         if (componentResource.isInView())
 214  
         {
 215  0
             if (componentResource.getParent() != null &&
 216  
                 componentResource.getParent().getId() != null &&
 217  
                 componentResource.getParent().getId().equals(JAVAX_FACES_LOCATION_PREFIX + target))
 218  
             {
 219  
                 // We can assume safely that the component is in place, because there is no way to 
 220  
                 // put a component resource on a component resource container without call addComponentResource
 221  
                 // so relocation here will not happen.
 222  0
                 alreadyAdded = true;
 223  
             }
 224  0
             else if (componentId != null)
 225  
             {
 226  0
                 for(Iterator<UIComponent> it = componentResources.iterator(); it.hasNext();)
 227  
                 {
 228  0
                     UIComponent component = it.next();
 229  0
                     if(componentId.equals(component.getId()) && componentResource != component)
 230  
                     {
 231  0
                         if (!component.isCachedFacesContext())
 232  
                         {
 233  
                             try
 234  
                             {
 235  0
                                 component.setCachedFacesContext(context);
 236  0
                                 it.remove();
 237  
                             }
 238  
                             finally
 239  
                             {
 240  0
                                 component.setCachedFacesContext(null);
 241  0
                             }
 242  
                         }
 243  
                         else
 244  
                         {
 245  0
                             it.remove();
 246  
                         }
 247  
                     }
 248  0
                     else if (componentResource == component)
 249  
                     {
 250  0
                         alreadyAdded = true;
 251  
                     }
 252  0
                 }
 253  
             }
 254  
         }
 255  0
         else if (componentId != null)
 256  
         {
 257  0
             for(Iterator<UIComponent> it = componentResources.iterator(); it.hasNext();)
 258  
             {
 259  0
                 UIComponent component = it.next();
 260  0
                 if(componentId.equals(component.getId()) && componentResource != component)
 261  
                 {
 262  0
                     if (!component.isCachedFacesContext())
 263  
                     {
 264  
                         try
 265  
                         {
 266  0
                             component.setCachedFacesContext(context);
 267  0
                             it.remove();
 268  
                         }
 269  
                         finally
 270  
                         {
 271  0
                             component.setCachedFacesContext(null);
 272  0
                         }
 273  
                     }
 274  
                     else
 275  
                     {
 276  0
                         it.remove();
 277  
                     }
 278  
                 }
 279  0
                 else if (componentResource == component)
 280  
                 {
 281  0
                     alreadyAdded = true;
 282  
                 }
 283  0
             }
 284  
         }
 285  
         
 286  
         // Add the component resource to the list
 287  0
         if (!alreadyAdded)
 288  
         {
 289  0
             if (!componentResource.isCachedFacesContext())
 290  
             {
 291  
                 try
 292  
                 {
 293  0
                     componentResource.setCachedFacesContext(context);
 294  0
                     componentResources.add(componentResource);
 295  
                 }
 296  
                 finally
 297  
                 {
 298  0
                     componentResource.setCachedFacesContext(context);
 299  0
                 }
 300  
             }
 301  
             else
 302  
             {
 303  0
                 componentResources.add(componentResource);
 304  
             }
 305  
         }
 306  0
     }
 307  
 
 308  
     /**
 309  
      * Adds a The phaseListeners attached to ViewRoot.
 310  
      */
 311  
     public void addPhaseListener(PhaseListener phaseListener)
 312  
     {
 313  12
         if (phaseListener == null)
 314  
         {
 315  0
             throw new NullPointerException("phaseListener");
 316  
         }
 317  
         
 318  12
         getStateHelper().add(PropertyKeys.phaseListeners, phaseListener);
 319  12
     }
 320  
 
 321  
     /**
 322  
      * @since 2.0
 323  
      */
 324  
     public void broadcastEvents(FacesContext context, PhaseId phaseId)
 325  
     {
 326  8
         if (_events == null)
 327  
         {
 328  4
             return;
 329  
         }
 330  
         
 331  4
         Events events = _getEvents(phaseId);
 332  
         
 333  
         // Spec. 3.4.2.6 Event Broadcasting:
 334  
         // Queue one or more additional events, from the same source
 335  
         // component or a different one, for processing during the
 336  
         // current lifecycle phase.
 337  
         
 338  
         // Unfortunately with that requirement it is easy to create infinite loop in processing. One example can be:
 339  
         //
 340  
         // public processAction(ActionEvent actionEvent)
 341  
         // {
 342  
         // actionEvent  = new ActionEvent(actionEvent.getComponent());
 343  
         // actionEvent.queue();
 344  
         // }
 345  
         // 
 346  
         // Thus we iterate here only 15x. If iteration overreachs 15 we output a warning  
 347  
         
 348  4
         int loops = 0;
 349  4
         int maxLoops = 15;
 350  4
         Collection<FacesEvent> eventsAborted = new LinkedList<FacesEvent>(); 
 351  
         do
 352  
         {
 353  
             // First broadcast events that have been queued for PhaseId.ANY_PHASE.
 354  32
             boolean noUnexpectedException = _broadcastAll(context, events.getAnyPhase(), eventsAborted);
 355  32
             if (!noUnexpectedException)
 356  
             {
 357  0
                 return;
 358  
             }
 359  32
             List<FacesEvent> eventsOnPhase = events.getOnPhase();
 360  32
             if (!eventsAborted.isEmpty())
 361  
             {
 362  0
                 eventsOnPhase.removeAll(eventsAborted);
 363  0
                 eventsAborted.clear();
 364  
             }
 365  32
             noUnexpectedException = _broadcastAll(context, eventsOnPhase, eventsAborted);
 366  32
             if (!noUnexpectedException)
 367  
             {
 368  0
                 return;
 369  
             }
 370  
 
 371  32
             events = _getEvents(phaseId);
 372  32
             loops++;
 373  
             
 374  32
         } while (events.hasMoreEvents() && loops < maxLoops);
 375  
         
 376  4
         if (loops == maxLoops && events.hasMoreEvents())
 377  
         {
 378  
             // broadcast reach maxLoops - probably a infinitive recursion:
 379  2
             boolean production = getFacesContext().isProjectStage(ProjectStage.Production);
 380  2
             Level level = production ? Level.FINE : Level.WARNING;
 381  2
             if (_getLogger().isLoggable(level))
 382  
             {
 383  2
                 List<String> name = new ArrayList<String>(events.getAnyPhase().size() + events.getOnPhase().size());
 384  2
                 for (FacesEvent facesEvent : events.getAnyPhase())
 385  
                 {
 386  0
                     String clientId = facesEvent.getComponent().getClientId(getFacesContext());
 387  0
                     name.add(clientId);
 388  0
                 }
 389  2
                 for (FacesEvent facesEvent : events.getOnPhase())
 390  
                 {
 391  4
                     String clientId = facesEvent.getComponent().getClientId(getFacesContext());
 392  4
                     name.add(clientId);
 393  4
                 }
 394  2
                 _getLogger().log(level,
 395  
                         "Event broadcating for PhaseId {0} at UIViewRoot {1} reaches maximal limit, please check " +
 396  
                         "listeners for infinite recursion. Component id: {2}",
 397  
                         new Object [] {phaseId, getViewId(), name});
 398  
             }
 399  
         }
 400  4
     }
 401  
 
 402  
 
 403  
     /**
 404  
      * Provides a unique id for this component instance.
 405  
      */
 406  
     public String createUniqueId()
 407  
     {
 408  20106
         return createUniqueId(getFacesContext(), null);
 409  
     }
 410  
 
 411  
     /**
 412  
      * 
 413  
      * {@inheritDoc}
 414  
      * 
 415  
      * @since 2.0
 416  
      */
 417  
     public String createUniqueId(FacesContext context, String seed)
 418  
     {
 419  
 
 420  
         // Generate an identifier for a component. The identifier will be prefixed with
 421  
         // UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.
 422  20108
         if(seed==null)
 423  
         {
 424  20108
             if (isResourceDependencyUniqueId())
 425  
             {
 426  0
                 Integer uniqueIdCounter = (Integer) getStateHelper().get(
 427  
                     PropertyKeys.resourceDependencyUniqueIdCounter);
 428  0
                 uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
 429  0
                 getStateHelper().put(PropertyKeys.resourceDependencyUniqueIdCounter, (uniqueIdCounter+1));
 430  0
                 if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_RD_IDS_SIZE)
 431  
                 {
 432  0
                     StringBuilder bld = _getSharedStringBuilder(context);
 433  0
                     return bld.append(UNIQUE_ID_PREFIX).append(
 434  
                         _ComponentUtils.RD_ID_PREFIX).append(uniqueIdCounter).toString();
 435  
                 }
 436  
                 else
 437  
                 {
 438  0
                     return _ComponentUtils.UNIQUE_COMPONENT_RD_IDS[uniqueIdCounter];
 439  
                 }
 440  
             }
 441  
             else
 442  
             {
 443  20108
                 Integer uniqueIdCounter = (Integer) getStateHelper().get(PropertyKeys.uniqueIdCounter);
 444  20108
                 uniqueIdCounter = (uniqueIdCounter == null) ? 0 : uniqueIdCounter;
 445  20108
                 getStateHelper().put(PropertyKeys.uniqueIdCounter, (uniqueIdCounter+1));
 446  20108
                 if (uniqueIdCounter >= _ComponentUtils.UNIQUE_COMPONENT_V_IDS_SIZE)
 447  
                 {
 448  19900
                     StringBuilder bld = _getSharedStringBuilder(context);
 449  19900
                     return bld.append(UNIQUE_ID_PREFIX).append(
 450  
                         _ComponentUtils.V_ID_PREFIX).append(uniqueIdCounter).toString();
 451  
                 }
 452  
                 else
 453  
                 {
 454  208
                     return _ComponentUtils.UNIQUE_COMPONENT_V_IDS[uniqueIdCounter];
 455  
                 }
 456  
             }
 457  
         }
 458  
         // Optionally, a unique seed value can be supplied by component creators which
 459  
         // should be included in the generated unique id.
 460  
         else
 461  
         {
 462  0
             StringBuilder bld = _getSharedStringBuilder(context);
 463  0
             return bld.append(UNIQUE_ID_PREFIX).append(seed).toString();
 464  
         }
 465  
     }
 466  
 
 467  
     @Override
 468  
     public void encodeBegin(FacesContext context) throws IOException
 469  
     {
 470  0
         checkNull(context, "context");
 471  
 
 472  0
         boolean skipPhase = false;
 473  
 
 474  
         try
 475  
         {
 476  0
             skipPhase = notifyListeners(context, PhaseId.RENDER_RESPONSE, getBeforePhaseListener(), true);
 477  
         }
 478  0
         catch (Exception e)
 479  
         {
 480  
             // following the spec we have to swallow the exception
 481  0
             _getLogger().log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e);
 482  0
         }
 483  
 
 484  0
         if (!skipPhase)
 485  
         {
 486  
             //prerendering happens, we now publish the prerender view event
 487  
             //the specs states that the viewroot as source is about to be rendered
 488  
             //hence we issue the event immediately before publish, if the phase is not skipped
 489  
             //context.getApplication().publishEvent(context, PreRenderViewEvent.class, this);
 490  
             //then the view rendering is about to begin
 491  0
             super.encodeBegin(context);
 492  
         }
 493  
         else
 494  
         {
 495  0
             pushComponentToEL(context, this);
 496  
         }
 497  0
     }
 498  
 
 499  
     /**
 500  
      * @since 2.0
 501  
      */
 502  
     @Override
 503  
     public void encodeChildren(FacesContext context) throws IOException
 504  
     {
 505  0
         if (context.getResponseComplete())
 506  
         {
 507  0
             return;
 508  
         }
 509  0
         PartialViewContext pContext = context.getPartialViewContext();
 510  
         
 511  
         // If PartialViewContext.isAjaxRequest() returns true
 512  0
         if (pContext.isAjaxRequest())
 513  
         {
 514  
             // Perform partial rendering by calling PartialViewContext.processPartial() with PhaseId.RENDER_RESPONSE.
 515  
             //sectin 13.4.3 of the jsf2 specification
 516  0
             pContext.processPartial(PhaseId.RENDER_RESPONSE);
 517  
         }
 518  
         else
 519  
         {
 520  
             // If PartialViewContext.isAjaxRequest() returns false
 521  
             // delegate to super.encodeChildren(javax.faces.context.FacesContext) method.
 522  0
             super.encodeChildren(context);
 523  
         }
 524  0
     }
 525  
 
 526  
     @Override
 527  
     public void encodeEnd(FacesContext context) throws IOException
 528  
     {
 529  0
         checkNull(context, "context");
 530  
 
 531  0
         if (!context.getResponseComplete())
 532  
         {
 533  0
             super.encodeEnd(context);
 534  
             
 535  
             // the call to encodeAll() on every UIViewParameter here is only necessary
 536  
             // if the current request is _not_ an AJAX request, because if it was an
 537  
             // AJAX request, the call would already have happened in PartialViewContextImpl and
 538  
             // would anyway be too late here, because the state would already have been generated
 539  0
             PartialViewContext partialContext = context.getPartialViewContext();
 540  0
             if (!partialContext.isAjaxRequest())
 541  
             {
 542  0
                 ViewDeclarationLanguage vdl
 543  
                         = context.getApplication().getViewHandler().getViewDeclarationLanguage(context, getViewId());
 544  0
                 if (vdl != null)
 545  
                 {
 546  
                     // If the current view has view parameters, as indicated by a non-empty
 547  
                     // and non-UnsupportedOperationException throwing
 548  
                     // return from ViewDeclarationLanguage.getViewMetadata(javax.faces.context.FacesContext, String)
 549  0
                     ViewMetadata metadata = null;
 550  
                     try
 551  
                     {
 552  0
                         metadata = vdl.getViewMetadata(context, getViewId());    
 553  
                     }
 554  0
                     catch(UnsupportedOperationException e)
 555  
                     {
 556  0
                         _getLogger().log(Level.SEVERE, "Exception while obtaining the view metadata: " +
 557  
                                 e.getMessage(), e);
 558  0
                     }
 559  
                     
 560  0
                     if (metadata != null)
 561  
                     {
 562  
                         try
 563  
                         {
 564  0
                             Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(this);    
 565  0
                             if(!viewParams.isEmpty())
 566  
                             {
 567  
                                 // call UIViewParameter.encodeAll(javax.faces.context.FacesContext) on each parameter.
 568  0
                                 for(UIViewParameter param : viewParams)
 569  
                                 {
 570  0
                                     param.encodeAll(context);
 571  0
                                 }
 572  
                             }
 573  
                         }
 574  0
                         catch(UnsupportedOperationException e)
 575  
                         {
 576  
                             // If calling getViewParameters() causes UnsupportedOperationException
 577  
                             // to be thrown, the exception must be silently swallowed.
 578  0
                         }
 579  
                     }
 580  
                 }
 581  
             }
 582  
         }
 583  
         
 584  
         try
 585  
         {
 586  0
             notifyListeners(context, PhaseId.RENDER_RESPONSE, getAfterPhaseListener(), false);
 587  
         }
 588  0
         catch (Exception e)
 589  
         {
 590  
             // following the spec we have to swallow the exception
 591  0
             _getLogger().log(Level.SEVERE, "Exception while processing phase listener: " + e.getMessage(), e);
 592  0
         }
 593  0
     }
 594  
 
 595  
     /**
 596  
      * MethodBinding pointing to a method that takes a javax.faces.event.PhaseEvent and returns void, called after every
 597  
      * phase except for restore view.
 598  
      *
 599  
      * @return the new afterPhaseListener value
 600  
      */
 601  
     @JSFProperty(returnSignature = "void", methodSignature = "javax.faces.event.PhaseEvent",
 602  
                  jspName = "afterPhase", stateHolder=true)
 603  
     public MethodExpression getAfterPhaseListener()
 604  
     {
 605  0
         return (MethodExpression) getStateHelper().eval(PropertyKeys.afterPhaseListener);
 606  
     }
 607  
 
 608  
     /**
 609  
      * MethodBinding pointing to a method that takes a javax.faces.event.PhaseEvent and returns void, called before
 610  
      * every phase except for restore view.
 611  
      *
 612  
      * @return the new beforePhaseListener value
 613  
      */
 614  
     @JSFProperty(returnSignature = "void", methodSignature = "javax.faces.event.PhaseEvent",
 615  
                  jspName = "beforePhase", stateHolder=true)
 616  
     public MethodExpression getBeforePhaseListener()
 617  
     {
 618  0
         return (MethodExpression) getStateHelper().eval(PropertyKeys.beforePhaseListener);
 619  
     }
 620  
 
 621  
     /**
 622  
      * @since 2.0
 623  
      */
 624  
     public List<UIComponent> getComponentResources(FacesContext context, String target)
 625  
     {
 626  0
         if (target == null)
 627  
         {
 628  0
             throw new NullPointerException("target");
 629  
         }
 630  
         // Locate the facet for the component by calling getFacet() using target as the argument
 631  0
         UIComponent facet = getFacet(target);
 632  
 
 633  
         /*
 634  
         // If the facet is not found,
 635  
         if (facet == null)
 636  
         {
 637  
             // create the facet by calling context.getApplication().createComponent()
 638  
             // using javax.faces.Panel as the argument
 639  
             facet = context.getApplication().createComponent("javax.faces.Panel");
 640  
 
 641  
             // Set the id of the facet to be target
 642  
             facet.setId(target);
 643  
 
 644  
             // Add the facet to the facets Map using target as the key
 645  
             getFacets().put(target, facet);
 646  
         }
 647  
 
 648  
         // Return the children of the facet
 649  
         // The API doc indicates that this method should "Return an unmodifiable
 650  
         // List of UIComponents for the provided target argument."
 651  
         // and also that "If no children are found for the facet, return Collections.emptyList()."
 652  
         List<UIComponent> children = facet.getChildren();
 653  
         return ( children == null ? Collections.<UIComponent>emptyList() : Collections.unmodifiableList(children) );
 654  
         */
 655  0
         if (facet != null)
 656  
         {
 657  0
             if (facet.getChildCount() > 0)
 658  
             {
 659  0
                 return Collections.unmodifiableList(facet.getChildren());
 660  
             }
 661  
             else
 662  
             {
 663  0
                 return Collections.<UIComponent>emptyList();
 664  
             }
 665  
         }
 666  0
         return Collections.<UIComponent>emptyList();
 667  
     }
 668  
     
 669  
     private List<UIComponent> _getComponentResources(FacesContext context, String target)
 670  
     {
 671  
         // Locate the facet for the component by calling getFacet() using target as the argument
 672  0
         UIComponent facet = getFacet(target);
 673  
 
 674  
         // If the facet is not found,
 675  0
         if (facet == null)
 676  
         {
 677  
             // create the facet by calling context.getApplication().createComponent()
 678  
             // using javax.faces.Panel as the argument
 679  0
             facet = context.getApplication().createComponent(context,
 680  
                 "javax.faces.ComponentResourceContainer", null);
 681  
 
 682  
             // Set the id of the facet to be target
 683  0
             if (target.equals("head"))
 684  
             {
 685  0
                 facet.setId(JAVAX_FACES_LOCATION_HEAD);
 686  
             }
 687  0
             else if (target.equals("body"))
 688  
             {
 689  0
                 facet.setId(JAVAX_FACES_LOCATION_BODY);
 690  
             }
 691  0
             else if (target.equals("form"))
 692  
             {
 693  0
                 facet.setId(JAVAX_FACES_LOCATION_FORM);
 694  
             }
 695  
             else
 696  
             {
 697  0
                 facet.setId(JAVAX_FACES_LOCATION_PREFIX + target);
 698  
             }
 699  
             
 700  
             // From jsr-314-open list it was made clear this facet is transient,
 701  
             // because all component resources does not change its inner state between
 702  
             // requests
 703  
             //
 704  
             // MYFACES-3047 It was found that resources added using ResourceDependency annotation
 705  
             // requires to be saved and restored, so it is not possible to mark this facets
 706  
             // as transient. The previous statement is true only for PSS.
 707  
             //facet.setTransient(true);
 708  
 
 709  
             // Add the facet to the facets Map using target as the key
 710  0
             getFacets().put(target, facet);
 711  
         }
 712  0
         return facet.getChildren();
 713  
     }
 714  
 
 715  
     @Override
 716  
     public String getFamily()
 717  
     {
 718  0
         return COMPONENT_FAMILY;
 719  
     }
 720  
 
 721  
     /**
 722  
      * The locale for this view.
 723  
      * <p>
 724  
      * Defaults to the default locale specified in the faces configuration file.
 725  
      * </p>
 726  
      */
 727  
     @JSFProperty
 728  
     public Locale getLocale()
 729  
     {
 730  68
         Object locale = getStateHelper().get(PropertyKeys.locale);
 731  68
         if (locale != null)
 732  
         {
 733  52
             return (Locale)locale;
 734  
         }
 735  16
         ValueExpression expression = getValueExpression(PropertyKeys.locale.toString());
 736  16
         if (expression != null)
 737  
         {
 738  0
             Object veLocale = expression.getValue(getFacesContext().getELContext());
 739  0
             if (veLocale instanceof Locale)
 740  
             {
 741  0
                 return (Locale) veLocale;
 742  
             }
 743  
             else
 744  
             {
 745  0
                 return (Locale) _LocaleUtils.toLocale(veLocale.toString());
 746  
             }
 747  
         }
 748  
         else
 749  
         {
 750  16
             locale = getFacesContext().getApplication().getViewHandler().calculateLocale(getFacesContext());
 751  
 
 752  16
             if (locale instanceof Locale)
 753  
             {
 754  14
                 return (Locale)locale;
 755  
             }
 756  2
             else if (locale instanceof String)
 757  
             {
 758  0
                 return _LocaleUtils.toLocale((String)locale);
 759  
             }
 760  
         }
 761  
 
 762  2
         return getFacesContext().getApplication().getViewHandler().calculateLocale(getFacesContext());
 763  
     }
 764  
 
 765  
     /**
 766  
      * @since 2.0
 767  
      */
 768  
     public List<PhaseListener> getPhaseListeners()
 769  
     {
 770  24
         List<PhaseListener> listeners = (List<PhaseListener>) getStateHelper().get(PropertyKeys.phaseListeners);
 771  24
         if (listeners == null)
 772  
         {
 773  8
             listeners = Collections.emptyList();
 774  
         }
 775  
         else
 776  
         {
 777  16
             listeners = Collections.unmodifiableList(listeners);
 778  
         }
 779  
 
 780  24
         return listeners;
 781  
     }
 782  
 
 783  
     /**
 784  
      * Defines what renderkit should be used to render this view.
 785  
      */
 786  
     @JSFProperty
 787  
     public String getRenderKitId()
 788  
     {
 789  270
         return (String) getStateHelper().eval(PropertyKeys.renderKitId);
 790  
     }
 791  
 
 792  
     /**
 793  
      * @since 2.0
 794  
      */
 795  
     @Override
 796  
     public boolean getRendersChildren()
 797  
     {
 798  
         // Call UIComponentBase.getRendersChildren() 
 799  
         // If PartialViewContext.isAjaxRequest()  returns true this method must return true.
 800  0
         PartialViewContext context = getFacesContext().getPartialViewContext();
 801  
 
 802  0
         return (context.isAjaxRequest()) ? true : super.getRendersChildren();
 803  
     }
 804  
 
 805  
     /**
 806  
      * A unique identifier for the "template" from which this view was generated.
 807  
      * <p>
 808  
      * Typically this is the filesystem path to the template file, but the exact details are the responsibility of the
 809  
      * current ViewHandler implementation.
 810  
      */
 811  
     @JSFProperty(tagExcluded = true)
 812  
     public String getViewId()
 813  
     {
 814  72
         return (String) getStateHelper().get(PropertyKeys.viewId);
 815  
     }
 816  
 
 817  
     /**
 818  
      * @since 2.0
 819  
      */
 820  
     public Map<String, Object> getViewMap()
 821  
     {
 822  0
         return this.getViewMap(true);
 823  
     }
 824  
 
 825  
     /**
 826  
      * @since 2.0
 827  
      */
 828  
     public Map<String, Object> getViewMap(boolean create)
 829  
     {
 830  0
         if (_viewScope == null && create)
 831  
         {
 832  0
             if (VIEW_SCOPE_PROXY_MAP_CLASS != null)
 833  
             {
 834  0
                 _viewScope = (Map<String, Object>)
 835  
                     _ClassUtils.newInstance(VIEW_SCOPE_PROXY_MAP_CLASS);
 836  
             }
 837  
             else
 838  
             {
 839  
                 //Default to map for testing purposes
 840  0
                 _viewScope = new ViewScope();
 841  
             }
 842  0
             FacesContext facesContext = getFacesContext();
 843  0
             if (facesContext != null)
 844  
             {
 845  0
                 facesContext.getApplication().publishEvent(facesContext, PostConstructViewMapEvent.class, this);
 846  
             }
 847  
         }
 848  
 
 849  0
         return _viewScope;
 850  
     }
 851  
     
 852  
     /**
 853  
      * {@inheritDoc}
 854  
      */
 855  
     @Override
 856  
     public boolean isInView()
 857  
     {
 858  64
         return true;
 859  
     }
 860  
 
 861  
     public void processApplication(final FacesContext context)
 862  
     {
 863  0
         checkNull(context, "context");
 864  0
         _process(context, PhaseId.INVOKE_APPLICATION, null);
 865  0
     }
 866  
 
 867  
     @Override
 868  
     public void processDecodes(FacesContext context)
 869  
     {
 870  0
         checkNull(context, "context");
 871  0
         _process(context, PhaseId.APPLY_REQUEST_VALUES, APPLY_REQUEST_VALUES_PROCESSOR);
 872  0
     }
 873  
 
 874  
     /**
 875  
      * @since 2.0
 876  
      */
 877  
     @Override
 878  
     public void processRestoreState(FacesContext context, Object state)
 879  
     {
 880  
         // The default implementation must call UIComponentBase.processRestoreState(javax.faces.context.FacesContext,
 881  
         // java.lang.Object) from within a try block.
 882  
         try
 883  
         {
 884  0
             super.processRestoreState(context, state);
 885  
         }
 886  
         finally
 887  
         {
 888  
             // The try block must have a finally block that ensures that no FacesEvents remain in the event queue
 889  0
             broadcastEvents(context, PhaseId.RESTORE_VIEW);
 890  
 
 891  
             //visitTree(VisitContext.createVisitContext(context), new RestoreStateCallback());
 892  0
         }
 893  0
     }
 894  
 
 895  
     @Override
 896  
     public void queueEvent(FacesEvent event)
 897  
     {
 898  64
         checkNull(event, "event");
 899  64
         if (_events == null)
 900  
         {
 901  4
             _events = new ArrayList<FacesEvent>();
 902  
         }
 903  
 
 904  64
         _events.add(event);
 905  64
     }
 906  
 
 907  
     @Override
 908  
     public void processValidators(FacesContext context)
 909  
     {
 910  0
         checkNull(context, "context");
 911  0
         _process(context, PhaseId.PROCESS_VALIDATIONS, PROCESS_VALIDATORS_PROCESSOR);
 912  0
     }
 913  
 
 914  
     @Override
 915  
     public void processUpdates(FacesContext context)
 916  
     {
 917  0
         checkNull(context, "context");
 918  0
         _process(context, PhaseId.UPDATE_MODEL_VALUES, UPDATE_MODEL_PROCESSOR);
 919  0
     }
 920  
 
 921  
     public void setLocale(Locale locale)
 922  
     {
 923  48
         getStateHelper().put(PropertyKeys.locale, locale );
 924  48
     }
 925  
 
 926  
     /**
 927  
      * Invoke view-specific phase listeners, plus an optional EL MethodExpression.
 928  
      * <p>
 929  
      * JSF1.2 adds the ability for PhaseListener objects to be added to a UIViewRoot instance, and for
 930  
      * "beforePhaseListener" and "afterPhaseListener" EL expressions to be defined on the viewroot. This method is
 931  
      * expected to be called at appropriate times, and will then execute the relevant listener callbacks.
 932  
      * <p>
 933  
      * Parameter "listener" may be null. If not null, then it is an EL expression pointing to a user method that will be
 934  
      * invoked.
 935  
      * <p>
 936  
      * Note that the global PhaseListeners are invoked via the Lifecycle implementation, not from this method here.
 937  
      * <p>
 938  
      * These PhaseListeners are processed with the same rules as the globally defined PhaseListeners, except
 939  
      * that any Exceptions, which may occur during the execution of the PhaseListeners, will only be logged
 940  
      * and not published to the ExceptionHandler.
 941  
      */
 942  
     private boolean notifyListeners(FacesContext context, PhaseId phaseId, MethodExpression listener,
 943  
                                     boolean beforePhase)
 944  
     {
 945  0
         List<PhaseListener> phaseListeners = (List<PhaseListener>) getStateHelper().get(PropertyKeys.phaseListeners);
 946  
         // Check if any listener was called
 947  0
         boolean listenerCalled = false;
 948  0
         if (listener != null || (phaseListeners != null && !phaseListeners.isEmpty()))
 949  
         {
 950  
             // how many listeners do we have? (the MethodExpression listener is counted in either way)
 951  
             // NOTE: beforePhaseSuccess[0] always refers to the MethodExpression listener
 952  0
             int listenerCount = (phaseListeners != null ? phaseListeners.size() + 1 : 1);
 953  
             
 954  
             boolean[] beforePhaseSuccess;
 955  0
             if (beforePhase)
 956  
             {
 957  0
                 beforePhaseSuccess = new boolean[listenerCount];
 958  0
                 _getListenerSuccessMap().put(phaseId, beforePhaseSuccess);
 959  
             }
 960  
             else
 961  
             {
 962  
                 // afterPhase - get beforePhaseSuccess from the Map
 963  0
                 beforePhaseSuccess = _getListenerSuccessMap().get(phaseId);
 964  0
                 if (beforePhaseSuccess == null)
 965  
                 {
 966  
                     // no Map available - assume that everything went well
 967  0
                     beforePhaseSuccess = new boolean[listenerCount];
 968  0
                     Arrays.fill(beforePhaseSuccess, true);
 969  
                 }
 970  
             }
 971  
             
 972  0
             PhaseEvent event = createEvent(context, phaseId);
 973  
 
 974  
             // only invoke the listener if we are in beforePhase
 975  
             // or if the related before PhaseListener finished without an Exception
 976  0
             if (listener != null && (beforePhase || beforePhaseSuccess[0]))
 977  
             {
 978  0
                 listenerCalled = true;
 979  
                 try
 980  
                 {
 981  0
                     listener.invoke(context.getELContext(), new Object[] { event });
 982  0
                     beforePhaseSuccess[0] = true;
 983  
                 }
 984  0
                 catch (Throwable t) 
 985  
                 {
 986  0
                     beforePhaseSuccess[0] = false; // redundant - for clarity
 987  0
                     _getLogger().log(Level.SEVERE, "An Exception occured while processing " +
 988  
                                              listener.getExpressionString() + 
 989  
                                              " in Phase " + phaseId, t);
 990  0
                     if (beforePhase)
 991  
                     {
 992  0
                         return context.getResponseComplete() ||
 993  
                                 (context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId));
 994  
                     }
 995  0
                 }
 996  
             }
 997  0
             else if (beforePhase)
 998  
             {
 999  
                 // there is no beforePhase MethodExpression listener
 1000  0
                 beforePhaseSuccess[0] = true;
 1001  
             }
 1002  
 
 1003  0
             if (phaseListeners != null && !phaseListeners.isEmpty())
 1004  
             {
 1005  0
                 if (beforePhase)
 1006  
                 {
 1007  
                     // process listeners in ascending order
 1008  0
                     for (int i = 0; i < beforePhaseSuccess.length - 1; i++)
 1009  
                     {
 1010  
                         PhaseListener phaseListener;
 1011  
                         try 
 1012  
                         {
 1013  0
                             phaseListener = phaseListeners.get(i);
 1014  
                         }
 1015  0
                         catch (IndexOutOfBoundsException e)
 1016  
                         {
 1017  
                             // happens when a PhaseListener removes another PhaseListener 
 1018  
                             // from UIViewRoot in its beforePhase method
 1019  0
                             throw new IllegalStateException("A PhaseListener must not remove " +
 1020  
                                     "PhaseListeners from UIViewRoot.");
 1021  0
                         }
 1022  0
                         PhaseId listenerPhaseId = phaseListener.getPhaseId();
 1023  0
                         if (phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId))
 1024  
                         {
 1025  0
                             listenerCalled = true;
 1026  
                             try
 1027  
                             {
 1028  0
                                 phaseListener.beforePhase(event);
 1029  0
                                 beforePhaseSuccess[i + 1] = true;
 1030  
                             }
 1031  0
                             catch (Throwable t) 
 1032  
                             {
 1033  0
                                 beforePhaseSuccess[i + 1] = false; // redundant - for clarity
 1034  0
                                 _getLogger().log(Level.SEVERE, "An Exception occured while processing the " +
 1035  
                                                          "beforePhase method of PhaseListener " + phaseListener +
 1036  
                                                          " in Phase " + phaseId, t);
 1037  0
                                 return context.getResponseComplete() ||
 1038  
                                         (context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId));
 1039  0
                             }
 1040  
                         }
 1041  
                     }
 1042  
                 }
 1043  
                 else
 1044  
                 {
 1045  
                     // afterPhase
 1046  
                     // process listeners in descending order
 1047  0
                     for (int i = beforePhaseSuccess.length - 1; i > 0; i--)
 1048  
                     {
 1049  
                         PhaseListener phaseListener;
 1050  
                         try 
 1051  
                         {
 1052  0
                             phaseListener = phaseListeners.get(i - 1);
 1053  
                         }
 1054  0
                         catch (IndexOutOfBoundsException e)
 1055  
                         {
 1056  
                             // happens when a PhaseListener removes another PhaseListener 
 1057  
                             // from UIViewRoot in its beforePhase or afterPhase method
 1058  0
                             throw new IllegalStateException("A PhaseListener must not remove " +
 1059  
                                     "PhaseListeners from UIViewRoot.");
 1060  0
                         }
 1061  0
                         PhaseId listenerPhaseId = phaseListener.getPhaseId();
 1062  0
                         if ((phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId))
 1063  
                                 && beforePhaseSuccess[i])
 1064  
                         {
 1065  0
                             listenerCalled = true;
 1066  
                             try
 1067  
                             {
 1068  0
                                 phaseListener.afterPhase(event);
 1069  
                             }
 1070  0
                             catch (Throwable t) 
 1071  
                             {
 1072  0
                                 logger.log(Level.SEVERE, "An Exception occured while processing the " +
 1073  
                                                          "afterPhase method of PhaseListener " + phaseListener +
 1074  
                                                          " in Phase " + phaseId, t);
 1075  0
                             }
 1076  
                         }
 1077  
                     }
 1078  
                 }
 1079  
             }
 1080  
         }
 1081  
 
 1082  
         // The spec javadoc says "... Upon return from the listener, call FacesContext.getResponseComplete() 
 1083  
         // and FacesContext.getRenderResponse(). If either return true set the internal state flag to true. ..."
 1084  
         // and later it says:
 1085  
         // "... Execute any processing for this phase if the internal state flag was not set. ..."
 1086  
         // But after some testing it seems if the internal state flag is not set, the check is not done and the
 1087  
         // phase is not skipped. The only exception is in render response phase.
 1088  0
         if (listenerCalled)
 1089  
         {
 1090  0
             if (beforePhase)
 1091  
             {
 1092  0
                 return context.getResponseComplete() ||
 1093  
                         (context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId));
 1094  
             }
 1095  
             else
 1096  
             {
 1097  0
                 return context.getResponseComplete() || context.getRenderResponse();
 1098  
             }
 1099  
         }
 1100  
         else
 1101  
         {
 1102  0
             if (beforePhase)
 1103  
             {
 1104  0
                 if (PhaseId.RENDER_RESPONSE.equals(phaseId))
 1105  
                 {
 1106  0
                     return context.getResponseComplete();
 1107  
                 }
 1108  
                 else
 1109  
                 {
 1110  
                     // Don't check and don't skip
 1111  0
                     return false;
 1112  
                 }
 1113  
             }
 1114  
             else
 1115  
             {
 1116  
                 // Note if is afterPhase the return value is not relevant.
 1117  0
                 return context.getResponseComplete() || context.getRenderResponse();
 1118  
             }
 1119  
         }
 1120  
     }
 1121  
 
 1122  
     private PhaseEvent createEvent(FacesContext context, PhaseId phaseId)
 1123  
     {
 1124  0
         if (_lifecycle == null)
 1125  
         {
 1126  0
             LifecycleFactory factory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
 1127  0
             String id = context.getExternalContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
 1128  0
             if (id == null)
 1129  
             {
 1130  0
                 id = LifecycleFactory.DEFAULT_LIFECYCLE;
 1131  
             }
 1132  0
             _lifecycle = factory.getLifecycle(id);
 1133  
         }
 1134  0
         return new PhaseEvent(context, phaseId, _lifecycle);
 1135  
     }
 1136  
 
 1137  
     /**
 1138  
      * Broadcast all events in the specified collection, stopping the at any time an AbortProcessingException
 1139  
      * is thrown.
 1140  
      *
 1141  
      * @param context the current JSF context
 1142  
      * @param events the events to broadcast
 1143  
      * @return 
 1144  
      *
 1145  
      * @return <code>true</code> if the broadcast was completed without unexpected abortion/exception,
 1146  
      *  <code>false</code> otherwise
 1147  
      */
 1148  
     private boolean _broadcastAll(FacesContext context,
 1149  
                                List<? extends FacesEvent> events,
 1150  
                                Collection<FacesEvent> eventsAborted)
 1151  
     {
 1152  64
         assert events != null;
 1153  
 
 1154  124
         for (int i = 0; i < events.size(); i++)
 1155  
         {
 1156  60
             FacesEvent event = events.get(i);
 1157  60
             UIComponent source = event.getComponent();
 1158  60
             UIComponent compositeParent = UIComponent.getCompositeComponentParent(source);
 1159  60
             if (compositeParent != null)
 1160  
             {
 1161  0
                 pushComponentToEL(context, compositeParent);
 1162  
             }
 1163  
             // Push the source as the current component
 1164  60
             pushComponentToEL(context, source);
 1165  
 
 1166  
             try
 1167  
             {
 1168  
                 // Actual event broadcasting
 1169  60
                 if (!source.isCachedFacesContext())
 1170  
                 {
 1171  
                     try
 1172  
                     {
 1173  60
                         source.setCachedFacesContext(context);
 1174  60
                         source.broadcast(event);
 1175  
                     }
 1176  
                     finally
 1177  
                     {
 1178  60
                         source.setCachedFacesContext(null);
 1179  60
                     }
 1180  
                 }
 1181  
                 else
 1182  
                 {
 1183  0
                     source.broadcast(event);
 1184  
                 }
 1185  
             }
 1186  0
             catch (Exception e)
 1187  
             {
 1188  
 
 1189  0
                 Throwable cause = e;
 1190  0
                 AbortProcessingException ape = null;
 1191  
                 do
 1192  
                 {
 1193  0
                     if (cause != null && cause instanceof AbortProcessingException)
 1194  
                     {
 1195  0
                         ape = (AbortProcessingException) cause;
 1196  0
                         break;
 1197  
                     }
 1198  0
                     cause = cause.getCause();
 1199  
                 }
 1200  0
                 while (cause != null);
 1201  
                 
 1202  
                 // for any other exception publish ExceptionQueuedEvent
 1203  
                 // publish the Exception to be handled by the ExceptionHandler
 1204  
                 // to publish or to not publish APE? That is the question : MYFACES-3199. We publish it,
 1205  
                 // because user can handle it in custom exception handler then. 
 1206  0
                 if (ape != null)
 1207  
                 {
 1208  0
                     e = ape;
 1209  
                 }
 1210  0
                 ExceptionQueuedEventContext exceptionContext 
 1211  
                         = new ExceptionQueuedEventContext(context, e, source, context.getCurrentPhaseId());
 1212  0
                 context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, exceptionContext);
 1213  
 
 1214  
                 
 1215  0
                 if (ape != null)
 1216  
                 {
 1217  
                     // APE found,  abortion for this event only
 1218  0
                     eventsAborted.add(event);
 1219  
                 }
 1220  
                 else
 1221  
                 {
 1222  
                     // We can't continue broadcast processing if other exception is thrown:
 1223  0
                     return false;
 1224  
                 }
 1225  
             }
 1226  
             finally
 1227  
             {
 1228  
                 // Restore the current component
 1229  60
                 source.popComponentFromEL(context);
 1230  60
                 if (compositeParent != null)
 1231  
                 {
 1232  0
                     compositeParent.popComponentFromEL(context);
 1233  
                 }
 1234  
             }
 1235  
         }
 1236  64
         return true;
 1237  
     }
 1238  
 
 1239  
     private void clearEvents()
 1240  
     {
 1241  0
         _events = null;
 1242  0
     }
 1243  
 
 1244  
     private void checkNull(Object value, String valueLabel)
 1245  
     {
 1246  242
         if (value == null)
 1247  
         {
 1248  0
             throw new NullPointerException(valueLabel + " is null");
 1249  
         }
 1250  242
     }
 1251  
 
 1252  
     public void setRenderKitId(String renderKitId)
 1253  
     {
 1254  524
         getStateHelper().put(PropertyKeys.renderKitId, renderKitId );
 1255  524
     }
 1256  
 
 1257  
     /**
 1258  
      * DO NOT USE.
 1259  
      * <p>
 1260  
      * This inherited property is disabled. Although this class extends a base-class that defines a read/write rendered
 1261  
      * property, this particular subclass does not support setting it. Yes, this is broken OO design: direct all
 1262  
      * complaints to the JSF spec group.
 1263  
      */
 1264  
     @Override
 1265  
     @JSFProperty(tagExcluded = true)
 1266  
     public void setRendered(boolean state)
 1267  
     {
 1268  
         // Call parent method due to TCK problems
 1269  0
         super.setRendered(state);
 1270  
         // throw new UnsupportedOperationException();
 1271  0
     }
 1272  
 
 1273  
     @JSFProperty(tagExcluded=true)
 1274  
     @Override
 1275  
     public void setId(String id)
 1276  
     {
 1277  30
         super.setId(id);
 1278  30
     }
 1279  
     
 1280  
     /**
 1281  
      * {@inheritDoc}
 1282  
      */
 1283  
     @Override
 1284  
     public void setInView(boolean isInView)
 1285  
     {
 1286  
         // no-op view root is always in view
 1287  0
     }
 1288  
 
 1289  
     public void removeComponentResource(FacesContext context, UIComponent componentResource)
 1290  
     {
 1291  0
         removeComponentResource(context, componentResource, null);
 1292  0
     }
 1293  
 
 1294  
     public void removeComponentResource(FacesContext context, UIComponent componentResource, String target)
 1295  
     {
 1296  
         // If the target argument is null
 1297  0
         if (target == null)
 1298  
         {
 1299  
             // Look for a target attribute on the component
 1300  0
             target = (String)componentResource.getAttributes().get("target");
 1301  
 
 1302  
             // If there is no target attribute
 1303  0
             if (target == null)
 1304  
             {
 1305  
                 // Set target to be the default value head
 1306  0
                 target = "head";
 1307  
             }
 1308  
         }
 1309  
 
 1310  
 
 1311  
         // Call getComponentResources to obtain the child list for the given target.
 1312  
         //List<UIComponent> componentResources = getComponentResources(context, target);
 1313  0
         UIComponent facet = getFacet(target);
 1314  0
         if (facet != null)
 1315  
         {
 1316  
             //Only if the facet is found it is possible to remove the resource,
 1317  
             //otherwise nothing should happen (call to getComponentResource trigger
 1318  
             //creation of facet)
 1319  
             // Remove the component resource from the child list
 1320  0
             facet.getChildren().remove(componentResource);
 1321  
         }
 1322  0
     }
 1323  
 
 1324  
     public void setViewId(String viewId)
 1325  
     {
 1326  
         // It really doesn't make much sense to allow null here.
 1327  
         // However the TCK does not check for it, and sun's implementation
 1328  
         // allows it so here we allow it too.
 1329  520
         getStateHelper().put(PropertyKeys.viewId, viewId );
 1330  520
     }
 1331  
 
 1332  
     /**
 1333  
      * Removes a The phaseListeners attached to ViewRoot.
 1334  
      */
 1335  
     public void removePhaseListener(PhaseListener phaseListener)
 1336  
     {
 1337  4
         if (phaseListener == null)
 1338  
         {
 1339  0
             return;
 1340  
         }
 1341  
 
 1342  4
         getStateHelper().remove(PropertyKeys.phaseListeners, phaseListener);
 1343  4
     }
 1344  
 
 1345  
     /**
 1346  
      * Sets
 1347  
      *
 1348  
      * @param beforePhaseListener
 1349  
      *            the new beforePhaseListener value
 1350  
      */
 1351  
     public void setBeforePhaseListener(MethodExpression beforePhaseListener)
 1352  
     {
 1353  0
         getStateHelper().put(PropertyKeys.beforePhaseListener, beforePhaseListener);
 1354  0
     }
 1355  
 
 1356  
     /**
 1357  
      * Sets
 1358  
      *
 1359  
      * @param afterPhaseListener
 1360  
      *            the new afterPhaseListener value
 1361  
      */
 1362  
     public void setAfterPhaseListener(MethodExpression afterPhaseListener)
 1363  
     {
 1364  0
         getStateHelper().put(PropertyKeys.afterPhaseListener, afterPhaseListener);
 1365  0
     }
 1366  
 
 1367  
     /**
 1368  
      * @return the clearTransientMapOnSaveState
 1369  
      */
 1370  
     int getResetSaveStateMode()
 1371  
     {
 1372  484
         return _resetSaveStateMode;
 1373  
     }
 1374  
 
 1375  
     /**
 1376  
      * @param clearTransientMapOnSaveState the clearTransientMapOnSaveState to set
 1377  
      */
 1378  
     void setResetSaveStateMode(int clearTransientMapOnSaveState)
 1379  
     {
 1380  0
         this._resetSaveStateMode = clearTransientMapOnSaveState;
 1381  0
     }
 1382  
 
 1383  
     @Override
 1384  
     public Map<String, Object> getAttributes()
 1385  
     {
 1386  64
         if (_attributesMap == null)
 1387  
         {
 1388  6
             _attributesMap = new _ViewAttributeMap(this, super.getAttributes());
 1389  
         }
 1390  64
         return _attributesMap;
 1391  
     }
 1392  
     
 1393  
     /**
 1394  
      * @since 2.2
 1395  
      * @param context
 1396  
      * @param clientIds 
 1397  
      */
 1398  
     public void resetValues(FacesContext context,
 1399  
                         java.util.Collection<java.lang.String> clientIds)    
 1400  
     {
 1401  0
         VisitContext visitContext = (VisitContext) VisitContext.createVisitContext(
 1402  
             context, clientIds, null);
 1403  0
         this.visitTree(visitContext, RESET_VALUES_CALLBACK);
 1404  0
     }
 1405  
 
 1406  
     /**
 1407  
      * Indicates if the component is created when facelets builds the view and
 1408  
      * is caused by the presence of a ResourceDependency annotation.
 1409  
      * 
 1410  
      * @return the _resourceDependencyUniqueId
 1411  
      */
 1412  
     boolean isResourceDependencyUniqueId()
 1413  
     {
 1414  20108
         return _resourceDependencyUniqueId;
 1415  
     }
 1416  
 
 1417  
     void setResourceDependencyUniqueId(boolean resourceDependencyUniqueId)
 1418  
     {
 1419  0
         this._resourceDependencyUniqueId = resourceDependencyUniqueId;
 1420  0
     }
 1421  
     
 1422  18
     enum PropertyKeys
 1423  
     {
 1424  2
          afterPhaseListener
 1425  2
         , beforePhaseListener
 1426  2
         , phaseListeners
 1427  2
         , locale
 1428  2
         , renderKitId
 1429  2
         , viewId
 1430  2
         , uniqueIdCounter
 1431  2
         , resourceDependencyUniqueIdCounter
 1432  
     }
 1433  
     
 1434  
     @Override
 1435  
     public Object saveState(FacesContext facesContext)
 1436  
     {
 1437  8
         if (getResetSaveStateMode() == RESET_MODE_SOFT)
 1438  
         {
 1439  
             // Clear view listeners.
 1440  0
             if (_systemEventListeners != null)
 1441  
             {
 1442  0
                 _systemEventListeners.clear();
 1443  
             }
 1444  0
             if (_events != null)
 1445  
             {
 1446  0
                 _events.clear();
 1447  
             }
 1448  0
             if (listenerSuccessMap != null)
 1449  
             {
 1450  0
                 listenerSuccessMap.clear();
 1451  
             }
 1452  0
             _restoreViewScopeStateCalled = false;
 1453  
         }
 1454  8
         if (getResetSaveStateMode() == RESET_MODE_HARD)
 1455  
         {
 1456  
             // Clear view listeners.
 1457  0
             if (_systemEventListeners != null)
 1458  
             {
 1459  0
                 _systemEventListeners.clear();
 1460  
             }
 1461  0
             if (_events != null)
 1462  
             {
 1463  0
                 _events.clear();
 1464  
             }
 1465  0
             if (listenerSuccessMap != null)
 1466  
             {
 1467  0
                 listenerSuccessMap.clear();
 1468  
             }
 1469  0
             if (_viewScope != null)
 1470  
             {
 1471  0
                 if (VIEW_SCOPE_PROXY_MAP_CLASS.isInstance(_viewScope))
 1472  
                 {
 1473  0
                     _viewScope = null;
 1474  
                 }
 1475  
                 else
 1476  
                 {
 1477  0
                     _viewScope.clear();
 1478  
                 }
 1479  
             }
 1480  0
             _restoreViewScopeStateCalled = false;
 1481  
         }
 1482  
         
 1483  8
         if (initialStateMarked())
 1484  
         {
 1485  6
             Object parentSaved = super.saveState(facesContext);
 1486  6
             if (_viewScope != null && 
 1487  
                 Boolean.TRUE.equals(facesContext.getAttributes().get(
 1488  
                 SKIP_VIEW_MAP_SAVE_STATE)))
 1489  
             {
 1490  0
                 if (parentSaved == null)
 1491  
                 {
 1492  0
                     return null;
 1493  
                 }
 1494  0
                 return new Object[]{parentSaved, null};
 1495  
             }
 1496  
             
 1497  6
             if (parentSaved == null && _viewScope == null)
 1498  
             {
 1499  
                 //No values
 1500  0
                 return null;
 1501  
             }
 1502  6
             else if (parentSaved == null && _viewScope != null && _viewScope.size() == 0
 1503  
                 && !(_viewScope instanceof StateHolder) )
 1504  
             {
 1505  
                 //Empty view scope, no values
 1506  0
                 return null;
 1507  
             }
 1508  
             
 1509  6
             Object[] values = new Object[2];
 1510  6
             values[0] = parentSaved;
 1511  6
             values[1] = saveAttachedState(facesContext,_viewScope);
 1512  6
             return values;
 1513  
         }
 1514  
         else
 1515  
         {
 1516  2
             if (_viewScope != null && 
 1517  
                 Boolean.TRUE.equals(facesContext.getAttributes().get(
 1518  
                 SKIP_VIEW_MAP_SAVE_STATE)))
 1519  
             {
 1520  0
                 return new Object[]{super.saveState(facesContext), null};
 1521  
             }
 1522  2
             Object[] values = new Object[2];
 1523  2
             values[0] = super.saveState(facesContext);
 1524  2
             values[1] = saveAttachedState(facesContext,_viewScope);
 1525  2
             return values;
 1526  
         }
 1527  
     }
 1528  
 
 1529  
     @SuppressWarnings("unchecked")
 1530  
     @Override
 1531  
     public void restoreState(FacesContext facesContext, Object state)
 1532  
     {
 1533  8
         if (state == null)
 1534  
         {
 1535  0
             return;
 1536  
         }
 1537  
         
 1538  8
         Object[] values = (Object[])state;
 1539  8
         super.restoreState(facesContext,values[0]);
 1540  
         // JSF 2.2 spec says that restoreViewScopeState can be called but only if
 1541  
         // StateManagementStrategy is used. If that's not the case (JSF 1.2 state saving),
 1542  
         // restoreViewScopeState could not be called, so this code should avoid restore
 1543  
         // the state twice.
 1544  8
         if (!_restoreViewScopeStateCalled)
 1545  
         {
 1546  8
             _viewScope = (Map<String, Object>) restoreAttachedState(facesContext, values[1]);
 1547  
         }
 1548  
         else
 1549  
         {
 1550  0
             _restoreViewScopeStateCalled = false;
 1551  
         }
 1552  8
     }
 1553  
     
 1554  
     /**
 1555  
      * @since 2.2
 1556  
      * @param facesContext
 1557  
      * @param state 
 1558  
      */
 1559  
     public void restoreViewScopeState(FacesContext facesContext, Object state)
 1560  
     {
 1561  0
         if (state == null)
 1562  
         {
 1563  0
             return;
 1564  
         }
 1565  
         //StateManagementStrategy says "... obtain the state of the UIViewRoot from the 
 1566  
         // state Object returned from ResponseStateManager.getState(javax.faces.context.FacesContext,
 1567  
         // java.lang.String) and pass that to UIViewRoot.restoreViewScopeState(
 1568  
         // javax.faces.context.FacesContext, java.lang.Object).
 1569  
         // Note restoreState() will be called later, and it will restore the view. If
 1570  
         // we restore the component state here, later it could be a problem in the later
 1571  
         // restoreState() call, because the initial state will not be the same.
 1572  
         
 1573  0
         Object[] values = (Object[])state;
 1574  0
         _viewScope = (Map<String, Object>) restoreAttachedState(facesContext, values[1]);
 1575  0
         _restoreViewScopeStateCalled = true;
 1576  0
     }
 1577  
     
 1578  
     public List<SystemEventListener> getViewListenersForEventClass(Class<? extends SystemEvent> systemEvent)
 1579  
     {
 1580  178
         checkNull (systemEvent, "systemEvent");
 1581  178
         if (_systemEventListeners == null)
 1582  
         {
 1583  178
             return null;
 1584  
         }
 1585  0
         return _systemEventListeners.get (systemEvent);
 1586  
     }
 1587  
     
 1588  
     public void subscribeToViewEvent(Class<? extends SystemEvent> systemEvent,
 1589  
             SystemEventListener listener)
 1590  
     {
 1591  
         List<SystemEventListener> listeners;
 1592  
         
 1593  0
         checkNull (systemEvent, "systemEvent");
 1594  0
         checkNull (listener, "listener");
 1595  
         
 1596  0
         if (_systemEventListeners == null)
 1597  
         {
 1598  0
             _systemEventListeners = new HashMap<Class<? extends SystemEvent>, List<SystemEventListener>>();
 1599  
         }
 1600  
         
 1601  0
         listeners = _systemEventListeners.get (systemEvent);
 1602  
         
 1603  0
         if (listeners == null)
 1604  
         {
 1605  0
             listeners = new ArrayList<SystemEventListener>();
 1606  
             
 1607  0
             _systemEventListeners.put (systemEvent, listeners);
 1608  
         }
 1609  
         
 1610  0
         listeners.add (listener);
 1611  0
     }
 1612  
     
 1613  
     public void unsubscribeFromViewEvent(Class<? extends SystemEvent> systemEvent,
 1614  
             SystemEventListener listener)
 1615  
     {
 1616  
         List<SystemEventListener> listeners;
 1617  
         
 1618  0
         checkNull (systemEvent, "systemEvent");
 1619  0
         checkNull (listener, "listener");
 1620  
         
 1621  0
         if (_systemEventListeners == null)
 1622  
         {
 1623  0
             return;
 1624  
         }
 1625  
         
 1626  0
         listeners = _systemEventListeners.get (systemEvent);
 1627  
         
 1628  0
         if (listeners != null)
 1629  
         {
 1630  0
             listeners.remove (listener);
 1631  
         }
 1632  0
     }
 1633  
 
 1634  
     /**
 1635  
      * Process the specified phase by calling PhaseListener.beforePhase for every phase listeners defined on this
 1636  
      * view root, then calling the process method of the processor, broadcasting relevant events and finally
 1637  
      * notifying the afterPhase method of every phase listeners registered on this view root.
 1638  
      *
 1639  
      * @param context
 1640  
      * @param phaseId
 1641  
      * @param processor
 1642  
      * @param broadcast
 1643  
      *
 1644  
      * @return
 1645  
      */
 1646  
     private boolean _process(FacesContext context, PhaseId phaseId, PhaseProcessor processor)
 1647  
     {
 1648  0
         RuntimeException processingException = null;
 1649  
         try
 1650  
         {
 1651  0
             if (!notifyListeners(context, phaseId, getBeforePhaseListener(), true))
 1652  
             {
 1653  
                 try
 1654  
                 {
 1655  0
                     if (processor != null)
 1656  
                     {
 1657  0
                         processor.process(context, this);
 1658  
                     }
 1659  
         
 1660  0
                     broadcastEvents(context, phaseId);
 1661  
                 }
 1662  0
                 catch (RuntimeException re)
 1663  
                 {
 1664  
                     // catch any Exception that occures while processing the phase
 1665  
                     // to ensure invocation of the afterPhase methods
 1666  0
                     processingException = re;
 1667  0
                 }
 1668  
             }
 1669  
         }
 1670  
         finally
 1671  
         {
 1672  0
             if (context.getRenderResponse() || context.getResponseComplete())
 1673  
             {
 1674  0
                 clearEvents();
 1675  
             }            
 1676  
         }
 1677  
 
 1678  0
         boolean retVal = notifyListeners(context, phaseId, getAfterPhaseListener(), false);
 1679  0
         if (processingException == null) 
 1680  
         {
 1681  0
             return retVal;   
 1682  
         }
 1683  
         else
 1684  
         {
 1685  0
             throw processingException;
 1686  
         }
 1687  
     }
 1688  
 
 1689  
     private void _processDecodesDefault(FacesContext context)
 1690  
     {
 1691  0
         super.processDecodes(context);
 1692  0
     }
 1693  
 
 1694  
     private void _processUpdatesDefault(FacesContext context)
 1695  
     {
 1696  0
         super.processUpdates(context);
 1697  0
     }
 1698  
 
 1699  
     private void _processValidatorsDefault(FacesContext context)
 1700  
     {
 1701  0
         super.processValidators(context);
 1702  0
     }
 1703  
 
 1704  
     /**
 1705  
      * Gathers all event for current and ANY phase
 1706  
      * @param phaseId current phase id
 1707  
      */
 1708  
     private Events _getEvents(PhaseId phaseId)
 1709  
     {
 1710  
         // Gather the events and purge the event list to prevent concurrent modification during broadcasting
 1711  36
         int size = _events.size();
 1712  36
         List<FacesEvent> anyPhase = new ArrayList<FacesEvent>(size);
 1713  36
         List<FacesEvent> onPhase = new ArrayList<FacesEvent>(size);
 1714  
         
 1715  100
         for (int i = 0; i < size; i++)
 1716  
         {
 1717  64
             FacesEvent event = _events.get(i);
 1718  64
             if (event.getPhaseId().equals(PhaseId.ANY_PHASE))
 1719  
             {
 1720  0
                 anyPhase.add(event);
 1721  0
                 _events.remove(i);
 1722  0
                 size--;
 1723  0
                 i--;
 1724  
             }
 1725  64
             else if (event.getPhaseId().equals(phaseId))
 1726  
             {
 1727  64
                 onPhase.add(event);
 1728  64
                 _events.remove(i);
 1729  64
                 size--;
 1730  64
                 i--;
 1731  
             }
 1732  
         }
 1733  
         
 1734  36
         return new Events(anyPhase, onPhase);
 1735  
     }
 1736  
     
 1737  
     private Logger _getLogger()
 1738  
     {
 1739  4
         if (logger == null)
 1740  
         {
 1741  2
             logger = Logger.getLogger(UIViewRoot.class.getName());
 1742  
         }
 1743  4
         return logger;
 1744  
     }
 1745  
 
 1746  
     private Map<PhaseId, boolean[]> _getListenerSuccessMap()
 1747  
     {
 1748  
         // lazy init: 
 1749  0
         if (listenerSuccessMap == null)
 1750  
         {
 1751  0
             listenerSuccessMap = new HashMap<PhaseId, boolean[]>();
 1752  
         }
 1753  0
         return listenerSuccessMap;
 1754  
     }
 1755  
 
 1756  
     private static interface PhaseProcessor
 1757  
     {
 1758  
         public void process(FacesContext context, UIViewRoot root);
 1759  
     }
 1760  
 
 1761  4
     private static class ApplyRequestValuesPhaseProcessor implements PhaseProcessor
 1762  
     {
 1763  
         public void process(FacesContext context, UIViewRoot root)
 1764  
         {
 1765  0
             PartialViewContext pvc = context.getPartialViewContext();
 1766  
             // Perform partial processing by calling PartialViewContext.processPartial(javax.faces.event.PhaseId)
 1767  
             // with PhaseId.UPDATE_MODEL_VALUES if:
 1768  
             //   * PartialViewContext.isPartialRequest() returns true and we don't have a request to process all
 1769  
             // components in the view (PartialViewContext.isExecuteAll() returns false)
 1770  
             //section 13.4.2 from the  JSF2  spec also see https://issues.apache.org/jira/browse/MYFACES-2119
 1771  0
             if (pvc.isPartialRequest() && !pvc.isExecuteAll())
 1772  
             {
 1773  0
                 pvc.processPartial(PhaseId.APPLY_REQUEST_VALUES);
 1774  
             }
 1775  
             // Perform full processing by calling UIComponentBase.processUpdates(javax.faces.context.FacesContext)
 1776  
             // if one of the following conditions are met:
 1777  
             // *   PartialViewContext.isPartialRequest() returns true and we have a request to process all components
 1778  
             // in the view (PartialViewContext.isExecuteAll() returns true)
 1779  
             // *   PartialViewContext.isPartialRequest() returns false
 1780  
             else
 1781  
             {
 1782  0
                 root._processDecodesDefault(context);
 1783  
             }
 1784  0
         }
 1785  
     }
 1786  
 
 1787  4
     private static class ProcessValidatorPhaseProcessor implements PhaseProcessor
 1788  
     {
 1789  
         public void process(FacesContext context, UIViewRoot root)
 1790  
         {
 1791  0
             PartialViewContext pvc = context.getPartialViewContext();
 1792  
             // Perform partial processing by calling PartialViewContext.processPartial(javax.faces.event.PhaseId)
 1793  
             // with PhaseId.UPDATE_MODEL_VALUES if:
 1794  
             // PartialViewContext.isPartialRequest() returns true and we don't have a request to process all components
 1795  
             // in the view (PartialViewContext.isExecuteAll() returns false)
 1796  
             //section 13.4.2 from the  JSF2  spec also see https://issues.apache.org/jira/browse/MYFACES-2119
 1797  0
             if (pvc.isPartialRequest() && !pvc.isExecuteAll())
 1798  
             {
 1799  0
                 pvc.processPartial(PhaseId.PROCESS_VALIDATIONS);
 1800  
             }
 1801  
             // Perform full processing by calling UIComponentBase.processUpdates(javax.faces.context.FacesContext)
 1802  
             // if one of the following conditions are met:
 1803  
             // *   PartialViewContext.isPartialRequest() returns true and we have a request to process all components
 1804  
             // in the view (PartialViewContext.isExecuteAll() returns true)
 1805  
             // *   PartialViewContext.isPartialRequest() returns false
 1806  
             else
 1807  
             {
 1808  0
                 root._processValidatorsDefault(context);
 1809  
             }
 1810  0
         }
 1811  
     }
 1812  
 
 1813  4
     private static class UpdateModelPhaseProcessor implements PhaseProcessor
 1814  
     {
 1815  
         public void process(FacesContext context, UIViewRoot root)
 1816  
         {
 1817  0
             PartialViewContext pvc = context.getPartialViewContext();
 1818  
             // Perform partial processing by calling PartialViewContext.processPartial(javax.faces.event.PhaseId)
 1819  
             // with PhaseId.UPDATE_MODEL_VALUES if:
 1820  
             //   * PartialViewContext.isPartialRequest() returns true and we don't have a request to process
 1821  
             // all components in the view (PartialViewContext.isExecuteAll() returns false)
 1822  
             //section 13.4.2 from the JSF2 spec also see https://issues.apache.org/jira/browse/MYFACES-2119
 1823  0
             if (pvc.isPartialRequest() && !pvc.isExecuteAll())
 1824  
             {
 1825  0
                 pvc.processPartial(PhaseId.UPDATE_MODEL_VALUES);
 1826  
             }
 1827  
             // Perform full processing by calling UIComponentBase.processUpdates(javax.faces.context.FacesContext)
 1828  
             // if one of the following conditions are met:
 1829  
             // *   PartialViewContext.isPartialRequest() returns true and we have a request to process all components
 1830  
             // in the view (PartialViewContext.isExecuteAll() returns true)
 1831  
             // *   PartialViewContext.isPartialRequest() returns false
 1832  
             else
 1833  
             {
 1834  0
                 root._processUpdatesDefault(context);
 1835  
             }
 1836  0
         }
 1837  
     }
 1838  
 
 1839  
 /*
 1840  
     private static class RestoreStateCallback implements VisitCallback
 1841  
     {
 1842  
         private PostRestoreStateEvent event;
 1843  
 
 1844  
         public VisitResult visit(VisitContext context, UIComponent target)
 1845  
         {
 1846  
             if (event == null)
 1847  
             {
 1848  
                 event = new PostRestoreStateEvent(target);
 1849  
             }
 1850  
             else
 1851  
             {
 1852  
                 event.setComponent(target);
 1853  
             }
 1854  
 
 1855  
             // call the processEvent method of the current component.
 1856  
             // The argument event must be an instance of AfterRestoreStateEvent whose component
 1857  
             // property is the current component in the traversal.
 1858  
             target.processEvent(event);
 1859  
             
 1860  
             return VisitResult.ACCEPT;
 1861  
         }
 1862  
     }
 1863  
 */
 1864  
 
 1865  
     // we cannot make this class a inner class, because the 
 1866  
     // enclosing class (UIViewRoot) would also have to be serialized.
 1867  
     /**
 1868  
      * @deprecated replaced by org.apache.myfaces.view.ViewScopeProxyMap
 1869  
      */
 1870  
     @Deprecated
 1871  0
     private static class ViewScope extends HashMap<String, Object>
 1872  
     {
 1873  
         
 1874  
         private static final long serialVersionUID = -1088893802269478164L;
 1875  
         
 1876  
         @Override
 1877  
         public void clear()
 1878  
         {
 1879  
             /*
 1880  
              * The returned Map must be implemented such that calling clear() on the Map causes
 1881  
              * Application.publishEvent(java.lang.Class, java.lang.Object) to be called, passing
 1882  
              * ViewMapDestroyedEvent.class as the first argument and this UIViewRoot instance as the second argument.
 1883  
              */
 1884  0
             FacesContext facesContext = FacesContext.getCurrentInstance();
 1885  0
             facesContext.getApplication().publishEvent(facesContext, 
 1886  
                     PreDestroyViewMapEvent.class, facesContext.getViewRoot());
 1887  
             
 1888  0
             super.clear();
 1889  0
         }
 1890  
         
 1891  
     }
 1892  
 
 1893  
     /**
 1894  
      * Agregates events for ANY_PHASE and current phase 
 1895  
      */
 1896  
     private static class Events
 1897  
     {
 1898  
         
 1899  
         private final List<FacesEvent> _anyPhase;
 1900  
         
 1901  
         private final List<FacesEvent> _onPhase;
 1902  
         
 1903  
         public Events(List<FacesEvent> anyPhase, List<FacesEvent> onPhase)
 1904  
         {
 1905  36
             super();
 1906  36
             this._anyPhase = anyPhase;
 1907  36
             this._onPhase = onPhase;
 1908  36
         }
 1909  
 
 1910  
         public boolean hasMoreEvents()
 1911  
         {
 1912  34
             return (_anyPhase != null && _anyPhase.size() > 0) || (_onPhase != null && _onPhase.size() > 0); 
 1913  
         }
 1914  
 
 1915  
         public List<FacesEvent> getAnyPhase()
 1916  
         {
 1917  36
             return _anyPhase;
 1918  
         }
 1919  
 
 1920  
         public List<FacesEvent> getOnPhase()
 1921  
         {
 1922  36
             return _onPhase;
 1923  
         }
 1924  
     }
 1925  
     
 1926  4
     private static class ResetValuesCallback implements VisitCallback
 1927  
     {
 1928  
         public VisitResult visit(VisitContext context, UIComponent target)
 1929  
         {
 1930  0
             if (target instanceof EditableValueHolder)
 1931  
             {
 1932  0
                 ((EditableValueHolder)target).resetValue();
 1933  
             }
 1934  0
             return VisitResult.ACCEPT;
 1935  
         }
 1936  
     }
 1937  
 }