1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jdo.impl.enhancer.core;
18
19 import java.io.PrintWriter;
20
21 import org.apache.jdo.impl.enhancer.meta.EnhancerMetaData;
22 import org.apache.jdo.impl.enhancer.util.Support;
23
24
25
26
27 /***
28 * Serves as a repository for the options for the enhancer.
29 */
30 public final class Environment
31 extends Support
32 {
33 /***
34 * Writer for regular program output and warnings.
35 */
36 private PrintWriter out = new PrintWriter(System.out, true);
37
38 /***
39 * Writer for error output.
40 */
41 private PrintWriter err = new PrintWriter(System.err, true);
42
43 /***
44 * If true, provide timing statistics.
45 */
46 private boolean timingOption = false;
47
48 /***
49 * If true, dump class.
50 */
51 private boolean dumpClassOption = false;
52
53 /***
54 * If true, don't apply augmentation to PC classes.
55 */
56 private boolean noAugmentOption = false;
57
58 /***
59 * If true, don't apply annotation to PC classes.
60 */
61 private boolean noAnnotateOption = false;
62
63 /***
64 * If true, provide verbose output.
65 */
66 private boolean verboseOption = false;
67
68 /***
69 * If true, squash warnings.
70 */
71 private boolean quietOption = false;
72
73 /***
74 * The number of errors encountered thus far.
75 */
76 private int errorsEncountered = 0;
77
78 /***
79 * The instance providing the JDO meta data.
80 */
81 private EnhancerMetaData jdoMetaData;
82
83 /***
84 * Last error message.
85 */
86 private String lastErrorMessage = null;
87
88 /***
89 * The constructor
90 */
91 public Environment()
92 {}
93
94 public void error(String error)
95 {
96 errorsEncountered++;
97 err.println(lastErrorMessage = getI18N("enhancer.enumerated_error",
98 errorsEncountered,
99 error));
100 }
101
102 public void warning(String warn)
103 {
104 if (!quietOption) {
105 out.println(getI18N("enhancer.warning", warn));
106 }
107 }
108
109 public void verbose(String msg)
110 {
111 if (verboseOption) {
112 out.println(msg);
113 }
114 }
115
116 public void message(String msg)
117 {
118 if (verboseOption) {
119 out.println(getI18N("enhancer.message", msg));
120 }
121 }
122
123 public void messageNL(String msg)
124 {
125 if (verboseOption) {
126 out.println();
127 out.println(getI18N("enhancer.message", msg));
128 }
129 }
130
131 public int errorCount()
132 {
133 return errorsEncountered;
134 }
135
136 public final String getLastErrorMessage()
137 {
138 return this.lastErrorMessage;
139 }
140
141 public void setDoTimingStatistics(boolean opt)
142 {
143 timingOption = opt;
144 }
145
146 public boolean doTimingStatistics()
147 {
148 return timingOption;
149 }
150
151 public void setDumpClass(boolean opt)
152 {
153 dumpClassOption = opt;
154 }
155
156 public boolean dumpClass()
157 {
158 return dumpClassOption;
159 }
160
161 public void setNoAugment(boolean opt)
162 {
163 noAugmentOption = opt;
164 }
165
166 public boolean noAugment()
167 {
168 return noAugmentOption;
169 }
170
171 public void setNoAnnotate(boolean opt)
172 {
173 noAnnotateOption = opt;
174 }
175
176 public boolean noAnnotate()
177 {
178 return noAnnotateOption;
179 }
180
181 public EnhancerMetaData getEnhancerMetaData()
182 {
183 return jdoMetaData;
184 }
185
186 public void setEnhancerMetaData(EnhancerMetaData jdoMetaData)
187 {
188 this.jdoMetaData = jdoMetaData;
189 }
190
191 public void setOutputWriter(PrintWriter out)
192 {
193 this.out = out;
194 }
195
196 public PrintWriter getOutputWriter()
197 {
198 return out;
199 }
200
201 public void setErrorWriter(PrintWriter err)
202 {
203 this.err = err;
204 }
205
206 public PrintWriter getErrorWriter()
207 {
208 return err;
209 }
210
211 public void setVerbose(boolean beVerbose)
212 {
213 verboseOption = beVerbose;
214 }
215
216 public boolean isVerbose()
217 {
218 return verboseOption;
219 }
220
221 public void setQuiet(boolean beQuiet)
222 {
223 quietOption = beQuiet;
224 }
225
226 public boolean isQuiet()
227 {
228 return quietOption;
229 }
230
231 /***
232 * Reset the environment.
233 */
234 public void reset()
235 {
236
237
238
239
240
241
242
243 errorsEncountered = 0;
244 }
245 }