Author: rdonkin
Date: Mon May  9 10:36:42 2011
New Revision: 1100945

URL: http://svn.apache.org/viewvc?rev=1100945&view=rev
Log:
Factor inheritance to delegation, adding Log interface.

Added:
    
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java
   (with props)
    
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java
   (with props)
Modified:
    
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
    
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysisFeeder.java
    
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/JDBCBayesianAnalyzer.java

Modified: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
URL: 
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java?rev=1100945&r1=1100944&r2=1100945&view=diff
==============================================================================
--- 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
 (original)
+++ 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysis.java
 Mon May  9 10:36:42 2011
@@ -120,7 +120,7 @@ import org.apache.mailet.base.RFC2822Hea
  * @since 2.3.0
  */
 
-public class BayesianAnalysis extends GenericMailet {
+public class BayesianAnalysis extends GenericMailet implements Log {
     /**
      * The JDBCUtil helper class
      */
@@ -133,16 +133,7 @@ public class BayesianAnalysis extends Ge
     /**
      * The JDBCBayesianAnalyzer class that does all the work.
      */
-    private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
-        protected void log(String logString) {
-            log("BayesianAnalysis: " + logString);
-        }
-
-        @Override
-        protected void log(String logString, Throwable t) {
-            log("BayesianAnalysis: " + logString, t);
-        }
-    };
+    private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer(this);
 
     DataSource datasource;
     private String repositoryPath;

Modified: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysisFeeder.java
URL: 
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysisFeeder.java?rev=1100945&r1=1100944&r2=1100945&view=diff
==============================================================================
--- 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysisFeeder.java
 (original)
+++ 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/BayesianAnalysisFeeder.java
 Mon May  9 10:36:42 2011
@@ -124,7 +124,7 @@ import org.apache.mailet.base.GenericMai
  * @since 2.3.0
  */
 
-public class BayesianAnalysisFeeder extends GenericMailet {
+public class BayesianAnalysisFeeder extends GenericMailet implements Log {
     /**
      * The JDBCUtil helper class
      */
@@ -137,17 +137,8 @@ public class BayesianAnalysisFeeder exte
     /**
      * The JDBCBayesianAnalyzer class that does all the work.
      */
-    private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer() {
-        protected void log(String logString) {
-            log("BayesianAnalysisFeeder: " + logString);
-        }
-        
-        @Override
-        protected void log(String logString, Throwable t) {
-            log("BayesianAnalysis: " + logString, t);
-        }
-    };
-
+    private JDBCBayesianAnalyzer analyzer = new JDBCBayesianAnalyzer(this);
+ 
     private DataSource datasource;
     private String repositoryPath;
 

Modified: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/JDBCBayesianAnalyzer.java
URL: 
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/JDBCBayesianAnalyzer.java?rev=1100945&r1=1100944&r2=1100945&view=diff
==============================================================================
--- 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/JDBCBayesianAnalyzer.java
 (original)
+++ 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/JDBCBayesianAnalyzer.java
 Mon May  9 10:36:42 2011
@@ -42,30 +42,12 @@ import org.w3c.dom.Document;
  * @since 2.3.0
  */
 
-abstract public class JDBCBayesianAnalyzer extends BayesianAnalyzer {
+public class JDBCBayesianAnalyzer extends BayesianAnalyzer {
 
     /** Public object representing a lock on database activity. */
     public final static String DATABASE_LOCK = "database lock";
 
-    /**
-     * An abstract method which child classes override to handle logging of
-     * errors in their particular environments.
-     * 
-     * @param errorString
-     *            the error message generated
-     */
-    abstract protected void log(String errorString);
 
-    /**
-     * An abstract method which child classes override to handle logging of
-     * errors in their particular environments.
-     * 
-     * @param errorString
-     *            the error message generated
-     * @param t 
-     *            exception 
-     */
-    abstract protected void log(String errorString, Throwable t);
     
     /**
      * The JDBCUtil helper class
@@ -76,6 +58,9 @@ abstract public class JDBCBayesianAnalyz
         }
     };
 
+    /** Logs messages. */
+    private Log log;
+    
     /** Contains all of the sql strings for this component. */
     private SqlResources sqlQueries = new SqlResources();
 
@@ -89,6 +74,51 @@ abstract public class JDBCBayesianAnalyz
     private static long lastDatabaseUpdateTime;
 
     /**
+     * Getter for static lastDatabaseUpdateTime.
+     * 
+     * @return Value of property lastDatabaseUpdateTime.
+     */
+    public static long getLastDatabaseUpdateTime() {
+
+        return lastDatabaseUpdateTime;
+    }
+
+    /**
+     * Sets static lastDatabaseUpdateTime to System.currentTimeMillis().
+     */
+    public static void touchLastDatabaseUpdateTime() {
+
+        lastDatabaseUpdateTime = System.currentTimeMillis();
+    }
+
+    
+    public JDBCBayesianAnalyzer() {
+        super();
+        log = new SystemLog();
+    }
+    
+    public JDBCBayesianAnalyzer(Log log) {
+        super();
+        this.log = log;
+    }
+
+    /**
+     * Gets the current log.
+     * @return current log, not null
+     */
+    public Log getLog() {
+        return log;
+    }
+
+    /**
+     * Sets the current log.
+     * @param log, not null
+     */
+    public void setLog(Log log) {
+        this.log = log;
+    }
+
+    /**
      * Getter for property sqlFileName.
      * 
      * @return Value of property sqlFileName.
@@ -131,30 +161,6 @@ abstract public class JDBCBayesianAnalyz
     }
 
     /**
-     * Getter for static lastDatabaseUpdateTime.
-     * 
-     * @return Value of property lastDatabaseUpdateTime.
-     */
-    public static long getLastDatabaseUpdateTime() {
-
-        return lastDatabaseUpdateTime;
-    }
-
-    /**
-     * Sets static lastDatabaseUpdateTime to System.currentTimeMillis().
-     */
-    public static void touchLastDatabaseUpdateTime() {
-
-        lastDatabaseUpdateTime = System.currentTimeMillis();
-    }
-
-    /**
-     * Default constructor.
-     */
-    public JDBCBayesianAnalyzer() {
-    }
-
-    /**
      * Loads the token frequencies from the database.
      * 
      * @param conn
@@ -456,4 +462,27 @@ abstract public class JDBCBayesianAnalyz
             }
         }
     }
+    
+    
+    /**
+     * Logs errors.
+     * 
+     * @param errorString
+     *            the error message generated
+     */
+    private void log(String errorString) {
+        log.log(errorString);
+    }
+
+    /**
+     * Logs errors.
+     * 
+     * @param errorString
+     *            the error message generated
+     * @param t 
+     *            exception 
+     */
+    private void log(String errorString, Throwable t) {
+        log.log(errorString);
+    }
 }

Added: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java
URL: 
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java?rev=1100945&view=auto
==============================================================================
--- 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java
 (added)
+++ 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java
 Mon May  9 10:36:42 2011
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.ai.classic;
+
+/**
+ * A simple logging mechanism.
+ */
+public interface Log {
+    
+    /**
+     * An abstract method which child classes override to handle logging of
+     * errors in their particular environments.
+     * 
+     * @param errorString
+     *            the error message generated
+     */
+    void log(String errorString);
+
+    /**
+     * An abstract method which child classes override to handle logging of
+     * errors in their particular environments.
+     * 
+     * @param errorString
+     *            the error message generated
+     * @param t 
+     *            exception 
+     */
+    void log(String errorString, Throwable t);
+}

Propchange: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/Log.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java
URL: 
http://svn.apache.org/viewvc/james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java?rev=1100945&view=auto
==============================================================================
--- 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java
 (added)
+++ 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java
 Mon May  9 10:36:42 2011
@@ -0,0 +1,37 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.ai.classic;
+
+/**
+ * Logs naively to system out. Not recommended for production.
+ */
+public class SystemLog implements Log {
+    
+    @Override
+    public void log(String errorString) {
+        System.err.println("[AI Classic] " + errorString);
+    }
+
+    @Override
+    public void log(String errorString, Throwable t) {
+        System.err.println("[AI Classic] " + errorString);
+        t.printStackTrace();
+    } 
+}

Propchange: 
james/mailet/ai/trunk/classic/src/main/java/org/apache/james/ai/classic/SystemLog.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to