KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > parser > lib > ErrorManager


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Mathieu Vadet.
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.parser.lib;
28
29 // Package dependencies
30
import org.objectweb.openccm.ast.api.Declaration;
31 import org.objectweb.openccm.ast.api.WithDeclarators;
32
33 /**
34  * This class manages errors.
35  *
36  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
37  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
38  *
39  * @version 0.3
40  */

41
42 public class ErrorManager
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     /**
51      * The file name.
52      */

53     private String JavaDoc fileName_;
54
55     /**
56      * The number of warnings.
57      */

58     private int nbWarnings_;
59
60     /**
61      * The number of errors.
62      */

63     private int nbErrors_;
64
65     // ==================================================================
66
//
67
// Constructor.
68
//
69
// ==================================================================
70

71     /**
72      * The constructor.
73      *
74      * @param fileName The name of the file that is being parsed.
75      */

76     public
77     ErrorManager(String JavaDoc fileName)
78     {
79         // Init internal state.
80
fileName_ = fileName;
81         nbWarnings_ = 0;
82         nbErrors_ = 0;
83     }
84
85     // ==================================================================
86
//
87
// Internal methods.
88
//
89
// ==================================================================
90

91     /**
92      * Display a message on the standart error stream.
93      *
94      * @param line The line number where the error (or warning) occured.
95      * @param kind The kind of the message ie "error" or "warning"
96      * or anything else.
97      * @param text The message to display.
98      */

99     protected void
100     log(int line, String JavaDoc kind, String JavaDoc text)
101     {
102         System.out.println(fileName_ + ':' + line + ": " + kind + ": " + text);
103     }
104
105     // ==================================================================
106
//
107
// Public methods.
108
//
109
// ==================================================================
110

111     /**
112      * Obtain the number of warnings.
113      *
114      * @return The number of warnings.
115      */

116     public int
117     getNbWarnings()
118     {
119         return nbWarnings_;
120     }
121
122     /**
123      * Obtain the number of errors.
124      *
125      * @return The number of errors.
126      */

127     public int
128     getNbErrors()
129     {
130         return nbErrors_;
131     }
132
133     /**
134      * Get the name of the file that is read.
135      *
136      * @return The name of the file.
137      */

138     public String JavaDoc
139     getFileName()
140     {
141         return fileName_;
142     }
143
144     /**
145      * Set the name of the file that is read.
146      *
147      * @param The name of the file.
148      */

149     public void
150     setFileName(String JavaDoc fileName)
151     {
152         fileName_ = fileName;
153     }
154
155     /**
156      * Display a warning.
157      *
158      * @param line The line number where the warning occured.
159      * @param text The message to display.
160      */

161     public void
162     warning(int line, String JavaDoc text)
163     {
164         log(line, "warning", text);
165         nbWarnings_ ++;
166     }
167
168     /**
169      * Display an error.
170      *
171      * @param line The line number where the error occured.
172      * @param text The message to display.
173      */

174     public void
175     error(int line, String JavaDoc text)
176     {
177         log(line, "error", text);
178         nbErrors_ ++;
179     }
180
181     /**
182      * Display an error.
183      *
184      * @param line The line number where the error occured.
185      * @param text The message to display.
186      * @param exc The exception to display.
187      */

188     public void
189     error(int line, String JavaDoc text, Exception JavaDoc exc)
190     {
191         error(line, text);
192         exc.printStackTrace();
193     }
194
195     /**
196      * Display an error.
197      *
198      * @param line The line number where the error occured.
199      * @param sysExc The system exception to display.
200      */

201     public void
202     error(int line, org.omg.CORBA.SystemException JavaDoc sysExc)
203     {
204         error(line, sysExc, null);
205     }
206
207     /**
208      * Display an error.
209      *
210      * @param line The line number where the error occured.
211      * @param sysExc The system exception to display.
212      * @param decl The declaration that threw the system exception.
213      */

214     public void
215     error(int line,
216           org.omg.CORBA.SystemException JavaDoc sysExc,
217           Declaration decl)
218     {
219         int minor = sysExc.minor;
220
221         if(sysExc instanceof org.omg.CORBA.BAD_PARAM JavaDoc)
222         {
223             switch(minor)
224             {
225             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.RidAlreadyDefined:
226                 error(line, '`' + decl.getId() +
227                         "' already defined in the IFR");
228                 return;
229
230             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameAlreadyUsed:
231                 error(line, '`' + decl.getName() +
232                         "' already defined in the context");
233                 return;
234
235             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidContainer:
236                 error(line, "Target is an invalid container");
237                 return;
238
239             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameClashInInheritedContext:
240                 error(line, '`' + decl.getName() +
241                         "' already defined in inherited context");
242                 return;
243
244             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidAbstractInterfaceInheritance:
245                 error(line, "invalid abstract interface inheritance");
246                 return;
247
248             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidLocalInterfaceInheritance:
249                 error(line, "invalid local interface inheritance");
250                 return;
251
252             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NotLocalObject:
253                 // Do nothing because the error was already reported!
254
return;
255
256             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NameAlreadyUsedByImmediateScope:
257                 error(line, '`' + decl.getName() +
258                             "' already used by immediate scope");
259                 return;
260
261             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NeedOnlyInParams:
262                 error(line, '`' + decl.getName() +
263                             "' only needs in parameters");
264                 return;
265
266             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.NoExceptionsForOnewayOperation:
267                 error(line, '`' + decl.getName() +
268                             "' no exceptions expected for oneway operation");
269                 return;
270
271             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.InvalidValueBoxType:
272                 error(line, '`' + decl.getName() +
273                             "' invalid valuebox type");
274                 return;
275             }
276
277             if (minor >= org.objectweb.openccm.ir3.SystemExceptionMinorValues.DuplicateDeclarator)
278             {
279                 int index = minor - org.objectweb.openccm.ir3.SystemExceptionMinorValues.DuplicateDeclarator;
280                 error(line, '`' + ((WithDeclarators)decl).declaratorAt(index) +
281                             "' duplicate declarator in " + decl.getAbsoluteName());
282                 return;
283             }
284
285         }
286
287         if(sysExc instanceof org.omg.CORBA.BAD_INV_ORDER JavaDoc)
288         {
289             switch(minor)
290             {
291             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.Dependency:
292                 error(line, "dependency exits in IFR preventing destruction");
293                 return;
294
295             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.CanNotBeDestroyed:
296                 error(line, "indestructible object");
297                 return;
298             }
299         }
300
301         if(sysExc instanceof org.omg.CORBA.INTF_REPOS JavaDoc)
302         {
303             switch(minor)
304             {
305             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.AmbiguousLookup:
306                 error(line, "ambiguous lookup");
307                 return;
308             }
309         }
310
311         if (decl != null)
312             error(line, sysExc.toString() + " on " + decl.getAbsoluteName());
313         else
314             error(line, sysExc.toString());
315
316         sysExc.printStackTrace();
317     }
318 }
319
Popular Tags