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

📄 raplamaincontainer.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.logger.Logger;
import org.rapla.components.util.IOUtil;
import org.rapla.components.xmlbundle.I18nBundle;
import org.rapla.components.xmlbundle.LocaleSelector;
import org.rapla.components.xmlbundle.impl.I18nBundleImpl;
import org.rapla.entities.domain.AppointmentFormater;
import org.rapla.framework.PluginDescriptor;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaDefaultContext;
import org.rapla.framework.RaplaException;
import org.rapla.framework.RaplaLocale;
import org.rapla.framework.StartupEnvironment;
import org.rapla.framework.internal.ConfigTools;
import org.rapla.framework.internal.ContainerImpl;
import org.rapla.framework.internal.LogManagerAdapter;
import org.rapla.gui.CalendarOptions;
import org.rapla.gui.CalendarOptionsImpl;
import org.rapla.server.ShutdownService;
import org.rapla.server.internal.ShutdownServiceImpl;
/**
The Rapla Main Container class for the basic container for Rapla specific services and the rapla plugin architecture.
The rapla container has only one instance at runtime. Configuration of the RaplaMainContainer is done in the rapla*.xconf
files. Typical configurations of the MainContainer are

 <ol>
 <li>Standalone (rapla.xconf): A ClientService, one facade (with preconfigured auto admin login) and a storage (file).</li>
 <li>Client (raplaclient.xconf ): A ClientService, one facade (without auto login) and a remote storage ( automaticaly pointing to the download server in webstart mode)</li>
 <li>Server (raplaserver.xconf ): A ServerService (providin a facade) a messaging server for handling the connections with the clients, a storage (file or db) and an extra service for importing and exporting in the db</li>
 <li>Embedded: Configuration example follows.</li>
 </ol>
<p>
The Main Container provides the following Services to all RaplaComponents
<ul>
<li>I18nBundle</li>
<li>AppointmentFormater</li>
<li>RaplaLocale</li>
<li>LocaleSelector</li>
<li>RaplaMainContainer.PLUGIN_LIST (A list of all available plugins)</li>
</ul>
</p>

  @see I18nBundle
  @see RaplaLocale
  @see AppointmentFormater
  @see LocaleSelector
 */
final public class RaplaMainContainer extends ContainerImpl
{
    public RaplaMainContainer() throws Exception {
        this(new RaplaStartupEnvironment());
    }

    public RaplaMainContainer(RaplaStartupEnvironment env) throws Exception {
        this( createRaplaContext(env,env.getLoggerConfig()),env  );
    }

    public RaplaMainContainer(StartupEnvironment env) throws Exception {
        this( createRaplaContext(env, null),env  );
    }

    RaplaMainContainer( RaplaContext context, StartupEnvironment env) throws Exception{
        super( context, env.getStartupConfiguration() );
        addContainerProvidedComponentInstance( StartupEnvironment.ROLE, env);
        addContainerProvidedComponentInstance( "download-server", env.getDownloadURL().getHost());
        addContainerProvidedComponentInstance( "download-url",  env.getDownloadURL());
        if (env.getContextRootURL() != null)
        {
            addContainerProvidedComponentInstance( "context-root", IOUtil.getFileFrom( env.getContextRootURL()));
        }
        initialize();
        
    }


    private static RaplaContext createRaplaContext( StartupEnvironment env, Configuration loggerConfig ) throws RaplaException
    {
        Logger logger = env.getBootstrapLogger();
        LogManagerAdapter logManager = null;
        if ( loggerConfig != null ) {
            if ( checkForAvalonLogManager()) {
                logManager = new RaplaLogKitAdapater( env, loggerConfig );
                // Replace bootstrap logger with new logkit logger
                logger = logManager.getDefaultLogger();
            } else {
                logger.warn("avalon logging jar not found. Using bootstrap logger.");
            }
        }

        RaplaDefaultContext context = new RaplaDefaultContext();
        if ( logManager != null)
        {
            context.put("logger-manager", logManager);
        }
        context.put( Logger.class.getName(),  logger);

        return context;
    }

    private static boolean checkForAvalonLogManager()
    {
        try {
            Class.forName("org.apache.avalon.excalibur.logger.LogKitLoggerManager");
            return true;
        } catch (Throwable ex ) {
            return false;
        }
    }

    protected Map getComponentInfos() {
        return new RaplaMetaConfigInfo();

    }

    private void initialize() throws Exception {
        addContainerProvidedComponent( ShutdownService.ROLE, ShutdownServiceImpl.class.getName());
        
        CalendarOptions calendarOptions = new CalendarOptionsImpl(m_config.getChild("locale"));
        addContainerProvidedComponentInstance( CalendarOptions.ROLE, calendarOptions );

        RaplaLocaleImpl raplaLocale = new RaplaLocaleImpl(m_config.getChild("locale"));
        addContainerProvidedComponentInstance( RaplaLocale.ROLE,raplaLocale);
        addContainerProvidedComponentInstance( LocaleSelector.ROLE,raplaLocale.getLocaleSelector());

        Configuration[] defaultBundles = m_config.getChildren("default-bundle");
        for ( int i=0;i< defaultBundles.length;i++) {
        	String defaultBundleName = defaultBundles[i].getValue();
            addContainerProvidedComponent
            (
             I18nBundle.ROLE
             ,I18nBundleImpl.class.getName()
             ,defaultBundleName
             ,I18nBundleImpl.createConfig( defaultBundleName )
             );
        }

        addContainerProvidedComponent
        (
         I18nBundle.ROLE
         ,I18nBundleImpl.class.getName()
         ,"org.rapla.RaplaResources"
         ,I18nBundleImpl.createConfig( "org.rapla.RaplaResources" )
         );

        addContainerProvidedComponentInstance( AppointmentFormater.ROLE, new AppointmentFormaterImpl( getContext()));

        // Override the intern Resource Bundle with user provided
        for ( int i=0;i< defaultBundles.length;i++) {
        	String defaultBundleName = defaultBundles[i].getValue();
            I18nBundleImpl i18n = (I18nBundleImpl)getContext().lookup( I18nBundle.ROLE + "/" + defaultBundleName);
            String parentId = i18n.getParentId();
            if ( parentId != null) {
            	addContainerProvidedComponentInstance(I18nBundle.ROLE,parentId, i18n);
            }
        }

        // Discover and register the plugins for Rapla
        Enumeration pluginEnum =  ConfigTools.class.getClassLoader().getResources("META-INF/rapla-plugin.list");
        List pluginList = new ArrayList( );
        while ( pluginEnum.hasMoreElements() ) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(((URL)pluginEnum.nextElement()).openStream()));
            while ( true ) {
                String plugin = reader.readLine();
                if ( plugin == null)
                    break;
                pluginList.add((PluginDescriptor) instanciate(plugin, null, getLogger()));
            }
        }
        addContainerProvidedComponentInstance( PluginDescriptor.PLUGIN_LIST, pluginList);

    }

    public void dispose() {
        getLogger().info("Shuting down rapla-container");
        super.dispose();
    }


 }

⌨️ 快捷键说明

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