From 7141cf67d134fffe2102a820f63f23a40f3c3a10 Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 12 Jul 2007 22:30:15 +0000 Subject: [PATCH] Allow ComplainingListener to be properly typed and to use Java's Logger. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2131 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/util/ComplainingListener.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/java/com/samskivert/util/ComplainingListener.java b/src/java/com/samskivert/util/ComplainingListener.java index 4fad7a01..2c8fb394 100644 --- a/src/java/com/samskivert/util/ComplainingListener.java +++ b/src/java/com/samskivert/util/ComplainingListener.java @@ -3,13 +3,14 @@ package com.samskivert.util; +import java.util.logging.Level; +import java.util.logging.Logger; /** - * A ResultListener that does nothing on success and logs a warning - * message on failure, that's all. + * A ResultListener that does nothing on success and logs a warning message on failure, that's all. */ -public class ComplainingListener - implements ResultListener +public class ComplainingListener + implements ResultListener { public ComplainingListener (Log log, String errorText) { @@ -17,18 +18,33 @@ public class ComplainingListener _errorText = errorText; } + public ComplainingListener (Logger logger, String errorText) + { + _logger = logger; + _errorText = errorText; + } + // documentation inherited from interface ResultListener - public void requestCompleted (Object result) { /* nada */ } + public void requestCompleted (T result) { /* nada */ } // documentation inherited from interface ResultListener public void requestFailed (Exception cause) { - _log.warning(_errorText + " [cause=" + cause + "]."); + if (_log != null) { + _log.warning(_errorText + " [cause=" + cause + "]."); + } else if (_logger != null) { + _logger.log(Level.WARNING, _errorText, cause); + } else { + System.err.println(_errorText + " [cause=" + cause + "]."); + } } - /** The log to which we'll log our error. */ + /** The log to which we'll log our error, may be null. */ protected Log _log; + /** The logger to which we'll log our error, may be null. */ + protected Logger _logger; + /** The text to output if the error happens. */ protected String _errorText; }