Package org.jboss.on.embedded.util

Source Code of org.jboss.on.embedded.util.TestBootstrapAction

/*
* Embedded Jopr Project
* Copyright (C) 2006-2009 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.jboss.on.embedded.util;

import java.io.File;
import java.util.Collection;

import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.ServerServices;
import org.rhq.core.pc.plugin.FileSystemPluginFinder;
import org.rhq.core.pc.plugin.PluginEnvironment;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;

import org.jboss.on.embedded.bean.history.operation.OperationServerServiceImpl;
import org.jboss.on.embedded.manager.ResourceManager;
import org.jboss.on.embedded.manager.ResourceManagerFactory;
import org.jboss.on.embedded.manager.history.operation.OperationHistoryManager;

/**
* Seam version of BootstrapServlet
*/
@Name("bootstrapAction")
@Scope(ScopeType.APPLICATION)
@Startup
@Install(precedence = (Install.MOCK))
// TODO this should be renamed TestBootstrapAction
// TODO this should just be able to extend the regular TestBootstrapAction and override
// a getPluginContainerConfiguration method to deal with getting references to the plugins differently
// have to check if we need to override anything else
public class TestBootstrapAction
{
    private static final Log LOG = LogFactory.getLog(TestBootstrapAction.class);

    @In(value = "historyManager", create = true)
    private OperationHistoryManager historyManager;

    @Create
    public void init() throws ServletException
    {
        try
        {
            bootstrap();
        }
        catch (Exception e)
        {
            LOG.error("Error bootstrapping Embedded Console", e);
        }
    }

    private void bootstrap()
            throws Exception
    {
        File pluginDir = new File("target/itest/plugins");

        PluginContainerConfiguration config = new PluginContainerConfiguration();
        config.setPluginFinder(new FileSystemPluginFinder(pluginDir));
        config.setPluginDirectory(pluginDir);

        ServerServices services = new ServerServices();
        OperationServerServiceImpl callbackListener = new OperationServerServiceImpl();
        callbackListener.setHistoryBean(historyManager);

        services.setOperationServerService(callbackListener);
        config.setServerServices(services);

        PluginContainer container = PluginContainer.getInstance();
        container.setConfiguration(config);

        LOG.info("Initializing Plugin Container");

        container.initialize();

        Collection<PluginEnvironment> plugins = container.getPluginManager().getPlugins();
        for (PluginEnvironment pluginEnvironment : plugins)
        {
            LOG.info("Loaded Plugin: " + pluginEnvironment.getPluginName());
        }

        LOG.info("Discovering Services");
        ResourceManager resourceManager = ResourceManagerFactory.resourceManager();
        resourceManager.discoverResources();

        LOG.info("===============================================");
    }
}
TOP

Related Classes of org.jboss.on.embedded.util.TestBootstrapAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.