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 jo...@apache.org on 2006/11/16 20:50:50 UTC

svn commit: r475896 [1/2] - in /james/server/sandbox/mailbox-namespaces/src: conf/ java/org/apache/james/imapserver/ java/org/apache/james/mailboxmanager/impl/ java/org/apache/james/mailboxmanager/mailbox/ java/org/apache/james/mailboxmanager/mailstore...

Author: joachim
Date: Thu Nov 16 11:50:48 2006
New Revision: 475896

URL: http://svn.apache.org/viewvc?view=rev&rev=475896
Log:
 - introducing VirtualMailboxManager, DefaultMailboxManagerProvider and MailboxManagerFactory
 - compiles, tests are passing - still not completeley working inside James
 - API seems to be realizable and has stabilized a bit

Added:
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml   (with props)
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml
Removed:
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerProvider.java
Modified:
    james/server/sandbox/mailbox-namespaces/src/conf/james-assembly.xml
    james/server/sandbox/mailbox-namespaces/src/conf/james-config.xml
    james/server/sandbox/mailbox-namespaces/src/conf/mailboxManagerSqlResources.xml
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSession.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSessionImpl.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/SelectedMailboxSession.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/imapserver/mock/MockImapHandlerConfigurationData.java
    james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/TorqueMailboxManagerProviderSingleton.java

Modified: james/server/sandbox/mailbox-namespaces/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/conf/james-assembly.xml?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/conf/james-assembly.xml (original)
+++ james/server/sandbox/mailbox-namespaces/src/conf/james-assembly.xml Thu Nov 16 11:50:48 2006
@@ -39,9 +39,16 @@
              role="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector" />
   </block>
 
+  <!-- 
   <block name="mailboxmanager" class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider">
     <provide name="filesystem" role="org.apache.james.services.FileSystem" />
   </block>  
+  -->   
+    
+  <block name="mailboxmanager" class="org.apache.james.mailboxmanager.impl.DefaultMailboxManagerProvider">
+      <provide name="filesystem" role="org.apache.james.services.FileSystem" />
+  </block>  
+
     
   <!-- The James Spool Manager block  -->
   <block name="spoolmanager" class="org.apache.james.transport.JamesSpoolManager" >

Modified: james/server/sandbox/mailbox-namespaces/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/conf/james-config.xml?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/conf/james-config.xml (original)
+++ james/server/sandbox/mailbox-namespaces/src/conf/james-config.xml Thu Nov 16 11:50:48 2006
@@ -94,19 +94,66 @@
       -->
    </James>
 
-   <!-- Experimental IMAP support -->
-   <mailboxmanager>
-       <torque-properties>
-           <property name="torque.database.default" value="mailboxmanager" />
-           <property name="torque.database.mailboxmanager.adapter" value="derby" />
-           <property name="torque.dsfactory.mailboxmanager.factory" value="org.apache.torque.dsfactory.SharedPoolDataSourceFactory" />
-           <property name="torque.dsfactory.mailboxmanager.connection.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
-           <property name="torque.dsfactory.mailboxmanager.connection.url" value="jdbc:derby:../apps/james/var/mailboxmanager-derbydb;create=true" />
-           <property name="torque.dsfactory.mailboxmanager.connection.user" value="app" />
-           <property name="torque.dsfactory.mailboxmanager.connection.password" value="app" />
-           <property name="torque.dsfactory.mailboxmanager.pool.maxActive" value="100" />
-      </torque-properties>  
-   </mailboxmanager>    
+
+    <mailboxmanager>
+        <namespaces>
+            <usernamespace name="#mail" delimiter="."/>
+        </namespaces>
+        <factory
+            class="org.apache.james.mailboxmanager.impl.VirtualMailboxManagerFactory">
+            <mounts>
+                <mount>
+                    <point point="#mail"/>
+                    <target class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerFactory">
+                        <torque-properties>
+                            <property name="torque.database.default"
+                                value="mailboxmanager"/>
+                            <property
+                                name="torque.database.mailboxmanager.adapter"
+                                value="derby"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.factory"
+                                value="org.apache.torque.dsfactory.SharedPoolDataSourceFactory"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.connection.driver"
+                                value="org.apache.derby.jdbc.EmbeddedDriver"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.connection.url"
+                                value="jdbc:derby:../apps/james/var/mailboxmanager-derbydb;create=true"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.connection.user"
+                                value="app"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.connection.password"
+                                value="app"/>
+                            <property
+                                name="torque.dsfactory.mailboxmanager.pool.maxActive"
+                                value="100"/>
+                        </torque-properties>
+                    </target>
+                </mount>
+                <mount>
+                    <point point="#mail.user1"/>
+                    <target
+                        class="org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManagerFactory">
+                        <repository destinationURL="file://var/mail/inboxes/user1"
+                            type="MAIL"/>
+                    </target>
+                </mount>        
+                <mount>
+                    <point point="#mail.user2"/>
+                    <target
+                        class="org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManagerFactory">
+                        <repository destinationURL="mbox://var/mail/inboxes/user2_extra"
+                            type="MAIL"/>
+                    </target>
+                </mount>            
+            </mounts>
+        </factory>
+    </mailboxmanager>
+	
+  <!-- Experimental IMAP support -->
+	
    <imapserver enabled="true">
       <port>10143</port>
       <handler>

Modified: james/server/sandbox/mailbox-namespaces/src/conf/mailboxManagerSqlResources.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/conf/mailboxManagerSqlResources.xml?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/conf/mailboxManagerSqlResources.xml (original)
+++ james/server/sandbox/mailbox-namespaces/src/conf/mailboxManagerSqlResources.xml Thu Nov 16 11:50:48 2006
@@ -22,7 +22,7 @@
 
   <dbOptions>
   </dbOptions>
-  <sqlDefs name="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider">
+  <sqlDefs name="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerFactory">
 
     <sql name="tableName">${table}</sql>
 

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSession.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSession.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSession.java Thu Nov 16 11:50:48 2006
@@ -115,8 +115,9 @@
 
     /**
      * closes the Mailbox if needed
+     * @throws MailboxManagerException 
      */
-    void closeMailbox();
+    void closeMailbox() throws MailboxManagerException;
 
     MailboxManager getMailboxManager() throws MailboxManagerException;
 

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSessionImpl.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSessionImpl.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/ImapSessionImpl.java Thu Nov 16 11:50:48 2006
@@ -181,10 +181,13 @@
         return this.state;
     }
 
-    public void closeMailbox()
+    public void closeMailbox() 
     {
         if (selectedMailbox != null) {
-            selectedMailbox.close();
+            try {
+                selectedMailbox.close();
+            } catch (MailboxManagerException e) {
+            }
             selectedMailbox=null;
         }
         
@@ -212,7 +215,7 @@
 
     public String buildFullName(String mailboxName) throws MailboxManagerException {
         if (!mailboxName.startsWith(NAMESPACE_PREFIX)) {
-            mailboxName = getMailboxManager().getPersonalDefaultNamespace(user).getName()+HIERARCHY_DELIMITER+mailboxName;
+            mailboxName = mailboxManagerProvider.getPersonalDefaultNamespace(user).getName()+HIERARCHY_DELIMITER+mailboxName;
         }
         return mailboxName;
     }

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/SelectedMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/SelectedMailboxSession.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/SelectedMailboxSession.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/SelectedMailboxSession.java Thu Nov 16 11:50:48 2006
@@ -75,7 +75,7 @@
     }
     
 
-    public void close()
+    public void close() throws MailboxManagerException
     {
         mailbox.close();
         mailbox=null;

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,135 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import org.apache.avalon.framework.activity.Initializable;
+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.service.Serviceable;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.Namespace;
+import org.apache.james.mailboxmanager.Namespaces;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.services.User;
+
+public class DefaultMailboxManagerProvider extends AbstractLogEnabled implements MailboxManagerProvider, Configurable, Serviceable, Initializable {
+
+    public static final char HIERARCHY_DELIMITER = '.';
+
+    public static final String USER_NAMESPACE = "#mail";
+
+    public static final String INBOX = "INBOX";
+
+    private MailboxManagerFactory mailboxManagerFactory;
+
+    private ServiceManager serviceManager;
+
+    protected MailboxManagerFactory getMailboxManagerFactory() {
+        return mailboxManagerFactory;
+    }
+
+    public void setMailboxManagerFactory(
+            MailboxManagerFactory mailboxManagerFactory) {
+        this.mailboxManagerFactory = mailboxManagerFactory;
+    }
+
+    public void deleteAllUserData(User authUser, User targetUser) {
+    }
+
+    public void deleteEverything() throws MailboxManagerException {
+        getMailboxManagerFactory().deleteEverything();
+    }
+
+    public MailboxSession getInboxSession(User user) throws MailboxManagerException {
+        return getMailboxManagerInstance(user).getMailboxSession(getInboxName(user));
+    }
+
+    public MailboxManager getMailboxManagerInstance(User user)
+            throws MailboxManagerException {
+        return getMailboxManagerFactory().getMailboxManagerInstance(user);
+    }
+
+    public MailboxSession getMailboxSession(User authUser, String mailboxName)
+            throws MailboxManagerException {
+        return getMailboxManagerInstance(authUser).getMailboxSession(mailboxName);
+    }
+
+    public Namespaces getNamespaces(User forUser) {
+        NamespacesImpl nameSpaces = new NamespacesImpl();
+        nameSpaces.setShared(new Namespace[0]);
+        Namespace userNamespace = new NamespaceImpl("" + HIERARCHY_DELIMITER,
+                USER_NAMESPACE);
+        nameSpaces.setUser(new Namespace[] { userNamespace });
+        Namespace personalDefault = getPersonalDefaultNamespace(forUser);
+        nameSpaces.setPersonal(new Namespace[] { personalDefault });
+        nameSpaces.setPersonalDefault(personalDefault);
+        return nameSpaces;
+    }
+
+    public Namespace getPersonalDefaultNamespace(User forUser) {
+        return new NamespaceImpl("" + HIERARCHY_DELIMITER, USER_NAMESPACE
+                + HIERARCHY_DELIMITER + forUser.getUserName());
+    }
+
+    String getInboxName(User user) {
+        Namespace nameSpace=getPersonalDefaultNamespace(user);
+        return nameSpace.getName()+nameSpace.getHierarchyDelimter()+INBOX;
+    }
+
+    public void configure(Configuration conf) throws ConfigurationException {
+        Configuration factoryConf=conf.getChild("factory",false);
+        String className=factoryConf.getAttribute("class");
+        MailboxManagerFactory factory=(MailboxManagerFactory) getClassInstace(className);
+        ContainerUtil.enableLogging(factory, getLogger());
+        ContainerUtil.configure(factory, factoryConf);
+        setMailboxManagerFactory(factory);
+    }
+    
+    private static Object getClassInstace(String name) {
+        Object object=null;
+        try {
+            Class clazz = Thread.currentThread().getContextClassLoader().loadClass(name);
+            object=clazz.newInstance();
+            return object;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        
+    }
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        this.serviceManager=serviceManager;
+        
+    }
+
+    public void initialize() throws Exception {
+        ContainerUtil.service(mailboxManagerFactory, serviceManager);
+        ContainerUtil.initialize(mailboxManagerFactory);
+    }
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo Thu Nov 16 11:50:48 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+  <!-- section to describe block -->
+  <block>
+    <version>1.0</version>
+  </block>
+
+  <!-- services that are offered by this block -->
+  <services> 
+      <service name="org.apache.james.mailboxmanager.manager.MailboxManagerProvider" version="1.0" />
+  </services>
+
+  <dependencies>
+    <dependency>
+      <service name="org.apache.james.services.FileSystem" version="1.0"/>
+    </dependency>
+  </dependencies>
+
+</blockinfo>

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProvider.xinfo
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,158 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.services.User;
+
+public class VirtualMailboxManager extends AbstractLogEnabled implements
+        MailboxManager {
+
+    private Map mountMap = null;
+    
+    private User user;
+    
+        
+    
+    public VirtualMailboxManager() {
+        
+    }
+
+    Map getMountMap() {
+        return mountMap;
+    }
+    
+    public void setMountMap(Map mountMap) {
+        this.mountMap=mountMap;
+    }
+    
+    
+
+    MailboxManager getMailboxManager(String mailboxName) throws MailboxManagerException {
+        MailboxManager mailboxManager = null;
+        Iterator it = getMountMap().entrySet().iterator();
+        while (it.hasNext() && mailboxManager == null) {
+            Entry entry = (Entry) it.next();
+            String key = (String) entry.getKey();
+            if (mailboxName.startsWith(key)) {
+                MailboxManagerFactory mailboxManagerFactory = (MailboxManagerFactory) entry.getValue();
+                mailboxManager=mailboxManagerFactory.getMailboxManagerInstance(user);
+            }
+        }
+        return mailboxManager;
+    }
+
+    public void addMountPoint(String attribute) {
+    }
+
+    public void close() {
+    }
+
+    public void copyMessages(GeneralMailbox from, GeneralMessageSet set,
+            String to) throws MailboxManagerException {
+        getMailboxManager(to).copyMessages(from, set, to);
+    }
+
+    public void createMailbox(String mailboxName)
+            throws MailboxManagerException {
+        getMailboxManager(mailboxName).createMailbox(mailboxName);
+
+    }
+
+    public void deleteMailbox(String mailboxName)
+            throws MailboxManagerException {
+        getMailboxManager(mailboxName).deleteMailbox(mailboxName);
+
+    }
+
+    public boolean existsMailbox(String mailboxName)
+            throws MailboxManagerException {
+        return getMailboxManager(mailboxName).existsMailbox(mailboxName);
+    }
+
+    public GeneralMailboxSession getGeneralMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        return getMailboxManager(mailboxName).getGeneralMailboxSession(
+                mailboxName);
+    }
+
+    public ImapMailboxSession getImapMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        return getMailboxManager(mailboxName)
+                .getImapMailboxSession(mailboxName);
+    }
+
+    public MailboxSession getMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        return getMailboxManager(mailboxName).getMailboxSession(mailboxName);
+    }
+
+    public ListResult[] list(String base, String expression, boolean subscribed)
+            throws MailboxManagerException {
+        // TODO call only base matching managers
+        List listResults=new ArrayList();
+        Iterator it = getMountMap().entrySet().iterator();
+        
+        while (it.hasNext()) {
+            Entry entry = (Entry) it.next();
+            MailboxManagerFactory mailboxManagerFactory = (MailboxManagerFactory) entry.getValue();
+            MailboxManager mailboxManager=mailboxManagerFactory.getMailboxManagerInstance(user);
+            ListResult[] thisListResults=mailboxManager.list(base, expression, subscribed);
+            for (int i = 0; i < thisListResults.length; i++) {
+                listResults.add(thisListResults[i]);
+            }
+        }
+        
+        return (ListResult[]) listResults.toArray(new ListResult[0]);
+    }
+
+    public void renameMailbox(String from, String to)
+            throws MailboxManagerException {
+        // TODO deal with implementation spanning renames
+        getMailboxManager(from).renameMailbox(from, to);
+    }
+
+    public void setSubscription(String mailboxName, boolean value)
+            throws MailboxManagerException {
+        getMailboxManager(mailboxName).setSubscription(mailboxName, value);
+    }
+
+    public void setUser(User user) {
+        this.user=user;
+    }
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,156 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.avalon.framework.activity.Initializable;
+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.service.Serviceable;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.services.User;
+
+public class VirtualMailboxManagerFactory extends AbstractLogEnabled implements
+        Configurable, MailboxManagerFactory, Serviceable, Initializable {
+
+    private Map mountMap = null;
+    private Collection mailboxManagerFactories = new LinkedList();
+
+
+    public void configure(Configuration conf) throws ConfigurationException {
+        Configuration[] mountsConfs = conf.getChild(
+                "mounts", false).getChildren("mount");
+        
+        for (int i = 0; i < mountsConfs.length; i++) {
+            addMountConfig(mountsConfs[i]);
+        }        
+    }
+
+    public void initialize() throws Exception {
+        for (Iterator iter = mailboxManagerFactories.iterator(); iter.hasNext();) {
+            ContainerUtil.initialize(iter.next());
+        }
+    }
+
+    void addMountConfig(Configuration conf) throws ConfigurationException {
+        String className = null;
+        try {
+            Configuration targetConf = conf.getChild("target");
+            className = targetConf.getAttribute("class").toString();
+            MailboxManagerFactory mailboxManagerFactory = (MailboxManagerFactory) getClassInstace(className);
+            mailboxManagerFactories.add(mailboxManagerFactory);
+            ContainerUtil.enableLogging(mailboxManagerFactory, getLogger()
+                    .getChildLogger(
+                            mailboxManagerFactory.getClass().getSimpleName()));
+            ContainerUtil.configure(mailboxManagerFactory, targetConf);
+            
+            Configuration[] pointConfs = conf.getChildren("point");
+            for (int i = 0; i < pointConfs.length; i++) {
+                String point = pointConfs[i].getAttribute("point");
+                mailboxManagerFactory.addMountPoint(point);
+                addMount(point, mailboxManagerFactory);
+            }
+        } catch (Exception e) {
+            throw new ConfigurationException("Error configure " + className, e);
+        }
+    }
+
+    private static Object getClassInstace(String name) {
+        Object object = null;
+        try {
+            Class clazz = Thread.currentThread().getContextClassLoader()
+                    .loadClass(name);
+            object = clazz.newInstance();
+            return object;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    public void deleteEverything() throws MailboxManagerException {
+        // TODO Auto-generated method stub
+
+    }
+
+    public MailboxManager getMailboxManagerInstance(User user)
+
+    throws MailboxManagerException {
+        VirtualMailboxManager virtualMailboxManager = new VirtualMailboxManager();
+        ContainerUtil.enableLogging(virtualMailboxManager, getLogger()
+                .getChildLogger(
+                        virtualMailboxManager.getClass().getSimpleName()));
+        virtualMailboxManager.setMountMap(mountMap);
+        virtualMailboxManager.setUser(user);
+
+        return virtualMailboxManager;
+    }
+
+    public void addMount(String point, MailboxManagerFactory mailboxManager) {
+        getMountMap().put(point, mailboxManager);
+    }
+
+    protected Map getMountMap() {
+        if (mountMap == null) {
+            mountMap = new TreeMap(new LengthComparator());
+        }
+        return mountMap;
+    }
+
+    static class LengthComparator implements Comparator {
+
+        public int compare(Object arg0, Object arg1) {
+            String s0 = (String) arg0;
+            String s1 = (String) arg1;
+            int comp = new Integer(s1.length()).compareTo(new Integer(s0
+                    .length()));
+            if (comp == 0) {
+                comp = s0.compareTo(s1);
+            }
+            return comp;
+        }
+
+    }
+
+    public void addMountPoint(String point) {
+    }
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        for (Iterator iter = mailboxManagerFactories.iterator(); iter.hasNext();) {
+            ContainerUtil.service(iter.next(),serviceManager);
+        }
+
+    }
+
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = 

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java Thu Nov 16 11:50:48 2006
@@ -19,9 +19,11 @@
 
 package org.apache.james.mailboxmanager.mailbox;
 
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
 public interface MailboxSession extends Mailbox {
 
-    void close();
+    void close() throws MailboxManagerException;
 
     boolean isWriteable();
 

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,105 @@
+/****************************************************************
+ * 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.mailboxmanager.mailstore;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.repository.MailRepositoryMailboxSession;
+import org.apache.james.services.User;
+
+public class MailStoreMailboxManager extends AbstractLogEnabled implements
+        MailboxManager {
+
+    MailstoreMailboxCache mailstoreMailboxCache;
+    private User user;
+    
+    public void close() {
+    }
+
+    public void copyMessages(GeneralMailbox from, GeneralMessageSet set,
+            String to) throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public void createMailbox(String mailboxName)
+            throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public void deleteMailbox(String mailboxName)
+            throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");    }
+
+    public boolean existsMailbox(String mailboxName)
+            throws MailboxManagerException {
+        return true;
+    }
+
+    public synchronized GeneralMailboxSession getGeneralMailboxSession(
+            String mailboxName) throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public ImapMailboxSession getImapMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public MailboxSession getMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        return mailstoreMailboxCache.getMailboxSession(mailboxName);
+    }
+
+    public ListResult[] list(String base, String expression, boolean subscribed)
+            throws MailboxManagerException {
+        return new ListResult[0];
+    }
+
+    public void renameMailbox(String from, String to)
+            throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public void setSubscription(String mailboxName, boolean value)
+            throws MailboxManagerException {
+        throw new RuntimeException("operation not supported");
+    }
+
+    public synchronized void releaseSession(MailRepositoryMailboxSession session)
+            throws MailboxManagerException {
+        mailstoreMailboxCache.releaseSession(session);
+    }
+
+    public void setMailstoreMailboxCache(MailstoreMailboxCache mailstoreMailboxCache) {
+        this.mailstoreMailboxCache=mailstoreMailboxCache;
+    }
+
+    public void setUser(User user) {
+        this.user=user;
+    }
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.mailboxmanager.mailstore;
+
+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.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.services.User;
+
+public class MailStoreMailboxManagerFactory extends AbstractLogEnabled implements MailboxManagerFactory  {
+    
+    private MailstoreMailboxCache mailstoreMailboxCache;
+
+    public void deleteEverything() throws MailboxManagerException {
+    }
+
+    public MailboxManager getMailboxManagerInstance(User user) throws MailboxManagerException {
+        MailStoreMailboxManager mailboxManager=new MailStoreMailboxManager();
+        mailboxManager.setMailstoreMailboxCache(getMailstoreMailboxCache());
+        mailboxManager.setUser(user);
+        return mailboxManager;
+    }
+    
+    
+    public void configure(Configuration conf) throws ConfigurationException {
+        getMailstoreMailboxCache().setRepositoryConf(conf.getChild("target").getChild("repository"));
+        String destinationURL = conf.getChild("repository").getAttribute(
+                "destinationURL");
+        getLogger().info("destinationURL:" + destinationURL);
+        getMailstoreMailboxCache().setDestinationURL(destinationURL);
+    }
+
+
+
+    public void addMountPoint(String mountPoint) {
+        if (getMailstoreMailboxCache().getMountPoint() == null) {
+            getLogger().info("set mount point: " + mountPoint);
+            getMailstoreMailboxCache().setMountPoint(mountPoint);
+        } else {
+            throw new RuntimeException("only one mountpoint supported");
+        }
+    }
+    
+    protected MailstoreMailboxCache getMailstoreMailboxCache() {
+        if (mailstoreMailboxCache == null) {
+            mailstoreMailboxCache = new MailstoreMailboxCache();
+            ContainerUtil.enableLogging(mailstoreMailboxCache, getLogger());
+        }
+        return mailstoreMailboxCache;
+    }
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,135 @@
+/****************************************************************
+ * 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.mailboxmanager.mailstore;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.mailboxmanager.repository.MailRepositoryMailboxSession;
+import org.apache.james.services.MailRepository;
+
+public class MailstoreMailboxCache extends AbstractLogEnabled {
+
+    private String mountPoint;
+
+    private String destinationURL;
+
+    private Configuration repositoryConf;
+
+    private Map repositoryCash = new HashMap();
+
+    private Map sessionCash = new HashMap();
+
+    private Store mailStore;
+
+    public MailboxSession getMailboxSession(String mailboxName)
+            throws MailboxManagerException {
+        String url = buildUrl(mailboxName);
+        MailRepository repository = (MailRepository) repositoryCash.get(url);
+        if (repository == null) {
+            try {
+                DefaultConfiguration conf = new DefaultConfiguration(
+                        repositoryConf);
+                conf.setAttribute("destinationURL", url);
+                repository = (MailRepository) getMailStore().select(conf);
+                repositoryCash.put(url, repository);
+                sessionCash.put(url, new HashSet());
+            } catch (Exception e) {
+                getLogger().error("Error optaining repository " + url);
+                throw new MailboxManagerException(e);
+            }
+        }
+        if (repository == null) {
+            throw new MailboxManagerException("could not optain repository "
+                    + url);
+        }
+        HashSet sessions = (HashSet) sessionCash.get(url);
+        MailRepositoryMailboxSession mailboxSession = new MailRepositoryMailboxSession(
+                this, repository, mailboxName);
+        sessions.add(mailboxSession);
+
+        return mailboxSession;
+    }
+
+    public synchronized void releaseSession(MailRepositoryMailboxSession session)
+            throws MailboxManagerException {
+        String mailboxName = session.getName();
+        String url = buildUrl(mailboxName);
+        Set sessions = (Set) sessionCash.get(url);
+        if (sessions != null && sessions.remove(session)) {
+            if (sessions.isEmpty()) {
+                repositoryCash.remove(url);
+            }
+        } else {
+            throw new MailboxManagerException("session not open");
+        }
+    }
+    
+    protected Store getMailStore() {
+        return mailStore;
+    }
+
+    public void setMailStore(Store mailStore) {
+        this.mailStore = mailStore;
+    }
+    
+    String buildUrl(String mailboxName) {
+        String url = destinationURL;
+
+        if (!mailboxName.startsWith(mountPoint)) {
+            throw new AssertionError("mailboxName does not start with "
+                    + mountPoint);
+        }
+        url += mailboxName.substring(mountPoint.length() + 1);
+
+        // TODO maybe INBOX treatment should only be done when in user
+        // namespace
+        if (url.toUpperCase().endsWith(".INBOX")) {
+            url = url.substring(0, url.length() - 6);
+        }
+
+        return url;
+    }
+    
+    public void setRepositoryConf(Configuration repositoryConf) {
+        this.repositoryConf = repositoryConf;
+    }
+
+    public void setDestinationURL(String destinationURL) {
+        this.destinationURL = destinationURL;
+    }
+
+    public String getMountPoint() {
+        return mountPoint;
+    }
+
+    public void setMountPoint(String mountPoint) {
+        this.mountPoint = mountPoint;
+    }
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailstore/MailstoreMailboxCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java Thu Nov 16 11:50:48 2006
@@ -22,13 +22,10 @@
 import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.ListResult;
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.Namespace;
-import org.apache.james.mailboxmanager.Namespaces;
 import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
 import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
 import org.apache.james.mailboxmanager.mailbox.MailboxSession;
-import org.apache.james.services.User;
 
 
 /**
@@ -87,28 +84,6 @@
     GeneralMailboxSession getGeneralMailboxSession(String mailboxName) throws MailboxManagerException;
     
     ImapMailboxSession getImapMailboxSession(String mailboxName) throws MailboxManagerException;
-
-    /**
-     * The Namespaces a user has access to.
-     * @param forUser TODO
-     * @param user
-     * 
-     * @return
-     */
-    Namespaces getNamespaces(User forUser);
-
-    /**
-     * To get the Inbox you can just to a mailbox
-     * defaultNameSpace=ImapMailboxRepository.getPersonalDefaultNameSpace(user)
-     * inbox=defaultNameSpace.getName()+defaultNameSpace.getHierarchyDelimter()+"INBOX";
-     * TODO add a convinience method to get directly a session mailbox for a users inbox
-     * @param forUser TODO
-     * 
-     * @return
-     */
-    Namespace getPersonalDefaultNamespace(User forUser);
-    
-    
 
     void createMailbox(String mailboxName) throws MailboxManagerException;
 

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.mailboxmanager.manager;
+
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.services.User;
+
+public interface MailboxManagerFactory {
+
+    public MailboxManager getMailboxManagerInstance(User user)
+            throws MailboxManagerException;
+
+    public void deleteEverything() throws MailboxManagerException;
+
+    public void addMountPoint(String point);
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java Thu Nov 16 11:50:48 2006
@@ -20,6 +20,8 @@
 package org.apache.james.mailboxmanager.manager;
 
 import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.Namespace;
+import org.apache.james.mailboxmanager.Namespaces;
 import org.apache.james.mailboxmanager.mailbox.MailboxSession;
 import org.apache.james.services.User;
 
@@ -35,13 +37,14 @@
      */
     public void deleteEverything() throws MailboxManagerException;
     
-    MailboxSession getInboxSession(User user);
+    MailboxSession getInboxSession(User user) throws MailboxManagerException;
 
     /** @param authUser the authorized User for checking credentials 
-        @param mailboxName a logical/hierarchical mailbox name **/ 
+        @param mailboxName a logical/hierarchical mailbox name *
+     * @throws MailboxManagerException */ 
 
     MailboxSession getMailboxSession(
-         User authUser, String mailboxName);
+         User authUser, String mailboxName) throws MailboxManagerException;
     
     /**
      * removes all data (mailboxes, quota, acls...) that is associated 
@@ -52,5 +55,26 @@
      */
     
     void deleteAllUserData(User authUser,User targetUser);
+    
+    /**
+     * The Namespaces a user has access to.
+     * @param forUser TODO
+     * @param user
+     * 
+     * @return
+     */
+    Namespaces getNamespaces(User forUser);
+
+    /**
+     * To get the Inbox you can just to a mailbox
+     * defaultNameSpace=ImapMailboxRepository.getPersonalDefaultNameSpace(user)
+     * inbox=defaultNameSpace.getName()+defaultNameSpace.getHierarchyDelimter()+"INBOX";
+     * TODO add a convinience method to get directly a session mailbox for a users inbox
+     * @param forUser TODO
+     * 
+     * @return
+     */
+    Namespace getPersonalDefaultNamespace(User forUser);
+
 
 }

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.mailboxmanager.repository;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.core.MailImpl;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManager;
+import org.apache.james.mailboxmanager.mailstore.MailstoreMailboxCache;
+import org.apache.james.services.MailRepository;
+import org.apache.mailet.Mail;
+
+public class MailRepositoryMailboxSession implements MailboxSession {
+
+    private MailRepository target;
+
+    private MailstoreMailboxCache cache;
+
+    private String name;
+
+
+    public MailRepositoryMailboxSession(MailstoreMailboxCache cache,
+            MailRepository target, String name) {
+        this.cache = cache;
+        this.target = target;
+        this.name = name;
+    }
+
+    public void close() throws MailboxManagerException {
+        cache.releaseSession(this);
+        target=null;
+    }
+
+    public boolean isWriteable() {
+        return true;
+    }
+
+    public int getMessageCount() throws MailboxManagerException {
+        return list().size();
+    }
+
+    public String getName() throws MailboxManagerException {
+        return name;
+    }
+
+    public Collection list() throws MailboxManagerException {
+        try {
+            ArrayList list = new ArrayList();
+            for (Iterator iter = target.list(); iter.hasNext();) {
+                list.add(iter.next());
+            }
+            return list;
+        } catch (MessagingException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+
+    public void remove(String key) throws MailboxManagerException {
+        try {
+            target.remove(key);
+        } catch (MessagingException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+
+    public MimeMessage retrieve(String key) throws MailboxManagerException {
+        try {
+            return target.retrieve(key).getMessage();
+        } catch (MessagingException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+
+    public String store(MimeMessage message) throws MailboxManagerException {
+        try {
+            Mail mail=new MailImpl(message);
+            target.store(mail);
+            return mail.getName();
+        } catch (MessagingException e) {
+            throw new MailboxManagerException(e);
+        }
+        
+    }
+
+    public String update(String key, MimeMessage message)
+            throws MailboxManagerException {
+        try {
+            Mail mail=new MailImpl(key,null,null,message);
+            target.store(mail);
+            return key;
+        } catch (MessagingException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+    
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailRepositoryMailboxSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java Thu Nov 16 11:50:48 2006
@@ -371,7 +371,10 @@
             if (open < 1) {
                 if (open == 0) {
                     if (mailbox != null) {
-                        ((MailboxSession) mailbox).close();
+                        try {
+                            ((MailboxSession) mailbox).close();
+                        } catch (MailboxManagerException e) {
+                        }
                         mailbox=null;
                     }
                 } else {
@@ -386,7 +389,7 @@
                 throw new RuntimeException("use<1 !");
             }
             if (mailbox == null) {
-                Namespace ns = getMailboxManager().getPersonalDefaultNamespace(
+                Namespace ns = mailboxManagerProvider.getPersonalDefaultNamespace(
                         user);
 
                 String inbox=ns.getName() + ns.getHierarchyDelimter()+ "INBOX";

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java Thu Nov 16 11:50:48 2006
@@ -29,11 +29,7 @@
 import org.apache.james.mailboxmanager.ListResult;
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageResult;
-import org.apache.james.mailboxmanager.Namespace;
-import org.apache.james.mailboxmanager.Namespaces;
 import org.apache.james.mailboxmanager.impl.ListResultImpl;
-import org.apache.james.mailboxmanager.impl.NamespaceImpl;
-import org.apache.james.mailboxmanager.impl.NamespacesImpl;
 import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
 import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
@@ -86,7 +82,8 @@
         // prepare to auto-create users Inbox
         
         // TODO inbox-auto-creation for authUser is not optimal. Use a autocreate boolean in getSessionMailbox?
-        String userInbox=getPersonalDefaultNamespace(authUser).getName()+HIERARCHY_DELIMITER+"INBOX";
+        // FIXME should access getPersonalDefaultNameSpace...
+        String userInbox=USER_NAMESPACE+HIERARCHY_DELIMITER+authUser.getUserName()+HIERARCHY_DELIMITER+"INBOX";
         if (userInbox.length()==mailboxName.length()) {
             int del=userInbox.length()-5;
             if (userInbox.substring(0,del).equals(mailboxName.substring(0,del))) {
@@ -137,20 +134,6 @@
        return mailboxCache;
     }
     
-    public Namespaces getNamespaces(User forUser) {
-        NamespacesImpl nameSpaces=new NamespacesImpl();
-        nameSpaces.setShared(new Namespace[0]);
-        Namespace userNamespace=new NamespaceImpl(""+HIERARCHY_DELIMITER,USER_NAMESPACE);
-        nameSpaces.setUser(new Namespace[] {userNamespace}); 
-        Namespace personalDefault = getPersonalDefaultNamespace(forUser);
-        nameSpaces.setPersonal(new Namespace[] {personalDefault}); 
-        nameSpaces.setPersonalDefault(personalDefault);
-        return nameSpaces;
-    }
-
-    public Namespace getPersonalDefaultNamespace(User forUser) {
-        return new NamespaceImpl("" + HIERARCHY_DELIMITER,USER_NAMESPACE+HIERARCHY_DELIMITER+forUser.getUserName());
-    }
 
     public void createMailbox(String namespaceName)
             throws MailboxManagerException {
@@ -320,6 +303,11 @@
             log=new SimpleLog("TorqueMailboxManager");
         }
         return log;
+    }
+
+    public void addMountPoint(String attribute) {
+        // TODO Auto-generated method stub
+        
     }
 
 }

Added: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,243 @@
+/****************************************************************
+ * 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.mailboxmanager.torque;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Locale;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.mailboxmanager.torque.om.MailboxRowPeer;
+import org.apache.james.mailboxmanager.torque.om.MessageBodyPeer;
+import org.apache.james.mailboxmanager.torque.om.MessageFlagsPeer;
+import org.apache.james.mailboxmanager.torque.om.MessageHeaderPeer;
+import org.apache.james.mailboxmanager.torque.om.MessageRowPeer;
+import org.apache.james.mailboxmanager.tracking.MailboxCache;
+import org.apache.james.services.FileSystem;
+import org.apache.james.services.User;
+import org.apache.james.util.SqlResources;
+import org.apache.torque.Torque;
+import org.apache.torque.TorqueException;
+import org.apache.torque.util.BasePeer;
+import org.apache.torque.util.Transaction;
+
+public class TorqueMailboxManagerFactory implements MailboxManagerFactory,
+        Configurable, Initializable, Serviceable {
+
+    private MailboxCache mailboxCache;
+
+    private BaseConfiguration torqueConf;
+
+    private boolean initialized;
+
+    private Log log;
+
+    private FileSystem fileSystem;
+
+    private static final String[] tableNames = new String[] {
+            MailboxRowPeer.TABLE_NAME, MessageRowPeer.TABLE_NAME,
+            MessageHeaderPeer.TABLE_NAME, MessageBodyPeer.TABLE_NAME,
+            MessageFlagsPeer.TABLE_NAME };
+
+    public MailboxManager getMailboxManagerInstance(User user)
+            throws MailboxManagerException {
+        if (!initialized) {
+            throw new MailboxManagerException("must be initialized first!");
+        }
+        return new TorqueMailboxManager(user, getMailboxCache(), getLog());
+    }
+
+    public void initialize() throws Exception {
+        if (!initialized) {
+            if (torqueConf == null) {
+                throw new RuntimeException("must be configured first!");
+            }
+            if (Torque.isInit()) {
+                throw new RuntimeException("Torque is already initialized!");
+            }
+            Connection conn = null;
+            try {
+                Torque.init(torqueConf);
+                conn = Transaction.begin(MailboxRowPeer.DATABASE_NAME);
+                SqlResources sqlResources = new SqlResources();
+                sqlResources.init(fileSystem
+                        .getFile("file://conf/mailboxManagerSqlResources.xml"),
+                        TorqueMailboxManagerFactory.class.getName(), conn,
+                        new HashMap());
+
+                DatabaseMetaData dbMetaData = conn.getMetaData();
+
+                for (int i = 0; i < tableNames.length; i++) {
+                    if (!tableExists(dbMetaData, tableNames[i])) {
+                        BasePeer.executeStatement(sqlResources
+                                .getSqlString("createTable_" + tableNames[i]),
+                                conn);
+                        System.out.println("Created table " + tableNames[i]);
+                        getLog().info("Created table " + tableNames[i]);
+                    }
+                }
+
+                Transaction.commit(conn);
+                initialized = true;
+                System.out.println("MailboxManager has been initialized");
+                getLog().info("MailboxManager has been initialized");
+            } catch (Exception e) {
+                System.err
+                        .println("============================================");
+                e.printStackTrace();
+                System.err
+                        .println("--------------------------------------------");
+                Transaction.safeRollback(conn);
+                try {
+                    Torque.shutdown();
+                } catch (TorqueException e1) {
+
+                }
+                throw new MailboxManagerException(e);
+            }
+        }
+    }
+
+    public void configureDefaults()
+            throws org.apache.commons.configuration.ConfigurationException {
+        File configFile = new File("torque.properties");
+        if (configFile.canRead()) {
+            torqueConf = new PropertiesConfiguration(configFile);
+        } else {
+            torqueConf = new BaseConfiguration();
+            torqueConf.addProperty("torque.database.default", "mailboxmanager");
+            torqueConf.addProperty("torque.database.mailboxmanager.adapter",
+                    "derby");
+            torqueConf.addProperty("torque.dsfactory.mailboxmanager.factory",
+                    "org.apache.torque.dsfactory.SharedPoolDataSourceFactory");
+            torqueConf.addProperty(
+                    "torque.dsfactory.mailboxmanager.connection.driver",
+                    "org.apache.derby.jdbc.EmbeddedDriver");
+            torqueConf.addProperty(
+                    "torque.dsfactory.mailboxmanager.connection.url",
+                    "jdbc:derby:target/testdb;create=true");
+            torqueConf.addProperty(
+                    "torque.dsfactory.mailboxmanager.connection.user", "app");
+            torqueConf.addProperty(
+                    "torque.dsfactory.mailboxmanager.connection.password",
+                    "app");
+            torqueConf.addProperty(
+                    "torque.dsfactory.mailboxmanager.pool.maxActive", "100");
+        }
+    }
+
+    public void configure(
+            org.apache.avalon.framework.configuration.Configuration conf)
+            throws ConfigurationException {
+        torqueConf = new BaseConfiguration();
+        org.apache.avalon.framework.configuration.Configuration[] tps = conf
+                .getChild("torque-properties").getChildren("property");
+        for (int i = 0; i < tps.length; i++) {
+            torqueConf.addProperty(tps[i].getAttribute("name"), tps[i]
+                    .getAttribute("value"));
+        }
+    }
+
+    private boolean tableExists(DatabaseMetaData dbMetaData, String tableName)
+            throws SQLException {
+        return (tableExistsCaseSensitive(dbMetaData, tableName)
+                || tableExistsCaseSensitive(dbMetaData, tableName
+                        .toUpperCase(Locale.US)) || tableExistsCaseSensitive(
+                dbMetaData, tableName.toLowerCase(Locale.US)));
+    }
+
+    private boolean tableExistsCaseSensitive(DatabaseMetaData dbMetaData,
+            String tableName) throws SQLException {
+        ResultSet rsTables = dbMetaData.getTables(null, null, tableName, null);
+        try {
+            boolean found = rsTables.next();
+            return found;
+        } finally {
+            if (rsTables != null) {
+                rsTables.close();
+            }
+        }
+    }
+
+    private MailboxCache getMailboxCache() {
+        if (mailboxCache == null) {
+            mailboxCache = new MailboxCache();
+        }
+        return mailboxCache;
+    }
+
+    public void deleteEverything() throws MailboxManagerException {
+        ((TorqueMailboxManager) getMailboxManagerInstance(null))
+                .deleteEverything();
+        mailboxCache = null;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    public String toString() {
+        return "TorqueMailboxManagerProvider";
+    }
+
+    protected Log getLog() {
+        if (log == null) {
+            log = new SimpleLog("TorqueMailboxManagerProvider");
+        }
+        return log;
+    }
+
+    public void enableLogging(Logger logger) {
+        log = new AvalonLogger(logger);
+
+    }
+
+    public void service(ServiceManager serviceManager) throws ServiceException {
+        setFileSystem((FileSystem) serviceManager.lookup(FileSystem.ROLE));
+    }
+
+    protected void setFileSystem(FileSystem system) {
+        this.fileSystem = system;
+    }
+
+    public void addMountPoint(String point) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/imapserver/mock/MockImapHandlerConfigurationData.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/imapserver/mock/MockImapHandlerConfigurationData.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/imapserver/mock/MockImapHandlerConfigurationData.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/imapserver/mock/MockImapHandlerConfigurationData.java Thu Nov 16 11:50:48 2006
@@ -1,8 +1,26 @@
+/****************************************************************
+ * 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.imapserver.mock;
 
 import org.apache.james.imapserver.ImapHandlerConfigurationData;
 import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
-import org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider;
 import org.apache.james.services.MailServer;
 import org.apache.james.services.UsersRepository;
 

Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import java.io.IOException;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory;
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+public class DefaultMailboxManagerProviderTest extends TestCase {
+
+    private DefaultMailboxManagerProvider mailboxManagerProvider;
+
+    public void setUp() {
+        mailboxManagerProvider = new DefaultMailboxManagerProvider();
+    }
+
+    public void testConfigure() throws ConfigurationException, SAXException,
+            IOException {
+        Configuration confFile = new DefaultConfigurationBuilder()
+                .build(getClass()
+                        .getResourceAsStream(
+                                "/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml"));
+        mailboxManagerProvider.configure(confFile.getChild("mailboxmanager",
+                false));
+        assertTrue(mailboxManagerProvider.getMailboxManagerFactory() instanceof MailboxManagerFactory);
+        MockMailboxManagerFactory factory = (MockMailboxManagerFactory) mailboxManagerProvider
+                .getMailboxManagerFactory();
+        assertEquals(confFile.getChild("mailboxmanager").getChild("factory"),
+                factory.configuration);
+    }
+
+}

Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/DefaultMailboxManagerProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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