org.eclipse.actf.util.logging
Class AbstractReporter

java.lang.Object
  extended by org.eclipse.actf.util.logging.AbstractReporter
All Implemented Interfaces:
IReporter
Direct Known Subclasses:
PrintWriterReporter, ValidationReporter

public abstract class AbstractReporter
extends Object
implements IReporter

base implementation of a Reporter. This class provides default behaviors for the org.eclipse.actf.core.logging.Reporter interface, which adds functionality for identifying the source of reported messages and for rerouting errors and exceptions using the error-logging features added to ACTF.

Note: Clients should subclass this class rather than implementing Reporter to avoid API incompatibilities and to insure appropriate behavior.

Author:
Mike Squillace
See Also:
IReporter

Field Summary
protected  ResourceBundle bundle
           
protected  Stack categories
           
static MessageFormat CATEGORY_FORMATTER
          formatter for forming category id strings.
protected  MessageFormat categoryFormatter
           
protected  int defaultOutputLevel
           
protected  List errorLoggers
           
protected static Map SOURCE_ID_MAP
           
protected  String sourceID
           
 
Fields inherited from interface org.eclipse.actf.util.logging.IReporter
CONFIG, CONFIGURATION, DEFAULT_LEVEL, DETAIL, ERROR, INFO, KEYS, MAX_LEVEL, MIN_LEVEL, SEVERE, SYSTEM_FATAL, SYSTEM_NONFATAL, TRACE, UNKNOWN, USER, VALIDATION, WARNING
 
Constructor Summary
AbstractReporter()
           
 
Method Summary
 void endCategory()
          end the current reporting category
 void endCategory(String id)
          end the category with the given id
 String getCategory()
          get the category id string of current reporting
 MessageFormat getCategoryFormatter()
           
 int getDefaultOutputLevel()
          get the default output level.
static IReporter getReporter(int traceLevel, String traceStream)
          utility method to construct reporters
 ResourceBundle getResourceBundle()
          get the underlying resource bundle
 String getSourceID()
          gets the id or name of this reporter
 String getSourceIDString(String id)
          get the source id string associated with the given key.
 void registerErrorLogger(IErrorLogger logger)
          add an error logger to the list of loggers to receive requests to report errors from this reporter.
 void report(int level, String message)
          report the message at the given level.
 void report(int level, String msg, Throwable t)
          reports an exception or error.
 void report(int level, Throwable t)
          reports an exception or error.
 void report(String message)
          report the message
 void report(String message, Object[] values)
          report an information message using the substitution values
 void report(Throwable t)
          reports an exception or error.
 void reset()
          reset the reporter.
 void setCategoryFormatter(MessageFormat formatter)
           
 void setDefaultOutputLevel(int level)
          set the default output level.
 void setResourceBundle(ResourceBundle bundle)
          set the resource bundle
 void setSourceID(String id)
          set the source id for future reports.
 void startCategory(String id)
          start a new category with the given id.
 void unregisterErrorLogger(IErrorLogger logger)
          remove an error logger from the list of loggers to receive errors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.actf.util.logging.IReporter
close, endReport, flush, getLastReport, isOpen, open, report, setLastReport, startReport
 

Field Detail

CATEGORY_FORMATTER

public static final MessageFormat CATEGORY_FORMATTER
formatter for forming category id strings. The default format is:
 <nodeName>[<nodeDescription>][@id=<nodeId>]
 

where:

The category formatter can be changed using the setCategoryFormatter(messageFormat) method.

See Also:
setCategoryFormatter(MessageFormat)

SOURCE_ID_MAP

protected static final Map SOURCE_ID_MAP

defaultOutputLevel

protected int defaultOutputLevel

categories

protected Stack categories

categoryFormatter

protected MessageFormat categoryFormatter

sourceID

protected String sourceID

bundle

protected ResourceBundle bundle

errorLoggers

protected List errorLoggers
Constructor Detail

AbstractReporter

public AbstractReporter()
Method Detail

registerErrorLogger

public void registerErrorLogger(IErrorLogger logger)
add an error logger to the list of loggers to receive requests to report errors from this reporter.

Specified by:
registerErrorLogger in interface IReporter
Parameters:
logger - - error logger for reporting errors

unregisterErrorLogger

public void unregisterErrorLogger(IErrorLogger logger)
remove an error logger from the list of loggers to receive errors

Specified by:
unregisterErrorLogger in interface IReporter
Parameters:
logger - - error logger to be removed

getResourceBundle

public ResourceBundle getResourceBundle()
get the underlying resource bundle

Returns:
bundle

setResourceBundle

public void setResourceBundle(ResourceBundle bundle)
set the resource bundle

Parameters:
bundle -

setCategoryFormatter

public void setCategoryFormatter(MessageFormat formatter)

getCategoryFormatter

public MessageFormat getCategoryFormatter()

setSourceID

public void setSourceID(String id)
set the source id for future reports. If no id is set, the word 'level' precedes the level of the violation.

The id can be one of the following:

Specified by:
setSourceID in interface IReporter
Parameters:
id - - name or id of this reporter

getSourceID

public String getSourceID()
gets the id or name of this reporter

Specified by:
getSourceID in interface IReporter
Returns:
name or id of this reporter
See Also:
IReporter.setSourceID(String)

getSourceIDString

public String getSourceIDString(String id)
get the source id string associated with the given key. This method will return null if one of the pre-defined symbolic constants in the Reporter interface are not used.

Parameters:
id -
Returns:
id associated with given key

setDefaultOutputLevel

public void setDefaultOutputLevel(int level)
set the default output level. This level determines the messages that are to be printed or logged. Messages reported at levels equal to or greater than this level are printed or logged whereas messages reported at levels lower than this default level are ignored by this reporter.

Specified by:
setDefaultOutputLevel in interface IReporter
Parameters:
level - - default output level

getDefaultOutputLevel

public int getDefaultOutputLevel()
get the default output level.

Specified by:
getDefaultOutputLevel in interface IReporter
Returns:
default output level
See Also:
IReporter.setDefaultOutputLevel(int)

report

public void report(String message)
report the message

Specified by:
report in interface IReporter
Parameters:
message - -- message to be written

report

public void report(String message,
                   Object[] values)
report an information message using the substitution values

Specified by:
report in interface IReporter
Parameters:
message - -- message to be reported
values - -- substitution values

report

public void report(int level,
                   String message)
report the message at the given level. Messages are reported if the given level is greater than or equal to the set or default level.

Specified by:
report in interface IReporter
Parameters:
level - -- level of message
message - -- message to be reported

report

public void report(Throwable t)
reports an exception or error. This method can be used to direct the stack trace of the given throwable to the appropriate output for this reporter (e.g. a GUI text area or stream).

The default level of this report message is Reporter.SEVERE.

Specified by:
report in interface IReporter
Parameters:
t - - Throwable being reported

report

public void report(int level,
                   Throwable t)
reports an exception or error. This method can be used to direct the stack trace of the given throwable to the appropriate output for this reporter (e.g. a GUI text area or stream). The level of the throwable is determined by the specified level parameter.

Specified by:
report in interface IReporter
Parameters:
level - - level of exception or error
t - - Throwable being reported

report

public void report(int level,
                   String msg,
                   Throwable t)
reports an exception or error. This method can be used to direct the stack trace of the given throwable to the appropriate output for this reporter (e.g. a GUI text area or stream). The level of the throwable is determined by the specified level parameter.

Specified by:
report in interface IReporter
Parameters:
level - - level of exception or error
msg - - optional message
t - - Throwable being reported

getCategory

public String getCategory()
get the category id string of current reporting

Specified by:
getCategory in interface IReporter
Returns:
current category id

startCategory

public void startCategory(String id)
start a new category with the given id.

Specified by:
startCategory in interface IReporter
Parameters:
id - -- new category id

endCategory

public void endCategory()
end the current reporting category

Specified by:
endCategory in interface IReporter

endCategory

public void endCategory(String id)
end the category with the given id

Specified by:
endCategory in interface IReporter
Parameters:
id - -- id of category to end

getReporter

public static IReporter getReporter(int traceLevel,
                                    String traceStream)
utility method to construct reporters

Parameters:
traceLevel - - level at which to report
traceStream - - stream to which report is sent (either a file, 'stderr', or 'stdout')
Returns:
PrintWriterReporter that reports to the given stream

reset

public void reset()
reset the reporter. This method should clear all categories and all remaining buffers and report records.

Specified by:
reset in interface IReporter