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