FileDocCategorySizeDatePackage
ErrorListenerModel.javaAPI DocExample6418Sun Sep 02 14:59:04 BST 2001com.oreilly.javaxslt.swingtrans

ErrorListenerModel

public class ErrorListenerModel extends AbstractTableModel implements ErrorListener
A JTable data model that provides detail information about a list of javax.xml.transform.TransformerException objects.

Fields Summary
private static final int
LINE_COL
private static final int
COLUMN_COL
private static final int
PUBLIC_ID_COL
private static final int
SYSTEM_ID_COL
private static final int
MESSAGE_AND_LOC_COL
private static final int
LOCATION_COL
private static final int
EXCEPTION_COL
private static final int
CAUSE_COL
private static final String[]
COLUMN_NAMES
private List
exceptionList
Constructors Summary
Methods Summary
public voiderror(javax.xml.transform.TransformerException te)
This is part of the javax.xml.transform.ErrorListener interface. Indicates that a recoverable error occurred.

        report(te);
    
public voidfatalError(javax.xml.transform.TransformerException te)
This is part of the javax.xml.transform.ErrorListener interface. Indicates that a non-recoverable error occurred.

        report(te);
    
public intgetColumnCount()
Part of the TableModel interface.

        return (this.exceptionList == null) ? 1 :
                COLUMN_NAMES.length;
    
public java.lang.StringgetColumnName(int column)
Part of the TableModel interface.

        return (this.exceptionList == null)
                ?  "Transformation Problems"
                : COLUMN_NAMES[column];
    
public java.lang.StringgetDetailReport(int row)

return
a detailed text report of the exception at the specified row.


                     
        
        if (this.exceptionList == null
                || row < 0 || row >= this.exceptionList.size()) {
            return "";
        }

        TransformerException te = (TransformerException)
                this.exceptionList.get(row);
        SourceLocator loc = te.getLocator(); // may be null

        // buffer the report
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        pw.println(te.getClass().getName());
        pw.println("-----------------------------------------------------");
        if (loc == null) {
            pw.println("Line Number  : [null SourceLocator]");
            pw.println("Column Number: [null SourceLocator]");
            pw.println("Public ID    : [null SourceLocator]");
            pw.println("System ID    : [null SourceLocator]");
        } else {
            pw.println("Line Number  : " + loc.getLineNumber());
            pw.println("Column Number: " + loc.getColumnNumber());
            pw.println("Public ID    : " + loc.getPublicId());
            pw.println("System ID    : " + loc.getSystemId());
        }

        pw.println("Message & Location : " + te.getMessageAndLocation());
        pw.println("Location           : " + te.getLocationAsString());

        pw.println("Exception          : " + te.getException());
        if (te.getException() != null) {
            te.getException().printStackTrace(pw);
        }

        pw.println("Cause              : " + te.getCause());
        if (te.getCause() != null && (te.getCause() != te.getException())) {
            te.getCause().printStackTrace(pw);
        }

        return sw.toString();
    
public intgetRowCount()
Part of the TableModel interface.

        return (this.exceptionList == null) ? 1 :
                this.exceptionList.size();
    
public java.lang.ObjectgetValueAt(int row, int column)
Part of the TableModel interface.

        if (this.exceptionList == null) {
            return "No errors or warnings";
        } else {
            TransformerException te = (TransformerException)
                    this.exceptionList.get(row);
            SourceLocator loc = te.getLocator();

            switch (column) {
            case LINE_COL:
                return (loc != null)
                        ? String.valueOf(loc.getLineNumber()) : "N/A";
            case COLUMN_COL:
                return (loc != null)
                        ? String.valueOf(loc.getColumnNumber()) : "N/A";
            case PUBLIC_ID_COL:
                return (loc != null) ? loc.getPublicId() : "N/A";
            case SYSTEM_ID_COL:
                return (loc != null) ? loc.getSystemId() : "N/A";
            case MESSAGE_AND_LOC_COL:
                return te.getMessageAndLocation();
            case LOCATION_COL:
                return te.getLocationAsString();
            case EXCEPTION_COL:
                return te.getException();
            case CAUSE_COL:
                return te.getCause();
            default:
                return "[error]"; // shouldn't happen
            }
        }
    
public booleanhasErrors()

return
true if any errors occurred.

        return this.exceptionList != null;
    
private voidreport(javax.xml.transform.TransformerException te)

        if (this.exceptionList == null) {
            this.exceptionList = new ArrayList();
            this.exceptionList.add(te);
            fireTableStructureChanged();
        } else {
            this.exceptionList.add(te);
            int row = this.exceptionList.size()-1;
            super.fireTableRowsInserted(row, row);
        }
    
public voidwarning(javax.xml.transform.TransformerException te)
This is part of the javax.xml.transform.ErrorListener interface. Indicates that a warning occurred. Transformers are required to continue processing after warnings, unless the error listener throws TransformerException.

        report(te);