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 2003/06/02 07:37:27 UTC

cvs commit: jakarta-james/src/java/org/apache/james/transport Loader.java JamesSpoolManager.java MailetLoader.java MatchLoader.java

noel        2003/06/01 22:37:27

  Modified:    src/java/org/apache/james/transport Tag: branch_2_1_fcs
                        JamesSpoolManager.java MailetLoader.java
                        MatchLoader.java
  Added:       src/java/org/apache/james/transport Tag: branch_2_1_fcs
                        Loader.java
  Log:
  Backported Danny's class loading enhancements from HEAD.  Custom Mailet classes can go into SAR-INF/classes; JAR files into SAR-INF/lib
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.20.4.5  +16 -5     jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java
  
  Index: JamesSpoolManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/JamesSpoolManager.java,v
  retrieving revision 1.20.4.4
  retrieving revision 1.20.4.5
  diff -u -r1.20.4.4 -r1.20.4.5
  --- JamesSpoolManager.java	8 Mar 2003 21:54:07 -0000	1.20.4.4
  +++ JamesSpoolManager.java	2 Jun 2003 05:37:27 -0000	1.20.4.5
  @@ -71,6 +71,8 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.james.core.MailImpl;
   import org.apache.james.services.MailStore;
   import org.apache.james.services.SpoolRepository;
  @@ -86,16 +88,14 @@
    * processor, and removing them from the spool when processing is
    * complete.
    *
  - * @author Serge Knystautas <se...@lokitech.com>
  - * @author Federico Barbieri <sc...@systemy.it>
  - *
    * @version This is $Revision$
    */
   public class JamesSpoolManager
       extends AbstractLogEnabled
       implements Composable, Configurable, Initializable,
  -               Runnable, Disposable, Component {
  +               Runnable, Disposable, Component, Contextualizable {
   
  +    private Context context;
       /**
        * Whether 'deep debugging' is turned on.
        */
  @@ -179,6 +179,10 @@
           MailetLoader mailetLoader = new MailetLoader();
           MatchLoader matchLoader = new MatchLoader();
           try {
  +            mailetLoader.setLogger(getLogger());
  +            matchLoader.setLogger(getLogger());
  +            mailetLoader.contextualize(context);
  +            matchLoader.contextualize(context);
               mailetLoader.configure(conf.getChild("mailetpackages"));
               matchLoader.configure(conf.getChild("matcherpackages"));
               compMgr.put(Resources.MAILET_LOADER, mailetLoader);
  @@ -500,5 +504,12 @@
               processor.dispose();
               processors.remove(processor);
           }
  +    }
  +
  +    /**
  +     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context)
  +     */
  +    public void contextualize(Context context) {
  +        this.context = context;
       }
   }
  
  
  
  1.7.4.3   +14 -45    jakarta-james/src/java/org/apache/james/transport/MailetLoader.java
  
  Index: MailetLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/MailetLoader.java,v
  retrieving revision 1.7.4.2
  retrieving revision 1.7.4.3
  diff -u -r1.7.4.2 -r1.7.4.3
  --- MailetLoader.java	8 Mar 2003 21:54:07 -0000	1.7.4.2
  +++ MailetLoader.java	2 Jun 2003 05:37:27 -0000	1.7.4.3
  @@ -57,8 +57,8 @@
    */
   
   package org.apache.james.transport;
  +import javax.mail.MessagingException;
   
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -66,41 +66,18 @@
   import org.apache.mailet.Mailet;
   import org.apache.mailet.MailetContext;
   import org.apache.mailet.MailetException;
  -
  -import javax.mail.MessagingException;
  -import java.util.Vector;
  -
   /**
    * Loads Mailets for use inside James.
    *
  - * @author Serge Knystautas <se...@lokitech.com>
  - * @author Federico Barbieri <sc...@systemy.it>
    */
  -public class MailetLoader implements Component, Configurable {
  -
  -    /**
  -     * The list of packages that may contain Mailets
  -     */
  -    private Vector mailetPackages;
  -
  -    /**
  +public class MailetLoader extends Loader implements Configurable {
  +           /**
        * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
        */
       public void configure(Configuration conf) throws ConfigurationException {
  -        mailetPackages = new Vector();
  -        mailetPackages.addElement("");
  -        final Configuration[] pkgConfs = conf.getChildren( "mailetpackage" );
  -        for ( int i = 0; i < pkgConfs.length; i++ )
  -        {
  -            Configuration c = pkgConfs[i];
  -            String packageName = c.getValue();
  -            if (!packageName.endsWith(".")) {
  -                packageName += ".";
  -            }
  -            mailetPackages.addElement(packageName);
  -        }
  +           getPackages(conf,MAILET_PACKAGE);
  +           configureMailetClassLoader();
       }
  -
       /**
        * Get a new Mailet with the specified name acting
        * in the specified context.
  @@ -113,20 +90,14 @@
       public Mailet getMailet(String mailetName, MailetContext context, Configuration configuration)
           throws MessagingException {
           try {
  -            for (int i = 0; i < mailetPackages.size(); i++) {
  -                String className = (String)mailetPackages.elementAt(i) + mailetName;
  -                ClassLoader theClassLoader = null;
  +            for (int i = 0; i < packages.size(); i++) {
  +                String className = (String) packages.elementAt(i) + mailetName;
                   try {
                       MailetConfigImpl configImpl = new MailetConfigImpl();
                       configImpl.setMailetName(mailetName);
                       configImpl.setConfiguration(configuration);
                       configImpl.setMailetContext(context);
  -
  -                    if (theClassLoader == null) {
  -                        theClassLoader = this.getClass().getClassLoader();
  -                    }
  -
  -                    Mailet mailet = (Mailet) theClassLoader.loadClass(className).newInstance();
  +                    Mailet mailet = (Mailet) mailetClassLoader.loadClass(className).newInstance();
                       mailet.init(configImpl);
                       return mailet;
                   } catch (ClassNotFoundException cnfe) {
  @@ -135,19 +106,17 @@
               }
               StringBuffer exceptionBuffer =
                   new StringBuffer(128)
  -                        .append("Requested mailet not found: ")
  -                        .append(mailetName)
  -                        .append(".  looked in ")
  -                        .append(mailetPackages.toString());
  +                    .append("Requested mailet not found: ")
  +                    .append(mailetName)
  +                    .append(".  looked in ")
  +                    .append(packages.toString());
               throw new ClassNotFoundException(exceptionBuffer.toString());
           } catch (MessagingException me) {
               throw me;
           } catch (Exception e) {
               StringBuffer exceptionBuffer =
  -                new StringBuffer(128)
  -                        .append("Could not load mailet (")
  -                        .append(mailetName)
  -                        .append(")");
  +                new StringBuffer(128).append("Could not load mailet (").append(mailetName).append(
  +                    ")");
               throw new MailetException(exceptionBuffer.toString(), e);
           }
       }
  
  
  
  1.8.4.3   +16 -46    jakarta-james/src/java/org/apache/james/transport/MatchLoader.java
  
  Index: MatchLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/MatchLoader.java,v
  retrieving revision 1.8.4.2
  retrieving revision 1.8.4.3
  diff -u -r1.8.4.2 -r1.8.4.3
  --- MatchLoader.java	8 Mar 2003 21:54:07 -0000	1.8.4.2
  +++ MatchLoader.java	2 Jun 2003 05:37:27 -0000	1.8.4.3
  @@ -57,8 +57,8 @@
    */
   
   package org.apache.james.transport;
  +import javax.mail.MessagingException;
   
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -66,41 +66,20 @@
   import org.apache.mailet.MailetContext;
   import org.apache.mailet.MailetException;
   import org.apache.mailet.Matcher;
  -
  -import javax.mail.MessagingException;
  -import java.util.Vector;
  -
   /**
    * Loads Matchers for use inside James.
    *
  - * @author Serge Knystautas <se...@lokitech.com>
  - * @author Federico Barbieri <sc...@systemy.it>
    */
  -public class MatchLoader implements Component, Configurable {
  -
  -    /**
  -     * The list of packages that may contain Mailets
  -     */
  -    private Vector matcherPackages;
  -
  -    /**
  +public class MatchLoader extends Loader implements Configurable {
  +        /**
        * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
        */
       public void configure(Configuration conf) throws ConfigurationException {
  -        matcherPackages = new Vector();
  -        matcherPackages.addElement("");
  -        final Configuration[] pkgConfs = conf.getChildren( "matcherpackage" );
  -        for ( int i = 0; i < pkgConfs.length; i++ )
  -        {
  -            Configuration c = pkgConfs[i];
  -            String packageName = c.getValue();
  -            if (!packageName.endsWith(".")) {
  -                packageName += ".";
  -            }
  -            matcherPackages.addElement(packageName);
  -        }
  +           getPackages(conf,MATCHER_PACKAGE);
  +           configureMailetClassLoader();
       }
   
  +
       /**
        * Get a new Matcher with the specified name acting
        * in the specified context.
  @@ -110,8 +89,7 @@
        *                matcher
        * @throws MessagingException if an error occurs
        */
  -    public Matcher getMatcher(String matchName, MailetContext context)
  -        throws MessagingException {
  +    public Matcher getMatcher(String matchName, MailetContext context) throws MessagingException {
           try {
               String condition = (String) null;
               int i = matchName.indexOf('=');
  @@ -119,20 +97,14 @@
                   condition = matchName.substring(i + 1);
                   matchName = matchName.substring(0, i);
               }
  -            ClassLoader theClassLoader = null;
  -            for (i = 0; i < matcherPackages.size(); i++) {
  -                String className = (String)matcherPackages.elementAt(i) + matchName;
  +            for (i = 0; i < packages.size(); i++) {
  +                String className = (String) packages.elementAt(i) + matchName;
                   try {
                       MatcherConfigImpl configImpl = new MatcherConfigImpl();
                       configImpl.setMatcherName(matchName);
                       configImpl.setCondition(condition);
                       configImpl.setMailetContext(context);
  -
  -                    if (theClassLoader == null) {
  -                        theClassLoader = this.getClass().getClassLoader();
  -                    }
  -
  -                    Matcher matcher = (Matcher) theClassLoader.loadClass(className).newInstance();
  +                    Matcher matcher = (Matcher) mailetClassLoader.loadClass(className).newInstance();
                       matcher.init(configImpl);
                       return matcher;
                   } catch (ClassNotFoundException cnfe) {
  @@ -141,19 +113,17 @@
               }
               StringBuffer exceptionBuffer =
                   new StringBuffer(128)
  -                        .append("Requested matcher not found: ")
  -                        .append(matchName)
  -                        .append(".  looked in ")
  -                        .append(matcherPackages.toString());
  +                    .append("Requested matcher not found: ")
  +                    .append(matchName)
  +                    .append(".  looked in ")
  +                    .append(packages.toString());
               throw new ClassNotFoundException(exceptionBuffer.toString());
           } catch (MessagingException me) {
               throw me;
           } catch (Exception e) {
               StringBuffer exceptionBuffer =
  -                new StringBuffer(128)
  -                        .append("Could not load matcher (")
  -                        .append(matchName)
  -                        .append(")");
  +                new StringBuffer(128).append("Could not load matcher (").append(matchName).append(
  +                    ")");
               throw new MailetException(exceptionBuffer.toString(), e);
           }
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.1   +3 -2      jakarta-james/src/java/org/apache/james/transport/Loader.java
  
  Index: Loader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/transport/Loader.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- Loader.java	28 Apr 2003 13:02:31 -0000	1.8
  +++ Loader.java	2 Jun 2003 05:37:27 -0000	1.8.2.1
  @@ -69,12 +69,13 @@
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.component.Component;
   
   /**
    *
    * $Id$
    */
  -public class Loader implements Contextualizable {
  +public class Loader implements Contextualizable, Component {
       protected ClassLoader mailetClassLoader = null;
       protected String baseDirectory = null;
       protected Logger logger;
  
  
  

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