org.activemath.omdocjdom.mbase
Class MBaseErrorReporter

java.lang.Object
  extended by org.activemath.omdocjdom.mbase.MBaseErrorReporter

public class MBaseErrorReporter
extends Object

MBaseErrorReporter is a configurable way to report errors when building and/or reloading a OmdocJdomMBase. This object is passed as argument to the methods candidate to throw errors (mostly for unresolved references) which then acts in various ways:

This object was created in the hope of facilitating the construction of clean OMdoc source collections so as to, one day, avoid the need of heuristical methods to resolve references.

Its only methods when in function are reportError(org.activemath.omdocjdom.MBaseBuildException) and warnForGuess(java.lang.String, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) which are to be used instead of the throw instruction. Note that warnForGuess(java.lang.String, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) is not yet really complete.

Version:

Field Summary
static String CVS_ID
           
 int maxErrors
          If -1 then never stops displaying errors, otherwise displays the given number of errors and then throws an exception.
 PrintStream out
          The stream to output the messages to, if any.
 boolean throwExceptions
          If true, throws the given exception
 boolean warnWhenGuessing
          If false, says nothing when warnForGuess(java.lang.String, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) is invoked.
 boolean withDetails
          If true prints the element XML dump and other content where the error occured.
 boolean withStackTrace
          If true, prints the stackTrace of the exception.
 
Constructor Summary
MBaseErrorReporter()
          Creates a fully ignoring error-reporter.
MBaseErrorReporter(boolean throwExceptions)
          Creates an error reporter that will throw exceptions which means that, most probably, the parsing or reload will stop.
MBaseErrorReporter(PrintStream out, boolean throwExceptions, boolean withDetails, boolean withStackTrace, boolean warnWhenGuessing, int maxErrors, String basePath)
          Creates a fully configure error-reporter.
MBaseErrorReporter(PrintStream out, boolean withDetails, int maxErrors)
          Create an error-reporter that no throw exceptions but simply report to the given print-stream.
 
Method Summary
 Hashtable makeAsRecord(MBaseBuildException exception)
          Makes a Hashtable of the given exception including the keys: message: the exception message exceptionClass: the exception class systemId: the path to the file lineNumber the line-number in the file columnNumber the column-number in the file
static void printErrorDetails(NoSuchIDException exception, PrintStream out)
          Outputs the things in full detail independent of the settings but does not print a stack-trace.
 void reportError(MBaseBuildException exception)
          Reports error according to the policy given.
 void reportError(String message)
           
 void resetErrorNumber()
          Resets the error counter so that, once again, the maxErrors number of errors is displayed.
 void setAccumulator(List accumulator)
          Sets a list where all further errors will be added as well.
 void warnForGuess(String message, Object faulty1, Object faulty2, Object faulty3, Object faulty4)
          This method wants to be quick, it will print a GUESS WARNING : followed by the toString conversion of all the objects given, if non-null and if warnWhenGuessing is turned on.
 void warnForGuess(String message, Object faulty1, Object faulty2, Object faulty3, Object faulty4, Object faulty5)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_ID

public static final String CVS_ID
See Also:
Constant Field Values

out

public PrintStream out
The stream to output the messages to, if any.


throwExceptions

public boolean throwExceptions
If true, throws the given exception


withDetails

public boolean withDetails
If true prints the element XML dump and other content where the error occured.


withStackTrace

public boolean withStackTrace
If true, prints the stackTrace of the exception.


warnWhenGuessing

public boolean warnWhenGuessing
If false, says nothing when warnForGuess(java.lang.String, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object) is invoked.


maxErrors

public int maxErrors
If -1 then never stops displaying errors, otherwise displays the given number of errors and then throws an exception.

Constructor Detail

MBaseErrorReporter

public MBaseErrorReporter()
Creates a fully ignoring error-reporter. All errors will be forgotten and some unpredicted behaviour is to be exepected.


MBaseErrorReporter

public MBaseErrorReporter(boolean throwExceptions)
Creates an error reporter that will throw exceptions which means that, most probably, the parsing or reload will stop. Error reporting is then left to the exception-catcher.

Parameters:
throwExceptions - Missing description of Parameter

MBaseErrorReporter

public MBaseErrorReporter(PrintStream out,
                          boolean withDetails,
                          int maxErrors)
Create an error-reporter that no throw exceptions but simply report to the given print-stream.

Parameters:
out - Missing description of Parameter
withDetails - Missing description of Parameter
maxErrors - Missing description of Parameter ignored.

MBaseErrorReporter

public MBaseErrorReporter(PrintStream out,
                          boolean throwExceptions,
                          boolean withDetails,
                          boolean withStackTrace,
                          boolean warnWhenGuessing,
                          int maxErrors,
                          String basePath)
Creates a fully configure error-reporter. Please see the meanings of all the variables in the instance variables description.

Parameters:
out - Missing description of Parameter
throwExceptions - Missing description of Parameter
withDetails - Missing description of Parameter
withStackTrace - Missing description of Parameter
warnWhenGuessing - Missing description of Parameter
maxErrors - Missing description of Parameter
basePath - The path from which one can compute relative paths
Method Detail

printErrorDetails

public static final void printErrorDetails(NoSuchIDException exception,
                                           PrintStream out)
Outputs the things in full detail independent of the settings but does not print a stack-trace. Best used when an error is caught.

Parameters:
exception - Missing description of Parameter
out - Missing description of Parameter

setAccumulator

public void setAccumulator(List accumulator)
Sets a list where all further errors will be added as well. This is thought for implementations to listen to errors being fired and report them, for example, remotely. Errors are input as record using the method makeAsRecord(org.activemath.omdocjdom.MBaseBuildException).

Parameters:
accumulator - a list where errors will be List.add(E)ed may be null in which case accumulating is disabled.

resetErrorNumber

public void resetErrorNumber()
Resets the error counter so that, once again, the maxErrors number of errors is displayed.


reportError

public final void reportError(MBaseBuildException exception)
                       throws NoSuchIDException
Reports error according to the policy given.

Parameters:
exception - Missing description of Parameter
Throws:
NoSuchIDException - Missing description of Exception

makeAsRecord

public Hashtable makeAsRecord(MBaseBuildException exception)
Makes a Hashtable of the given exception including the keys:


reportError

public void reportError(String message)

warnForGuess

public final void warnForGuess(String message,
                               Object faulty1,
                               Object faulty2,
                               Object faulty3,
                               Object faulty4)
This method wants to be quick, it will print a GUESS WARNING : followed by the toString conversion of all the objects given, if non-null and if warnWhenGuessing is turned on. The idea of passing these four objects instead of a one string is to avoid the conversion to String of the parameters if the warnWhenGuessing is off. Don't use it as: warnForGuess("This variable " + varA + " is stupid, value " + value, null, null, null, null)

Parameters:
message - Missing description of Parameter
faulty1 - Missing description of Parameter
faulty2 - Missing description of Parameter
faulty3 - Missing description of Parameter
faulty4 - Missing description of Parameter

warnForGuess

public final void warnForGuess(String message,
                               Object faulty1,
                               Object faulty2,
                               Object faulty3,
                               Object faulty4,
                               Object faulty5)