📄 avalonusersstore.java
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation. * * All rights reserved. * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You * * may obtain a copy of the License at: * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * * implied. See the License for the specific language governing * * permissions and limitations under the License. * ***********************************************************************/package org.apache.james.core;import org.apache.avalon.framework.activity.Initializable;import org.apache.avalon.framework.component.Component;import org.apache.avalon.framework.component.ComponentException;import org.apache.avalon.framework.component.ComponentManager;import org.apache.avalon.framework.component.Composable;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.context.Context;import org.apache.avalon.framework.context.ContextException;import org.apache.avalon.framework.context.Contextualizable;import org.apache.avalon.framework.logger.AbstractLogEnabled;import org.apache.james.services.UsersRepository;import org.apache.james.services.UsersStore;import java.util.HashMap;import java.util.Iterator;/** * Provides a registry of user repositories. * */public class AvalonUsersStore extends AbstractLogEnabled implements Component, Contextualizable, Composable, Configurable, Initializable, UsersStore { /** * A mapping of respository identifiers to actual repositories * This mapping is obtained from the component configuration */ private HashMap repositories; /** * The Avalon context used by the instance */ protected Context context; /** * The Avalon configuration used by the instance */ protected Configuration configuration; /** * The Avalon component manager used by the instance */ protected ComponentManager componentManager; /** * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context) */ public void contextualize(final Context context) throws ContextException { this.context = context; } /** * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager) */ public void compose( final ComponentManager componentManager ) throws ComponentException { this.componentManager = componentManager; } /** * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */ public void configure( final Configuration configuration ) throws ConfigurationException { this.configuration = configuration; } /** * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { getLogger().info("AvalonUsersStore init..."); repositories = new HashMap(); Configuration[] repConfs = configuration.getChildren("repository"); ClassLoader theClassLoader = null; for ( int i = 0; i < repConfs.length; i++ ) { Configuration repConf = repConfs[i]; String repName = repConf.getAttribute("name"); String repClass = repConf.getAttribute("class"); if (getLogger().isDebugEnabled()) { getLogger().debug("Starting " + repClass); } if (theClassLoader == null) { theClassLoader = this.getClass().getClassLoader(); } UsersRepository rep = (UsersRepository) theClassLoader.loadClass(repClass).newInstance(); setupLogger((Component)rep); if (rep instanceof Contextualizable) { ((Contextualizable) rep).contextualize(context); } if (rep instanceof Composable) { ((Composable) rep).compose( componentManager ); } if (rep instanceof Configurable) { ((Configurable) rep).configure(repConf); } if (rep instanceof Initializable) { ((Initializable) rep).initialize(); } repositories.put(repName, rep); if (getLogger().isInfoEnabled()) { StringBuffer logBuffer = new StringBuffer(64) .append("UsersRepository ") .append(repName) .append(" started."); getLogger().info(logBuffer.toString()); } } getLogger().info("AvalonUsersStore ...init"); } /** * Get the repository, if any, whose name corresponds to * the argument parameter * * @param name the name of the desired repository * * @return the UsersRepository corresponding to the name parameter */ public UsersRepository getRepository(String name) { UsersRepository response = (UsersRepository) repositories.get(name); if ((response == null) && (getLogger().isWarnEnabled())) { getLogger().warn("No users repository called: " + name); } return response; } /** * Yield an <code>Iterator</code> over the set of repository * names managed internally by this store. * * @return an Iterator over the set of repository names * for this store */ public Iterator getRepositoryNames() { return this.repositories.keySet().iterator(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -