001: /* *****************************************************************************
002: * CompilationErrorHandler.java
003: * ****************************************************************************/
004:
005: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006: * Copyright 2001-2006 Laszlo Systems, Inc. All Rights Reserved. *
007: * Use is subject to license terms. *
008: * J_LZ_COPYRIGHT_END *********************************************************/
009:
010: package org.openlaszlo.compiler;
011:
012: import org.jdom.Element;
013: import org.openlaszlo.utils.ChainedException;
014: import java.lang.Integer;
015: import java.io.*;
016: import java.util.*;
017: import org.openlaszlo.server.*;
018: import org.openlaszlo.utils.*;
019: import org.openlaszlo.xml.internal.*;
020:
021: /** Hold a list of errors generated during compilation of an lzx file.
022: *
023: * The list of Errors are all wrapped by CompilationError
024: */
025: public class CompilationErrorHandler {
026: /** List of errors, these should all be of type CompilationError */
027: private List errors = new Vector();
028: protected String fileBase = "";
029:
030: public CompilationErrorHandler() {
031: }
032:
033: /** Set the base directory relative to which pathnames are
034: * reported. */
035: public void setFileBase(String fileBase) {
036: this .fileBase = fileBase;
037: }
038:
039: /** Append an error to list of errors.
040: * @param e the error which occurred
041: */
042: void addError(CompilationError e) {
043: e.setFileBase(fileBase);
044: errors.add(e);
045: }
046:
047: /** Returns the list of errors
048: * @return the list of errors
049: */
050: public List getErrors() {
051: return errors;
052: }
053:
054: /**
055: * @return length of error list */
056: public int size() {
057: return errors.size();
058: }
059:
060: public boolean isEmpty() {
061: return errors.isEmpty();
062: }
063:
064: /**
065: * Appends all the errors from ERRS into our list of errors.
066: * @param other a list of errors to append from
067: */
068: public void appendErrors(CompilationErrorHandler other) {
069: for (Iterator iter = other.getErrors().iterator(); iter
070: .hasNext();) {
071: CompilationError error = (CompilationError) iter.next();
072: errors.add(error);
073: }
074: }
075:
076: /** @return a single consolidated error which holds list of error
077: message strings which were collected during a compile.
078: */
079: public CompilationError toCompilationError() {
080: StringBuffer buffer = new StringBuffer();
081: for (Iterator iter = errors.iterator(); iter.hasNext();) {
082: CompilationError error = (CompilationError) iter.next();
083: buffer.append(error.getMessage());
084: if (iter.hasNext()) {
085: buffer.append('\n');
086: }
087: }
088: return new CompilationError(buffer.toString());
089: }
090:
091: public String toXML() {
092: StringBuffer buffer = new StringBuffer();
093: for (Iterator iter = errors.iterator(); iter.hasNext();) {
094: CompilationError error = (CompilationError) iter.next();
095: buffer.append(error.toXML());
096: if (iter.hasNext()) {
097: buffer.append("<br/>");
098: }
099: }
100: return buffer.toString();
101: }
102: }
|