Coverage Report - org.mule.util.SplashScreen
 
Classes in this File Line Coverage Branch Coverage Complexity
SplashScreen
55%
17/31
50%
1/2
1.222
 
 1  
 /*
 2  
  * $Id: SplashScreen.java 12150 2008-06-24 22:42:52Z aguenther $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.util;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 
 15  
 import java.util.ArrayList;
 16  
 import java.util.HashMap;
 17  
 import java.util.List;
 18  
 import java.util.Map;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 
 23  
 /**
 24  
  * Implements singleton pattern to allow different splash-screen implementations
 25  
  * following the concept of header, body, and footer. Header and footer are
 26  
  * reserved internally to Mule but body can be used to customize splash-screen
 27  
  * output. External code can e.g. hook into the start-up splash-screen as follows:
 28  
  * <pre><code>
 29  
  *   SplashScreen splashScreen = SplashScreen.getInstance(ServerStartupSplashScreen.class);
 30  
  *   splashScreen.addBody("Some extra text");
 31  
  * </code></pre>
 32  
  */
 33  
 public abstract class SplashScreen
 34  
 {
 35  2
     protected List header = new ArrayList();
 36  2
     protected List body = new ArrayList();
 37  2
     protected List footer = new ArrayList();
 38  
     
 39  2
     private static Log logger = LogFactory.getLog(SplashScreen.class);
 40  
     
 41  2
     private static final Map instances = new HashMap();    
 42  
     
 43  
     public static synchronized SplashScreen getInstance(Class clazz)
 44  
     {
 45  2
         SplashScreen splashScreen = (SplashScreen) instances.get(clazz);
 46  
         
 47  2
         if (splashScreen == null)
 48  
         {
 49  
             try
 50  
             {
 51  2
                 splashScreen = (SplashScreen) clazz.newInstance();
 52  2
                 instances.put(clazz, splashScreen);
 53  
             }
 54  0
             catch (Exception ignore)
 55  
             {
 56  0
                 logger.debug(ignore);
 57  2
             }
 58  
         }
 59  
         
 60  2
         return splashScreen;
 61  
     }
 62  
 
 63  
     /**
 64  
      * Setting the header clears body and footer assuming a new
 65  
      * splash-screen is built.
 66  
      * 
 67  
      * @param context
 68  
      */
 69  
     final public void setHeader(MuleContext context)
 70  
     {
 71  0
         header.clear();
 72  0
         doHeader(context);
 73  0
     }
 74  
     
 75  
     final public void addBody(String line)
 76  
     {
 77  0
         doBody(line);
 78  0
     }
 79  
     
 80  
     final public void setFooter(MuleContext context)
 81  
     {
 82  0
         footer.clear();
 83  0
         doFooter(context);
 84  0
     }
 85  
     
 86  
     protected void doHeader(MuleContext context)
 87  
     {
 88  
         // default reserved for mule core info
 89  0
     }   
 90  
     
 91  
     protected void doBody(String line)
 92  
     {
 93  0
         body.add(line);
 94  0
     }
 95  
 
 96  
     protected void doFooter(MuleContext context)
 97  
     {
 98  
         // default reserved for mule core info
 99  0
     }    
 100  
     
 101  
     public String toString()
 102  
     {
 103  6
         List boilerPlate = new ArrayList(header);
 104  6
         boilerPlate.addAll(body);
 105  6
         boilerPlate.addAll(footer);
 106  6
         return StringMessageUtils.getBoilerPlate(boilerPlate, '*', 70);
 107  
     }
 108  
     
 109  
     protected SplashScreen()
 110  2
     {
 111  
         // make sure no one else creates an instance
 112  2
     }
 113  
 }