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  
21  
22  package org.apache.james.core;
23  
24  import org.apache.avalon.framework.configuration.Configuration;
25  import org.apache.james.api.user.UsersRepository;
26  import org.apache.james.api.user.UsersStore;
27  
28  import java.util.Iterator;
29  
30  /**
31   * Provides a registry of user repositories.
32   *
33   */
34  public class AvalonUsersStore
35      extends AbstractAvalonStore
36      implements UsersStore {
37  
38      /** 
39       * Get the repository, if any, whose name corresponds to
40       * the argument parameter
41       *
42       * @param name the name of the desired repository
43       *
44       * @return the UsersRepository corresponding to the name parameter
45       */
46      public UsersRepository getRepository(String name) {
47          UsersRepository response = (UsersRepository) getObject(name);
48          if ((response == null) && (getLogger().isWarnEnabled())) {
49              getLogger().warn("No users repository called: " + name);
50          }
51          return response;
52      }
53  
54      /** 
55       * Yield an <code>Iterator</code> over the set of repository
56       * names managed internally by this store.
57       *
58       * @return an Iterator over the set of repository names
59       *         for this store
60       */
61      public Iterator getRepositoryNames() {
62          return getObjectNames();
63      }
64      
65      /**
66       * @see org.apache.james.core.AbstractAvalonStore#getClassInstance(java.lang.ClassLoader, java.lang.String)
67       */
68      public Object getClassInstance(ClassLoader loader, String repClass) throws Exception {
69          return  (UsersRepository) loader.loadClass(repClass).newInstance();
70      }
71  
72      /**
73       * @see org.apache.james.core.AbstractAvalonStore#getConfigurations(org.apache.avalon.framework.configuration.Configuration)
74       */
75      public Configuration[] getConfigurations(Configuration config) {
76          return configuration.getChildren("repository");
77      }
78      
79      /**
80       * @see org.apache.james.core.AbstractAvalonStore#getStoreName()
81       */
82      public String getStoreName() {
83          return "AvolonUsersStore";
84      }
85  }