james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r882589 - in /james/server/trunk: core-library/src/test/java/org/apache/james/test/mock/james/ phoenix-deployment/src/conf/ spoolmanager-function/ spoolmanager-function/src/main/java/org/apache/james/ spoolmanager-function/src/main/java/org...
Date Fri, 20 Nov 2009 14:51:29 GMT
Author: norman
Date: Fri Nov 20 14:51:20 2009
New Revision: 882589

URL: http://svn.apache.org/viewvc?rev=882589&view=rev
Log:
More decoupling of Avalon to move to Guice (JAMES-893)

Added:
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractAvalonJamesLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMailetLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMatcherLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesSpoolManager.java
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/AvalonJamesMailetLoader.xinfo
      - copied unchanged from r829946, james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/AvalonJamesMatcherLoader.xinfo
      - copied unchanged from r829946, james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/AvalonJamesSpoolManager.xinfo
      - copied unchanged from r829946, james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesSpoolManager.xinfo
Removed:
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
    james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesSpoolManager.xinfo
Modified:
    james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/InMemorySpoolRepository.java
    james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
    james/server/trunk/spoolmanager-function/pom.xml
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/James.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesSpoolManager.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/LinearProcessor.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetConfigImpl.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetContextWrapper.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetLoader.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/StateAwareProcessorList.java
    james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/JamesMailetLoaderTest.java

Modified: james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/InMemorySpoolRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/InMemorySpoolRepository.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/InMemorySpoolRepository.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/james/InMemorySpoolRepository.java Fri Nov 20 14:51:20 2009
@@ -55,7 +55,7 @@
     protected final static boolean DEEP_DEBUG = true;
     private Lock lock;
     private MockLogger logger;
-    private Hashtable spool;
+    private Hashtable<String, Mail> spool;
 
     private MockLogger getLogger() {
         if (logger == null) {
@@ -233,10 +233,10 @@
      * @throws MessagingException
      * @since 2.2.0
      */
-    public void remove(Collection mails) throws MessagingException {
-        Iterator delList = mails.iterator();
+    public void remove(Collection<Mail> mails) throws MessagingException {
+        Iterator<Mail> delList = mails.iterator();
         while (delList.hasNext()) {
-            remove((Mail)delList.next());
+            remove(delList.next());
         }
     }
 
@@ -271,12 +271,12 @@
      * @return an <code>Iterator</code> over the list of keys in the repository
      *
      */
-    public Iterator list() {
+    public Iterator<String> list() {
         // Fix ConcurrentModificationException by cloning 
         // the keyset before getting an iterator
-        final ArrayList clone;
+        final ArrayList<String> clone;
         synchronized(spool) {
-            clone = new ArrayList(spool.keySet());
+            clone = new ArrayList<String>(spool.keySet());
         }
         return clone.iterator();
     }
@@ -377,8 +377,8 @@
             getLogger().debug("Method accept(Filter) called");
         }
         while (!Thread.currentThread().isInterrupted()) try {
-            for (Iterator it = list(); it.hasNext(); ) {
-                String s = it.next().toString();
+            for (Iterator<String> it = list(); it.hasNext(); ) {
+                String s = it.next();
                 if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
                     StringBuffer logBuffer =
                         new StringBuffer(64)
@@ -426,7 +426,7 @@
      * 
      */
     public InMemorySpoolRepository() {
-        spool = new Hashtable();
+        spool = new Hashtable<String,Mail>();
         lock = new Lock();
     }
 
@@ -436,9 +436,9 @@
 
     public void clear() {
         if (spool != null) {
-            Iterator i = list();
+            Iterator<String> i = list();
             while (i.hasNext()) {
-                String key = (String) i.next();
+                String key = i.next();
                 try {
                     remove(key);
                 } catch (MessagingException e) {
@@ -454,7 +454,7 @@
     public String toString() {
         StringBuffer result = new StringBuffer();
         result.append(super.toString());
-        Iterator i = list();
+        Iterator<String> i = list();
         while (i.hasNext()) {
             result.append("\n\t"+i.next());
         }

Modified: james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml Fri Nov 20 14:51:20 2009
@@ -60,18 +60,18 @@
   </block>
    
   <!-- The James Spool Manager block  -->
-  <block name="spoolmanager" class="org.apache.james.transport.JamesSpoolManager" >
+  <block name="spoolmanager" class="org.apache.james.transport.AvalonJamesSpoolManager" >
     <provide name="spoolrepository" role="org.apache.james.services.SpoolRepository"/>
     <provide name="matcherpackages" role="org.apache.james.transport.MatcherLoader"/>
     <provide name="mailetpackages" role="org.apache.james.transport.MailetLoader"/>
     <proxy disable='true'/>
   </block>
 
-  <block name="matcherpackages" class="org.apache.james.transport.JamesMatcherLoader" >
+  <block name="matcherpackages" class="org.apache.james.transport.AvalonJamesMatcherLoader" >
     <proxy disable='true'/>
   </block>
 
-  <block name="mailetpackages" class="org.apache.james.transport.JamesMailetLoader" >
+  <block name="mailetpackages" class="org.apache.james.transport.AvalonJamesMailetLoader" >
     <proxy disable='true'/>
   </block>
 

Modified: james/server/trunk/spoolmanager-function/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/pom.xml?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/pom.xml (original)
+++ james/server/trunk/spoolmanager-function/pom.xml Fri Nov 20 14:51:20 2009
@@ -96,6 +96,32 @@
       <groupId>org.apache.james</groupId>
       <artifactId>apache-mime4j</artifactId>
     </dependency>
+    
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency> 
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.code.guice</groupId>
+      <artifactId>guice</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.guiceyfruit</groupId>
+      <artifactId>guiceyfruit-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>spring-aopalliance</groupId>
+      <artifactId>spring-aopalliance</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>james-server-avalon-guice-bridge-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
       <artifactId>apache-standard-mailets</artifactId>

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/James.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/James.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/James.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/James.java Fri Nov 20 14:51:20 2009
@@ -440,7 +440,11 @@
         DefaultConfiguration conf = new DefaultConfiguration("mailet", "generated:James.initialize()");
         MailetConfigImpl configImpl = new MailetConfigImpl();
         configImpl.setMailetName("LocalDelivery");
-        configImpl.setConfiguration(conf);
+        try {
+            configImpl.setConfiguration(new ConfigurationAdapter(conf));
+        } catch (org.apache.commons.configuration.ConfigurationException e) {
+            throw new MessagingException(e.getMessage());
+        }
         configImpl.setMailetContext(this);
         localDeliveryMailet = new LocalDelivery();
         localDeliveryMailet.init(configImpl);

Added: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractAvalonJamesLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractAvalonJamesLoader.java?rev=882589&view=auto
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractAvalonJamesLoader.java (added)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractAvalonJamesLoader.java Fri Nov 20 14:51:20 2009
@@ -0,0 +1,97 @@
+/****************************************************************
+ * 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.transport;
+
+import javax.mail.MessagingException;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.kernel.LoaderService;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.james.util.ConfigurationAdapter;
+import org.apache.mailet.Mailet;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
+public abstract class AbstractAvalonJamesLoader implements Configurable, Initializable, LogEnabled, GuiceInjected {
+
+    
+
+    private ConfigurationAdapter config;
+    private AvalonLogger logger;
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        try {
+            this.config = new ConfigurationAdapter(config);
+        } catch (org.apache.commons.configuration.ConfigurationException e) {
+            throw new ConfigurationException("Unable to convert configuration", e);
+        }
+    }
+
+    
+    /**
+     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+     */
+    public void enableLogging(Logger logger) {
+        this.logger = new AvalonLogger(logger);
+    }
+
+
+    protected class Module extends AbstractModule {
+
+        @Override
+        protected void configure() {
+            bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+            bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+            bind(LoaderService.class).annotatedWith(Names.named("org.apache.james.LoaderService")).toProvider(new Provider<LoaderService>() {
+
+                public LoaderService get() {
+                    return new MyLoaderService();
+                }
+                
+                // Mimic the loaderservice
+                class MyLoaderService implements LoaderService {
+                    Injector injector = Guice.createInjector(new Module(), new Jsr250Module());
+
+                    public <T> T load(Class<T> type) {
+                        return injector.getInstance(type);
+                    }
+                    
+                }
+            });
+        }
+        
+    }
+}

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java Fri Nov 20 14:51:20 2009
@@ -19,14 +19,16 @@
 
 
 package org.apache.james.transport;
+import java.util.List;
 import java.util.Vector;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.kernel.LoaderService;
 import org.apache.mailet.MailetContext;
 import org.apache.mailet.MailetException;
@@ -34,7 +36,7 @@
 /**
  * Common services for loaders.
  */
-public abstract class AbstractLoader extends AbstractLogEnabled implements Configurable {
+public abstract class AbstractLoader {
 
     /**
      * The list of packages that may contain Mailets or matchers
@@ -48,6 +50,10 @@
 
     private LoaderService loaderService;
 
+    private Log logger;
+
+    private HierarchicalConfiguration config;
+
     
     /**
      * Gets the loader service used by this instance.
@@ -66,42 +72,55 @@
         this.loaderService = loaderService;
     }
 
+    @Resource(name="org.apache.commons.logging.Log")
+    public final void setLogger(Log logger) {
+        this.logger = logger;
+    }
+    
+
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public final void setConfiguration(HierarchicalConfiguration config) {
+        this.config = config;
+    }
     /**
      * Set the MailetContext
      * 
      * @param mailetContext the MailetContext
      */
- // Pheonix used to play games with service names
- // TODO: Support type based injection
-    @Resource(name="James") 
+    @Resource(name="org.apache.mailet.MailetContext") 
     public void setMailetContext(MailetContext mailetContext) {
         this.mailetContext = mailetContext;
     }
 
+    protected Log getLogger() {
+        return logger;
+    }
     protected Object load(String className) throws ClassNotFoundException {
         final Object newInstance = loaderService.load(Thread.currentThread().getContextClassLoader().loadClass(className));
         return newInstance;
     }
 
-    protected void getPackages(Configuration conf, String packageType)
+    @SuppressWarnings("unchecked")
+    protected void getPackages(HierarchicalConfiguration conf, String packageType)
         throws ConfigurationException {
         packages = new Vector<String>();
         packages.addElement("");
-        final Configuration[] pkgConfs = conf.getChildren(packageType);
-        for (int i = 0; i < pkgConfs.length; i++) {
-            Configuration c = pkgConfs[i];
-            String packageName = c.getValue();
+        final List<String> pkgConfs = conf.getList(packageType);
+        for (int i = 0; i < pkgConfs.size(); i++) {
+            String packageName = pkgConfs.get(i);
             if (!packageName.endsWith(".")) {
                 packageName += ".";
             }
             packages.addElement(packageName);
         }
     }
+    
+    @PostConstruct
+    public void init() throws Exception {
+        configure(config);
+    }
         
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
-     */
-    public abstract void configure(Configuration arg0) throws ConfigurationException;
+    protected abstract void configure(HierarchicalConfiguration arg0) throws ConfigurationException;
     
     /**
      * Gets a human readable description of the loader.

Added: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMailetLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMailetLoader.java?rev=882589&view=auto
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMailetLoader.java (added)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMailetLoader.java Fri Nov 20 14:51:20 2009
@@ -0,0 +1,34 @@
+package org.apache.james.transport;
+
+import javax.mail.MessagingException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.kernel.LoaderService;
+import org.apache.james.util.ConfigurationAdapter;
+import org.apache.mailet.Mailet;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
+public class AvalonJamesMailetLoader extends AbstractAvalonJamesLoader implements MailetLoader{
+
+    
+
+    private MailetLoader loader;
+    private ConfigurationAdapter config;
+
+
+    public void initialize() throws Exception {
+        loader = Guice.createInjector(new Jsr250Module(), new Module()).getInstance(JamesMailetLoader.class);
+    }
+ 
+    public Mailet getMailet(String mailetName, Configuration configuration) throws MessagingException {
+        return loader.getMailet(mailetName, configuration);
+    }
+}

Added: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMatcherLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMatcherLoader.java?rev=882589&view=auto
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMatcherLoader.java (added)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesMatcherLoader.java Fri Nov 20 14:51:20 2009
@@ -0,0 +1,41 @@
+/****************************************************************
+ * 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.transport;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Matcher;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.Guice;
+
+public class AvalonJamesMatcherLoader extends AbstractAvalonJamesLoader implements MatcherLoader{
+
+    private MatcherLoader loader;
+    public void initialize() throws Exception {
+        loader = Guice.createInjector(new Jsr250Module(), new Module()).getInstance(JamesMatcherLoader.class);
+    }
+
+    public Matcher getMatcher(String matchName) throws MessagingException {
+        return loader.getMatcher(matchName);
+    }
+
+}

Added: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesSpoolManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesSpoolManager.java?rev=882589&view=auto
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesSpoolManager.java (added)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AvalonJamesSpoolManager.java Fri Nov 20 14:51:20 2009
@@ -0,0 +1,110 @@
+package org.apache.james.transport;
+
+import java.util.List;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.api.kernel.LoaderService;
+import org.apache.james.services.SpoolManager;
+import org.apache.james.services.SpoolRepository;
+import org.apache.james.util.ConfigurationAdapter;
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.MatcherConfig;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
+public class AvalonJamesSpoolManager implements Initializable, LogEnabled, Serviceable, Configurable, Disposable, SpoolManager{
+
+    private SpoolManager mgmt;
+    private ConfigurationAdapter config;
+    private AvalonLogger logger;
+    private SpoolRepository repos;
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        try {
+            this.config = new ConfigurationAdapter(config);
+        } catch (org.apache.commons.configuration.ConfigurationException e) {
+            throw new ConfigurationException("Unable to convert configuration", e);
+        }
+    }
+
+    
+    /**
+     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
+     */
+    public void enableLogging(Logger logger) {
+        this.logger = new AvalonLogger(logger);
+    }
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+     */
+    public void service(ServiceManager comp) throws ServiceException {
+        repos = (SpoolRepository) comp.lookup(SpoolRepository.ROLE);
+    }
+
+
+    public void dispose() {        
+    }
+
+    public List<MailetConfig> getMailetConfigs(String processorName) {
+        return mgmt.getMailetConfigs(processorName);
+    }
+
+    public List<MatcherConfig> getMatcherConfigs(String processorName) {
+        return mgmt.getMatcherConfigs(processorName);
+    }
+
+    public String[] getProcessorNames() {
+        return mgmt.getProcessorNames();
+    }
+
+    protected class Module extends AbstractModule {
+
+        @Override
+        protected void configure() {
+            bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+            bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+            bind(SpoolRepository.class).annotatedWith(Names.named("org.apache.james.services.SpoolRepository")).toInstance(repos);
+            bind(LoaderService.class).annotatedWith(Names.named("org.apache.james.LoaderService")).toProvider(new Provider<LoaderService>() {
+
+                public LoaderService get() {
+                    return new MyLoaderService();
+                }
+                
+                class MyLoaderService implements LoaderService{
+
+                    public <T> T load(Class<T> type) {
+                        return Guice.createInjector(new Jsr250Module(), new Module()).getInstance(type);
+                    }
+                    
+                }
+                
+            });
+            
+           
+        }
+        
+    }
+
+    public void initialize() throws Exception {
+        mgmt = Guice.createInjector(new Jsr250Module(), new Module()).getInstance(JamesSpoolManager.class);
+    }  
+}

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java Fri Nov 20 14:51:20 2009
@@ -19,10 +19,12 @@
 
 
 package org.apache.james.transport;
+import javax.annotation.PostConstruct;
 import javax.mail.MessagingException;
 
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.mailet.Mailet;
 /**
  * Loads Mailets for use inside James.
@@ -34,15 +36,22 @@
     
     private final String MAILET_PACKAGE = "mailetpackage";
     
+
+    @PostConstruct
+    public void init() throws Exception {
+        super.init();
+    }
+    
     /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+     * @see org.apache.james.transport.AbstractLoader#configure(org.apache.commons.configuration.HierarchicalConfiguration)
      */
-    public void configure(Configuration conf) throws ConfigurationException {
+    public void configure(HierarchicalConfiguration conf) throws ConfigurationException {
         getPackages(conf,MAILET_PACKAGE);
     }
 
     /**
-     * @see org.apache.james.transport.MailetLoader#getMailet(java.lang.String, org.apache.avalon.framework.configuration.Configuration)
+     * (non-Javadoc)
+     * @see org.apache.james.transport.MailetLoader#getMailet(java.lang.String, org.apache.commons.configuration.Configuration)
      */
     public Mailet getMailet(final String mailetName, final Configuration configuration) throws MessagingException {
         try {
@@ -54,7 +63,7 @@
                     final MailetConfigImpl configImpl = new MailetConfigImpl();
                     configImpl.setMailetName(mailetName);
                     configImpl.setConfiguration(configuration);
-                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger().getChildLogger(mailetName))); 
+                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger())); 
                     mailet.init(configImpl);
                     
                     return mailet;
@@ -66,6 +75,7 @@
         } catch (MessagingException me) {
             throw me;
         } catch (Exception e) {
+            e.printStackTrace();
             throw loadFailed(mailetName, e);
         }
     }

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java Fri Nov 20 14:51:20 2009
@@ -20,10 +20,11 @@
 
 
 package org.apache.james.transport;
+import javax.annotation.PostConstruct;
 import javax.mail.MessagingException;
 
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.mailet.Matcher;
 /**
  * Loads Matchers for use inside James.
@@ -33,10 +34,17 @@
     private static final String DISPLAY_NAME = "matcher";
     private final String MATCHER_PACKAGE = "matcherpackage";
 
+    
+    @PostConstruct
+    public void init() throws Exception {
+        super.init();
+    }
+    
+    
     /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+     * @see org.apache.james.transport.AbstractLoader#configure(org.apache.commons.configuration.HierarchicalConfiguration)
      */
-    public void configure(Configuration conf) throws ConfigurationException {
+    public void configure(HierarchicalConfiguration conf) throws ConfigurationException {
            getPackages(conf,MATCHER_PACKAGE);
     }
 
@@ -59,7 +67,7 @@
                     final MatcherConfigImpl configImpl = new MatcherConfigImpl();
                     configImpl.setMatcherName(matchName);
                     configImpl.setCondition(condition);
-                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger().getChildLogger(matchName)));
+                    configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger()));
                     matcher.init(configImpl);
                     
                     return matcher;

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesSpoolManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesSpoolManager.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesSpoolManager.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesSpoolManager.java Fri Nov 20 14:51:20 2009
@@ -26,16 +26,15 @@
 import java.util.List;
 
 import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.kernel.LoaderService;
 import org.apache.james.services.SpoolManager;
 import org.apache.james.services.SpoolRepository;
 import org.apache.mailet.Mail;
@@ -50,14 +49,7 @@
  *
  * @version CVS $Revision$ $Date$
  */
-public class JamesSpoolManager
-    extends AbstractLogEnabled
-    implements Serviceable, Configurable, Runnable, Disposable, SpoolManager {
-
-    /**
-     * System component manager
-     */
-    private ServiceManager compMgr;
+public class JamesSpoolManager implements Runnable, SpoolManager {
 
     /**
      * The spool that this manager will process
@@ -106,65 +98,69 @@
      */
     private MailProcessor processorList;
 
+    private Log logger;
+
+    private LoaderService loaderService;
+
+    private HierarchicalConfiguration config;
+
     /**
      * Set the SpoolRepository
      * 
      * @param spool the SpoolRepository
      */
-    public void setSpool(SpoolRepository spool) {
+    @Resource(name="org.apache.james.services.SpoolRepository")
+    public void setSpoolRepository(SpoolRepository spool) {
         this.spool = spool;
     }
 
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
-     */
-    public void service(ServiceManager comp) throws ServiceException {
-        compMgr = comp;
-        setSpool((SpoolRepository) compMgr.lookup(SpoolRepository.ROLE));
-    }
 
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
-     */
-    public void configure(Configuration conf) throws ConfigurationException {
-        numThreads = conf.getChild("threads").getValueAsInteger(1);
+    @Resource(name="org.apache.james.LoaderService")
+    public final void setLoaderService(LoaderService service) {
+        this.loaderService = service;
+    }
+    
+    @Resource(name="org.apache.commons.logging.Log")
+    public final void setLogger(Log logger) {
+        this.logger = logger;
+    }
+    
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public final void setConfiguration(HierarchicalConfiguration config) {
+        this.config = config;
+    }
+    
+    
+    protected void configure(HierarchicalConfiguration config) throws ConfigurationException {
+        numThreads = config.getInt("threads",1);
 
-        String processorClass = conf.getChild("processorClass").getValue("org.apache.james.transport.StateAwareProcessorList");
+        String processorClass = config.getString("processorClass","org.apache.james.transport.StateAwareProcessorList");
         try {
-            processorList = (MailProcessor) Thread.currentThread().getContextClassLoader().loadClass(processorClass).newInstance();
+            Class<?> cObj = Thread.currentThread().getContextClassLoader().loadClass(processorClass);
+            processorList = (MailProcessor) loaderService.load(cObj);
         } catch (Exception e1) {
-            getLogger().error("Unable to instantiate spoolmanager processor: "+processorClass, e1);
+            logger.error("Unable to instantiate spoolmanager processor: "+processorClass, e1);
             throw new ConfigurationException("Instantiation exception: "+processorClass, e1);
         }
 
-        try {
-            ContainerUtil.enableLogging(processorList, getLogger());
-            ContainerUtil.service(processorList, compMgr);
-        } catch (ServiceException e) {
-            getLogger().error(e.getMessage(), e);
-            throw new ConfigurationException("Servicing failed with error: "+e.getMessage(),e);
-        }
-
-        ContainerUtil.configure(processorList, conf);
     }
 
     /**
      * Initialises the spool manager.
      */
     @PostConstruct
-    public void initialize() throws Exception {
-
-        getLogger().info("JamesSpoolManager init...");
-
+    public void init() throws Exception {
+        logger.info("JamesSpoolManager init...");
+        configure(config);
         ContainerUtil.initialize(processorList);
 
-        if (getLogger().isInfoEnabled()) {
+        if (logger.isInfoEnabled()) {
             StringBuffer infoBuffer =
                 new StringBuffer(64)
                     .append("Spooler Manager uses ")
                     .append(numThreads)
                     .append(" Thread(s)");
-            getLogger().info(infoBuffer.toString());
+            logger.info(infoBuffer.toString());
         }
 
         active = true;
@@ -183,11 +179,10 @@
      */
     public void run() {
 
-        if (getLogger().isInfoEnabled())
-        {
-            getLogger().info("Run JamesSpoolManager: "
+        if (logger.isInfoEnabled()) {
+            logger.info("Run JamesSpoolManager: "
                              + Thread.currentThread().getName());
-            getLogger().info("Spool=" + spool.getClass().getName());
+            logger.info("Spool=" + spool.getClass().getName());
         }
 
         numActive++;
@@ -196,13 +191,13 @@
             try {
                 Mail mail = (Mail)spool.accept();
                 key = mail.getName();
-                if (getLogger().isDebugEnabled()) {
+                if (logger.isDebugEnabled()) {
                     StringBuffer debugBuffer =
                         new StringBuffer(64)
                                 .append("==== Begin processing mail ")
                                 .append(mail.getName())
                                 .append("====");
-                    getLogger().debug(debugBuffer.toString());
+                    logger.debug(debugBuffer.toString());
                 }
 
                 processorList.service(mail);
@@ -214,13 +209,13 @@
                     (mail.getRecipients().size() == 0)) {
                     ContainerUtil.dispose(mail);
                     spool.remove(key);
-                    if (getLogger().isDebugEnabled()) {
+                    if (logger.isDebugEnabled()) {
                         StringBuffer debugBuffer =
                             new StringBuffer(64)
                                     .append("==== Removed from spool mail ")
                                     .append(key)
                                     .append("====");
-                        getLogger().debug(debugBuffer.toString());
+                        logger.debug(debugBuffer.toString());
                     }
                 }
                 else {
@@ -235,10 +230,10 @@
                 }
                 mail = null;
             } catch (InterruptedException ie) {
-                getLogger().info("Interrupted JamesSpoolManager: " + Thread.currentThread().getName());
+                logger.info("Interrupted JamesSpoolManager: " + Thread.currentThread().getName());
             } catch (Throwable e) {
-                if (getLogger().isErrorEnabled()) {
-                    getLogger().error("Exception processing " + key + " in JamesSpoolManager.run "
+                if (logger.isErrorEnabled()) {
+                    logger.error("Exception processing " + key + " in JamesSpoolManager.run "
                                       + e.getMessage(), e);
                 }
                 /* Move the mail to ERROR state?  If we do, it could be
@@ -257,9 +252,8 @@
                 */
             }
         }
-        if (getLogger().isInfoEnabled())
-        {
-            getLogger().info("Stop JamesSpoolManager: " + Thread.currentThread().getName());
+        if (logger.isInfoEnabled()){
+            logger.info("Stop JamesSpoolManager: " + Thread.currentThread().getName());
         }
         numActive--;
     }
@@ -274,8 +268,9 @@
      * 
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
+    @PreDestroy
     public void dispose() {
-        getLogger().info("JamesSpoolManager dispose...");
+        logger.info("JamesSpoolManager dispose...");
         active = false; // shutdown the threads
         for (Thread thread: spoolThreads) {
             thread.interrupt(); // interrupt any waiting accept() calls.
@@ -288,7 +283,7 @@
                 Thread.sleep(1000);
             } catch (Exception ignored) {}
         }
-        getLogger().info("JamesSpoolManager thread shutdown completed.");
+        logger.info("JamesSpoolManager thread shutdown completed.");
 
         ContainerUtil.dispose(processorList);
     }

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/LinearProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/LinearProcessor.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/LinearProcessor.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/LinearProcessor.java Fri Nov 20 14:51:20 2009
@@ -32,6 +32,7 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.SpoolRepository;
+import org.apache.james.util.ConfigurationAdapter;
 import org.apache.mailet.base.MatcherInverter;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.base.GenericMatcher;
@@ -625,7 +626,7 @@
                 throw new ConfigurationException("Unable to init matcher",c,ex);
             }
             try {
-                mailet = mailetLoader.getMailet(mailetClassName, c);
+                mailet = mailetLoader.getMailet(mailetClassName, new ConfigurationAdapter(c));
                 if (getLogger().isInfoEnabled()) {
                     StringBuffer infoBuffer =
                         new StringBuffer(64)
@@ -651,6 +652,9 @@
                 System.err.println("Unable to init mailet " + mailetClassName);
                 System.err.println("Check spool manager logs for more details.");
                 throw new ConfigurationException("Unable to init mailet",c,ex);
+            } catch (org.apache.commons.configuration.ConfigurationException e) {
+                throw new ConfigurationException("Unable to wrap config",e);
+
             }
             //Add this pair to the processor
             add(matcher, mailet);

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetConfigImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetConfigImpl.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetConfigImpl.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetConfigImpl.java Fri Nov 20 14:51:20 2009
@@ -21,8 +21,7 @@
 
 package org.apache.james.transport;
 
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.Configuration;
 import org.apache.mailet.MailetConfig;
 import org.apache.mailet.MailetContext;
 
@@ -68,24 +67,7 @@
      * @return the parameter value
      */
     public String getInitParameter(String name) {
-        try {
-            String result = null;
-
-            final Configuration[] values = configuration.getChildren( name );
-            for ( int i = 0; i < values.length; i++ ) {
-                if (result == null) {
-                    result = "";
-                } else {
-                    result += ",";
-                }
-                Configuration conf = values[i];
-                result += conf.getValue();
-            }
-            return result;
-        } catch (ConfigurationException ce) {
-            throw new RuntimeException("Embedded configuration exception was: " + ce.getMessage());
-        }
-
+        return configuration.getString(name);
     }
 
     /**
@@ -93,26 +75,9 @@
      *
      * @return an iterator over the set of configuration parameter names.
      */
+    @SuppressWarnings("unchecked")
     public Iterator<String> getInitParameterNames() {
-        return new Iterator<String> () {
-            Configuration[] children;
-            int count = 0;
-            {
-                children = configuration.getChildren();
-            }
-
-            public boolean hasNext() {
-                return count < children.length;
-            }
-
-            public String next() {
-                return children[count++].getName();
-            }
-
-            public void remove() {
-                throw new UnsupportedOperationException ("remove not supported");
-            }
-        };
+        return configuration.getKeys();
     }
 
     /**
@@ -123,7 +88,7 @@
      * @return the attribute value or null if missing
      */
     public String getInitAttribute(String name) {
-        return configuration.getAttribute(name, null);
+        return configuration.getString("[@" +name+ "]", null);
     }
 
     /**

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetContextWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetContextWrapper.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetContextWrapper.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetContextWrapper.java Fri Nov 20 14:51:20 2009
@@ -6,7 +6,7 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetContext;
@@ -19,7 +19,7 @@
     /** the mailetContext */
     private MailetContext mailetContext;
     /** the logger */
-    private Logger logger;
+    private Log logger;
 
     /**
      * Create a mailetContext wrapper that use a different logger for the log
@@ -28,7 +28,7 @@
      * @param mailetContext the mailet context to be wrapped
      * @param logger the logger to be used instead of the parent one. 
      */
-    public MailetContextWrapper(MailetContext mailetContext, Logger logger) {
+    public MailetContextWrapper(MailetContext mailetContext, Log logger) {
         this.mailetContext = mailetContext;
         this.logger = logger;
     }

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetLoader.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetLoader.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/MailetLoader.java Fri Nov 20 14:51:20 2009
@@ -21,7 +21,7 @@
 
 package org.apache.james.transport;
 
-import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.commons.configuration.Configuration;
 import org.apache.mailet.Mailet;
 
 import javax.mail.MessagingException;

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/StateAwareProcessorList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/StateAwareProcessorList.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/StateAwareProcessorList.java (original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/StateAwareProcessorList.java Fri Nov 20 14:51:20 2009
@@ -21,22 +21,25 @@
 
 package org.apache.james.transport;
 
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetException;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
 import javax.mail.MessagingException;
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,81 +48,82 @@
  *
  * @version CVS $Revision: 405882 $ $Date: 2006-05-12 23:30:04 +0200 (ven, 12 mag 2006) $
  */
-public class StateAwareProcessorList
-    extends AbstractLogEnabled
-    implements Serviceable, Configurable, Initializable, Disposable, MailProcessor, ProcessorList {
-
-    /**
-     * System component manager
-     */
-    private ServiceManager compMgr;
-
-    /**
-     * The configuration object used by this spool manager.
-     */
-    private Configuration conf;
+public class StateAwareProcessorList implements MailProcessor, ProcessorList {
 
     /**
      * The map of processor names to processors
      */
     private final Map<String, MailProcessor> processors;
+
+    private Log logger;
+
+    private HierarchicalConfiguration config;
     
     public StateAwareProcessorList() {
         super();
         this.processors = new HashMap<String, MailProcessor>();
     }
 
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
-     */
-    public void service(ServiceManager comp) throws ServiceException {
-        compMgr = comp;
+    
+    @Resource(name="org.apache.commons.logging.Log")
+    public final void setLogger(Log logger) {
+        this.logger = logger;
     }
-
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
-     */
-    public void configure(Configuration conf) throws ConfigurationException {
-        this.conf = conf;
+    
+    
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public final void setConfiguration(HierarchicalConfiguration config) {
+        this.config = config;
     }
+    
 
     /**
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
-    public void initialize() throws Exception {
-
-        final Configuration[] processorConfs = conf.getChildren( "processor" );
-        for ( int i = 0; i < processorConfs.length; i++ )
+    @SuppressWarnings("unchecked")
+    @PostConstruct
+    public void init() throws Exception {
+        final List<HierarchicalConfiguration> processorConfs = config.configurationsAt( "processor" );
+        for ( int i = 0; i < processorConfs.size(); i++ )
         {
-            Configuration processorConf = processorConfs[i];
-            String processorName = processorConf.getAttribute("name");
-            String processorClass = processorConf.getAttribute("class","org.apache.james.transport.LinearProcessor");
+            final HierarchicalConfiguration processorConf = processorConfs.get(i);
+            String processorName = processorConf.getString("[@name]");
+            String processorClass = processorConf.getString("[@class]","org.apache.james.transport.LinearProcessor");
 
             try {
-                MailProcessor processor = (MailProcessor) Thread.currentThread().getContextClassLoader().loadClass(processorClass).newInstance();
+                Class<MailProcessor> cObj = (Class<MailProcessor>) Thread.currentThread().getContextClassLoader().loadClass(processorClass);
+                MailProcessor processor = Guice.createInjector(new Jsr250Module(), new AbstractModule() {
+
+                    @Override
+                    protected void configure() {
+                        bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(processorConf);
+                        bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+                    }
+                    
+                }).getInstance(cObj);
                 processors.put(processorName, processor);
                 
-                setupLogger(processor, processorName);
-                ContainerUtil.service(processor, compMgr);
-                ContainerUtil.configure(processor, processorConf);
+                //setupLogger(processor, processorName);
+                //ContainerUtil.service(processor, compMgr);
+                //ContainerUtil.configure(processor, processorConf);
                 
-                if (getLogger().isInfoEnabled()) {
+                if (logger.isInfoEnabled()) {
                     StringBuffer infoBuffer =
                         new StringBuffer(64)
                                 .append("Processor ")
                                 .append(processorName)
                                 .append(" instantiated.");
-                    getLogger().info(infoBuffer.toString());
+                    logger.info(infoBuffer.toString());
                 }
             } catch (Exception ex) {
-                if (getLogger().isErrorEnabled()) {
+                if (logger.isErrorEnabled()) {
                     StringBuffer errorBuffer =
                        new StringBuffer(256)
                                .append("Unable to init processor ")
                                .append(processorName)
                                .append(": ")
                                .append(ex.toString());
-                    getLogger().error( errorBuffer.toString(), ex );
+                    logger.error( errorBuffer.toString(), ex );
                 }
                 throw ex;
             }
@@ -152,30 +156,30 @@
                             .append(" requested for processing of ")
                             .append(mail.getName());
                     String exceptionMessage = exceptionMessageBuffer.toString();
-                    getLogger().debug(exceptionMessage);
+                    logger.debug(exceptionMessage);
                     mail.setState(Mail.ERROR);
                     throw new MailetException(exceptionMessage);
                 }
                 StringBuffer logMessageBuffer = null;
-                if (getLogger().isDebugEnabled()) {
+                if (logger.isDebugEnabled()) {
                     logMessageBuffer =
                         new StringBuffer(64)
                                 .append("Processing ")
                                 .append(mail.getName())
                                 .append(" through ")
                                 .append(processorName);
-                    getLogger().debug(logMessageBuffer.toString());
+                    logger.debug(logMessageBuffer.toString());
                 }
                 processor.service(mail);
-                if (getLogger().isDebugEnabled()) {
+                if (logger.isDebugEnabled()) {
                     logMessageBuffer =
                         new StringBuffer(128)
                                 .append("Processed ")
                                 .append(mail.getName())
                                 .append(" through ")
                                 .append(processorName);
-                    getLogger().debug(logMessageBuffer.toString());
-                    getLogger().debug("Result was " + mail.getState());
+                    logger.debug(logMessageBuffer.toString());
+                    logger.debug("Result was " + mail.getState());
                 }
                 return;
             } catch (Throwable e) {
@@ -186,7 +190,7 @@
                             .append("Exception in processor <")
                             .append(processorName)
                             .append(">");
-                getLogger().error(exceptionBuffer.toString(), e);
+                logger.error(exceptionBuffer.toString(), e);
                 if (processorName.equals(Mail.ERROR)) {
                     // We got an error on the error processor...
                     // kill the message
@@ -201,15 +205,15 @@
                     mail.setErrorMessage(e.getMessage());
                 }
             }
-            if (getLogger().isErrorEnabled()) {
+            if (logger.isErrorEnabled()) {
                 StringBuffer logMessageBuffer =
                     new StringBuffer(128)
                             .append("An error occurred processing ")
                             .append(mail.getName())
                             .append(" through ")
                             .append(processorName);
-                getLogger().error(logMessageBuffer.toString());
-                getLogger().error("Result was " + mail.getState());
+                logger.error(logMessageBuffer.toString());
+                logger.error("Result was " + mail.getState());
             }
         }
     }
@@ -224,15 +228,15 @@
      *
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
+    @PreDestroy
     public void dispose() {
         Iterator<String> it = processors.keySet().iterator();
         while (it.hasNext()) {
             String processorName = it.next();
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Processor " + processorName);
+            if (logger.isDebugEnabled()) {
+                logger.debug("Processor " + processorName);
             }
             Object processor = processors.get(processorName);
-            ContainerUtil.dispose(processor);
             processors.remove(processor);
         }
     }

Modified: james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/JamesMailetLoaderTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/JamesMailetLoaderTest.java?rev=882589&r1=882588&r2=882589&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/JamesMailetLoaderTest.java (original)
+++ james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/JamesMailetLoaderTest.java Fri Nov 20 14:51:20 2009
@@ -23,30 +23,32 @@
 
 import junit.framework.TestCase;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.test.util.Util;
 import org.apache.james.transport.mailets.MailetLoaderTestMailet;
+import org.apache.james.util.ConfigurationAdapter;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.MailetConfig;
 
 import javax.mail.MessagingException;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 public class JamesMailetLoaderTest extends TestCase {
     private JamesMailetLoader m_jamesMailetLoader  = new JamesMailetLoader();
     private JamesMailetLoaderConfiguration m_conf = new JamesMailetLoaderConfiguration();
 
     private class JamesMailetLoaderConfiguration extends DefaultConfiguration {
-        private ArrayList m_packageNames = new ArrayList();
+        private List<String> m_packageNames = new ArrayList<String>();
         
         public JamesMailetLoaderConfiguration() {
             super("mailetpackages");
         }
 
         public void init() {
-            for (Iterator iterator = m_packageNames.iterator(); iterator.hasNext();) {
+            for (Iterator<String> iterator = m_packageNames.iterator(); iterator.hasNext();) {
                 String packageName = (String) iterator.next();
                 addChild(Util.getValuedConfiguration("mailetpackage", packageName));
             }
@@ -63,11 +65,12 @@
 
     }
 
-    private void setUpLoader() throws ConfigurationException {
+    private void setUpLoader() throws Exception {
         m_conf.init();
-        m_jamesMailetLoader.enableLogging(new MockLogger());
-        m_jamesMailetLoader.configure(m_conf);
+        m_jamesMailetLoader.setLogger(new SimpleLog("Test"));
+        m_jamesMailetLoader.setConfiguration(new ConfigurationAdapter(m_conf));
         m_jamesMailetLoader.setLoaderService(new FakeLoaderService());
+        m_jamesMailetLoader.init();
     }
 
     private void assetIsNullMailet(Mailet mailet) {
@@ -76,11 +79,11 @@
     }
 
 
-    public void testUsingEmtpyConfig() throws ConfigurationException {
+    public void testUsingEmtpyConfig() throws Exception {
         setUpLoader();
     }
 
-    public void testFullQualifiedUsingFakeConfig() throws ConfigurationException, MessagingException {
+    public void testFullQualifiedUsingFakeConfig() throws Exception {
         m_conf.add("none.existing.package"); // has to be here so the Loader won't choke
         setUpLoader();
 
@@ -88,7 +91,7 @@
         assetIsNullMailet(mailet);
     }
 
-    public void testStandardMailets() throws ConfigurationException, MessagingException {
+    public void testStandardMailets() throws Exception {
         m_conf.addStandardPackages();
         setUpLoader();
 
@@ -102,7 +105,7 @@
 
     }
 
-    public void testTestMailets() throws ConfigurationException, MessagingException {
+    public void testTestMailets() throws Exception {
         m_conf.addStandardPackages();
         setUpLoader();
 
@@ -114,8 +117,8 @@
 
     private void checkTestMailet(String mailetName) throws MessagingException {
         // use standard package
-        DefaultConfiguration configuration = new DefaultConfiguration("mailetLoaderTest");
-        configuration.addChild(Util.getValuedConfiguration("testMailetKey", "testMailetValue"));
+        DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();
+        configuration.addProperty("testMailetKey", "testMailetValue");
 
         Mailet mailet = m_jamesMailetLoader.getMailet(mailetName, configuration);
         assertTrue("MailetLoaderTestMailet mailet is expected class", mailet instanceof MailetLoaderTestMailet);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message