Coverage Report - org.apache.myfaces.application.ApplicationFactoryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplicationFactoryImpl
0%
0/26
0%
0/12
2
 
 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.application;
 20  
 
 21  
 import javax.faces.application.Application;
 22  
 import javax.faces.application.ApplicationFactory;
 23  
 import javax.faces.context.ExternalContext;
 24  
 import javax.faces.context.FacesContext;
 25  
 
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 /**
 30  
  * @author Manfred Geiler (latest modification by $Author: lu4242 $)
 31  
  * @author Thomas Spiegl
 32  
  * @version $Revision: 775008 $ $Date: 2009-05-15 00:23:20 -0500 (Fri, 15 May 2009) $
 33  
  */
 34  
 public class ApplicationFactoryImpl
 35  
     extends ApplicationFactory
 36  
 {
 37  0
     private static final Log log = LogFactory.getLog(ApplicationFactoryImpl.class);
 38  
 
 39  
     /**
 40  
      * Application is thread-safe (see Application javadoc)
 41  
      * "Application represents a per-web-application singleton object..."
 42  
      * FactoryFinder has a ClassLoader-Factory Map. Since each webapp has it's
 43  
      * own ClassLoader, each webapp will have it's own private factory instances.
 44  
      */
 45  
     private Application _application;
 46  
     
 47  0
     private boolean _myfacesInstanceAddedToApplicationMap = false;
 48  
 
 49  
     public ApplicationFactoryImpl()
 50  0
     {
 51  0
         createAndLogNewApplication();
 52  0
     }
 53  
 
 54  
     private void createAndLogNewApplication() {
 55  0
         _application = new ApplicationImpl();
 56  0
         putApplicationOnMap();
 57  0
         if (log.isTraceEnabled()) log.trace("New ApplicationFactory instance created");
 58  0
     }
 59  
 
 60  
     public void purgeApplication(){
 61  0
         createAndLogNewApplication();
 62  0
     }
 63  
 
 64  
     public Application getApplication()
 65  
     {
 66  
         //Put it on ApplicationMap, so javax.faces.application.Application
 67  
         //class can find it. This allows wrapped jsf 1.1 application instances
 68  
         //to work correctly in jsf 1.2 as ri does.
 69  0
         if (_application != null && !_myfacesInstanceAddedToApplicationMap)
 70  
         {
 71  0
             putApplicationOnMap();
 72  
         }
 73  
 
 74  0
         return _application;
 75  
     }
 76  
 
 77  
     public void setApplication(Application application)
 78  
     {
 79  0
         if (application == null)
 80  
         {
 81  0
             throw new NullPointerException("Cannot set a null application in the ApplicationFactory");
 82  
         }
 83  0
         _application = application;
 84  0
         putApplicationOnMap();
 85  0
     }
 86  
     
 87  
     private void putApplicationOnMap()
 88  
     {
 89  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 90  0
         if (facesContext != null)
 91  
         {
 92  0
             ExternalContext externalContext = facesContext.getExternalContext();
 93  0
             if (externalContext != null)
 94  
             {
 95  0
                 externalContext.
 96  
                     getApplicationMap().put("org.apache.myfaces.application.ApplicationImpl", _application);
 97  0
                 _myfacesInstanceAddedToApplicationMap = true;
 98  
             }
 99  
         }        
 100  0
     }
 101  
 
 102  
 }