You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/12/17 14:45:49 UTC

svn commit: r1050382 - in /james/server/trunk: container-spring/ container-spring/src/main/config/examples/ container-spring/src/main/config/james/ container-spring/src/main/config/james/context/ container-spring/src/main/java/org/apache/james/containe...

Author: norman
Date: Fri Dec 17 13:45:48 2010
New Revision: 1050382

URL: http://svn.apache.org/viewvc?rev=1050382&view=rev
Log:
move MailetLoader and MatcherLoader implementation to container-spring as this kind of stuff should get implemented by the container (class loading etc). Also adjust the two interface a bit to make the api cleaner..

Added:
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMailetLoader.java
      - copied, changed from r1049797, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailetLoader.java
    james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMatcherLoader.java
      - copied, changed from r1049797, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMatcherLoader.java
Removed:
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/AbstractLoader.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailetLoader.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMatcherLoader.java
    james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/JamesMailetLoaderTest.java
    james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/MailetLoaderTestMailet.java
    james/server/trunk/mailetcontainer-library/src/test/java/org/apache/james/mailetcontainer/lib/MockMailet.java
Modified:
    james/server/trunk/container-spring/pom.xml
    james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml
    james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
    james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml
    james/server/trunk/mailetcontainer-api/pom.xml
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetLoader.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherLoader.java
    james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java

Modified: james/server/trunk/container-spring/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/pom.xml?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/container-spring/pom.xml (original)
+++ james/server/trunk/container-spring/pom.xml Fri Dec 17 13:45:48 2010
@@ -410,11 +410,6 @@
       <artifactId>james-server-resolver-api</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.james</groupId>
-      <artifactId>james-server-core</artifactId>
-      <scope>runtime</scope>
-    </dependency>
-    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-core</artifactId>
     </dependency>
@@ -443,6 +438,32 @@
       <artifactId>commons-logging</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>james-server-mailetcontainer-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mailet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${javax.mail.groupId}</groupId>
+      <artifactId>${javax.mail.artifactId}</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james.protocols</groupId>
+      <artifactId>protocols-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>james-server-core</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
       <scope>runtime</scope>
@@ -631,11 +652,6 @@
       <artifactId>jackrabbit-core</artifactId>
       <scope>runtime</scope>
     </dependency>    
-       <dependency>
-      <groupId>javax.jcr</groupId>
-      <artifactId>jcr</artifactId>
-      <scope>compile</scope>
-    </dependency>
 
     <dependency>
       <groupId>org.apache.derby</groupId>
@@ -708,9 +724,6 @@
       <artifactId>jaxb-impl</artifactId>
       <scope>runtime</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.james.protocols</groupId>
-      <artifactId>protocols-api</artifactId>
-    </dependency>
+
   </dependencies>
 </project>

Modified: james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml (original)
+++ james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml Fri Dec 17 13:45:48 2010
@@ -25,23 +25,6 @@
       <!-- Number of spool threads -->
       <threads> 20 </threads>
 
-      <!-- Set the Java packages from which to load mailets -->
-      <mailetpackages>
-        <mailetpackage>org.apache.james.transport.mailets</mailetpackage>
-        <!-- Cryptography Mailets -->
-        <mailetpackage>org.apache.james.mailet.crypto.mailet</mailetpackage>
-        <!-- Sieve Mail Scripting -->
-        <mailetpackage>org.apache.james.imapserver.sieve</mailetpackage>      
-      </mailetpackages>
-
-      <!-- Set the Java packages from which to load matchers -->
-      <matcherpackages>
-        <matcherpackage>org.apache.james.transport.matchers</matcherpackage>
-        <!-- Crytographic matchers -->
-        <matcherpackage>org.apache.james.mailet.crypto.matchers</matcherpackage>
-        <!-- Composite matchers -->
-        <matcherpackage>org.apache.james.mailetcontainer.lib.matchers</matcherpackage>
-      </matcherpackages>
       
       <!-- The root processor is a required processor - James routes all mail on the spool -->
       <!-- through this processor first. -->

Modified: james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml (original)
+++ james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml Fri Dec 17 13:45:48 2010
@@ -47,8 +47,6 @@
             <map>
                 <entry key="mailProcessor" value="mailetcontainer"/>
                 <entry key="mailspooler" value="mailetcontainer"/>
-                <entry key="mailetloader" value="mailetcontainer"/>
-                <entry key="matcherloader" value="mailetcontainer"/>
                 <entry key="mailetcontext" value="mailetcontainer"/>
              </map>
         </property>
@@ -65,9 +63,8 @@
         <property name="logMappings">
             <map>
                 <entry key="mailProcessor" value="mailetcontainer"/>
-                <entry key="mailspooler" value="mailetcontainer"/>
-                <entry key="mailetloader" value="mailetcontainer"/>
                 <entry key="matcherloader" value="mailetcontainer"/>
+                <entry key="mailetcontext" value="mailetcontainer"/>
             </map>
         </property>
     </bean>
@@ -137,8 +134,8 @@
     <bean id="mailProcessor" name="processorRoute" class="org.apache.james.mailetcontainer.camel.CamelMailProcessorList"/>
     <bean id="mailspooler" class="org.apache.james.mailetcontainer.lib.JamesMailSpooler"/>
     <bean id="mailetcontext" class="org.apache.james.mailetcontainer.lib.JamesMailetContext"/>
-    <bean id="mailetloader" class="org.apache.james.mailetcontainer.lib.JamesMailetLoader" />
-    <bean id="matcherloader" class="org.apache.james.mailetcontainer.lib.JamesMatcherLoader" />
+    <bean id="mailetloader" class="org.apache.james.container.spring.mailetcontainer.JamesMailetLoader" />
+    <bean id="matcherloader" class="org.apache.james.container.spring.mailetcontainer.JamesMatcherLoader" />
 
     <!-- 
       DNS Service

Modified: james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml (original)
+++ james/server/trunk/container-spring/src/main/config/james/mailetcontainer.xml Fri Dec 17 13:45:48 2010
@@ -25,18 +25,6 @@
     
     <threads> 20 </threads>
 
-    <mailetpackages>
-      <mailetpackage>org.apache.james.transport.mailets</mailetpackage>
-      <mailetpackage>org.apache.james.mailet.crypto.mailet</mailetpackage>
-      <mailetpackage>org.apache.james.imapserver.sieve</mailetpackage>      
-    </mailetpackages>
-
-    <matcherpackages>
-      <matcherpackage>org.apache.james.transport.matchers</matcherpackage>
-      <matcherpackage>org.apache.james.mailet.crypto.matchers</matcherpackage>
-      <matcherpackage>org.apache.james.mailetcontainer.lib.matchers</matcherpackage>
-    </matcherpackages>
-
     <processor name="root">
        <mailet match="All" class="PostmasterAlias"/>
        <mailet match="RelayLimit=30" class="Null"/>

Copied: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMailetLoader.java (from r1049797, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailetLoader.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMailetLoader.java?p2=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMailetLoader.java&p1=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailetLoader.java&r1=1049797&r2=1050382&rev=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailetLoader.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMailetLoader.java Fri Dec 17 13:45:48 2010
@@ -18,69 +18,80 @@
  ****************************************************************/
 
 
-package org.apache.james.mailetcontainer.lib;
+package org.apache.james.container.spring.mailetcontainer;
 import javax.mail.MessagingException;
 
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.mailetcontainer.api.MailetLoader;
 import org.apache.mailet.Mailet;
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.MailetException;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 /**
- * Loads Mailets for use inside James.
+ * Loads Mailets for use inside James by using the {@link ConfigurableListableBeanFactory} of spring.
+ * 
+ * The Mailets are not registered in the factory after loading them!
  *
  */
-public class JamesMailetLoader extends AbstractLoader implements MailetLoader {
+public class BeanFactoryMailetLoader implements MailetLoader, BeanFactoryAware {
     
-    private static final String DISPLAY_NAME = "mailet";
+    private ConfigurableListableBeanFactory beanFactory;
     
-    private final String MAILET_PACKAGE = "mailetpackage";
 
-    
     /*
      * (non-Javadoc)
-     * @see org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+     * @see org.apache.james.mailetcontainer.api.MailetLoader#getMailet(org.apache.mailet.MailetConfig)
      */
-    public void configure(HierarchicalConfiguration conf) throws ConfigurationException {
-        getPackages(conf.configurationAt("mailetpackages"),MAILET_PACKAGE);
-    }
+    @SuppressWarnings("unchecked")
+    public Mailet getMailet(final MailetConfig config) throws MessagingException {
+        String mailetName = config.getMailetName();
 
-    /**
-     * (non-Javadoc)
-     * @see org.apache.james.mailetcontainer.api.MailetLoader#getMailet(java.lang.String, org.apache.commons.configuration.Configuration)
-     */
-    public Mailet getMailet(final String mailetName, final Configuration configuration) throws MessagingException {
         try {
-            for (final String packageName:packages) {
-                final String className = packageName + mailetName;
-                try {
-                    final Mailet mailet = (Mailet)factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(className));
-                    
-                    final MailetConfigImpl configImpl = new MailetConfigImpl();
-                    configImpl.setMailetName(mailetName);
-                    configImpl.setConfiguration(configuration);
-                    configImpl.setMailetContext(mailetContext);
-                    mailet.init(configImpl);
-                    
-                    return mailet;
-                } catch (ClassNotFoundException cnfe) {
-                    //do this so we loop through all the packages
-                }
+            String fullName;
+            if (mailetName.indexOf(".") < 1) {
+                fullName = "org.apache.james.transport.mailets." + mailetName;
+            } else {
+                fullName = mailetName;
             }
-            throw classNotFound(mailetName);
+            
+            // Use the classloader which is used for bean instance stuff
+            Class clazz = beanFactory.getBeanClassLoader().loadClass(fullName);
+            final Mailet mailet = (Mailet) beanFactory.createBean(clazz);
+
+            // init the mailet
+            mailet.init(config);
+
+            
+            return mailet;
+            
         } catch (MessagingException me) {
             throw me;
         } catch (Exception e) {
-            e.printStackTrace();
             throw loadFailed(mailetName, e);
         }
     }
 
     /**
-     * @see AbstractLoader#getDisplayName()
+     * Constructs an appropriate exception with an appropriate message.
+     * @param name not null
+     * @param e not null
+     * @return not null
+     */
+    protected MailetException loadFailed(String name, Exception e) {
+        final StringBuilder builder =
+            new StringBuilder(128).append("Could not load ").append("mailet")
+                .append(" (").append(name).append(")");
+        final MailetException mailetException = new MailetException(builder.toString(), e);
+        return mailetException;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
      */
-    @Override
-    protected String getDisplayName() {
-        return DISPLAY_NAME;
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
     }
 }

Copied: james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMatcherLoader.java (from r1049797, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMatcherLoader.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMatcherLoader.java?p2=james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMatcherLoader.java&p1=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMatcherLoader.java&r1=1049797&r2=1050382&rev=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMatcherLoader.java (original)
+++ james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/mailetcontainer/BeanFactoryMatcherLoader.java Fri Dec 17 13:45:48 2010
@@ -19,71 +19,81 @@
 
 
 
-package org.apache.james.mailetcontainer.lib;
+package org.apache.james.container.spring.mailetcontainer;
 import javax.mail.MessagingException;
 
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.mailetcontainer.api.MatcherLoader;
+import org.apache.mailet.MailetException;
 import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
 /**
- * Loads Matchers for use inside James.
+ * Loads Matchers for use inside James using the {@link ConfigurableListableBeanFactory} of spring.
+ * 
+ * The Matchers are not registered in the factory after loading them!
  *
  */
-public class JamesMatcherLoader extends AbstractLoader implements MatcherLoader {
-    private static final String DISPLAY_NAME = "matcher";
-    private final String MATCHER_PACKAGE = "matcherpackage";
+public class BeanFactoryMatcherLoader implements MatcherLoader, BeanFactoryAware {
+
+    
+    private ConfigurableListableBeanFactory beanFactory;
 
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+     * @see org.apache.james.mailetcontainer.api.MatcherLoader#getMatcher(org.apache.mailet.MatcherConfig)
      */
-    public void configure(HierarchicalConfiguration conf) throws ConfigurationException {
-           getPackages(conf.configurationAt("matcherpackages"),MATCHER_PACKAGE);
-    }
-
-    /**
-     * @see org.apache.james.mailetcontainer.api.MatcherLoader#getMatcher(java.lang.String)
-    */
-    public Matcher getMatcher(String matchName) throws MessagingException {
+    @SuppressWarnings("unchecked")
+    public Matcher getMatcher(MatcherConfig config) throws MessagingException {
+        String matchName = config.getMatcherName();
         try {
-            String condition = (String) null;
-            int i = matchName.indexOf('=');
-            if (i != -1) {
-                condition = matchName.substring(i + 1);
-                matchName = matchName.substring(0, i);
-            }
-            for (final String packageName: packages) {
-                final String className = packageName + matchName;
-                try {
-                    final Matcher matcher = (Matcher) factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(className));
-                    
-                    final MatcherConfigImpl configImpl = new MatcherConfigImpl();
-                    configImpl.setMatcherName(matchName);
-                    configImpl.setCondition(condition);
-                    configImpl.setMailetContext(mailetContext);
-
-                    matcher.init(configImpl);
-                    
-                    return matcher;
-                } catch (ClassNotFoundException cnfe) {
-                    //do this so we loop through all the packages
-                }
+            
+            String fullName;
+            if (matchName.indexOf(".") < 1) {
+                fullName = "org.apache.james.transport.matchers." + matchName;
+            } else {
+                fullName = matchName;
             }
-            throw classNotFound(matchName);
+            // Use the classloader which is used for bean instance stuff
+            Class clazz = beanFactory.getBeanClassLoader().loadClass(fullName);
+            final Matcher matcher = (Matcher) beanFactory.createBean(clazz);
+
+            // init the matcher
+            matcher.init(config);
+            
+            return matcher;
         } catch (MessagingException me) {
             throw me;
         } catch (Exception e) {
             throw loadFailed(matchName, e);
         }
     }
+    
 
     /**
-     * @see AbstractLoader#getDisplayName()
+     * Constructs an appropriate exception with an appropriate message.
+     * @param name not null
+     * @param e not null
+     * @return not null
      */
-    @Override
-    protected String getDisplayName() {
-        return DISPLAY_NAME;
+    protected MailetException loadFailed(String name, Exception e) {
+        final StringBuilder builder =
+            new StringBuilder(128).append("Could not load ").append("mailet")
+                .append(" (").append(name).append(")");
+        final MailetException mailetException = new MailetException(builder.toString(), e);
+        return mailetException;
     }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory =  (ConfigurableListableBeanFactory) beanFactory;
+    }
+
 }

Modified: james/server/trunk/mailetcontainer-api/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/pom.xml?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/pom.xml (original)
+++ james/server/trunk/mailetcontainer-api/pom.xml Fri Dec 17 13:45:48 2010
@@ -67,10 +67,6 @@
       <artifactId>apache-mailet</artifactId>
     </dependency>
     <dependency>
-      <groupId>commons-configuration</groupId>
-      <artifactId>commons-configuration</artifactId>
-    </dependency> 
-    <dependency>
       <groupId>${javax.mail.groupId}</groupId>
       <artifactId>${javax.mail.artifactId}</artifactId>
     </dependency>

Modified: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetLoader.java?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetLoader.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetLoader.java Fri Dec 17 13:45:48 2010
@@ -21,23 +21,26 @@
 
 package org.apache.james.mailetcontainer.api;
 
-import org.apache.commons.configuration.Configuration;
 import org.apache.mailet.Mailet;
+import org.apache.mailet.MailetConfig;
 
 import javax.mail.MessagingException;
 
+/**
+ * Implementations of this interface are responsible to create {@link Mailet} instances
+ * 
+ *
+ */
 public interface MailetLoader {
     
     /**
-     * Get a new Mailet with the specified name acting
-     * in the specified context.
+     * Get a new {@link Mailet} instance for the given {@link MailetConfig}. The returned {@link Mailet} needs to
+     * be fully initialized, so the returned instance is "read-to-use"
      *
-     * @param mailetName the name of the mailet to be loaded
-     * @param configuration the Configuration to be passed to the new
-     *                mailet
+     * @param config
      * @throws MessagingException if an error occurs
      */
-    public Mailet getMailet(String mailetName, Configuration configuration)
+    public Mailet getMailet(MailetConfig config)
             throws MessagingException;
 
 }

Modified: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherLoader.java?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherLoader.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherLoader.java Fri Dec 17 13:45:48 2010
@@ -22,18 +22,24 @@
 package org.apache.james.mailetcontainer.api;
 
 import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
 
 import javax.mail.MessagingException;
 
+/**
+ * Implementations of this interface are responsible for loading {@link Matcher} instances
+ * 
+ *
+ */
 public interface MatcherLoader {
 
     /**
-     * Get a new Matcher with the specified name acting
-     * in the specified context.
+     * Get a new {@link Matcher} for the given {@link MatcherConfig}. The returned {@link Matcher} needs to
+     * be fully initialized, so the returned instance is "read-to-use"
      *
-     * @param matchName the name of the matcher to be loaded
+     * @param config
      * @throws MessagingException if an error occurs
      */
-    public Matcher getMatcher(String matchName) throws MessagingException;
+    public Matcher getMatcher(MatcherConfig config) throws MessagingException;
 
 }

Modified: james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java?rev=1050382&r1=1050381&r2=1050382&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java Fri Dec 17 13:45:48 2010
@@ -53,13 +53,16 @@ import org.apache.james.mailetcontainer.
 import org.apache.james.mailetcontainer.api.ProcessorManagementMBean;
 import org.apache.james.mailetcontainer.lib.MailetConfigImpl;
 import org.apache.james.mailetcontainer.lib.MailetManagement;
+import org.apache.james.mailetcontainer.lib.MatcherConfigImpl;
 import org.apache.james.mailetcontainer.lib.MatcherManagement;
 import org.apache.james.mailetcontainer.lib.ProcessorDetail;
 import org.apache.james.mailetcontainer.lib.matchers.CompositeMatcher;
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.MailetConfig;
+import org.apache.mailet.MailetContext;
 import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.base.MatcherInverter;
 
@@ -84,6 +87,7 @@ public class CamelMailProcessorList impl
     
     private final Map<String,MailProcessor> processors = new HashMap<String,MailProcessor>();
     private final UseLatestAggregationStrategy aggr = new UseLatestAggregationStrategy();
+    private MailetContext mailetContext;
        
     @Resource(name = "matcherloader")
     public void setMatcherLoader(MatcherLoader matcherLoader) {
@@ -94,6 +98,11 @@ public class CamelMailProcessorList impl
     public void setMailetLoader(MailetLoader mailetLoader) {
         this.mailetLoader = mailetLoader;
     }
+    
+    @Resource(name= "mailetcontext")
+    public void setMailetContext(MailetContext mailetContext) {
+        this.mailetContext = mailetContext;
+    }
 
     private ProducerTemplate producerTemplate;
 	private CamelContext camelContext;
@@ -383,20 +392,20 @@ public class CamelMailProcessorList impl
                             matcher = compositeMatchers.get(matcherName);
                             if (matcher == null) {
                                 // no composite Matcher found, try to load it via MatcherLoader
-                                matcher = matcherLoader.getMatcher(matcherName);
+                                matcher = matcherLoader.getMatcher(createMatcherConfig(matcherName));
                             }
                         } else if (invertedMatcherName != null) {
                             // try to load from compositeMatchers first
                             matcher = compositeMatchers.get(matcherName);
                             if (matcher == null) {
                                 // no composite Matcher found, try to load it via MatcherLoader
-                                matcher = matcherLoader.getMatcher(invertedMatcherName);
+                                matcher = matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName));
                             }
                             matcher = new MatcherInverter(matcher);
 
                         } else {
                             // default matcher is All
-                            matcher = matcherLoader.getMatcher("All");
+                            matcher = matcherLoader.getMatcher(createMatcherConfig("All"));
                         }
 
                         // The matcher itself should log that it's been inited.
@@ -419,7 +428,7 @@ public class CamelMailProcessorList impl
                         throw new ConfigurationException("Unable to init matcher", ex);
                     }
                     try {
-                        mailet = mailetLoader.getMailet(mailetClassName, c);
+                        mailet = mailetLoader.getMailet(createMailetConfig(mailetClassName, c));
                         if (logger.isInfoEnabled()) {
                             StringBuffer infoBuffer = new StringBuffer(64).append("Mailet ").append(mailetClassName).append(" instantiated.");
                             logger.info(infoBuffer.toString());
@@ -504,7 +513,33 @@ public class CamelMailProcessorList impl
             checkProcessors();
   
         }
-        
+       
+    }
+    
+    
+    private MailetConfig createMailetConfig(String mailetName, HierarchicalConfiguration configuration) {
+
+        final MailetConfigImpl configImpl = new MailetConfigImpl();
+        configImpl.setMailetName(mailetName);
+        configImpl.setConfiguration(configuration);
+        configImpl.setMailetContext(mailetContext);
+        return configImpl;
+    }
+    
+    private MatcherConfig createMatcherConfig(String matchName) {
+
+        String condition = (String) null;
+        int i = matchName.indexOf('=');
+        if (i != -1) {
+            condition = matchName.substring(i + 1);
+            matchName = matchName.substring(0, i);
+        }
+        final MatcherConfigImpl configImpl = new MatcherConfigImpl();
+        configImpl.setMatcherName(matchName);
+        configImpl.setCondition(condition);
+        configImpl.setMailetContext(mailetContext);
+        return configImpl;
+
     }
     
     /**
@@ -562,7 +597,7 @@ public class CamelMailProcessorList impl
                 // if no matcher is configured throw an Exception
                 throw new ConfigurationException("Please configure only match or nomatch per mailet");
             } else if (matcherName != null) {
-                matcher = matcherLoader.getMatcher(matcherName);
+                matcher = matcherLoader.getMatcher(createMatcherConfig(matcherName));
                 if (matcher instanceof CompositeMatcher) {
                     CompositeMatcher compMatcher = (CompositeMatcher) matcher;
                     
@@ -572,7 +607,7 @@ public class CamelMailProcessorList impl
                     }
                 }
             } else if (invertedMatcherName != null) {
-                Matcher m = matcherLoader.getMatcher(invertedMatcherName);
+                Matcher m = matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName));
                 if (m instanceof CompositeMatcher) {
                     CompositeMatcher compMatcher = (CompositeMatcher) m;
                     



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