View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.common.util.inform;
17  
18  import java.io.PrintStream;
19  
20  import org.kuali.common.util.Assert;
21  import org.kuali.common.util.log.LogMsg;
22  
23  public final class Inform {
24  
25  	public static final PrintStream DEFAULT_PRINT_STREAM = System.out;
26  	public static final String DEFAULT_START_TOKEN = "[INFO] Progress: ";
27  	public static final String DEFAULT_PROGRESS_TOKEN = ".";
28  	public static final String DEFAULT_COMPLETE_TOKEN = "\n";
29  	public static final LogMsg DEFAULT_START_MESSAGE = LogMsg.NOOP;
30  	public static final LogMsg DEFAULT_STOP_MESSAGE = LogMsg.NOOP;
31  
32  	public static final Inform DEFAULT_INFORM = new Inform();
33  
34  	public Inform() {
35  		this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, DEFAULT_START_MESSAGE, DEFAULT_STOP_MESSAGE);
36  	}
37  
38  	public Inform(LogMsg startMessage) {
39  		this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, startMessage, DEFAULT_STOP_MESSAGE);
40  	}
41  
42  	public Inform(LogMsg startMessage, LogMsg stopMessage) {
43  		this(DEFAULT_PRINT_STREAM, DEFAULT_START_TOKEN, DEFAULT_PROGRESS_TOKEN, DEFAULT_COMPLETE_TOKEN, startMessage, stopMessage);
44  	}
45  
46  	public Inform(PrintStream printStream, String startToken, String progressToken, String completeToken, LogMsg startMessage, LogMsg stopMessage) {
47  		Assert.noNulls(printStream, startMessage, stopMessage, completeToken);
48  		// Printing a whitespace character to indicate progress completion is ok
49  		// Assert.noBlanks(startToken, progressToken,completeToken);
50  		Assert.noBlanks(startToken, progressToken);
51  		this.printStream = printStream;
52  		this.startToken = startToken;
53  		this.progressToken = progressToken;
54  		this.completeToken = completeToken;
55  		this.startMessage = startMessage;
56  		this.stopMessage = stopMessage;
57  	}
58  
59  	private final PrintStream printStream;
60  	private final String startToken;
61  	private final String progressToken;
62  	private final String completeToken;
63  	private final LogMsg startMessage;
64  	private final LogMsg stopMessage;
65  
66  	public PrintStream getPrintStream() {
67  		return printStream;
68  	}
69  
70  	public String getStartToken() {
71  		return startToken;
72  	}
73  
74  	public String getCompleteToken() {
75  		return completeToken;
76  	}
77  
78  	public LogMsg getStartMessage() {
79  		return startMessage;
80  	}
81  
82  	public LogMsg getStopMessage() {
83  		return stopMessage;
84  	}
85  
86  	public String getProgressToken() {
87  		return progressToken;
88  	}
89  
90  }