Coverage report

  %line %branch
net.sf.infrared.agent.setup.InfraREDServletContextListener
64% 
100% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  * 
 16  
  *
 17  
  *
 18  
  * Original Author:  kamal.govindraj (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.agent.setup;
 23  
 
 24  
 import java.net.InetAddress;
 25  
 import java.net.UnknownHostException;
 26  
 
 27  
 import javax.servlet.ServletContext;
 28  
 import javax.servlet.ServletContextEvent;
 29  
 import javax.servlet.ServletContextListener;
 30  
 
 31  
 import net.sf.infrared.agent.MonitorConfigImpl;
 32  
 import net.sf.infrared.base.util.LoggingFactory;
 33  
 
 34  
 import org.apache.log4j.Logger;
 35  
 
 36  
 /**
 37  
  * ServletContextListener implementation that setups up infraRED.
 38  
  */
 39  
 public class InfraREDServletContextListener implements ServletContextListener {
 40  
     public static final String KEY_CONFIGURATIONPROVIDER = "net.sf.infrared.configurationprovider";
 41  
 
 42  1
     private static final Logger log = 
 43  1
         LoggingFactory.getLogger(InfraREDServletContextListener.class);
 44  
 
 45  
     private InfraREDLifeCycleListener lifeCycleListener; 
 46  
     
 47  1
     public InfraREDServletContextListener() {
 48  1
         lifeCycleListener = new InfraREDLifeCycleListener();
 49  1
     }
 50  
 
 51  
     public void contextInitialized(ServletContextEvent event) {
 52  0
         ServletContext context = event.getServletContext();
 53  0
         initialized(context);
 54  0
     }
 55  
 
 56  
     public void contextDestroyed(ServletContextEvent event) {
 57  0
         destroyed(event.getServletContext());
 58  0
     }
 59  
     
 60  
     public void initialized(ServletContext context) {
 61  1
         String configProvider = 
 62  
             (String) context.getAttribute(KEY_CONFIGURATIONPROVIDER);
 63  1
         if (configProvider == null) {
 64  1
             configProvider = MonitorConfigImpl.DEFAULT_CONFIG_LOCATION;
 65  
         }
 66  
 
 67  1
         String appName = context.getServletContextName();
 68  1
         if (appName == null) {
 69  1
             appName = "unknown";
 70  1
             log.info("Application name is not set in the war");
 71  
         }
 72  1
         getLifeCycleListener().initialized(appName, getInstanceId(), configProvider);
 73  1
     }
 74  
     
 75  
     public void destroyed(ServletContext context) {
 76  0
         getLifeCycleListener().destroyed(context.getServletContextName());
 77  0
     }
 78  
 
 79  
     public String getInstanceId() {
 80  1
         String instanceId = "unknown";
 81  
         try {
 82  1
             instanceId = InetAddress.getLocalHost().getHostName();
 83  0
         } catch (UnknownHostException e) {
 84  0
             log.error(e);
 85  1
         }
 86  1
         return instanceId;
 87  
     }
 88  
     
 89  
     InfraREDLifeCycleListener getLifeCycleListener() {
 90  0
         return this.lifeCycleListener;
 91  
     }
 92  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.