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 2009/10/26 16:30:14 UTC

svn commit: r829826 - in /james/server/trunk/avalon-user-function/src/main/java/org/apache/james: core/ userrepository/

Author: norman
Date: Mon Oct 26 15:30:13 2009
New Revision: 829826

URL: http://svn.apache.org/viewvc?rev=829826&view=rev
Log:
More guice stuff (JAMES-893)

Added:
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractGuiceStore.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceUsersStore.java
      - copied, changed from r829709, james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceVirtualUserTableStore.java
      - copied, changed from r829709, james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java
Modified:
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractAvalonStore.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
    james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/UsersFileRepository.java

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractAvalonStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractAvalonStore.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractAvalonStore.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractAvalonStore.java Mon Oct 26 15:30:13 2009
@@ -25,145 +25,39 @@
 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.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.Serviceable;
-
-import java.util.HashMap;
-import java.util.Iterator;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.james.bridge.GuiceInjected;
+import org.apache.james.util.ConfigurationAdapter;
 
 /**
  * Provides a registry of objects
  *
  */
 public abstract class AbstractAvalonStore
-    extends AbstractLogEnabled
-    implements Serviceable, Configurable, Initializable {
+    implements Serviceable, Configurable, Initializable, LogEnabled, GuiceInjected {
 
-    private HashMap<String,Object> objects;
 
-    /**
-     * The Avalon configuration used by the instance
-     */
-    protected Configuration          configuration;
-
-    /**
-     * The Avalon component manager used by the instance
-     */
-    protected ServiceManager       manager;
-
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
-     */
-    public void service( final ServiceManager manager )
-        throws ServiceException {
-        this.manager = manager;
-    }
+    protected HierarchicalConfiguration configuration;
+    protected Log logger;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
      */
     public void configure( final Configuration configuration )
         throws ConfigurationException {
-        this.configuration = configuration;
-    }
-
-    /**
-     * @see org.apache.avalon.framework.activity.Initializable#initialize()
-     */
-    public void initialize()
-        throws Exception {
-
-        getLogger().info(getStoreName() + " init...");
-        objects = new HashMap<String,Object>();
-
-        Configuration[] repConfs = getConfigurations(configuration);
-        ClassLoader theClassLoader = null;
-        for ( int i = 0; i < repConfs.length; i++ )
-        {
-            Configuration repConf = repConfs[i];
-            String repName = repConf.getAttribute("name");
-            String repClass = repConf.getAttribute("class");
-
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Starting " + repClass);
-            }
-
-            if (theClassLoader == null) {
-                theClassLoader = Thread.currentThread().getContextClassLoader();
-            }
-
-            Object object = getClassInstance(theClassLoader,repClass);
-
-            setupLogger(object);
-
-            ContainerUtil.service(object,manager);
-
-            ContainerUtil.configure(object,repConf);
-            ContainerUtil.initialize(object);
-            
-            
-            objects.put(repName, object);
-            if (getLogger().isInfoEnabled()) {
-                StringBuffer logBuffer = 
-                    new StringBuffer(64)
-                            .append("Store  ")
-                            .append(repName)
-                            .append(" started.");
-                getLogger().info(logBuffer.toString());
-            }
+        try {
+            this.configuration = new ConfigurationAdapter(configuration);
+        } catch (org.apache.commons.configuration.ConfigurationException e) {
+            throw new ConfigurationException("Unable to convert config",e);
         }
     }
 
-
-    /** 
-     * Get the object, if any, whose name corresponds to
-     * the argument parameter
-     *
-     * @param name the name of the desired object
-     *
-     * @return the Object corresponding to the name parameter
-     */
-    protected Object getObject(String name) {
-        return objects.get(name);
-    }
-
-    /** 
-     * Yield an <code>Iterator</code> over the set of object
-     * names managed internally by this store.
-     *
-     * @return an Iterator over the set of repository names
-     *         for this store
-     */
-    protected Iterator<String> getObjectNames() {
-        return this.objects.keySet().iterator();
+    public void enableLogging(Logger arg0) {
+        this.logger = new AvalonLogger(arg0);
     }
-    
-    /**
-     * Return new Object of the loader classname
-     * 
-     * @param loader the ClassLoader
-     * @param className the classname
-     * @return the loaded Objected
-     * @throws Exception
-     */
-    public abstract Object getClassInstance(ClassLoader loader, String className) throws Exception;
-    
-    /**
-     * Return the Store configurations 
-     * 
-     * @param config the main config
-     * @return configurations
-     */
-    public abstract Configuration[] getConfigurations(Configuration config);
-    
-    /**
-     * Return the Store name which should be used for logging
-     * 
-     * @return the name
-     */
-    public abstract String getStoreName();
-    
 }

Added: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractGuiceStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractGuiceStore.java?rev=829826&view=auto
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractGuiceStore.java (added)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AbstractGuiceStore.java Mon Oct 26 15:30:13 2009
@@ -0,0 +1,161 @@
+/****************************************************************
+ * 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.core;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+
+/**
+ * Abstract base class for Stores which use Guice to load stuff
+ *
+ * @param <Type>
+ */
+public abstract class AbstractGuiceStore<Type> {
+
+    private HashMap<String,Type> objects;
+    
+    protected Log logger;
+
+    protected HierarchicalConfiguration config;
+    
+    @Resource(name="org.apache.commons.logging.Log")
+    public void setLogger(Log logger) {
+        this.logger = logger;
+    }
+    
+    protected Log getLogger() {
+        return logger;
+    }
+    
+    @Resource(name="org.apache.commons.configuration.Configuration")
+    public void setConfiguration(HierarchicalConfiguration config) {
+        this.config = config;
+    }   
+
+    /**
+     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     */
+    @SuppressWarnings("unchecked")
+    @PostConstruct
+    public void init()
+        throws Exception {
+
+        getLogger().info(getStoreName() + " init...");
+        objects = new HashMap<String,Type>();
+
+        List<HierarchicalConfiguration> repConfs = getConfigurations(config);
+        ClassLoader theClassLoader = null;
+        for ( int i = 0; i < repConfs.size(); i++ )
+        {
+            final HierarchicalConfiguration repConf = repConfs.get(i);
+            String repName = repConf.getString("/ @name");
+            String repClass = repConf.getString("/ @class");
+
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Starting " + repClass);
+            }
+            if (theClassLoader == null) {
+                theClassLoader = Thread.currentThread().getContextClassLoader();
+            }            
+            Type object = (Type) Guice.createInjector(getModule(),new Jsr250Module(), new AbstractModule() {
+
+                @Override
+                protected void configure() {
+                    bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(repConf);
+                }
+                
+            }).getInstance(theClassLoader.loadClass(repClass));
+            
+            if (getLogger().isDebugEnabled()) {
+                getLogger().debug("Load instance " + object);
+            }
+            
+            objects.put(repName, object);
+            if (getLogger().isInfoEnabled()) {
+                StringBuffer logBuffer = 
+                    new StringBuffer(64)
+                            .append("Store  ")
+                            .append(repName)
+                            .append(" started.");
+                getLogger().info(logBuffer.toString());
+            }
+        }
+    }
+
+
+    /** 
+     * Get the object, if any, whose name corresponds to
+     * the argument parameter
+     *
+     * @param name the name of the desired object
+     *
+     * @return the Object corresponding to the name parameter
+     */
+    protected Type getObject(String name) {
+        return objects.get(name);
+    }
+
+    /** 
+     * Yield an <code>Iterator</code> over the set of object
+     * names managed internally by this store.
+     *
+     * @return an Iterator over the set of repository names
+     *         for this store
+     */
+    protected Iterator<String> getObjectNames() {
+        return this.objects.keySet().iterator();
+    }
+    
+    
+    /**
+     * Return the Store configurations 
+     * 
+     * @param config the main config
+     * @return configurations
+     */
+    public abstract List<HierarchicalConfiguration> getConfigurations(HierarchicalConfiguration config);
+    
+    /**
+     * Return the Store name which should be used for logging
+     * 
+     * @return the name
+     */
+    public abstract String getStoreName();
+    
+    /**
+     * Return the Module to use for Injecting
+     * 
+     * @return module
+     */
+    protected abstract Module getModule();
+    
+}

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java Mon Oct 26 15:30:13 2009
@@ -16,70 +16,61 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.core;
 
-import org.apache.avalon.framework.configuration.Configuration;
+import java.util.Iterator;
+
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.api.user.UsersStore;
+import org.apache.james.services.FileSystem;
+import org.guiceyfruit.jsr250.Jsr250Module;
 
-import java.util.Iterator;
-
-/**
- * Provides a registry of user repositories.
- *
- */
-public class AvalonUsersStore
-    extends AbstractAvalonStore
-    implements UsersStore {
-
-    /** 
-     * Get the repository, if any, whose name corresponds to
-     * the argument parameter
-     *
-     * @param name the name of the desired repository
-     *
-     * @return the UsersRepository corresponding to the name parameter
-     */
-    public UsersRepository getRepository(String name) {
-        UsersRepository response = (UsersRepository) getObject(name);
-        if ((response == null) && (getLogger().isWarnEnabled())) {
-            getLogger().warn("No users repository called: " + name);
-        }
-        return response;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
+
+public class AvalonUsersStore extends AbstractAvalonStore implements UsersStore{
+
+    private DataSourceSelector selector;
+    private FileSystem fs;
+    private UsersStore uStore;
+    private Store store;
+    
+    public void service(ServiceManager manager) throws ServiceException {
+        selector = (DataSourceSelector) manager.lookup(DataSourceSelector.ROLE);
+        fs = (FileSystem) manager.lookup(FileSystem.ROLE);
+        store = (Store) manager.lookup(Store.ROLE);
     }
 
-    /** 
-     * Yield an <code>Iterator</code> over the set of repository
-     * names managed internally by this store.
-     *
-     * @return an Iterator over the set of repository names
-     *         for this store
-     */
-    public Iterator<String> getRepositoryNames() {
-        return getObjectNames();
+    public void initialize() throws Exception {
+        uStore = Guice.createInjector(new Jsr250Module(), new AvalonUserStoreModule()).getInstance(GuiceUsersStore.class);
     }
     
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getClassInstance(java.lang.ClassLoader, java.lang.String)
-     */
-    public Object getClassInstance(ClassLoader loader, String repClass) throws Exception {
-        return  (UsersRepository) loader.loadClass(repClass).newInstance();
-    }
+    public class AvalonUserStoreModule extends AbstractModule {
 
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getConfigurations(org.apache.avalon.framework.configuration.Configuration)
-     */
-    public Configuration[] getConfigurations(Configuration config) {
-        return configuration.getChildren("repository");
+        @Override
+        protected void configure() {
+            bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(configuration);
+            bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+            bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(selector);
+            bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fs);
+            bind(Store.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.store.Store")).toInstance(store);
+        }
+        
     }
+
     
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
-     */
-    public String getStoreName() {
-        return "AvolonUsersStore";
+    public UsersRepository getRepository(String name) {
+        return uStore.getRepository(name);
+    }
+
+    public Iterator<String> getRepositoryNames() {
+        return uStore.getRepositoryNames();
     }
 }

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java Mon Oct 26 15:30:13 2009
@@ -16,58 +16,55 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.core;
 
-import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.vut.VirtualUserTable;
 import org.apache.james.api.vut.VirtualUserTableStore;
+import org.apache.james.services.FileSystem;
+import org.guiceyfruit.jsr250.Jsr250Module;
 
-/**
- * Provides a registry of VirtualUserTables
- *
- */
-public class AvalonVirtualUserTableStore
-    extends AbstractAvalonStore
-    implements VirtualUserTableStore {
-
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
+
+public class AvalonVirtualUserTableStore extends AbstractAvalonStore implements VirtualUserTableStore{
+    private DataSourceSelector selector;
+    private FileSystem fs;
+    private VirtualUserTableStore vStore;
+    private DNSService dns;
    
-    /** 
-     * Get the repository, if any, whose name corresponds to
-     * the argument parameter
-     *
-     * @param name the name of the desired repository
-     *
-     * @return the VirtualUserTable corresponding to the name parameter
-     */
-    public VirtualUserTable getTable(String name) {
-        VirtualUserTable response = (VirtualUserTable) getObject(name);
-        if ((response == null) && (getLogger().isWarnEnabled())) {
-            getLogger().warn("No virtualUserTable called: " + name);
-        }
-        return response;
+    
+    public void service(ServiceManager manager) throws ServiceException {
+        selector = (DataSourceSelector) manager.lookup(DataSourceSelector.ROLE);
+        fs = (FileSystem) manager.lookup(FileSystem.ROLE);
+        dns = (DNSService) manager.lookup(DNSService.ROLE);
     }
 
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getClassInstance(ClassLoader, String)
-     */
-    public Object getClassInstance(ClassLoader loader, String repClass) throws Exception {
-        return (VirtualUserTable) loader.loadClass(repClass).newInstance();
+    public void initialize() throws Exception {
+        vStore = Guice.createInjector(new Jsr250Module(), new AvalonVirtualUserTableStoreModule()).getInstance(GuiceVirtualUserTableStore.class);
     }
 
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getConfigurations(org.apache.avalon.framework.configuration.Configuration)
-     */
-    public Configuration[] getConfigurations(Configuration config) {
-        return configuration.getChildren("table");
+    public VirtualUserTable getTable(String name) {
+        return vStore.getTable(name);
     }
+    
+    public class AvalonVirtualUserTableStoreModule extends AbstractModule {
 
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
-     */
-    public String getStoreName() {
-        return "AvalonVirtualUserTableStore";
+        @Override
+        protected void configure() {
+            bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(configuration);
+            bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+            bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(selector);
+            bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fs);
+            bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns);
+        }
+        
     }
+    
 }

Copied: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceUsersStore.java (from r829709, james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceUsersStore.java?p2=james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceUsersStore.java&p1=james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java&r1=829709&r2=829826&rev=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonUsersStore.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceUsersStore.java Mon Oct 26 15:30:13 2009
@@ -21,20 +21,58 @@
 
 package org.apache.james.core;
 
-import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.api.user.UsersStore;
+import org.apache.james.services.FileSystem;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
 
 import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 
 /**
  * Provides a registry of user repositories.
  *
  */
-public class AvalonUsersStore
-    extends AbstractAvalonStore
+public class GuiceUsersStore
+    extends AbstractGuiceStore<UsersRepository>
     implements UsersStore {
 
+    private FileSystem fs;
+    private DataSourceSelector selector;
+    private Store store;
+
+    @Resource(name="org.apache.james.services.FileSystem")
+    public void setFileSystem(FileSystem fs) {
+        this.fs = fs;
+    }
+    
+    @Resource(name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")
+    public void setDataSourceSelector(DataSourceSelector selector) {
+        this.selector = selector;
+    }
+    
+    @Resource(name="org.apache.avalon.cornerstone.services.store.Store")
+    public void setStore(Store store) {
+        this.store = store;
+    }
+    
+    // TODO: REMOVE ME!!
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
+
     /** 
      * Get the repository, if any, whose name corresponds to
      * the argument parameter
@@ -44,7 +82,7 @@
      * @return the UsersRepository corresponding to the name parameter
      */
     public UsersRepository getRepository(String name) {
-        UsersRepository response = (UsersRepository) getObject(name);
+        UsersRepository response = getObject(name);
         if ((response == null) && (getLogger().isWarnEnabled())) {
             getLogger().warn("No users repository called: " + name);
         }
@@ -61,25 +99,34 @@
     public Iterator<String> getRepositoryNames() {
         return getObjectNames();
     }
-    
+
     /**
-     * @see org.apache.james.core.AbstractAvalonStore#getClassInstance(java.lang.ClassLoader, java.lang.String)
+     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
      */
-    public Object getClassInstance(ClassLoader loader, String repClass) throws Exception {
-        return  (UsersRepository) loader.loadClass(repClass).newInstance();
+    public String getStoreName() {
+        return "GuiceUsersStore";
     }
 
     /**
-     * @see org.apache.james.core.AbstractAvalonStore#getConfigurations(org.apache.avalon.framework.configuration.Configuration)
+     * @see org.apache.james.core.AbstractGuiceStore#getConfigurations(org.apache.commons.configuration.HierarchicalConfiguration)
      */
-    public Configuration[] getConfigurations(Configuration config) {
-        return configuration.getChildren("repository");
+    @SuppressWarnings("unchecked")
+    public List<HierarchicalConfiguration> getConfigurations(
+            HierarchicalConfiguration config) {
+        return config.configurationsAt("repository");
     }
-    
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
-     */
-    public String getStoreName() {
-        return "AvolonUsersStore";
+
+    @Override
+    protected Module getModule() {
+        return new AbstractModule() {
+            
+            @Override
+            protected void configure() {
+                bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+                bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(selector);
+                bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fs);
+                bind(Store.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.store.Store")).toInstance(store);
+            }
+        };
     }
 }

Copied: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceVirtualUserTableStore.java (from r829709, james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceVirtualUserTableStore.java?p2=james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceVirtualUserTableStore.java&p1=james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java&r1=829709&r2=829826&rev=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/AvalonVirtualUserTableStore.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/core/GuiceVirtualUserTableStore.java Mon Oct 26 15:30:13 2009
@@ -21,19 +21,59 @@
 
 package org.apache.james.core;
 
-import org.apache.avalon.framework.configuration.Configuration;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.vut.VirtualUserTable;
 import org.apache.james.api.vut.VirtualUserTableStore;
+import org.apache.james.services.FileSystem;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
 
 /**
  * Provides a registry of VirtualUserTables
  *
  */
-public class AvalonVirtualUserTableStore
-    extends AbstractAvalonStore
+public class GuiceVirtualUserTableStore
+    extends AbstractGuiceStore<VirtualUserTable>
     implements VirtualUserTableStore {
 
-   
+    private FileSystem fs;
+    private DNSService dns;
+    private DataSourceSelector selector;
+
+
+    // TODO: REMOVE ME!!
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
+
+    @Resource(name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")
+    public void setDataSourceSelector(DataSourceSelector selector) {
+        this.selector = selector;
+    }
+    
+    
+    @Resource(name="org.apache.james.services.FileSystem")
+    public void setFileSystem(FileSystem fs) {
+        this.fs = fs;
+    }
+    
+    @Resource(name="org.apache.james.api.dnsservice.DNSService")
+    public void setDNSService(DNSService dns) {
+        this.dns = dns;
+    }
+    
     /** 
      * Get the repository, if any, whose name corresponds to
      * the argument parameter
@@ -43,7 +83,7 @@
      * @return the VirtualUserTable corresponding to the name parameter
      */
     public VirtualUserTable getTable(String name) {
-        VirtualUserTable response = (VirtualUserTable) getObject(name);
+        VirtualUserTable response = getObject(name);
         if ((response == null) && (getLogger().isWarnEnabled())) {
             getLogger().warn("No virtualUserTable called: " + name);
         }
@@ -51,23 +91,34 @@
     }
 
     /**
-     * @see org.apache.james.core.AbstractAvalonStore#getClassInstance(ClassLoader, String)
+     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
      */
-    public Object getClassInstance(ClassLoader loader, String repClass) throws Exception {
-        return (VirtualUserTable) loader.loadClass(repClass).newInstance();
+    public String getStoreName() {
+        return "AvalonVirtualUserTableStore";
     }
 
+
     /**
-     * @see org.apache.james.core.AbstractAvalonStore#getConfigurations(org.apache.avalon.framework.configuration.Configuration)
+     * @see org.apache.james.core.AbstractGuiceStore#getConfigurations(org.apache.commons.configuration.HierarchicalConfiguration)
      */
-    public Configuration[] getConfigurations(Configuration config) {
-        return configuration.getChildren("table");
+    @SuppressWarnings("unchecked")
+    public List<HierarchicalConfiguration> getConfigurations(
+            HierarchicalConfiguration config) {
+        return config.configurationsAt("table");
     }
 
-    /**
-     * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
-     */
-    public String getStoreName() {
-        return "AvalonVirtualUserTableStore";
+
+    @Override
+    protected Module getModule() {
+        return new AbstractModule() {
+            
+            @Override
+            protected void configure() {
+                bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+                bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(selector);
+                bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.service.FileSystem")).toInstance(fs);
+                bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns);
+            }
+        };
     }
 }

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java Mon Oct 26 15:30:13 2009
@@ -390,7 +390,7 @@
      * @see org.apache.james.impl.jamesuser.AbstractUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
      */
     @SuppressWarnings("unchecked")
-    public void doConfigure(HierarchicalConfiguration configuration)
+    protected void doConfigure(HierarchicalConfiguration configuration)
             throws ConfigurationException {
         StringBuffer logBuffer = null;
         if (getLogger().isDebugEnabled()) {
@@ -401,7 +401,10 @@
 
         // Parse the DestinationURL for the name of the datasource,
         // the table to use, and the (optional) repository Key.
-        String destUrl = configuration.getString("/ @destinationURL");
+        String destUrl = configuration.getString("/ @destinationURL", null);
+        // throw an exception if the attribute is missing
+        if (destUrl == null) throw new ConfigurationException("destinatURL attribute is missing from Configuration");
+        
         // normalise the destination, to simplify processing.
         if (!destUrl.endsWith("/")) {
             destUrl += "/";

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java Mon Oct 26 15:30:13 2009
@@ -28,6 +28,8 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.annotation.PostConstruct;
+
 
 /**
  * A Jdbc-backed UserRepository which handles User instances
@@ -42,6 +44,13 @@
  */
 public class DefaultUsersJdbcRepository extends AbstractJdbcUsersRepository
 {
+    // REMOVE ME!
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
+    
     /**
      * @see org.apache.james.userrepository.AbstractJdbcUsersRepository#readUserFromResultSet(java.sql.ResultSet)
      */

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java Mon Oct 26 15:30:13 2009
@@ -30,11 +30,23 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.annotation.PostConstruct;
+
 /**
  * A Jdbc-backed UserRepository which handles User instances of the <CODE>DefaultJamesUser</CODE>
  * class, or any superclass.
  */
 public class JamesUsersJdbcRepository extends AbstractJdbcUsersRepository {
+    
+    
+    // REMOVE ME!
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
+
+
     /**
      * @see org.apache.james.userrepository.AbstractJdbcUsersRepository#readUserFromResultSet(java.sql.ResultSet)
      */

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/ListUsersJdbcRepository.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/ListUsersJdbcRepository.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/ListUsersJdbcRepository.java Mon Oct 26 15:30:13 2009
@@ -28,6 +28,8 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.annotation.PostConstruct;
+
 /**
  * A very lightweight UserRepository, which persists a list
  * of user names in a database. Password information is not 
@@ -37,6 +39,12 @@
 public class ListUsersJdbcRepository extends AbstractJdbcUsersRepository
 {
 
+    // REMOVE ME!
+    @PostConstruct
+    @Override
+    public void init() throws Exception {
+        super.init();
+    }
     
     /**
      * @see org.apache.james.impl.jamesuser.AbstractUsersRepository#test(java.lang.String, java.lang.String)

Modified: james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/UsersFileRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/UsersFileRepository.java?rev=829826&r1=829825&r2=829826&view=diff
==============================================================================
--- james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/UsersFileRepository.java (original)
+++ james/server/trunk/avalon-user-function/src/main/java/org/apache/james/userrepository/UsersFileRepository.java Mon Oct 26 15:30:13 2009
@@ -80,7 +80,7 @@
     /**
      * @see org.apache.james.impl.jamesuser.AbstractUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
      */
-    public void doConfigure( final HierarchicalConfiguration configuration )
+    protected void doConfigure( final HierarchicalConfiguration configuration )
         throws ConfigurationException {
         destination = configuration.getString( "destination/ @URL" );
 



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