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 pg...@apache.org on 2002/08/14 04:11:01 UTC

cvs commit: jakarta-james/src/java/org/apache/james/userrepository AbstractJdbcUsersRepository.java

pgoldstein    2002/08/13 19:11:01

  Modified:    src/java/org/apache/james/mailrepository
                        JDBCMailRepository.java
               src/java/org/apache/james/nntpserver/repository
                        NNTPUtil.java
               src/java/org/apache/james/userrepository
                        AbstractJdbcUsersRepository.java
  Added:       src/java/org/apache/james/context
                        AvalonContextConstants.java
  Log:
  This patch is intended to reduce our coupling to Phoenix and allow
  James code to run in any Avalon framework container that honors
  the Avalon lifecycle contract.
  
  Revision  Changes    Path
  1.1                  jakarta-james/src/java/org/apache/james/context/AvalonContextConstants.java
  
  Index: AvalonContextConstants.java
  ===================================================================
  package org.apache.james.context;
  
  /**
   * This class is a placeholder for Avalon Context keys.
   *
   * In order to decouple James from Phoenix, and to allow James
   * to run in any Avalon Framework container it is necessary that
   * James not depend on the BlockContext class from Phoenix, but
   * rather only on the Context interface.  This requires that we
   * look up context values directly, using String keys.  This
   * class stores the String keys that are used by James to
   * look up context values.
   * 
   * The lifetime of this class is expected to be limited.  At some
   * point in the near future the Avalon folks will make a decision
   * about how exactly to define, describe, and publish context
   * values.  At that point we can replace this temporary mechanism
   * with the Avalon mechanism.  Unfortunately right now that decision
   * is still unmade, so we need to use this class as a temporary
   * solution.
   */
  public class AvalonContextConstants {
  
      /**
       * Private constructor to prevent instantiation or subclassing
       */
      private AvalonContextConstants() {}
  
      /**
       * The context key associated with the home directory of the application
       * being run.  The object returned on a 
       * context.get(AvalonContextConstants.APPLICATION_HOME) should be of
       * type <code>java.io.File</code> and should be the home directory
       * for the application (in our case, James)
       */
      public static final String APPLICATION_HOME = "app.home";
  }
  
  
  
  1.22      +19 -3     jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
  
  Index: JDBCMailRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- JDBCMailRepository.java	12 Aug 2002 07:41:36 -0000	1.21
  +++ JDBCMailRepository.java	14 Aug 2002 02:11:00 -0000	1.22
  @@ -24,7 +24,7 @@
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.phoenix.BlockContext;
  +import org.apache.james.context.AvalonContextConstants;
   import org.apache.james.core.MailImpl;
   import org.apache.james.core.MimeMessageWrapper;
   import org.apache.james.services.MailRepository;
  @@ -246,8 +246,24 @@
               // Initialise the sql strings.
               String fileName = sqlFileName.substring("file://".length());
               if (!(fileName.startsWith("/"))) {
  -                fileName = ((BlockContext)context).getBaseDirectory() +
  -                           File.separator + fileName;
  +                String baseDirectory = "";
  +                try {
  +                    File applicationHome =
  +                        (File)context.get(AvalonContextConstants.APPLICATION_HOME);
  +                    baseDirectory = applicationHome.toString();
  +                } catch (ContextException ce) {
  +                    getLogger().fatalError("Encountered exception when resolving application home in Avalon context.", ce);
  +                    throw ce;
  +                } catch (ClassCastException cce) {
  +                    getLogger().fatalError("Application home object stored in Avalon context was not of type java.io.File.", cce);
  +                    throw cce;
  +                }
  +                StringBuffer fileNameBuffer =
  +                    new StringBuffer(128)
  +                            .append(baseDirectory)
  +                            .append(File.separator)
  +                            .append(fileName);
  +                fileName = fileNameBuffer.toString();
               }
               File sqlFile = (new File(fileName)).getCanonicalFile();
   
  
  
  
  1.8       +17 -3     jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPUtil.java
  
  Index: NNTPUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPUtil.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NNTPUtil.java	7 Aug 2002 23:38:48 -0000	1.7
  +++ NNTPUtil.java	14 Aug 2002 02:11:00 -0000	1.8
  @@ -15,7 +15,7 @@
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.phoenix.BlockContext;
  +import org.apache.james.context.AvalonContextConstants;
   import org.apache.james.nntpserver.NNTPException;
   
   import java.io.File;
  @@ -47,8 +47,22 @@
           }
           fileName = fileName.substring(prefixLength);
           if (!(fileName.startsWith("/"))) {
  -            fileName = ((BlockContext)context).getBaseDirectory() +
  -                       File.separator + fileName;
  +            String baseDirectory = "";
  +            try {
  +                File applicationHome =
  +                    (File)context.get(AvalonContextConstants.APPLICATION_HOME);
  +                baseDirectory = applicationHome.toString();
  +            } catch (ContextException ce) {
  +                throw new ConfigurationException("Encountered exception when resolving application home in Avalon context.", ce);
  +            } catch (ClassCastException cce) {
  +                throw new ConfigurationException("Application home object stored in Avalon context was not of type java.io.File.", cce);
  +            }
  +            StringBuffer fileNameBuffer =
  +                new StringBuffer(128)
  +                        .append(baseDirectory)
  +                        .append(File.separator)
  +                        .append(fileName);
  +            fileName = fileNameBuffer.toString();
           }
           File f = new File(fileName);
           if ( f.exists() && f.isFile() )
  
  
  
  1.8       +19 -3     jakarta-james/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
  
  Index: AbstractJdbcUsersRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractJdbcUsersRepository.java	12 Aug 2002 07:41:36 -0000	1.7
  +++ AbstractJdbcUsersRepository.java	14 Aug 2002 02:11:01 -0000	1.8
  @@ -21,7 +21,7 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.phoenix.BlockContext;
  +import org.apache.james.context.AvalonContextConstants;
   import org.apache.james.services.User;
   import org.apache.james.util.JDBCUtil;
   import org.apache.james.util.SqlResources;
  @@ -232,8 +232,24 @@
               // Initialise the sql strings.
               String fileName = m_sqlFileName.substring("file://".length());
               if (!(fileName.startsWith("/"))) {
  -                fileName = ((BlockContext)context).getBaseDirectory() +
  -                           File.separator + fileName;
  +                String baseDirectory = "";
  +                try {
  +                    File applicationHome =
  +                        (File)context.get(AvalonContextConstants.APPLICATION_HOME);
  +                    baseDirectory = applicationHome.toString();
  +                } catch (ContextException ce) {
  +                    getLogger().fatalError("Encountered exception when resolving application home in Avalon context.", ce);
  +                    throw ce;
  +                } catch (ClassCastException cce) {
  +                    getLogger().fatalError("Application home object stored in Avalon context was not of type java.io.File.", cce);
  +                    throw cce;
  +                }
  +                StringBuffer fileNameBuffer =
  +                    new StringBuffer(128)
  +                            .append(baseDirectory)
  +                            .append(File.separator)
  +                            .append(fileName);
  +                fileName = fileNameBuffer.toString();
               }
               File sqlFile = (new File(fileName)).getCanonicalFile();
               
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>