View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util;
8   
9   import org.mule.api.MuleContext;
10  
11  import java.util.ArrayList;
12  import java.util.List;
13  
14  /**
15   * Implements singleton pattern to allow different splash-screen implementations
16   * following the concept of header, body, and footer. Header and footer are
17   * reserved internally to Mule but body can be used to customize splash-screen
18   * output. External code can e.g. hook into the start-up splash-screen as follows:
19   * <pre><code>
20   *   SplashScreen splashScreen = SplashScreen.getInstance(ServerStartupSplashScreen.class);
21   *   splashScreen.addBody("Some extra text");
22   * </code></pre>
23   */
24  public abstract class SplashScreen
25  {
26      protected List<String> header = new ArrayList<String>();
27      protected List<String> body = new ArrayList<String>();
28      protected List<String> footer = new ArrayList<String>();
29      
30      /**
31       * Setting the header clears body and footer assuming a new
32       * splash-screen is built.
33       * 
34       */
35      final public void setHeader(MuleContext context)
36      {
37          header.clear();
38          doHeader(context);
39      }
40      
41      final public void addBody(String line)
42      {
43          doBody(line);
44      }
45      
46      final public void setFooter(MuleContext context)
47      {
48          footer.clear();
49          doFooter(context);
50      }
51  
52      public static String miniSplash(final String message)
53      {
54          // middle dot char
55          return StringMessageUtils.getBoilerPlate(message, '+', 60);
56      }
57  
58      protected void doHeader(MuleContext context)
59      {
60          // default reserved for mule core info
61      }   
62      
63      protected void doBody(String line)
64      {
65          body.add(line);
66      }
67  
68      protected void doFooter(MuleContext context)
69      {
70          // default reserved for mule core info
71      }    
72      
73      public String toString()
74      {
75          List<String> boilerPlate = new ArrayList<String>(header);
76          boilerPlate.addAll(body);
77          boilerPlate.addAll(footer);
78          return StringMessageUtils.getBoilerPlate(boilerPlate, '*', 70);
79      }
80      
81      protected SplashScreen()
82      {
83          // make sure no one else creates an instance
84      }
85  }