[CVS spice] Initial version of a context monitor writing to System.out and System.err
sjoberg-yCVjj/[email protected] 19 Oct 2005 14:46:54 -0000
| Newsgroups | gmane.comp.java.spice.cvs |
|---|---|
| Message-ID | <[email protected]> |
<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>spice/components/jervlet/src/java/org/codehaus/spice/jervlet/impl</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1"><span id="added">SystemOutContextMonitor.java</span></a></tt></td><td align="right" id="added">+240</td><td></td><td nowrap="nowrap" align="right">added 1.1</td></tr>
</table>
<pre class="comment">
Initial version of a context monitor writing to System.out and System.err
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname" id="added">spice/components/jervlet/src/java/org/codehaus/spice/jervlet/impl<br /></span>
<div class="fileheader" id="added"><big><b>SystemOutContextMonitor.java</b></big> <small id="info">added at 1.1</small></div>
<pre class="diff"><small id="info">diff -N SystemOutContextMonitor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SystemOutContextMonitor.java 19 Oct 2005 14:46:54 -0000 1.1
@@ -0,0 +1,240 @@
</small></pre><pre class="diff" id="added">+package org.codehaus.spice.jervlet.impl;
+
+import org.codehaus.spice.jervlet.ContextException;
+import org.codehaus.spice.jervlet.ContextMonitor;
+import org.codehaus.spice.jervlet.Context;
+
+/**
+ * Context monitor writing to System.out and System.err
+ *
+ * @author Johan Sjoberg
+ */
+public class SystemOutContextMonitor implements ContextMonitor
+{
+
+ /**
+ * Report that an Exception was thrown when adding a Context
+ *
+ * @param reportingClass Class reporting the error
+ * @param context Context that couldn't be added
+ * @param e Exception that was thrown
+ * @throws org.codehaus.spice.jervlet.ContextException A new exception describing the reported error
+ */
+ public void addContextException( Class reportingClass, Context context, Exception e )
+ throws ContextException
+ {
+ final String message = "\"Got exception when adding context\" "
+ + getExceptionMessage( reportingClass, context, e );
+ System.err.println( message );
+ throwContextException( e );
+ }
+
+ /**
+ * Report that an Exception was thrown when removing a Context
+ *
+ * @param reportingClass Class reporting the error
+ * @param context Context that couldn't be removed
+ * @param e Exception that was thrown
+ * @throws org.codehaus.spice.jervlet.ContextException A new exception describing the reported error
+ */
+ public void removeContextException( Class reportingClass, Context context, Exception e )
+ throws ContextException
+ {
+ final String message = "\"Got exception when removing context\" "
+ + getExceptionMessage( reportingClass, context, e );
+ System.err.println( message );
+ throwContextException( e );
+ }
+
+ /**
+ * Report that an Exception was thrown when starting a Context
+ *
+ * @param reportingClass Class reporting the error
+ * @param context Context that couldn't be started
+ * @param e Exception that was thrown
+ * @throws org.codehaus.spice.jervlet.ContextException A new exception describing the error
+ */
+ public void startContextException( Class reportingClass, Context context, Exception e )
+ throws ContextException
+ {
+ final String message = "\"Got exception when starting context\" "
+ + getExceptionMessage( reportingClass, context, e );
+ System.err.println( message );
+ throwContextException( e );
+ }
+
+ /**
+ * Report that an Exception was thrown when stopping a Context
+ *
+ * @param reportingClass Class reporting the error
+ * @param context Context that couldn't be stopped
+ * @param e Exception that was thrown
+ * @throws org.codehaus.spice.jervlet.ContextException A new exception decribing the error
+ */
+ public void stopContextException( Class reportingClass, Context context, Exception e )
+ throws ContextException
+ {
+ final String message = "\"Got exception when stopping context\" "
+ + getExceptionMessage( reportingClass, context, e );
+ System.err.println( message );
+ throwContextException( e );
+ }
+
+ /**
+ * Report a warning about the addition of a Context
+ *
+ * @param reportingClass Class reporting the warning
+ * @param context Context the warning conserns
+ * @param message A message describing the warning
+ */
+ public void addContextWarning( Class reportingClass, Context context, String message )
+ {
+ final String logMessage = "\"Context addition warning\" "
+ + getWarning( reportingClass, context, message );
+ System.out.println( logMessage );
+ }
+
+ /**
+ * Report a warning about the removal of a Context
+ *
+ * @param reportingClass Class reporting the warning
+ * @param context Context the warning conserns
+ * @param message A message describing the warning
+ */
+ public void removeContextWarning( Class reportingClass, Context context, String message )
+ {
+ final String logMessage = "\"Context removal warning\" "
+ + getWarning( reportingClass, context, message );
+ System.out.println( logMessage );
+ }
+
+ /**
+ * Report a warning about starting a Context
+ *
+ * @param reportingClass Class reporting the warning
+ * @param context Context the warning conserns
+ * @param message A message describing the warning
+ */
+ public void startContextWarning( Class reportingClass, Context context, String message )
+ {
+ final String logMessage = "\"Context start warning\" "
+ + getWarning( reportingClass, context, message );
+ System.out.println( logMessage );
+ }
+
+ /**
+ * Report a warning about stopping a Context
+ *
+ * @param reportingClass Class reporting the warning
+ * @param context Context the warning conserns
+ * @param message A message describing the warning
+ */
+ public void stopContextWarning( Class reportingClass, Context context, String message )
+ {
+ final String logMessage = "\"Context stop warning\" "
+ + getWarning( reportingClass, context, message );
+ System.out.println( logMessage );
+ }
+
+ /**
+ * Report that a Context was added
+ *
+ * @param reportingClass Class reporting the additon
+ * @param context Context that was added
+ */
+ public void addContextNotification( Class reportingClass, Context context )
+ {
+ final String message = "\"Added context\" "
+ + getNotification( reportingClass, context );
+ System.out.println( message );
+ }
+
+ /**
+ * Report that a Context was removed
+ *
+ * @param reportingClass Class reporting the removal
+ * @param context Context that was removed
+ */
+ public void removeContextNotification( Class reportingClass, Context context )
+ {
+ final String message = "\"Removed context\" "
+ + getNotification( reportingClass, context );
+ System.out.println( message );
+ }
+
+ /**
+ * Report that a Context was started
+ *
+ * @param reportingClass Reporting class
+ * @param context Context that was started
+ */
+ public void startContextNotification( Class reportingClass, Context context )
+ {
+ final String message = "\"Started context\" "
+ + getNotification( reportingClass, context );
+ System.out.println( message );
+ }
+
+ /**
+ * Report that a Context was stopped
+ *
+ * @param reportingClass Reporting class
+ * @param context Context that was stopped
+ */
+ public void stopContextNotification( Class reportingClass, Context context )
+ {
+ final String message = "\"Stopped context\" "
+ + getNotification( reportingClass, context );
+ System.out.println( message );
+ }
+ /**
+ * Throw a <code>ContextException</code>
+ *
+ * @param e Original Exception
+ * @throws ContextException A new ListenerException instance
+ */
+ private void throwContextException( Exception e )
+ throws ContextException
+ {
+ throw new ContextException( e.getMessage(), e.getCause() );
+ }
+
+ /**
+ * Form an exception message
+ *
+ * @return a new Exception message
+ */
+ private String getExceptionMessage( Class reportingClass, Context context, Exception e )
+ {
+ return new StringBuffer().append( "\"" )
+ .append( reportingClass.getName() ).append( "\" \"" )
+ .append( context ).append( "\" \"" ).append( e.getMessage() )
+ .append( "\"" ).toString();
+ }
+
+ /**
+ * Form a message
+ *
+ * @return a new warning message
+ */
+ private String getWarning( Class reportingClass, Context context, String message )
+ {
+ return new StringBuffer().append( "\"" )
+ .append( reportingClass.getName() ).append( "\" \"" )
+ .append( context ).append( "\" \"" ).append( message )
+ .append( "\"" ).toString();
+ }
+
+ /**
+ * Form a notification
+ *
+ * @return a new notification message
+ */
+ private String getNotification( Class reportingClass, Context context )
+ {
+ return new StringBuffer().append( "\"" )
+ .append( reportingClass.getName() )
+ .append( "\" \"" ).append( context )
+ .append( "\" \"\"" ).toString();
+ }
+}
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.8</small></center>
</body></html>