View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software 
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License.
16   */
17  
18  package org.apache.jdo.impl.enhancer;
19  
20  import java.io.PrintWriter;
21  
22  import org.apache.jdo.impl.enhancer.util.Support;
23  
24  
25  
26  /***
27   * Provides some basic utilities for main classes.
28   *
29   * @author Martin Zaun
30   */
31  class LogSupport
32      extends Support
33  {
34      /***
35       * The stream to write messages to.
36       */
37      protected final PrintWriter out;
38  
39      /***
40       * The stream to write error messages to.
41       */
42      protected final PrintWriter err;
43      
44      /***
45       * Creates an instance.
46       */
47      public LogSupport(PrintWriter out,
48                        PrintWriter err) 
49      {
50          affirm(out != null);
51          affirm(err != null);
52          this.out = out;
53          this.err = err;
54      }
55  
56      /***
57       * Prints out an error message.
58       */
59      protected void printlnErr(String msg,
60                                Throwable ex,
61                                boolean verbose)
62      {
63          out.flush();
64          if (msg != null) {
65              err.println(msg);
66          }
67          if (ex != null) {
68              if (verbose) {
69                  ex.printStackTrace(err);
70              }
71              else {
72                  err.println(ex.toString());
73              }
74          }
75      }
76  
77      /***
78       * Prints out an error message.
79       */
80      protected void printlnErr(String msg,
81                                Throwable ex)
82      {
83          out.flush();
84          err.println(msg + ": " + ex.getMessage());
85          ex.printStackTrace(err);
86      }
87  
88      /***
89       * Prints out an error message.
90       */
91      protected void printlnErr(String msg)
92      {
93          out.flush();
94          err.println(msg);
95      }
96  
97      /***
98       * Prints out an error message.
99       */
100     protected void printlnErr()
101     {
102         out.flush();
103         err.println();
104     }
105 
106     /***
107      * Prints out a message.
108      */
109     protected void print(String msg)
110     {
111         out.print(msg);
112     }
113 
114     /***
115      * Prints out a message.
116      */
117     protected void println(String msg)
118     {
119         out.println(msg);
120     }
121 
122     /***
123      * Prints out a message.
124      */
125     protected void println()
126     {
127         out.println();
128     }
129 
130     /***
131      * Flushes streams.
132      */
133     protected void flush()
134     {
135         out.flush();
136         err.flush();
137     }
138 
139     // ----------------------------------------------------------------------
140 
141 //^olsen: support for I18N
142 
143     /***
144      *  Prints out a warning message.
145      *
146      *  @param msg the message
147      */
148 /*
149     public void printWarning(String msg)
150     {
151         out.println(getI18N("enhancer.warning", msg));
152     }
153 */
154     /***
155      *  Prints out a verbose message.
156      *
157      *  @param msg the message
158      */
159 /*
160     public void printMessage(String msg)
161     {
162         if (options.verbose.value) {
163             out.println(getI18N("enhancer.message", msg));
164         }
165     }
166 */
167 }