View Javadoc

1   /*
2    * $Id: SplashScreen.java 21785 2011-05-04 13:31:45Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.List;
17  
18  /**
19   * Implements singleton pattern to allow different splash-screen implementations
20   * following the concept of header, body, and footer. Header and footer are
21   * reserved internally to Mule but body can be used to customize splash-screen
22   * output. External code can e.g. hook into the start-up splash-screen as follows:
23   * <pre><code>
24   *   SplashScreen splashScreen = SplashScreen.getInstance(ServerStartupSplashScreen.class);
25   *   splashScreen.addBody("Some extra text");
26   * </code></pre>
27   */
28  public abstract class SplashScreen
29  {
30      protected List<String> header = new ArrayList<String>();
31      protected List<String> body = new ArrayList<String>();
32      protected List<String> footer = new ArrayList<String>();
33      
34      /**
35       * Setting the header clears body and footer assuming a new
36       * splash-screen is built.
37       * 
38       */
39      final public void setHeader(MuleContext context)
40      {
41          header.clear();
42          doHeader(context);
43      }
44      
45      final public void addBody(String line)
46      {
47          doBody(line);
48      }
49      
50      final public void setFooter(MuleContext context)
51      {
52          footer.clear();
53          doFooter(context);
54      }
55  
56      public static String miniSplash(final String message)
57      {
58          // middle dot char
59          return StringMessageUtils.getBoilerPlate(message, '+', 60);
60      }
61  
62      protected void doHeader(MuleContext context)
63      {
64          // default reserved for mule core info
65      }   
66      
67      protected void doBody(String line)
68      {
69          body.add(line);
70      }
71  
72      protected void doFooter(MuleContext context)
73      {
74          // default reserved for mule core info
75      }    
76      
77      public String toString()
78      {
79          List<String> boilerPlate = new ArrayList<String>(header);
80          boilerPlate.addAll(body);
81          boilerPlate.addAll(footer);
82          return StringMessageUtils.getBoilerPlate(boilerPlate, '*', 70);
83      }
84      
85      protected SplashScreen()
86      {
87          // make sure no one else creates an instance
88      }
89  }