⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avalonmailstore.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**************************************************************** * Licensed to the Apache Software Foundation (ASF) under one   * * or more contributor license agreements.  See the NOTICE file * * distributed with this work for additional information        * * regarding copyright ownership.  The ASF licenses this file   * * to you under the Apache License, Version 2.0 (the            * * "License"); you may not use this file except in compliance   * * with the License.  You may obtain a copy of the License at   * *                                                              * *   http://www.apache.org/licenses/LICENSE-2.0                 * *                                                              * * Unless required by applicable law or agreed to in writing,   * * software distributed under the License is distributed on an  * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       * * KIND, either express or implied.  See the License for the    * * specific language governing permissions and limitations      * * under the License.                                           * ****************************************************************/package org.apache.james.core;import org.apache.avalon.cornerstone.services.store.Store;import org.apache.avalon.framework.activity.Initializable;import org.apache.avalon.framework.component.Composable;import org.apache.avalon.framework.service.DefaultServiceManager;import org.apache.avalon.framework.service.ServiceManager;import org.apache.avalon.framework.service.ServiceException;import org.apache.avalon.framework.service.Serviceable;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.configuration.DefaultConfiguration;import org.apache.avalon.framework.container.ContainerUtil;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.avalon.framework.logger.LogEnabled;import org.apache.commons.collections.ReferenceMap;import java.util.HashMap;import java.util.Map;/** * Provides a registry of mail repositories. A mail repository is uniquely * identified by its destinationURL, type and model. * */public class AvalonMailStore    extends AbstractLogEnabled    implements Contextualizable, Serviceable, Configurable, Initializable, Store {    // Prefix for repository names    private static final String REPOSITORY_NAME = "Repository";    // Static variable used to name individual repositories.  Should only    // be accessed when a lock on the AvalonMailStore.class is held    private static long id;    // map of [destinationURL + type]->Repository    private Map repositories;    // map of [protocol(destinationURL) + type ]->classname of repository;    private Map classes;    // map of [protocol(destinationURL) + type ]->default config for repository.    private Map defaultConfigs;    /**     * 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 ServiceManager       m_manager;    /**     * @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.service.Servicable#service(ServiceManager)     */    public void service( final ServiceManager manager )        throws ServiceException    {        DefaultServiceManager def_manager = new DefaultServiceManager(manager);        def_manager.put(Store.ROLE, this);        m_manager = def_manager;    }    /**     * @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("JamesMailStore init...");        repositories = new ReferenceMap();        classes = new HashMap();        defaultConfigs = new HashMap();        Configuration[] registeredClasses            = configuration.getChild("repositories").getChildren("repository");        for ( int i = 0; i < registeredClasses.length; i++ )        {            registerRepository(registeredClasses[i]);        }    }    /**     * <p>Registers a new mail repository type in the mail store's     * registry based upon a passed in <code>Configuration</code> object.</p>     *     * <p>This is presumably synchronized to prevent corruption of the     * internal registry.</p>     *     * @param repConf the Configuration object used to register the     *                repository     *     * @throws ConfigurationException if an error occurs accessing the     *                                Configuration object     */    public synchronized void registerRepository(Configuration repConf)        throws ConfigurationException {        String className = repConf.getAttribute("class");        boolean infoEnabled = getLogger().isInfoEnabled();        Configuration[] protocols            = repConf.getChild("protocols").getChildren("protocol");        Configuration[] types = repConf.getChild("types").getChildren("type");        for ( int i = 0; i < protocols.length; i++ )        {            String protocol = protocols[i].getValue();            // Get the default configuration for these protocol/type combinations.            Configuration defConf = repConf.getChild("config");            for ( int j = 0; j < types.length; j++ )            {                String type = types[j].getValue();                String key = protocol + type ;                if (infoEnabled) {                    StringBuffer infoBuffer =                        new StringBuffer(128)                            .append("Registering Repository instance of class ")                            .append(className)                            .append(" to handle ")                            .append(protocol)                            .append(" protocol requests for repositories of type ")                            .append(type);                    getLogger().info(infoBuffer.toString());                }                if (classes.get(key) != null) {                    throw new ConfigurationException("The combination of protocol and type comprise a unique key for repositories.  This constraint has been violated.  Please check your repository configuration.");                }                classes.put(key, className);                if (defConf != null) {                    defaultConfigs.put(key, defConf);                }            }        }    }    /**     * This method accept a Configuration object as hint and return the     * corresponding MailRepository.     * The Configuration must be in the form of:     * <repository destinationURL="[URL of this mail repository]"     *             type="[repository type ex. OBJECT or STREAM or MAIL etc.]"     *             model="[repository model ex. PERSISTENT or CACHE etc.]">     *   [addition configuration]     * </repository>     *     * @param hint the Configuration object used to look up the repository     *     * @return the selected repository     *     * @throws ServiceException if any error occurs while parsing the 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -