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