Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SplashScreen |
|
| 0.0;0 |
1 | /* | |
2 | * $Id: SplashScreen.java 19191 2010-08-25 21:05:23Z tcarlson $ | |
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 | 0 | protected List<String> header = new ArrayList<String>(); |
31 | 0 | protected List<String> body = new ArrayList<String>(); |
32 | 0 | 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 | 0 | header.clear(); |
42 | 0 | doHeader(context); |
43 | 0 | } |
44 | ||
45 | final public void addBody(String line) | |
46 | { | |
47 | 0 | doBody(line); |
48 | 0 | } |
49 | ||
50 | final public void setFooter(MuleContext context) | |
51 | { | |
52 | 0 | footer.clear(); |
53 | 0 | doFooter(context); |
54 | 0 | } |
55 | ||
56 | protected void doHeader(MuleContext context) | |
57 | { | |
58 | // default reserved for mule core info | |
59 | 0 | } |
60 | ||
61 | protected void doBody(String line) | |
62 | { | |
63 | 0 | body.add(line); |
64 | 0 | } |
65 | ||
66 | protected void doFooter(MuleContext context) | |
67 | { | |
68 | // default reserved for mule core info | |
69 | 0 | } |
70 | ||
71 | public String toString() | |
72 | { | |
73 | 0 | List<String> boilerPlate = new ArrayList<String>(header); |
74 | 0 | boilerPlate.addAll(body); |
75 | 0 | boilerPlate.addAll(footer); |
76 | 0 | return StringMessageUtils.getBoilerPlate(boilerPlate, '*', 70); |
77 | } | |
78 | ||
79 | protected SplashScreen() | |
80 | 0 | { |
81 | // make sure no one else creates an instance | |
82 | 0 | } |
83 | } |