Package org.apache.geronimo.kernel.osgi

Source Code of org.apache.geronimo.kernel.osgi.KernelActivator

/*
* 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.geronimo.kernel.osgi;

import java.io.InputStream;
import java.net.URL;
import java.util.Dictionary;

import org.apache.geronimo.gbean.AbstractName;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelFactory;
import org.apache.geronimo.kernel.config.ConfigurationData;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

/**
* @version $Rev: 1324838 $ $Date: 2012-04-12 00:09:46 +0800 (Thu, 12 Apr 2012) $
*/
public class KernelActivator implements BundleActivator {

    private ServiceRegistration kernelRegistration;

    public void start(BundleContext bundleContext) throws Exception {
        Kernel kernel = KernelFactory.newInstance(bundleContext).createKernel("geronimo");
        kernel.boot();
        Dictionary dictionary = null;//new Hashtable();
        kernelRegistration = bundleContext.registerService(Kernel.class.getName(), kernel, dictionary);
        //boot the root configuration
        Bundle bundle = bundleContext.getBundle();
        URL plan = bundle.getEntry("META-INF/config.ser");
        InputStream in = plan.openStream();
        try {
            //TODO there are additional consistency checks in RepositoryConfigurationStore that we should use.
            ConfigurationData data = ConfigurationUtil.readConfigurationData(in);
            data.setBundleContext(bundleContext);
            AbstractName name = ConfigurationUtil.loadBootstrapConfiguration(kernel, data, bundleContext, false);
//            Artifact id = data.getId();
//            manager.startConfiguration(id);
        } finally {
            in.close();
        }

    }

    public void stop(BundleContext bundleContext) throws Exception {
        Kernel kernel = (Kernel) bundleContext.getService(kernelRegistration.getReference());
        kernel.shutdown();
        kernelRegistration.unregister();
        kernelRegistration = null;
    }
}
TOP

Related Classes of org.apache.geronimo.kernel.osgi.KernelActivator

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.