james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/core AvalonMailStore.java AvalonMailStore.xinfo AvalonUsersStore.xinfo
Date Tue, 11 Sep 2001 04:32:44 GMT
serge       01/09/10 21:32:44

  Modified:    src/java/org/apache/james/core AvalonMailStore.java
                        AvalonMailStore.xinfo AvalonUsersStore.xinfo
  Log:
  Adding code from userstore branch.
  
  Revision  Changes    Path
  1.6       +68 -5     jakarta-james/src/java/org/apache/james/core/AvalonMailStore.java
  
  Index: AvalonMailStore.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/core/AvalonMailStore.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AvalonMailStore.java	2001/08/16 13:53:16	1.5
  +++ AvalonMailStore.java	2001/09/11 04:32:44	1.6
  @@ -19,6 +19,7 @@
   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.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.logger.Loggable;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.james.services.MailRepository;
  @@ -28,12 +29,12 @@
   import org.apache.avalon.phoenix.Block;
   
   /**
  - *
  - * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
  - *
    * Provides Registry of mail repositories. A mail repository is uniquely
  - * identified 
  + * identified
    * by destinationURL, type and model.
  + * 
  + * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
  + * @author Darrell DeBoer <dd@bigdaz.com>
    */
   public class AvalonMailStore
       extends AbstractLoggable
  @@ -46,6 +47,10 @@
   
       // map of [protocol(destinationURL) + type ]->classname of repository;
       private HashMap classes;
  +
  +    // map of [Repository Class]->default config for repository.
  +    private HashMap defaultConfigs;
  +
       protected Configuration          configuration;
       protected ComponentManager       componentManager;
   
  @@ -69,6 +74,7 @@
           getLogger().info("JamesMailStore init...");
           repositories = new HashMap();
           classes = new HashMap();
  +        defaultConfigs = new HashMap();
           Configuration[] registeredClasses
               = configuration.getChild("repositories").getChildren("repository");
           for ( int i = 0; i < registeredClasses.length; i++ )
  @@ -109,6 +115,12 @@
                   getLogger().info("Registered class: " + key+"->"+className);
               }
           }
  +
  +        // Get the default configuration for this Repository class.
  +        Configuration defConf = repConf.getChild("config");
  +        if ( defConf != null ) {
  +            defaultConfigs.put(className, defConf);
  +        }
       }
   
       public void release(Component component)
  @@ -155,6 +167,22 @@
                   getLogger().debug( "Need instance of " + repClass +
                                      " to handle: " + protocol + "," + type  );
   
  +                // If default values have been set, create a new repository 
  +                // configuration element using the default values 
  +                // and the values in the selector.
  +                // If no default values, just use the selector.
  +                Configuration config;
  +                Configuration defConf = (Configuration)defaultConfigs.get(repClass);
  +                if ( defConf == null) {
  +                    config = repConf;
  +                }
  +                else {
  +                    config = new DefaultConfiguration(repConf.getName(), 
  +                                                      repConf.getLocation());
  +                    copyConfig(defConf, (DefaultConfiguration)config);
  +                    copyConfig(repConf, (DefaultConfiguration)config);
  +                }
  + 
                   try {
                       reply
                       = (MailRepository) Class.forName(repClass).newInstance();
  @@ -162,7 +190,7 @@
   		       setupLogger(reply);
                       }
                       if (reply instanceof Configurable) {
  -                        ((Configurable) reply).configure(repConf);
  +                        ((Configurable) reply).configure(config);
                       }
                       if (reply instanceof Composable) {
                           ((Composable) reply).compose( componentManager );
  @@ -207,5 +235,40 @@
               getLogger().error("Exception AvalonMailStore.hasComponent-"+ex.toString());
           }
           return (comp != null);
  +    }
  +
  +    /**
  +     * Copies values from one config into another, overwriting duplicate attributes
  +     * and merging children.
  +     */
  +    private void copyConfig(Configuration fromConfig, DefaultConfiguration toConfig)
  +    {
  +        // Copy attributes
  +        String[] attrs = fromConfig.getAttributeNames();
  +        for ( int i = 0; i < attrs.length; i++ ) {
  +            String attrName = attrs[i];
  +            String attrValue = fromConfig.getAttribute(attrName, null);
  +            toConfig.setAttribute(attrName, attrValue);
  +        }
  +
  +        // Copy children
  +        Configuration[] children = fromConfig.getChildren();
  +        for ( int i = 0; i < children.length; i++ ) {
  +            Configuration child = children[i];
  +            String childName = child.getName();
  +            Configuration existingChild = toConfig.getChild(childName, false);
  +            if ( existingChild == null ) {
  +                toConfig.addChild(child);
  +            }
  +            else {
  +                copyConfig(child, (DefaultConfiguration)existingChild);
  +            }
  +        }
  +
  +        // Copy value
  +        String val = fromConfig.getValue(null);
  +        if ( val != null ) {
  +            toConfig.setValue(val);
  +        }
       }
   }
  
  
  
  1.2       +4 -0      jakarta-james/src/java/org/apache/james/core/AvalonMailStore.xinfo
  
  Index: AvalonMailStore.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/core/AvalonMailStore.xinfo,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AvalonMailStore.xinfo	2001/05/11 09:15:43	1.1
  +++ AvalonMailStore.xinfo	2001/09/11 04:32:44	1.2
  @@ -21,6 +21,10 @@
         <role>org.apache.avalon.cornerstone.services.store.Store</role>
         <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
       </dependency>
  +    <dependency>
  +      <role>org.apache.avalon.cornerstone.services.datasource.DataSourceSelector</role>
  +      <service name="org.apache.avalon.cornerstone.services.datasource.DataSourceSelector"
version="1.0"/>
  +    </dependency>
     </dependencies>
   
   </blockinfo>
  
  
  
  1.2       +4 -0      jakarta-james/src/java/org/apache/james/core/AvalonUsersStore.xinfo
  
  Index: AvalonUsersStore.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/core/AvalonUsersStore.xinfo,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AvalonUsersStore.xinfo	2001/05/11 09:15:43	1.1
  +++ AvalonUsersStore.xinfo	2001/09/11 04:32:44	1.2
  @@ -20,6 +20,10 @@
         <role>org.apache.avalon.cornerstone.services.store.Store</role>
         <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
       </dependency>
  +    <dependency>
  +      <role>org.apache.avalon.cornerstone.services.datasource.DataSourceSelector</role>
  +      <service name="org.apache.avalon.cornerstone.services.datasource.DataSourceSelector"
version="1.0"/>
  +    </dependency>
     </dependencies>
   
   </blockinfo>
  
  
  

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


Mime
View raw message