001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.util;
012:
013: import java.util.EventObject;
014:
015: public class KeYRecoderExcHandler extends KeYExceptionHandlerImpl
016: implements recoder.service.ErrorHandler {
017:
018: private ExtList recoderExceptions = new ExtList();
019: private int recoderErrorCount = 0;
020: private int recoderErrorThreshold;
021:
022: public void reportException(Throwable e) {
023: super .reportException(e);
024: if (getExceptions().size() != 0) {
025: throw new ExceptionHandlerException(e);
026: }
027: }
028:
029: public KeYRecoderExcHandler() {
030: super ();
031: setErrorThreshold(0);
032: }
033:
034: public KeYRecoderExcHandler(int errorThreshold) {
035: super ();
036: setErrorThreshold(recoderErrorThreshold);
037: }
038:
039: public void clear() {
040: super .clear();
041: recoderExceptions = new ExtList();
042: recoderErrorCount = 0;
043: }
044:
045: public boolean error() {
046: return ((super .error()) || (!recoderExceptions.isEmpty()));
047: }
048:
049: public ExtList getExceptions() {
050: ExtList excList = new ExtList();
051: if (!(exceptions == null))
052: excList.addAll(exceptions);
053: if (!(recoderExceptions == null))
054: excList.addAll(recoderExceptions);
055: return excList;
056: }
057:
058: // Implementation of recoder.service.ErrorHandler
059:
060: protected int getErrorCount() {
061: return recoderErrorCount;
062: }
063:
064: public int getErrorThreshold() {
065: return recoderErrorThreshold;
066: }
067:
068: public void setErrorThreshold(int maxCount) {
069: if (maxCount < 0) {
070: throw new IllegalArgumentException(
071: "Recoder: Threshold should be >= 0");
072: }
073: recoderErrorThreshold = maxCount;
074: }
075:
076: protected void recoderExitAction() {
077: String msg = "Recoder: " + recoderErrorCount
078: + " errors have occured - aborting.";
079: recoderErrorCount = 0;
080: throw (ExceptionHandlerException) new ExceptionHandlerException(
081: msg)
082: .initCause((Throwable) recoderExceptions.getFirst());
083: }
084:
085: public void reportError(Exception e) {
086: recoderErrorCount += 1;
087: recoderExceptions.add(e);
088: if (recoderErrorCount > recoderErrorThreshold) {
089: recoderExitAction();
090: }
091: }
092:
093: public void modelUpdating(EventObject event) {
094: }
095:
096: public void modelUpdated(EventObject event) {
097: if (recoderErrorCount > 0) {
098: recoderExitAction();
099: }
100: }
101: }
|