1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.slf4j;
20
21 import java.io.PrintStream;
22
23 /**
24 * This class encapsulates the user's choice of output target.
25 *
26 * @author Ceki Gülcü
27 *
28 */
29 class OutputChoice {
30
31 enum OutputChoiceType {
32 SYS_OUT,
33 CACHED_SYS_OUT,
34 SYS_ERR,
35 CACHED_SYS_ERR,
36 FILE;
37 }
38
39 final OutputChoiceType outputChoiceType;
40 final PrintStream targetPrintStream;
41
42 OutputChoice(OutputChoiceType outputChoiceType) {
43 if (outputChoiceType == OutputChoiceType.FILE) {
44 throw new IllegalArgumentException();
45 }
46 this.outputChoiceType = outputChoiceType;
47 if (outputChoiceType == OutputChoiceType.CACHED_SYS_OUT) {
48 this.targetPrintStream = System.out;
49 } else if (outputChoiceType == OutputChoiceType.CACHED_SYS_ERR) {
50 this.targetPrintStream = System.err;
51 } else {
52 this.targetPrintStream = null;
53 }
54 }
55
56 OutputChoice(PrintStream printStream) {
57 this.outputChoiceType = OutputChoiceType.FILE;
58 this.targetPrintStream = printStream;
59 }
60
61 PrintStream getTargetPrintStream() {
62 switch (outputChoiceType) {
63 case SYS_OUT:
64 return System.out;
65 case SYS_ERR:
66 return System.err;
67 case CACHED_SYS_ERR:
68 case CACHED_SYS_OUT:
69 case FILE:
70 return targetPrintStream;
71 default:
72 throw new IllegalArgumentException();
73 }
74 }
75 }