Author: norman
Date: Fri Jan  7 09:52:19 2011
New Revision: 1056231

URL: http://svn.apache.org/viewvc?rev=1056231&view=rev
Log:
Create MailetContextLog class in util to share some more code

Added:
    
james/server/trunk/util/src/main/java/org/apache/james/util/MailetContextLog.java
Modified:
    
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
    
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/SieveMailet.java

Modified: 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=1056231&r1=1056230&r2=1056231&view=diff
==============================================================================
--- 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
 (original)
+++ 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
 Fri Jan  7 09:52:19 2011
@@ -21,7 +21,6 @@
 
 package org.apache.james.transport.mailets;
 
-import org.apache.commons.logging.Log;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.TemporaryResolutionException;
 import org.apache.james.domainlist.api.DomainList;
@@ -32,6 +31,7 @@ import org.apache.james.queue.api.MailQu
 import org.apache.james.queue.api.MailQueue.MailQueueException;
 import org.apache.james.queue.api.MailQueue.MailQueueItem;
 import org.apache.james.util.MXHostAddressIterator;
+import org.apache.james.util.MailetContextLog;
 import org.apache.james.util.TimeConverter;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.HostAddress;
@@ -194,7 +194,7 @@ public class RemoteDelivery extends Gene
 
     private String heloName;
 
-    private final Log logAdapter = new MailetLog();
+    private MailetContextLog logAdapter;
     
     
     
@@ -229,6 +229,8 @@ public class RemoteDelivery extends Gene
         // Set isDebug flag.
         isDebug = (getInitParameter("debug") == null) ? false : new 
Boolean(getInitParameter("debug")).booleanValue();
 
+        logAdapter = new MailetContextLog(getMailetContext(), isDebug);
+        
         // Create list of Delay Times.
         ArrayList<Delay> delayTimesList = new ArrayList<Delay>();
         try {
@@ -1578,91 +1580,4 @@ public class RemoteDelivery extends Gene
         }
     }
   
-    private final class MailetLog implements Log {
-
-        public void debug(Object arg0) {
-            if (isDebug) {
-                log(arg0.toString());
-            }
-        }
-
-        public void debug(Object arg0, Throwable arg1) {
-            if (isDebug) {
-                log(arg0.toString(), arg1);
-            }            
-        }
-
-        public void error(Object arg0) {
-            log(arg0.toString());
-            
-        }
-
-        public void error(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-            
-        }
-
-        public void fatal(Object arg0) {
-            log(arg0.toString());
-            
-        }
-
-        public void fatal(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-            
-        }
-
-        public void info(Object arg0) {
-            log(arg0.toString());
-            
-        }
-
-        public void info(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-            
-        }
-
-        public boolean isDebugEnabled() {
-            return isDebug;
-        }
-
-        public boolean isErrorEnabled() {
-            return true;
-        }
-
-        public boolean isFatalEnabled() {
-            return true;
-        }
-
-        public boolean isInfoEnabled() {
-            return true;
-
-        }
-
-        public boolean isTraceEnabled() {
-            return false;
-        }
-
-        public boolean isWarnEnabled() {
-            return true;
-        }
-
-        public void trace(Object arg0) {            
-        }
-
-        public void trace(Object arg0, Throwable arg1) {
-            
-        }
-
-        public void warn(Object arg0) {
-            log(arg0.toString());
-            
-        }
-
-        public void warn(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-            
-        }
-        
-    }
 }

Modified: 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/SieveMailet.java?rev=1056231&r1=1056230&r2=1056231&view=diff
==============================================================================
--- 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
 (original)
+++ 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
 Fri Jan  7 09:52:19 2011
@@ -25,7 +25,6 @@ import javax.annotation.Resource;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.commons.logging.Log;
 import org.apache.james.core.MimeMessageInputStream;
 import org.apache.james.mailbox.MailboxConstants;
 import org.apache.james.mailbox.MailboxManager;
@@ -34,6 +33,7 @@ import org.apache.james.mailbox.MailboxS
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
+import org.apache.james.util.MailetContextLog;
 import org.apache.jsieve.mailet.Poster;
 import org.apache.jsieve.mailet.SieveMailboxMailet;
 import org.apache.mailet.Mail;
@@ -153,7 +153,7 @@ public class SieveMailet extends SieveMa
                         throw new MessagingException("Unable to 
accessUsersRepository", e);
                     }
 
-                    final MailboxSession session = 
mailboxManager.createSystemSession(user, new MailetLog());
+                    final MailboxSession session = 
mailboxManager.createSystemSession(user, new 
MailetContextLog(getMailetContext()));
 
                     // start processing request
                     mailboxManager.startProcessingRequest(session);
@@ -196,87 +196,4 @@ public class SieveMailet extends SieveMa
             }
         }
     }
-
-    private final class MailetLog implements Log {
-
-        public void debug(Object arg0) {
-
-        }
-
-        public void debug(Object arg0, Throwable arg1) {
-        }
-
-        public void error(Object arg0) {
-            log(arg0.toString());
-        }
-
-        public void error(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-
-        }
-
-        public void fatal(Object arg0) {
-            log(arg0.toString());
-
-        }
-
-        public void fatal(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-
-        }
-
-        public void info(Object arg0) {
-            log(arg0.toString());
-
-        }
-
-        public void info(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-
-        }
-
-        public boolean isDebugEnabled() {
-            return false;
-        }
-
-        public boolean isErrorEnabled() {
-            return true;
-        }
-
-        public boolean isFatalEnabled() {
-            return true;
-        }
-
-        public boolean isInfoEnabled() {
-            return true;
-        }
-
-        public boolean isTraceEnabled() {
-            return false;
-        }
-
-        public boolean isWarnEnabled() {
-            return true;
-        }
-
-        public void trace(Object arg0) {
-
-        }
-
-        public void trace(Object arg0, Throwable arg1) {
-
-        }
-
-        public void warn(Object arg0) {
-            log(arg0.toString());
-
-        }
-
-        public void warn(Object arg0, Throwable arg1) {
-            log(arg0.toString(), arg1);
-
-        }
-
-    }
-
 }

Added: 
james/server/trunk/util/src/main/java/org/apache/james/util/MailetContextLog.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/util/src/main/java/org/apache/james/util/MailetContextLog.java?rev=1056231&view=auto
==============================================================================
--- 
james/server/trunk/util/src/main/java/org/apache/james/util/MailetContextLog.java
 (added)
+++ 
james/server/trunk/util/src/main/java/org/apache/james/util/MailetContextLog.java
 Fri Jan  7 09:52:19 2011
@@ -0,0 +1,191 @@
+/****************************************************************
+ * 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.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.mailet.MailetContext;
+
+/**
+ * {...@link Log} implementation which delegate the logging to a {...@link 
MailetContext}
+ * 
+ *
+ */
+public class MailetContextLog implements Log {
+
+    private boolean isDebug;
+    private MailetContext context;
+
+    public MailetContextLog(MailetContext context, boolean isDebug) {
+        this.context = context;
+        this.isDebug = isDebug;
+    }
+    
+    public MailetContextLog(MailetContext context) {
+        this(context, false);
+        
+    }
+    
+
+    /**
+     * Only log if {...@link #isDebugEnabled()} is true
+     */
+    public void debug(Object arg0) {
+        if (isDebug) {
+            context.log(arg0.toString());
+        }
+    }
+
+    /**
+     * Only log if {...@link #isDebugEnabled()} is true
+     */
+    public void debug(Object arg0, Throwable arg1) {
+        if (isDebug) {
+            context.log(arg0.toString(), arg1);
+        }            
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#error(java.lang.Object)
+     */
+    public void error(Object arg0) {
+        context.log(arg0.toString());
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#error(java.lang.Object, 
java.lang.Throwable)
+     */
+    public void error(Object arg0, Throwable arg1) {
+        context.log(arg0.toString(), arg1);
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#fatal(java.lang.Object)
+     */
+    public void fatal(Object arg0) {
+        context.log(arg0.toString());
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#fatal(java.lang.Object, 
java.lang.Throwable)
+     */
+    public void fatal(Object arg0, Throwable arg1) {
+        context.log(arg0.toString(), arg1);
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#info(java.lang.Object)
+     */
+    public void info(Object arg0) {
+        context.log(arg0.toString());
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#info(java.lang.Object, 
java.lang.Throwable)
+     */
+    public void info(Object arg0, Throwable arg1) {
+        context.log(arg0.toString(), arg1);
+        
+    }
+
+    /**
+     * Return true if debug logging is enabled
+     */
+    public boolean isDebugEnabled() {
+        return isDebug;
+    }
+
+    /**
+     * Enabled, return true
+     */
+    public boolean isErrorEnabled() {
+        return true;
+    }
+
+    /**
+     * Enabled, return true
+     */
+    public boolean isFatalEnabled() {
+        return true;
+    }
+
+    /**
+     * Enabled, return true
+     */
+    public boolean isInfoEnabled() {
+        return true;
+
+    }
+
+    /**
+     * Not enabled return false
+     */
+    public boolean isTraceEnabled() {
+        return false;
+    }
+
+    /**
+     * Enabled, return true
+     */
+    public boolean isWarnEnabled() {
+        return true;
+    }
+
+    /**
+     * Do nothing
+     */
+    public void trace(Object arg0) {            
+    }
+
+    /**
+     * Do nothing
+     */
+    public void trace(Object arg0, Throwable arg1) {
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#warn(java.lang.Object)
+     */
+    public void warn(Object arg0) {
+        context.log(arg0.toString());
+        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.commons.logging.Log#warn(java.lang.Object, 
java.lang.Throwable)
+     */
+    public void warn(Object arg0, Throwable arg1) {
+        context.log(arg0.toString(), arg1);
+        
+    }
+    
+}



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

Reply via email to