KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > CompilationErrorHandler


1 /* *****************************************************************************
2  * CompilationErrorHandler.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11 import org.jdom.Element;
12 import org.openlaszlo.utils.ChainedException;
13 import java.lang.Integer JavaDoc;
14 import java.io.*;
15 import java.util.*;
16 import org.openlaszlo.server.*;
17 import org.openlaszlo.utils.*;
18 import org.openlaszlo.xml.internal.*;
19
20 /** Hold a list of errors generated during compilation of an lzx file.
21  *
22  * The list of Errors are all wrapped by CompilationError
23  */

24 public class CompilationErrorHandler {
25     /** List of errors, these should all be of type CompilationError */
26     private List errors = new Vector();
27     protected String JavaDoc fileBase = "";
28     
29     public CompilationErrorHandler() {
30     }
31     
32     /** Set the base directory relative to which pathnames are
33      * reported. */

34     public void setFileBase(String JavaDoc fileBase) {
35         this.fileBase = fileBase;
36     }
37     
38     /** Append an error to list of errors.
39      * @param error the error which occurred
40      */

41     void addError(CompilationError e) {
42         e.setFileBase(fileBase);
43         errors.add(e);
44     }
45
46     /** Returns the list of errors
47      * @return the list of errors
48      */

49     public List getErrors()
50     {
51         return errors;
52     }
53
54     /**
55      * @return length of error list */

56     public int size()
57     {
58         return errors.size();
59     }
60
61     public boolean isEmpty() {
62         return errors.isEmpty();
63     }
64
65     /**
66      * Appends all the errors from ERRS into our list of errors.
67      * @param other a list of errors to append from
68      */

69     public void appendErrors(CompilationErrorHandler other) {
70         for (Iterator iter = other.getErrors().iterator(); iter.hasNext(); ) {
71             CompilationError error = (CompilationError) iter.next();
72             errors.add(error);
73         }
74     }
75
76     /** @return a single consolidated error which holds list of error
77         message strings which were collected during a compile.
78      */

79     public CompilationError toCompilationError() {
80         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81         for (Iterator iter = errors.iterator(); iter.hasNext(); ) {
82             CompilationError error = (CompilationError) iter.next();
83             buffer.append(error.getMessage());
84             if (iter.hasNext()) {
85                 buffer.append('\n');
86             }
87         }
88         return new CompilationError(buffer.toString());
89     }
90     
91     public String JavaDoc toXML() {
92         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
93         for (Iterator iter = errors.iterator(); iter.hasNext(); ) {
94             CompilationError error = (CompilationError) iter.next();
95             buffer.append(error.toXML());
96             if (iter.hasNext()) {
97                 buffer.append("<br/>");
98             }
99         }
100         return buffer.toString();
101     }
102 }
103
Popular Tags