forrest-svn mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bd...@apache.org
Subject svn commit: r1096981 - in /forrest/trunk/whiteboard/forrest-osgi: org.apache.forrest.log/src/java/org/apache/forrest/log/ org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/ org.apache.forrest.plugin.input.xdoc/src/java/org/apache/for...
Date Wed, 27 Apr 2011 02:18:53 GMT
Author: bdube
Date: Wed Apr 27 02:18:52 2011
New Revision: 1096981

URL: http://svn.apache.org/viewvc?rev=1096981&view=rev
Log:
Refactor logging and use convenience wrapper in plugins

Modified:
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.log/src/java/org/apache/forrest/log/LogPlugin.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseInputPlugin.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseOutputPlugin.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.input.xdoc/src/java/org/apache/forrest/plugin/input/xdoc/service/XDocInput.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.output.html/src/java/org/apache/forrest/plugin/output/html/service/HtmlOutput.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServlet.java
    forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServletPlugin.java

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.log/src/java/org/apache/forrest/log/LogPlugin.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.log/src/java/org/apache/forrest/log/LogPlugin.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.log/src/java/org/apache/forrest/log/LogPlugin.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.log/src/java/org/apache/forrest/log/LogPlugin.java
Wed Apr 27 02:18:52 2011
@@ -44,7 +44,7 @@ public class LogPlugin implements Bundle
       System.out.println("Registering LogWriter");
       LogReaderService readerService = (LogReaderService) context.getService(readerRef);
       readerService.addLogListener(new LogWriter());
-      getDefault().getLogService().log(LogService.LOG_DEBUG, "Log bundle starting (and self-hosting)");
+      LOG.debug("Log bundle starting (and self-hosting)");
     } else {
       System.out.println("Could not add log listener (LogReaderService is unavailable)");
     }
@@ -56,14 +56,30 @@ public class LogPlugin implements Bundle
     System.out.println("Log bundle stopping");
   }
 
-  public static LogPlugin getDefault() {
-    return sInstance;
+  public LogService getLogService() {
+    LogService service = (LogService) mLogTracker.getService();
+
+    return service;
   }
 
-  public LogService getLogService() {
-    LogService theServ = (LogService) mLogTracker.getService();
+  /*
+   * Convenience wrapper to allow typing LOG.debug(msg)
+   * FIXME: this is probably a terrible idea
+   */
+  public static class LOG {
+
+    public static void debug(String msg) {
+      LogService service = sInstance.getLogService();
+
+      if (null != service) {
+        service.log(LogService.LOG_DEBUG, msg);
+      }
+    }
+
+    public static void debug(String msg, Throwable t) {
+      debug(msg + ": " + t.getMessage());
+    }
 
-    return theServ;
   }
 
 }

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseInputPlugin.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseInputPlugin.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseInputPlugin.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseInputPlugin.java
Wed Apr 27 02:18:52 2011
@@ -20,7 +20,7 @@ import java.net.URI;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 import org.apache.forrest.plugin.api.ForrestResult;
 import org.apache.forrest.plugin.api.ForrestSource;
 
@@ -31,15 +31,13 @@ public class BaseInputPlugin extends Abs
   }
 
   public ForrestSource getSource(URI uri) {
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG, "BaseInputPlugin.getSource() must be implemented by a plugin,
ignoring");
+    LOG.debug("BaseInputPlugin.getSource() must be implemented by a plugin, ignoring");
 
     return null;
   }
 
   public ForrestResult transform(ForrestSource source) {
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG, "transform() called on an input plugin, ignoring");
+    LOG.debug("transform() called on an input plugin, ignoring");
 
     return null;
   }

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseOutputPlugin.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseOutputPlugin.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseOutputPlugin.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.api/src/java/org/apache/forrest/plugin/api/BaseOutputPlugin.java
Wed Apr 27 02:18:52 2011
@@ -20,7 +20,7 @@ import java.net.URI;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 import org.apache.forrest.plugin.api.ForrestResult;
 import org.apache.forrest.plugin.api.ForrestSource;
 
@@ -31,15 +31,13 @@ public class BaseOutputPlugin extends Ab
   }
 
   public ForrestSource getSource(URI uri) {
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG, "getSource() called on an output plugin, ignoring");
+    LOG.debug("getSource() called on an output plugin, ignoring");
 
     return null;
   }
 
   public ForrestResult transform(ForrestSource source) {
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG, "BaseOutputPlugin.transform() must be implemented by a plugin,
ignoring");
+    LOG.debug("BaseOutputPlugin.transform() must be implemented by a plugin, ignoring");
 
     return null;
   }

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.input.xdoc/src/java/org/apache/forrest/plugin/input/xdoc/service/XDocInput.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.input.xdoc/src/java/org/apache/forrest/plugin/input/xdoc/service/XDocInput.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.input.xdoc/src/java/org/apache/forrest/plugin/input/xdoc/service/XDocInput.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.input.xdoc/src/java/org/apache/forrest/plugin/input/xdoc/service/XDocInput.java
Wed Apr 27 02:18:52 2011
@@ -35,7 +35,7 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 import org.apache.forrest.plugin.api.BaseInputPlugin;
 import org.apache.forrest.plugin.api.ForrestResult;
 import org.apache.forrest.plugin.api.ForrestSource;
@@ -55,12 +55,11 @@ public class XDocInput extends BaseInput
       throw new IllegalArgumentException("I told you, null won't work");
     }
 
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG,
-       "Hello, this is the xdoc input plugin handling getSource(" + uri + ")");
+    LOG.debug("Hello, this is the xdoc input plugin handling getSource(" + uri + ")");
 
     try {
-      ServiceReference[] refs = getBundleContext().getServiceReferences(TransformerFactory.class.getName(),
null);
+      ServiceReference[] refs = getBundleContext().getServiceReferences
+        (TransformerFactory.class.getName(), null);
       TransformerFactory factory = null;
 
       if (null != refs) {
@@ -69,47 +68,30 @@ public class XDocInput extends BaseInput
           Object obj = getBundleContext().getService(refs[i]);
 
           if (null != obj && obj instanceof TransformerFactory) {
-            LogPlugin.getDefault().getLogService().log
-              (LogService.LOG_DEBUG,
-               "Found the right class: " + obj.getClass().getName());
             factory = (TransformerFactory) obj;
             break;
           } else {
             if (null != obj) {
-              LogPlugin.getDefault().getLogService().log
-                (LogService.LOG_DEBUG,
-                 "Found the wrong class: " + obj.getClass().getName());
+              LOG.debug("Found the wrong class: " + obj.getClass().getName());
             } else {
-              LogPlugin.getDefault().getLogService().log
-                (LogService.LOG_DEBUG,
-                 "Null service");
+              LOG.debug("Could not find TransformerFactory through service registry");
             }
           }
         }
       }
 
       if (null != factory) {
-        LogPlugin.getDefault().getLogService().log
-          (LogService.LOG_DEBUG,
-           "factory " + factory.getClass().getName());
+        LOG.debug("factory " + factory.getClass().getName());
 
         InputStream in = XDocInput.class.getClassLoader().getResourceAsStream
           ("resources/stylesheets/documentv20-to-internal.xsl");
 
         if (null != in) {
-          LogPlugin.getDefault().getLogService().log
-            (LogService.LOG_DEBUG,
-             "Found the input stylesheet");
+          LOG.debug("Found the input stylesheet");
 
           Transformer transformer = factory.newTransformer
             (new StreamSource(in));
 
-          if (null != transformer) {
-            LogPlugin.getDefault().getLogService().log
-              (LogService.LOG_DEBUG,
-               "transformer " + transformer.getClass().getName());
-          }
-
           ByteArrayOutputStream bytes = new ByteArrayOutputStream();
           StreamResult internalStream = new StreamResult(bytes);
 
@@ -132,41 +114,21 @@ public class XDocInput extends BaseInput
 
           return forrestSource;
         } else {
-          LogPlugin.getDefault().getLogService().log
-            (LogService.LOG_DEBUG,
-             "Didn't find the stylesheet");
+          LOG.debug("Didn't find the stylesheet");
         }
       }
     } catch (InvalidSyntaxException ise) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "Check your filter string",
-         ise);
+      LOG.debug("Check your filter string", ise);
     } catch (TransformerFactoryConfigurationError tfce) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "There is a problem at the factory",
-         tfce);
+      LOG.debug("There is a problem at the factory", tfce);
     } catch (TransformerConfigurationException tce) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "The transformer could not be configured",
-         tce);
+      LOG.debug("The transformer could not be configured", tce);
     } catch (TransformerException te) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "The transformation broke",
-         te);
+      LOG.debug("The transformation broke", te);
     } catch (MalformedURLException mue) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "The given URL is invalid",
-         mue);
+      LOG.debug("The given URL is invalid", mue);
     } catch (IOException ioe) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "There is a problem reading the resource",
-         ioe);
+      LOG.debug("There is a problem reading the resource", ioe);
     }
 
     return null;

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.output.html/src/java/org/apache/forrest/plugin/output/html/service/HtmlOutput.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.output.html/src/java/org/apache/forrest/plugin/output/html/service/HtmlOutput.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.output.html/src/java/org/apache/forrest/plugin/output/html/service/HtmlOutput.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.plugin.output.html/src/java/org/apache/forrest/plugin/output/html/service/HtmlOutput.java
Wed Apr 27 02:18:52 2011
@@ -36,7 +36,7 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 import org.apache.forrest.plugin.api.BaseOutputPlugin;
 import org.apache.forrest.plugin.api.ForrestResult;
 import org.apache.forrest.plugin.api.ForrestSource;
@@ -56,12 +56,11 @@ public class HtmlOutput extends BaseOutp
       throw new IllegalArgumentException("I told you, null won't work");
     }
 
-    LogPlugin.getDefault().getLogService().log
-      (LogService.LOG_DEBUG,
-       "Hello, this is the html output plugin handling transform(" + source + ")");
+    LOG.debug("Hello, this is the html output plugin handling transform(" + source + ")");
 
     try {
-      ServiceReference[] refs = getBundleContext().getServiceReferences(TransformerFactory.class.getName(),
null);
+      ServiceReference[] refs = getBundleContext().getServiceReferences
+        (TransformerFactory.class.getName(), null);
       TransformerFactory factory = null;
 
       if (null != refs) {
@@ -70,47 +69,28 @@ public class HtmlOutput extends BaseOutp
           Object obj = getBundleContext().getService(refs[i]);
 
           if (null != obj && obj instanceof TransformerFactory) {
-            LogPlugin.getDefault().getLogService().log
-              (LogService.LOG_DEBUG,
-               "Found the right class: " + obj.getClass().getName());
             factory = (TransformerFactory) obj;
             break;
           } else {
             if (null != obj) {
-              LogPlugin.getDefault().getLogService().log
-                (LogService.LOG_DEBUG,
-                 "Found the wrong class: " + obj.getClass().getName());
+              LOG.debug("Found the wrong class: " + obj.getClass().getName());
             } else {
-              LogPlugin.getDefault().getLogService().log
-                (LogService.LOG_DEBUG,
-                 "Null service");
+              LOG.debug("Could not find TransformerFactory through service registry");
             }
           }
         }
       }
 
       if (null != factory) {
-        LogPlugin.getDefault().getLogService().log
-          (LogService.LOG_DEBUG,
-           "factory " + factory.getClass().getName());
-
         InputStream in = HtmlOutput.class.getClassLoader().getResourceAsStream
           ("resources/stylesheets/internal-to-html.xsl");
 
         if (null != in) {
-          LogPlugin.getDefault().getLogService().log
-            (LogService.LOG_DEBUG,
-             "Found the output stylesheet");
+          LOG.debug("Found the output stylesheet");
 
           Transformer transformer = factory.newTransformer
             (new StreamSource(in));
 
-          if (null != transformer) {
-            LogPlugin.getDefault().getLogService().log
-              (LogService.LOG_DEBUG,
-               "transformer " + transformer.getClass().getName());
-          }
-
           ByteArrayOutputStream bytes = new ByteArrayOutputStream();
           StreamResult internalStream = new StreamResult(bytes);
 
@@ -155,31 +135,17 @@ public class HtmlOutput extends BaseOutp
 
           return forrestResult;
         } else {
-          LogPlugin.getDefault().getLogService().log
-            (LogService.LOG_DEBUG,
-             "Didn't find the stylesheet");
+          LOG.debug("Didn't find the stylesheet");
         }
       }
     } catch (InvalidSyntaxException ise) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "Check your filter string",
-         ise);
+      LOG.debug("Check your filter string", ise);
     } catch (TransformerFactoryConfigurationError tfce) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "There is a problem at the factory",
-         tfce);
+      LOG.debug("There is a problem at the factory", tfce);
     } catch (TransformerConfigurationException tce) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "The transformer could not be configured",
-         tce);
+      LOG.debug("The transformer could not be configured", tce);
     } catch (TransformerException te) {
-      LogPlugin.getDefault().getLogService().log
-        (LogService.LOG_DEBUG,
-         "The transformation broke",
-         te);
+      LOG.debug("The transformation broke", te);
     }
 
     return null;

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServlet.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServlet.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServlet.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServlet.java
Wed Apr 27 02:18:52 2011
@@ -41,7 +41,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 import org.apache.forrest.plugin.api.ForrestPlugin;
 import org.apache.forrest.plugin.api.ForrestResult;
 import org.apache.forrest.util.ContentType;
@@ -282,19 +282,4 @@ public class ForrestServlet extends Http
     return path + (path.endsWith("/") ? "" : "/") + index;
   }
 
-  /*
-   * Convenience wrapper to allow typing LOG.debug(msg)
-   */
-  static class LOG {
-
-    static void debug(String msg) {
-      LogService service = LogPlugin.getDefault().getLogService();
-
-      if (null != service) {
-        service.log(LogService.LOG_DEBUG, msg);
-      }
-    }
-
-  }
-
 }

Modified: forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServletPlugin.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServletPlugin.java?rev=1096981&r1=1096980&r2=1096981&view=diff
==============================================================================
--- forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServletPlugin.java
(original)
+++ forrest/trunk/whiteboard/forrest-osgi/org.apache.forrest.servlet/src/java/org/apache/forrest/http/ForrestServletPlugin.java
Wed Apr 27 02:18:52 2011
@@ -26,7 +26,7 @@ import org.osgi.service.http.NamespaceEx
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
 
-import org.apache.forrest.log.LogPlugin;
+import org.apache.forrest.log.LogPlugin.LOG;
 
 public class ForrestServletPlugin implements BundleActivator {
 
@@ -35,7 +35,7 @@ public class ForrestServletPlugin implem
 
   // @Override
   public void start(final BundleContext context) throws Exception {
-    LogPlugin.getDefault().getLogService().log(LogService.LOG_DEBUG, "http activator");
+    LOG.debug("Servlet plugin starting");
 
     // track OSGi HTTP service
     mHttpTracker = new ServiceTracker(context, HttpService.class.getName(), null);
@@ -71,6 +71,7 @@ public class ForrestServletPlugin implem
 
   // @Override
   public void stop(BundleContext context) throws Exception {
+    LOG.debug("Servlet plugin stopping");
     mHttpTracker.close();
   }
 



Mime
View raw message