View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  
17  package org.apache.jdo.impl.enhancer;
18  
19  import java.io.PrintWriter;
20  
21  import org.apache.jdo.impl.enhancer.util.Support;
22  
23  
24  
25  /***
26   * Provides some basic utilities for main classes.
27   *
28   * @author Martin Zaun
29   */
30  class LogSupport
31      extends Support
32  {
33      /***
34       * The stream to write messages to.
35       */
36      protected final PrintWriter out;
37  
38      /***
39       * The stream to write error messages to.
40       */
41      protected final PrintWriter err;
42      
43      /***
44       * Creates an instance.
45       */
46      public LogSupport(PrintWriter out,
47                        PrintWriter err) 
48      {
49          affirm(out != null);
50          affirm(err != null);
51          this.out = out;
52          this.err = err;
53      }
54  
55      /***
56       * Prints out an error message.
57       */
58      protected void printlnErr(String msg,
59                                Throwable ex,
60                                boolean verbose)
61      {
62          out.flush();
63          if (msg != null) {
64              err.println(msg);
65          }
66          if (ex != null) {
67              if (verbose) {
68                  ex.printStackTrace(err);
69              }
70              else {
71                  err.println(ex.toString());
72              }
73          }
74      }
75  
76      /***
77       * Prints out an error message.
78       */
79      protected void printlnErr(String msg,
80                                Throwable ex)
81      {
82          out.flush();
83          err.println(msg + ": " + ex.getMessage());
84          ex.printStackTrace(err);
85      }
86  
87      /***
88       * Prints out an error message.
89       */
90      protected void printlnErr(String msg)
91      {
92          out.flush();
93          err.println(msg);
94      }
95  
96      /***
97       * Prints out an error message.
98       */
99      protected void printlnErr()
100     {
101         out.flush();
102         err.println();
103     }
104 
105     /***
106      * Prints out a message.
107      */
108     protected void print(String msg)
109     {
110         out.print(msg);
111     }
112 
113     /***
114      * Prints out a message.
115      */
116     protected void println(String msg)
117     {
118         out.println(msg);
119     }
120 
121     /***
122      * Prints out a message.
123      */
124     protected void println()
125     {
126         out.println();
127     }
128 
129     /***
130      * Flushes streams.
131      */
132     protected void flush()
133     {
134         out.flush();
135         err.flush();
136     }
137 
138     // ----------------------------------------------------------------------
139 
140 //^olsen: support for I18N
141 
142     /***
143      *  Prints out a warning message.
144      *
145      *  @param msg the message
146      */
147 /*
148     public void printWarning(String msg)
149     {
150         out.println(getI18N("enhancer.warning", msg));
151     }
152 */
153     /***
154      *  Prints out a verbose message.
155      *
156      *  @param msg the message
157      */
158 /*
159     public void printMessage(String msg)
160     {
161         if (options.verbose.value) {
162             out.println(getI18N("enhancer.message", msg));
163         }
164     }
165 */
166 }