All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yaoqiang.bpmn.model.BPMNModelParsingErrors Maven / Gradle / Ivy

package org.yaoqiang.bpmn.model;

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

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

/**
 * BPMNModelParsingErrors
 * 
 * @author Shi Yaoqiang([email protected])
 */
public class BPMNModelParsingErrors implements ErrorHandler {

	public static String ERROR = "[Error]";
	public static String WARNING = "[Warning]";
	public static String FATAL_ERROR = "[Fatal Error]";
	public static String AT_LINE_NO_STRING = " at line number ";

	public BPMNModelParsingErrors() {
		super();
	}

	List errorMessages = new ArrayList();

	public void warning(SAXParseException ex) {
		store(ex, WARNING);
	}

	public void error(SAXParseException ex) {
		store(ex, ERROR);
	}

	public void fatalError(SAXParseException ex) throws SAXException {
		store(ex, FATAL_ERROR);
	}

	public List getErrorMessages() {
		return errorMessages;
	}

	public void clearErrors() {
		errorMessages.clear();
	}

	void store(SAXParseException ex, String type) {

		String errorString = type + AT_LINE_NO_STRING + ex.getLineNumber() + ": " + ex.getMessage() + "\n";
		errorMessages.add(new ErrorMessage(type, ex.getLineNumber(), ex.getMessage()));
		System.err.println(errorString);
	}

	public class ErrorMessage {

		protected String type;

		protected int lineNumber;

		protected String message;

		private ErrorMessage(String type, int lineNumber, String message) {
			this.type = type;
			this.lineNumber = lineNumber;
			this.message = message;
		}

		public final String getType() {
			return type;
		}

		public final int getLineNumber() {
			return lineNumber;
		}

		public final String getMessage() {
			return message;
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy