View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.james.imapserver;
21  
22  
23  import org.apache.avalon.framework.configuration.Configuration;
24  import org.apache.avalon.framework.configuration.ConfigurationException;
25  import org.apache.avalon.framework.logger.Logger;
26  import org.apache.james.imap.api.process.ImapProcessor;
27  import org.apache.james.api.user.UsersRepository;
28  import org.apache.james.imap.mailbox.MailboxManager;
29  import org.apache.james.imap.main.DefaultImapDecoderFactory;
30  import org.apache.james.imap.main.ImapRequestHandler;
31  import org.apache.james.imap.decode.ImapDecoder;
32  import org.apache.james.imap.encode.ImapEncoder;
33  import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
34  import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
35  import org.apache.james.mailboxmanager.torque.DefaultMailboxManager;
36  import org.apache.james.mailboxmanager.torque.DefaultUserManager;
37  import org.apache.james.services.FileSystem;
38  import org.apache.james.user.impl.file.FileUserMetaDataRepository;
39  
40  public class DefaultImapFactory {
41  
42      private final ImapEncoder encoder;
43      private final ImapDecoder decoder;
44      private final ImapProcessor processor;
45      private final DefaultMailboxManager mailboxManager;
46      
47      public DefaultImapFactory(FileSystem fileSystem, UsersRepository users, Logger logger) {
48          super();
49          decoder = new DefaultImapDecoderFactory().buildImapDecoder();
50          encoder = new DefaultImapEncoderFactory().buildImapEncoder();
51          mailboxManager = new DefaultMailboxManager(new DefaultUserManager(
52                  new FileUserMetaDataRepository("var/users"), users), fileSystem, logger);
53          processor = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager);
54      }
55  
56      /**
57       * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
58       */
59      public void configure( final Configuration configuration ) throws ConfigurationException {
60          mailboxManager.configure(configuration);
61      }
62  
63      public void initialize() throws Exception {
64          mailboxManager.initialize();
65      }
66      
67      public ImapRequestHandler createHandler()
68      { 
69          return new ImapRequestHandler(decoder, processor, encoder);
70      }
71  
72      /**
73       * This is required until James supports IoC assembly.
74       * @return the mailbox
75       */
76      public final MailboxManager getMailbox() {
77          return mailboxManager;
78      }    
79  }