You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/05/31 12:18:04 UTC
[3/3] jena git commit: Add an ErrorHandler that throws
RiotParseException with all details.
Add an ErrorHandler that throws RiotParseException with all details.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/186ee415
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/186ee415
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/186ee415
Branch: refs/heads/master
Commit: 186ee41500b1946261a8e4cfa83ae972157e2334
Parents: f3a1faa
Author: Andy Seaborne <an...@apache.org>
Authored: Tue May 30 12:27:48 2017 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Wed May 31 13:16:59 2017 +0100
----------------------------------------------------------------------
.../jena/riot/system/ErrorHandlerFactory.java | 132 ++++++++++---------
1 file changed, 71 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/186ee415/jena-arq/src/main/java/org/apache/jena/riot/system/ErrorHandlerFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/ErrorHandlerFactory.java b/jena-arq/src/main/java/org/apache/jena/riot/system/ErrorHandlerFactory.java
index e65bdac..cc7d4bc 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/system/ErrorHandlerFactory.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/system/ErrorHandlerFactory.java
@@ -20,6 +20,7 @@ package org.apache.jena.riot.system;
import static org.apache.jena.riot.SysRIOT.fmtMessage ;
import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.RiotParseException ;
import org.apache.jena.riot.SysRIOT ;
import org.slf4j.Logger ;
@@ -40,19 +41,36 @@ public class ErrorHandlerFactory
/** Warning error handler - logs to stdLogger - mesages for warnings and some errors */
static public final ErrorHandler errorHandlerWarn = errorHandlerWarning(stdLogger) ;
- /** Silent error handler */
+ /** Silent error handler : ignores warnings, throws exceptions for errors */
static public final ErrorHandler errorHandlerNoLogging = errorHandlerSimple() ;
/** Silent, strict error handler */
static public final ErrorHandler errorHandlerStrictNoLogging = errorHandlerStrictSilent() ;
+ /** Silent, strict error handler, nologging */
public static ErrorHandler errorHandlerStrictSilent() { return new ErrorHandlerStrict(null) ; }
+
+ /** Strict error handler, with logging */
public static ErrorHandler errorHandlerStrict(Logger log) { return new ErrorHandlerStrict(log) ; }
+
+ /** An error handler that logs messages, then throws exceptions for errors but not warnings */
public static ErrorHandler errorHandlerStd(Logger log) { return new ErrorHandlerStd(log) ; }
+
+ /** An error handler that logs error and fatal messages, but not warnings */
public static ErrorHandler errorHandlerNoWarnings(Logger log) { return new ErrorHandlerNoWarnings(log) ; }
+
+ /** An error handler that logs messages for errors and warnings and attempts to carry on */
public static ErrorHandler errorHandlerWarning(Logger log) { return new ErrorHandlerWarning(log) ; }
+
+ /** Ignores warnings, throws exceptions for errors */
public static ErrorHandler errorHandlerSimple() { return new ErrorHandlerSimple() ; }
+ /**
+ * An error handler that throws a {@link RiotParseException}, hence it
+ * exposes the details of errors.
+ */
+ public static ErrorHandler errorHandlerDetailed() { return new ErrorHandlerRiotParseException() ; }
+
private static ErrorHandler defaultErrorHandler = errorHandlerStd ;
/** Get the current default error handler */
public static ErrorHandler getDefaultErrorHandler() { return defaultErrorHandler ; }
@@ -61,40 +79,34 @@ public class ErrorHandlerFactory
public static void setDefaultErrorHandler(ErrorHandler errorHandler) { defaultErrorHandler = errorHandler ; }
/** Messages to a logger. This is not an ErrorHandler */
- private static class ErrorLogger
- {
+ private static class ErrorLogger {
protected final Logger log ;
- public ErrorLogger(Logger log)
- {
+ public ErrorLogger(Logger log) {
this.log = log ;
}
/** report a warning */
- public void logWarning(String message, long line, long col)
- {
+ public void logWarning(String message, long line, long col) {
if ( log != null )
log.warn(fmtMessage(message, line, col)) ;
}
-
+
/** report an error */
- public void logError(String message, long line, long col)
- {
+ public void logError(String message, long line, long col) {
if ( log != null )
log.error(fmtMessage(message, line, col)) ;
}
- /** report a catastrophic error */
- public void logFatal(String message, long line, long col)
- {
+ /** report a catastrophic error */
+ public void logFatal(String message, long line, long col) {
if ( log != null )
logError(message, line, col) ;
}
}
/** Ignores warnings, throws exceptions for errors */
- private static class ErrorHandlerSimple implements ErrorHandler
- {
+ private static class ErrorHandlerSimple implements ErrorHandler {
@Override
public void warning(String message, long line, long col)
{}
@@ -108,10 +120,8 @@ public class ErrorHandlerFactory
}
/** An error handler that logs message then throws exceptions for errors but not warnings */
- private static class ErrorHandlerStd extends ErrorLogger implements ErrorHandler
- {
- public ErrorHandlerStd(Logger log)
- {
+ private static class ErrorHandlerStd extends ErrorLogger implements ErrorHandler {
+ public ErrorHandlerStd(Logger log) {
super(log) ;
}
@@ -122,26 +132,22 @@ public class ErrorHandlerFactory
/** report an error */
@Override
- public void error(String message, long line, long col)
- {
+ public void error(String message, long line, long col) {
logError(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
/** report a fatal error - does not return */
@Override
- public void fatal(String message, long line, long col)
- {
+ public void fatal(String message, long line, long col) {
logFatal(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
}
/** An error handler that logs message then throws exceptions for errors but not warnings */
- private static class ErrorHandlerNoWarnings extends ErrorLogger implements ErrorHandler
- {
- public ErrorHandlerNoWarnings(Logger log)
- {
+ private static class ErrorHandlerNoWarnings extends ErrorLogger implements ErrorHandler {
+ public ErrorHandlerNoWarnings(Logger log) {
super(log) ;
}
@@ -152,81 +158,71 @@ public class ErrorHandlerFactory
/** report an error */
@Override
- public void error(String message, long line, long col)
- {
+ public void error(String message, long line, long col) {
logError(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
/** report a fatal error - does not return */
@Override
- public void fatal(String message, long line, long col)
- {
+ public void fatal(String message, long line, long col) {
logFatal(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
}
/** An error handler that logs message for errors and warnings and throw exceptions on either */
- private static class ErrorHandlerStrict extends ErrorLogger implements ErrorHandler
- {
- public ErrorHandlerStrict(Logger log)
- {
+ private static class ErrorHandlerStrict extends ErrorLogger implements ErrorHandler {
+ public ErrorHandlerStrict(Logger log) {
super(log) ;
}
-
- /** report a warning - do not carry on */
+
+ /** report a warning - do not carry on */
@Override
- public void warning(String message, long line, long col)
- {
+ public void warning(String message, long line, long col) {
logWarning(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
-
+
/** report an error - do not carry on */
@Override
- public void error(String message, long line, long col)
- {
+ public void error(String message, long line, long col) {
logError(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
@Override
- public void fatal(String message, long line, long col)
- {
+ public void fatal(String message, long line, long col) {
logFatal(message, line, col) ;
throw new RiotException(fmtMessage(message, line, col)) ;
}
}
- /** An error handler that throw exceptions on warnings and errors but does not log */
- private static class ErrorHandlerStrictSilent implements ErrorHandler
- {
- /** report a warning - do not carry on */
+ /**
+ * An error handler that throw exceptions on warnings and errors but does
+ * not log
+ */
+ private static class ErrorHandlerStrictSilent implements ErrorHandler {
+ /** report a warning - do not carry on */
@Override
- public void warning(String message, long line, long col)
- {
+ public void warning(String message, long line, long col) {
throw new RiotException(fmtMessage(message, line, col)) ;
}
-
+
/** report an error - do not carry on */
@Override
- public void error(String message, long line, long col)
- {
+ public void error(String message, long line, long col) {
throw new RiotException(fmtMessage(message, line, col)) ;
}
@Override
- public void fatal(String message, long line, long col)
- {
+ public void fatal(String message, long line, long col) {
throw new RiotException(fmtMessage(message, line, col)) ;
}
}
-
/** An error handler that logs messages for errors and warnings and attempt to carry on */
- private static class ErrorHandlerWarning extends ErrorLogger implements ErrorHandler
- {
+ private static class ErrorHandlerWarning extends ErrorLogger implements ErrorHandler {
public ErrorHandlerWarning(Logger log)
{ super(log) ; }
@@ -240,10 +236,24 @@ public class ErrorHandlerFactory
{ logError(message, line, col) ; }
@Override
- public void fatal(String message, long line, long col)
- {
+ public void fatal(String message, long line, long col) {
logFatal(message, line, col) ;
- throw new RiotException(SysRIOT.fmtMessage(message, line, col)) ;
+ throw new RiotException(SysRIOT.fmtMessage(message, line, col)) ;
+ }
+ }
+
+ /** An error handler that throws a RiotParseException, hence it exposes the details of errors. */
+ private static class ErrorHandlerRiotParseException implements ErrorHandler {
+ public ErrorHandlerRiotParseException() {}
+ @Override public void warning(String message, long line, long col) { }
+
+ @Override public void error(String message, long line, long col) {
+ throw new RiotParseException(message, line, col);
+ }
+
+ @Override public void fatal(String message, long line, long col) {
+ throw new RiotParseException(message, line, col);
}
}
+
}