Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Fabric3
   * Copyright (c) 2009 Metaform Systems
   *
   * Fabric3 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, either version 3 of
   * the License, or (at your option) any later version, with the
   * following exception:
  *
  * Linking this software statically or dynamically with other
  * modules is making a combined work based on this software.
  * Thus, the terms and conditions of the GNU General Public
  * License cover the whole combination.
  *
  * As a special exception, the copyright holders of this software
  * give you permission to link this software with independent
  * modules to produce an executable, regardless of the license
  * terms of these independent modules, and to copy and distribute
  * the resulting executable under terms of your choice, provided
  * that you also meet, for each linked independent module, the
  * terms and conditions of the license of that module. An
  * independent module is a module which is not derived from or
  * based on this software. If you modify this software, you may
  * extend this exception to your version of the software, but
  * you are not obligated to do so. If you do not wish to do so,
  * delete this exception statement from your version.
  *
  * Fabric3 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 General Public License for more details.
  *
  * You should have received a copy of the
  * GNU General Public License along with Fabric3.
  * If not, see <http://www.gnu.org/licenses/>.
  *
  * ----------------------------------------------------
  *
  * Portions originally based on Apache Tuscany 2007
  * licensed under the Apache 2.0 license.
  *
  */
 package org.fabric3.fabric.runtime.bootstrap;
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 
 import static org.fabric3.host.Names.BOOT_CONTRIBUTION;
 import static org.fabric3.host.Names.HOST_CONTRIBUTION;
The base Bootstrapper implementation.

Version:
$Rev: 8495 $ $Date: 2009-12-31 13:05:04 +0100 (Thu, 31 Dec 2009) $
public abstract class AbstractBootstrapper implements Bootstrapper {
    private static final URI RUNTIME_SERVICES = URI.create("fabric3://RuntimeServices");
    // bootstrap components - these are disposed of after the core runtime system components are booted
    // runtime components - these are persistent and supplied by the runtime implementation
    private MetaDataStore metaDataStore;
    private ScopeRegistry scopeRegistry;
    private XMLFactory xmlFactory;
    private Domain runtimeDomain;
    private Fabric3Runtime<?> runtime;
    private ClassLoader bootClassLoader;
    private Map<StringStringexportedPackages;
    private ClassLoader hostClassLoader;
    protected AbstractBootstrapper(XMLFactory xmlFactory) {
        this. = xmlFactory;
        // create components needed for to bootstrap the runtime
        IntrospectionHelper helper = new DefaultIntrospectionHelper();
         = new JavaContractProcessorImpl(helper);
         = BootstrapIntrospectionFactory.createSystemImplementationProcessor();
    }
    public void bootRuntimeDomain(Fabric3Runtime<?> runtime,
                                  ClassLoader bootClassLoader,
                                  List<ComponentRegistrationcomponents,
                                  Map<StringStringexportedPackagesthrows InitializationException {
        this. = runtime;
        this. = bootClassLoader;
        this. = exportedPackages;
        // classloader shared by extension and application classes
        this. = runtime.getHostClassLoader();
         = runtime.getMonitorFactory();
        HostInfo hostInfo = runtime.getHostInfo();
        RuntimeServices runtimeServices = runtime.getComponent(RuntimeServices.class);
         = runtimeServices.getLogicalComponentManager();
         = runtimeServices.getComponentManager();
         = runtimeServices.getClassLoaderRegistry();
         = runtimeServices.getMetaDataStore();
         = runtimeServices.getScopeRegistry();
         = runtimeServices.getScopeContainer();
                                                        ,
                                                        ,
                                                        ,
                                                        ,
                                                        );
        // register primordial components provided by the runtime itself
        registerRuntimeComponents(components);
        MBeanServer mbeanServer = runtime.getMBeanServer();
         = BootstrapAssemblyFactory.createDomain(,
                                                              ,
                                                              ,
                                                              ,
                                                              ,
                                                              ,
                                                              mbeanServer,
                                                              hostInfo);
        // create and register bootstrap components provided by this bootstrapper
        registerDomain();
        // register the classloaders
        synthesizeContributions();
    }
    public void bootSystem() throws InitializationException {
        try {
            // load the system composite
            // load system configuration
            Document systemConfig = loadSystemConfig();
            if (systemConfig != null) {
                LogicalProperty logicalProperty = new LogicalProperty("systemConfig"systemConfigfalse);
                .setProperties(logicalProperty);
            }
            // deploy the composite to the runtime domain
            .include(composite);
        } catch (DeploymentException e) {
            throw new InitializationException(e);
        }
    }
    protected XMLFactory getXmlFactory() {
        return ;
    }

    
Loads the composite that supplies core system components to the runtime.

Parameters:
contributionUri the synthetic contrbution URI the core components are part of
bootClassLoader the classloader core components are loaded in
processor the ImplementationProcessor for introspecting component implementations.
Returns:
the loaded composite
Throws:
org.fabric3.host.runtime.InitializationException if an error occurs loading the composite
    protected abstract Composite loadSystemComposite(URI contributionUri,
                                                     ClassLoader bootClassLoader,
                                                     ImplementationProcessor<SystemImplementationprocessorthrows InitializationException;

    
Subclasses return a Document representing the domain-level runtime configuration property or null if none is defined. This property may be referenced entirely or in part via XPath by components in the runtime domain to supply configuration values.

Returns:
a Document representing the domain-level user configuration property or null if none is defined
Throws:
org.fabric3.host.runtime.InitializationException if an error occurs loading the configuration file
    protected abstract Document loadSystemConfig() throws InitializationException;

    
Registers the primordial runtime components.

Parameters:
registrations host components to register
Throws:
InitializationException if there is an error during registration
    @SuppressWarnings({"unchecked"})
    private <T extends HostInfo, S, I extends S> void registerRuntimeComponents(List<ComponentRegistrationregistrations)
            throws InitializationException {
        // services available through the outward facing Fabric3Runtime API
        registerComponent("MonitorFactory"MonitorFactory.classtrue);
        Class<T> type = (Class<T>) .getHostInfoType();
        T info = (T) .getHostInfo();
        registerComponent("HostInfo"typeinfotrue);
        MBeanServer mbServer = .getMBeanServer();
        if (mbServer != null) {
            registerComponent("MBeanServer"MBeanServer.classmbServerfalse);
        }
        // services available through the inward facing RuntimeServices SPI
        registerComponent("ComponentManager"ComponentManager.classtrue);
        registerComponent("RuntimeLogicalComponentManager"LogicalComponentManager.classtrue);
        registerComponent("CompositeScopeContainer"ScopeContainer.classtrue);
        registerComponent("ClassLoaderRegistry"ClassLoaderRegistry.classtrue);
        registerComponent("ScopeRegistry"ScopeRegistry.classtrue);
        registerComponent("MetaDataStore"MetaDataStore.classtrue);
        // register other components provided by the host environment
        for (ComponentRegistration registration : registrations) {
            String name = registration.getName();
            Class<S> service = (Class<S>) registration.getService();
            I instance = (I) registration.getInstance();
            boolean introspect = registration.isIntrospect();
            registerComponent(nameserviceinstanceintrospect);
        }
    }

    
Registers the runtime domain

Throws:
org.fabric3.host.runtime.InitializationException if there is an error during registration
    private void registerDomain() throws InitializationException {
        registerComponent("RuntimeDomain"Domain.classtrue);
        // the following initializes the Domain and MetaDataStore so they may be reinjected
    }


    
Registers a primordial component

Parameters:
name the component name
type the service interface type
instance the component instance
introspect true if the component should be introspected for references
Throws:
org.fabric3.host.runtime.InitializationException if there is an error during registration
    private <S, I extends S> void registerComponent(String nameClass<S> type, I instanceboolean introspectthrows InitializationException {
        try {
            .registerComponent(nametypeinstanceintrospect);
        } catch (ComponentRegistrationException e) {
            throw new InitializationException(e);
        }
    }

    
Creates contributions for the host and boot classloaders. These contributions may be imported by extensions and user contributions.

Throws:
org.fabric3.host.runtime.InitializationException if there is an error synthesizing the contributions
    private void synthesizeContributions() throws InitializationException {
        try {
            // export packages included in JDK 6
            synthesizeContribution(, Java6HostExports.getExports(), );
            // add default boot exports
            .putAll(BootExports.getExports());
        } catch (ContributionException e) {
            throw new InitializationException(e);
        }
    }

    
Synthesizes a contribution from a classloader and installs it.

Parameters:
contributionUri the contribution URI
exportedPackages the packages exported by the contribution
loader the classloader
Throws:
org.fabric3.host.contribution.ContributionException if there is an error synthesizing the contribution
    private void synthesizeContribution(URI contributionUriMap<StringStringexportedPackagesClassLoader loader)
            throws ContributionException {
        Contribution contribution = new Contribution(contributionUri);
        contribution.setState(.);
        ContributionManifest manifest = contribution.getManifest();
        // add the ContributionExport
        manifest.addExport(new ContributionExport(contributionUri));
        for (Map.Entry<StringStringentry : exportedPackages.entrySet()) {
            PackageVersion version = new PackageVersion(entry.getValue());
            PackageInfo info = new PackageInfo(entry.getKey(), version);
            JavaExport export = new JavaExport(info);
            manifest.addExport(export);
        }
        .store(contribution);
        .register(contributionUriloader);
    }
New to GrepCode? Check out our FAQ X