Package de.danet.an.workflow.util

Source Code of de.danet.an.workflow.util.CollectingErrorHandler

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: CollectingErrorHandler.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1  2003/06/30 20:05:17  drmlipp
* Initial import
*
* Revision 1.3  2003/06/27 08:51:44  lipp
* Fixed copyright/license information.
*
* Revision 1.2  2003/04/25 14:50:58  lipp
* Fixed javadoc errors and warnings.
*
* Revision 1.1  2003/03/07 08:01:29  huaiyang
* initial.
*
*
*/
package de.danet.an.workflow.util;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import de.danet.an.workflow.api.PrioritizedMessage;

/**
* This class collects errors while parsing and validating document.
*/
public class CollectingErrorHandler implements ErrorHandler {

    private List debugs = new ArrayList ();
    private List infos = new ArrayList ();
    private List warnings = new ArrayList ();
    private List errors = new ArrayList ();
    private List fatals = new ArrayList ();
    private List messages = new ArrayList ();

    /**
     * Return all accumulated debug messages.
     * @return list with debug messages (may be an empty list).
     */
    public List getDebugs() {
  return debugs;
    }
    /**
     * Return all accumulated infos messages.
     * @return list with info messages (may be an empty list).
     */
    public List getInfos() {
  return infos;
    }
    /**
     * Return all accumulated warnings.
     * @return list with warning messages (may be an empty list).
     */
    public List getWarnings() {
  return warnings;
    }

    /**
     * Return all accumulated errors.
     * @return list with error messages (may be an empty list).
     */
    public List getErrors() {
  return errors;
    }

    /**
     * Return all accumulated fatal errors.
     * @return list with fatal error messages (may be an empty list).
     */
    public List getFatalErrors() {
  return fatals;
    }

    /**
     * Return all accumulated messages, i.e. debugs, info, warnings,
     * errors and fatal errors.
     * @return list with error messages (may be an empty list).
     */
    public List getMessages() {
  return messages;
    }

    private String layoutMessage (SAXParseException exc) {
  return Integer.toString (exc.getLineNumber())
      + ": " + exc.getMessage();
    }

    /**
     * Handles parser warnings.
     * @param exc Parser exception
     */
    public void warning(SAXParseException exc) {
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.WARN, layoutMessage (exc));
  warnings.add (pm);
  messages.add (pm);
    }
    /**
     * Handles parser errors.
     * @param exc Parser exception
     * @throws SAXException Propagation of given SAXParseException
     */
    public void error(SAXParseException exc) throws SAXException {
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.ERROR, layoutMessage (exc));
  errors.add (pm);
  messages.add (pm);
    }
    /**
     * Handles fatal parser errors.
     * @param exc Parser exception
     * @throws SAXException Propagation of given SAXParseException
     */
    public void fatalError(SAXParseException exc) throws SAXException {
  PrioritizedMessage pm = new PrioritizedMessage
      (PrioritizedMessage.Priority.FATAL, layoutMessage (exc));
  fatals.add (pm);
  messages.add (pm);
    }

    /**
     * Append a prioritized message. This method may be used to add a message
     * from outside the immediate scope of the parser, and handle it like a
     * parse exception.
     * @param prioritizedMessage the given message.
     */
    public void add (PrioritizedMessage prioritizedMessage) {
  PrioritizedMessage.Priority priority = prioritizedMessage.priority();
  if (priority.compareTo(PrioritizedMessage.Priority.DEBUG) == 0) {
      debugs.add (prioritizedMessage);
  } else if (priority.compareTo(PrioritizedMessage.Priority.INFO) == 0) {
      infos.add (prioritizedMessage);
  } else if (priority.compareTo(PrioritizedMessage.Priority.WARN) == 0) {
      warnings.add (prioritizedMessage);
  } else if (priority.compareTo(PrioritizedMessage.Priority.ERROR) == 0){
      errors.add (prioritizedMessage);
  } else if (priority.compareTo(PrioritizedMessage.Priority.FATAL) == 0){
      fatals.add (prioritizedMessage);
  }
  messages.add (prioritizedMessage);
    }
}
TOP

Related Classes of de.danet.an.workflow.util.CollectingErrorHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.