tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r524852 - in /incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core: bootstrap/ component/ deployer/ implementation/composite/ loader/ model/ runtime/ wire/
Date Mon, 02 Apr 2007 17:47:44 GMT
Author: rfeng
Date: Mon Apr  2 10:47:43 2007
New Revision: 524852

URL: http://svn.apache.org/viewvc?view=rev&rev=524852
Log:
Bring up the minicore

Added:
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java   (with props)
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.java
      - copied unchanged from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/CallbackReferenceImpl.java
      - copied unchanged from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/CallbackReferenceImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
      - copied, changed from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.java
      - copied unchanged from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
      - copied unchanged from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java   (with props)
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java   (with props)
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/
      - copied from r523780, incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/loader/
Removed:
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/DependencyLoader.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/JNDIPropertyFactory.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/model/
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorGenerator.java
Modified:
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
    incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java

Modified: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java?view=diff&rev=524852&r1=524851&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java Mon Apr  2 10:47:43 2007
@@ -18,16 +18,12 @@
  */
 package org.apache.tuscany.core.bootstrap;
 
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.host.MonitorFactory;
 import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.ComponentManager;
 import org.apache.tuscany.spi.component.ScopeRegistry;
-import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.deployer.Deployer;
-import org.apache.tuscany.spi.implementation.java.Introspector;
-import org.apache.tuscany.spi.loader.Loader;
-import org.apache.tuscany.spi.loader.PropertyObjectFactory;
-
-import org.apache.tuscany.core.resolver.AutowireResolver;
-import org.apache.tuscany.host.MonitorFactory;
 
 /**
  * Interface that abstracts the process used to create a running Tuscany system. Implementation of this may provide
@@ -58,7 +54,7 @@
      *
      * @return a new primordial ScopeRegistry
      */
-    ScopeRegistry createScopeRegistry();
+    ScopeRegistry getScopeRegistry();
 
     /**
      * Create a Connector that can wire together primordial components.
@@ -73,5 +69,7 @@
      * @return the AutowireResolver that resolves autowire targets
      */
     AutowireResolver getAutowireResolver();
+    
+    ComponentManager getComponentManager();
 
 }

Modified: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java?view=diff&rev=524852&r1=524851&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java Mon Apr  2 10:47:43 2007
@@ -22,10 +22,24 @@
 
 import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
 import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.binding.local.LocalBindingLoader;
 import org.apache.tuscany.core.builder.BuilderRegistryImpl;
+import org.apache.tuscany.core.component.scope.AbstractScopeContainer;
 import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.RequestScopeContainer;
 import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
 import org.apache.tuscany.core.deployer.DeployerImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeBuilder;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentTypeLoader;
+import org.apache.tuscany.core.implementation.composite.CompositeLoader;
+import org.apache.tuscany.core.loader.ComponentLoader;
+import org.apache.tuscany.core.loader.ComponentTypeElementLoader;
+import org.apache.tuscany.core.loader.IncludeLoader;
+import org.apache.tuscany.core.loader.LoaderRegistryImpl;
+import org.apache.tuscany.core.loader.PropertyLoader;
+import org.apache.tuscany.core.loader.ReferenceLoader;
+import org.apache.tuscany.core.loader.ServiceLoader;
 import org.apache.tuscany.core.resolver.AutowireResolver;
 import org.apache.tuscany.host.MonitorFactory;
 import org.apache.tuscany.spi.builder.Builder;
@@ -35,12 +49,16 @@
 import org.apache.tuscany.spi.component.ScopeRegistry;
 import org.apache.tuscany.spi.deployer.Deployer;
 import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.loader.Loader;
 import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.CompositeImplementation;
 
 /**
- * A default implementation of a Bootstrapper. Please see the documentation on the individual methods for how the
- * primordial components are created.
- *
+ * A default implementation of a Bootstrapper. Please see the documentation on
+ * the individual methods for how the primordial components are created.
+ * 
  * @version $Rev$ $Date$
  */
 public class DefaultBootstrapper implements Bootstrapper {
@@ -53,32 +71,31 @@
 
     /**
      * Create a default bootstrapper.
-     *
-     * @param monitorFactory   the MonitorFactory to be used to create monitors for the primordial components
-     * @param xmlFactory       the XMLInputFactory to be used by the components to load XML artifacts
+     * 
+     * @param monitorFactory the MonitorFactory to be used to create monitors
+     *            for the primordial components
+     * @param xmlFactory the XMLInputFactory to be used by the components to
+     *            load XML artifacts
      * @param componentManager the component manager for the runtime instance
-     * @param resolver         the autowire resolver for the runtime instance
-     * @param connector        the connector for the runtime instance
-     * @param scopeRegistry    the scope registry for the runtime instance
+     * @param resolver the autowire resolver for the runtime instance
+     * @param connector the connector for the runtime instance
      */
     public DefaultBootstrapper(MonitorFactory monitorFactory,
                                XMLInputFactory xmlFactory,
                                ComponentManager componentManager,
                                AutowireResolver resolver,
-                               Connector connector,
-                               ScopeRegistry scopeRegistry
-    ) {
+                               Connector connector) {
         this.monitorFactory = monitorFactory;
         this.xmlFactory = xmlFactory;
         this.componentManager = componentManager;
         this.resolver = resolver;
         this.connector = connector;
-        this.scopeRegistry = scopeRegistry;
+        this.scopeRegistry = createScopeRegistry();
     }
 
     /**
      * Returns the MonitorFactory being used by this bootstrapper.
-     *
+     * 
      * @return the MonitorFactory being used by this bootstrapper
      */
     public MonitorFactory getMonitorFactory() {
@@ -86,71 +103,122 @@
     }
 
     /**
-     * Create primordial deployer that can be used to load the system definition.
-     *
+     * Create primordial deployer that can be used to load the system
+     * definition.
+     * 
      * @return the primordial deployer
      */
     public Deployer createDeployer() {
+        ScopeRegistry scopeRegistry = getScopeRegistry();
         Builder builder = createBuilder(scopeRegistry);
-        DeployerImpl deployer = new DeployerImpl(xmlFactory, builder, componentManager, resolver, connector);
+        Loader loader = createLoader(null, null);
+        DeployerImpl deployer = new DeployerImpl(xmlFactory, loader, builder, componentManager, resolver, connector);
         deployer.setMonitor(getMonitorFactory().getMonitor(ScopeContainerMonitor.class));
-        deployer.setScopeRegistry(scopeRegistry);
+        deployer.setScopeRegistry(getScopeRegistry());
         return deployer;
     }
 
     /**
-     * Create a basic ScopeRegistry containing the ScopeContainers that are available to components in the system
-     * definition. The implementation returned only support COMPOSITE scope.
-     *
+     * Create a basic ScopeRegistry containing the ScopeContainers that are
+     * available to components in the system definition. The implementation
+     * returned only support COMPOSITE scope.
+     * 
      * @return a new ScopeRegistry
      */
-    public ScopeRegistry createScopeRegistry() {
+    private ScopeRegistry createScopeRegistry() {
         ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
-        CompositeScopeContainer scopeContainer =
-            new CompositeScopeContainer(monitorFactory.getMonitor(ScopeContainerMonitor.class));
-        scopeContainer.start();
-        scopeRegistry.register(scopeContainer);
+        ScopeContainerMonitor monitor = monitorFactory.getMonitor(ScopeContainerMonitor.class);
+        AbstractScopeContainer[] containers = new AbstractScopeContainer[] {new CompositeScopeContainer(monitor),
+                                                                            new StatelessScopeContainer(monitor),
+                                                                            new RequestScopeContainer(monitor),
+        // new ConversationalScopeContainer(monitor),
+        // new HttpSessionScopeContainer(monitor)
+        };
+        for (AbstractScopeContainer c : containers) {
+            c.start();
+            scopeRegistry.register(c);
+        }
+
         return scopeRegistry;
     }
 
-
     /**
-     * Create a new Connector that can be used to wire primordial components together.
-     *
+     * Create a new Connector that can be used to wire primordial components
+     * together.
+     * 
      * @return a new Connector
      */
     public Connector getConnector() {
         return connector;
     }
 
-
     public AutowireResolver getAutowireResolver() {
         return resolver;
     }
 
     /**
-     * Helper method for registering a loader with the registry. The Loader is registered once for the QName returned by
-     * its {@link LoaderExtension#getXMLType()} method.
-     *
+     * Helper method for registering a loader with the registry. The Loader is
+     * registered once for the QName returned by its
+     * {@link LoaderExtension#getXMLType()} method.
+     * 
      * @param registry the LoaderRegistry to register with
-     * @param loader   the Loader to register
+     * @param loader the Loader to register
      */
     protected void registerLoader(LoaderRegistry registry, LoaderExtension<?> loader) {
         registry.registerLoader(loader.getXMLType(), loader);
     }
 
+    public LoaderRegistry createLoader(PropertyObjectFactory propertyFactory, Introspector introspector) {
+        LoaderRegistryImpl loaderRegistry = new LoaderRegistryImpl(monitorFactory
+            .getMonitor(LoaderRegistryImpl.Monitor.class));
+
+        // register element loaders
+        registerLoader(loaderRegistry, new ComponentLoader(loaderRegistry, propertyFactory));
+        registerLoader(loaderRegistry, new ComponentTypeElementLoader(loaderRegistry));
+        registerLoader(loaderRegistry, new CompositeLoader(loaderRegistry, null));
+        registerLoader(loaderRegistry, new IncludeLoader(loaderRegistry));
+        registerLoader(loaderRegistry, new PropertyLoader(loaderRegistry));
+        registerLoader(loaderRegistry, new ReferenceLoader(loaderRegistry));
+        registerLoader(loaderRegistry, new ServiceLoader(loaderRegistry));
+        registerLoader(loaderRegistry, new LocalBindingLoader(loaderRegistry));
+
+        loaderRegistry.registerLoader(CompositeImplementation.class, new CompositeComponentTypeLoader(loaderRegistry));
+        return loaderRegistry;
+    }
+
     /**
-     * Create a Builder that can be used to build the components in the system definition. The default implementation
-     * only supports implementations from the system programming model.
-     *
-     * @param scopeRegistry the ScopeRegistry defining the component scopes that will be supported
+     * Create a Builder that can be used to build the components in the system
+     * definition. The default implementation only supports implementations from
+     * the system programming model.
+     * 
+     * @param scopeRegistry the ScopeRegistry defining the component scopes that
+     *            will be supported
      * @return a new Builder
      */
     private Builder createBuilder(ScopeRegistry scopeRegistry) {
-        BuilderRegistryImpl builderRegistry =
-            new BuilderRegistryImpl(scopeRegistry);
+        BuilderRegistryImpl builderRegistry = new BuilderRegistryImpl(scopeRegistry);
+        CompositeBuilder compositeBuilder = new CompositeBuilder();
+        compositeBuilder.setBuilderRegistry(builderRegistry);
+        compositeBuilder.setScopeRegistry(scopeRegistry);
+        compositeBuilder.init();
+        // builderRegistry.register(CompositeImplementation.class,
+        // compositeBuilder);
         builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
         return builderRegistry;
+    }
+
+    /**
+     * @return the componentManager
+     */
+    public ComponentManager getComponentManager() {
+        return componentManager;
+    }
+
+    /**
+     * @return the scopeRegistry
+     */
+    public ScopeRegistry getScopeRegistry() {
+        return scopeRegistry;
     }
 
 }

Added: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java?view=auto&rev=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java (added)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java Mon Apr  2 10:47:43 2007
@@ -0,0 +1,31 @@
+/*
+ * 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.tuscany.core.bootstrap;
+
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ExtensionActivator {
+    void start(LoaderRegistry loaderRegistry, BuilderRegistry builderRegistry);
+    void stop();
+}

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/bootstrap/ExtensionActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java (from r521965, incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java?view=diff&rev=524852&p1=incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java&r1=521965&p2=incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java Mon Apr  2 10:47:43 2007
@@ -25,6 +25,9 @@
 import org.osoa.sca.ServiceRuntimeException;
 
 import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
 
 /**
  * Implementation of ComponentContext that delegates to a ComponentContextProvider.
@@ -79,7 +82,9 @@
     }
 
     public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
-        return null;
+        // FIXME: How to get the ObjectFactory?
+        ObjectFactory<B> factory = ((AtomicComponent) component).createObjectFactory();
+        return new ServiceReferenceImpl<B>(businessInterface, factory);
     }
 
     public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {

Modified: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java?view=diff&rev=524852&r1=524851&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java Mon Apr  2 10:47:43 2007
@@ -55,20 +55,24 @@
  */
 public class DeployerImpl implements Deployer {
     private XMLInputFactory xmlFactory;
+    private Loader loader;
     private Builder builder;
     private ScopeContainerMonitor monitor;
     private AutowireResolver resolver;
     private Connector connector;
     private ComponentManager componentManager;
     private ScopeRegistry scopeRegistry;
+    
 
     public DeployerImpl(XMLInputFactory xmlFactory,
+                        Loader loader,
                         Builder builder,
                         ComponentManager componentManager,
                         AutowireResolver resolver,
                         Connector connector) {
         this.xmlFactory = xmlFactory;
         this.builder = builder;
+        this.loader = loader;
         this.componentManager = componentManager;
         this.resolver = resolver;
         this.connector = connector;
@@ -117,6 +121,7 @@
         DeploymentContext deploymentContext =
             new RootDeploymentContext(null, null, groupId, xmlFactory, scopeContainer, false);
         // load the model
+        load(parent, componentDefinition, deploymentContext);
         // resolve autowires
         resolver.resolve(null, componentDefinition);
         // build runtime artifacts
@@ -145,6 +150,20 @@
         connector.connect(componentDefinition);
         return components;
     }
+    
+    /**
+     * Load the componentDefinition type information for the componentDefinition being deployed. For a typical
+     * deployment this will result in the SCDL definition being loaded.
+     *
+     * @param componentDefinition the componentDefinition being deployed
+     * @param deploymentContext   the current deployment context
+     */
+    protected <I extends Implementation<?>> void load(Component parent,
+                                                      ComponentDefinition<I> componentDefinition,
+                                                      DeploymentContext deploymentContext) throws LoaderException {
+        loader.loadComponentType(componentDefinition.getImplementation(), deploymentContext);
+    }
+    
 
     /**
      * Build the runtime context for a loaded componentDefinition.
@@ -159,6 +178,20 @@
                                                             DeploymentContext deploymentContext)
         throws BuilderException {
         return builder.build(componentDefinition, deploymentContext);
+    }
+
+    /**
+     * @return the builder
+     */
+    public Builder getBuilder() {
+        return builder;
+    }
+
+    /**
+     * @return the loader
+     */
+    public Loader getLoader() {
+        return loader;
     }
 
 }

Added: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java?view=auto&rev=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java (added)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java Mon Apr  2 10:47:43 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.tuscany.core.implementation.composite;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
+
+/**
+ * Loads a composite component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentTypeLoader extends ComponentTypeLoaderExtension<CompositeImplementation> {
+    public CompositeComponentTypeLoader() {
+    }
+
+    public CompositeComponentTypeLoader(LoaderRegistry loaderRegistry) {
+        super(loaderRegistry);
+    }
+
+    protected Class<CompositeImplementation> getImplementationClass() {
+        return CompositeImplementation.class;
+    }
+
+    public void load(CompositeImplementation implementation, DeploymentContext context) throws LoaderException {
+        URL scdlLocation = implementation.getScdlLocation();
+        ClassLoader cl = new CompositeClassLoader(null, implementation.getClassLoader());
+        URI componentId = URI.create(context.getComponentId().toString() + '/');
+        DeploymentContext childContext =
+            new ChildDeploymentContext(context, cl, scdlLocation, componentId, context.isAutowire());
+        CompositeComponentType componentType = loadFromSidefile(scdlLocation, childContext);
+        implementation.setComponentType(componentType);
+    }
+
+    protected CompositeComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext)
+        throws LoaderException {
+        return loaderRegistry.load(null, url, CompositeComponentType.class, deploymentContext);
+    }
+}

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java?view=auto&rev=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java (added)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java Mon Apr  2 10:47:43 2007
@@ -0,0 +1,224 @@
+/*
+ * 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.tuscany.core.implementation.composite;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Constants.SCA_NS;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidServiceException;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.WireDefinition;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Loads a composite component definition from an XML-based assembly file
+ * 
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoader extends LoaderExtension<CompositeComponentType> {
+    public static final QName COMPOSITE = new QName(SCA_NS, "composite");
+    public static final String URI_DELIMITER = "/";
+
+    private final ArtifactRepository artifactRepository;
+
+    public CompositeLoader(@Reference
+    LoaderRegistry registry, @Reference
+    ArtifactRepository artifactRepository) {
+        super(registry);
+        this.artifactRepository = artifactRepository;
+    }
+
+    public QName getXMLType() {
+        return COMPOSITE;
+    }
+
+    public CompositeComponentType load(ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext)
+        throws XMLStreamException, LoaderException {
+
+        String name = reader.getAttributeValue(null, "name");
+        String targetNamespace = reader.getAttributeValue(null, "targetNamespace");
+        boolean autowire = Boolean.parseBoolean(reader.getAttributeValue(null, "autowire"));
+
+        CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(
+                                                                                                                                                                           new QName(
+                                                                                                                                                                                     targetNamespace,
+                                                                                                                                                                                     name));
+        type.setAutowire(autowire);
+        boolean done = false;
+        while (!done) {
+            switch (reader.next()) {
+                case START_ELEMENT:
+                    boolean oldAutowire = deploymentContext.isAutowire();
+                    deploymentContext.setAutowire(autowire);
+                    ModelObject o = registry.load(type, reader, deploymentContext);
+                    deploymentContext.setAutowire(oldAutowire);
+                    if (o instanceof ServiceDefinition) {
+                        type.add((ServiceDefinition)o);
+                    } else if (o instanceof ReferenceDefinition) {
+                        type.add((ReferenceDefinition)o);
+                    } else if (o instanceof Property<?>) {
+                        type.add((Property<?>)o);
+                    } else if (o instanceof ComponentDefinition<?>) {
+                        type.add((ComponentDefinition<?>)o);
+                    } else if (o instanceof Include) {
+                        type.add((Include)o);
+                    } else if (o instanceof WireDefinition) {
+                        type.add((WireDefinition)o);
+                    } else {
+                        // add as an unknown model extension
+                        if (o != null) {
+                            type.getExtensions().put(o.getClass(), o);
+                        }
+                    }
+                    reader.next();
+                    break;
+                case END_ELEMENT:
+                    if (COMPOSITE.equals(reader.getName())) {
+                        // if there are wire defintions then link them up to the
+                        // relevant components
+                        resolveWires(type);
+                        verifyCompositeCompleteness(type);
+                        done = true;
+                        break;
+                    }
+            }
+        }
+        for (ComponentDefinition<? extends Implementation<?>> c : type.getComponents().values()) {
+            // PropertyHelper.processProperties(type, c, deploymentContext);
+        }
+        return type;
+    }
+
+    protected void resolveWires(CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+        throws InvalidWireException {
+        ComponentDefinition componentDefinition;
+        ServiceDefinition serviceDefinition;
+        List<WireDefinition> wireDefns = composite.getDeclaredWires();
+        for (WireDefinition wire : wireDefns) {
+            URI targetUri = wire.getTarget();
+            // validate the target before finding the source
+            validateTarget(targetUri, composite);
+
+            String sourceName = wire.getSource().getPath(); // new
+                                                            // QualifiedName(wire.getSource().getPath());
+            serviceDefinition = composite.getDeclaredServices().get(sourceName);
+            if (serviceDefinition != null) {
+                serviceDefinition.setTarget(wire.getTarget());
+            } else {
+                componentDefinition = composite.getDeclaredComponents().get(sourceName);
+                if (componentDefinition != null) {
+                    if (wire.getSource().getFragment() == null) {
+                        throw new InvalidWireException("Source reference not specified", sourceName);
+                    }
+                    URI referenceName = URI.create(wire.getSource().getFragment());
+                    ReferenceTarget referenceTarget = createReferenceTarget(referenceName,
+                                                                            targetUri,
+                                                                            componentDefinition);
+                    componentDefinition.add(referenceTarget);
+                } else {
+                    throw new InvalidWireException("Source not found", sourceName);
+                }
+            }
+        }
+    }
+
+    private ReferenceTarget createReferenceTarget(URI componentReferenceName,
+                                                  URI target,
+                                                  ComponentDefinition componentDefn) throws InvalidWireException {
+        ComponentType componentType = componentDefn.getImplementation().getComponentType();
+        if (componentReferenceName == null) {
+            // if there is ambiguity in determining the source of the wire or
+            // there is no reference to be wired
+            if (componentType.getReferences().size() > 1 || componentType.getReferences().isEmpty()) {
+                throw new InvalidWireException("Unable to determine unique source reference");
+            } else {
+                Map references = componentType.getReferences();
+                ReferenceDefinition definition = (ReferenceDefinition)references.values().iterator().next();
+                componentReferenceName = definition.getUri();
+            }
+        }
+
+        ReferenceTarget referenceTarget = new ReferenceTarget();
+        referenceTarget.setReferenceName(componentReferenceName);
+        referenceTarget.addTarget(target);
+        return referenceTarget;
+    }
+
+    protected void verifyCompositeCompleteness(CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+        throws InvalidServiceException {
+        // check if all of the composite services have been wired
+        for (ServiceDefinition svcDefn : composite.getDeclaredServices().values()) {
+            if (svcDefn.getTarget() == null) {
+                String identifier = svcDefn.getUri().toString();
+                throw new InvalidServiceException("Composite service not wired to a target", identifier);
+            }
+        }
+    }
+
+    private void validateTarget(URI target,
+                                CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+        throws InvalidWireException {
+        // if target is not a reference of the composite
+        String targetName = target.getPath();
+        if (composite.getReferences().get(targetName) == null) {
+            ComponentDefinition<?> targetDefinition = composite.getDeclaredComponents().get(targetName);
+            // if a target component exists in this composite
+            if (targetDefinition != null) {
+                Implementation<?> implementation = targetDefinition.getImplementation();
+                ComponentType<?, ?, ?> componentType = implementation.getComponentType();
+                Map<String, ? extends ServiceDefinition> services = componentType.getServices();
+                if (target.getFragment() == null) {
+                    if (services.size() > 1 || services.isEmpty()) {
+                        throw new InvalidWireException("Ambiguous target", target.toString());
+                    }
+                } else {
+                    if (services.get(target.getFragment()) == null) {
+                        throw new InvalidWireException("Invalid target service", target.toString());
+                    }
+                }
+            } else {
+                throw new InvalidWireException("Target not found", target.toString());
+            }
+        }
+    }
+}

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java?view=diff&rev=524852&r1=523780&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java Mon Apr  2 10:47:43 2007
@@ -18,30 +18,30 @@
  */
 package org.apache.tuscany.core.loader;
 
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Constants.SCA_NS;
+
 import java.lang.reflect.Type;
 import java.net.URI;
-import java.net.URL;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
+
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
-import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.w3c.dom.Document;
-import static org.osoa.sca.Constants.SCA_NS;
-import org.osoa.sca.annotations.Constructor;
-import org.osoa.sca.annotations.Reference;
-
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
 import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.QualifiedName;
-import org.apache.tuscany.spi.databinding.extension.DOMHelper;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.extension.LoaderExtension;
 import org.apache.tuscany.spi.loader.InvalidReferenceException;
@@ -69,10 +69,9 @@
 import org.apache.tuscany.spi.model.ReferenceDefinition;
 import org.apache.tuscany.spi.model.ReferenceTarget;
 import org.apache.tuscany.spi.model.ServiceDefinition;
-
-import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
-import org.apache.tuscany.core.deployer.ChildDeploymentContext;
-import org.apache.tuscany.core.property.SimplePropertyObjectFactory;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+import org.w3c.dom.Document;
 
 /**
  * Loads a component definition from an XML-based assembly file
@@ -220,7 +219,7 @@
             LoaderUtil.skipToEndElement(reader);
         } else {
             try {
-                DocumentBuilder documentBuilder = DOMHelper.newDocumentBuilder();
+                DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                 Document value = PropertyUtils.createPropertyValue(reader, property.getXmlType(), documentBuilder);
                 propertyValue = new PropertyValue<Type>(name, value);
             } catch (ParserConfigurationException e) {
@@ -302,8 +301,8 @@
                         PropertyValue propertyValue = new PropertyValue();
                         propertyValue.setName(aProperty.getName());
                         propertyValue.setValue(aProperty.getDefaultValue());
-                        propertyValue.setValueFactory(new SimplePropertyObjectFactory(aProperty,
-                            propertyValue.getValue()));
+//                        propertyValue.setValueFactory(new SimplePropertyObjectFactory(aProperty,
+//                            propertyValue.getValue()));
                         propertyValues.put(aProperty.getName(), propertyValue);
                     }
                 }

Modified: incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java?view=diff&rev=524852&r1=524851&r2=524852
==============================================================================
--- incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java (original)
+++ incubator/tuscany/sandbox/rfeng/minicore/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java Mon Apr  2 10:47:43 2007
@@ -22,43 +22,54 @@
 import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_SYSTEM;
 import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_SYSTEM_ROOT;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.xml.stream.XMLInputFactory;
 
 import org.apache.tuscany.core.bootstrap.Bootstrapper;
 import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
+import org.apache.tuscany.core.bootstrap.ExtensionActivator;
 import org.apache.tuscany.core.builder.ConnectorImpl;
 import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.SimpleWorkContext;
 import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
 import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.deployer.DeployerImpl;
 import org.apache.tuscany.core.monitor.NullMonitorFactory;
 import org.apache.tuscany.core.resolver.AutowireResolver;
 import org.apache.tuscany.core.resolver.DefaultAutowireResolver;
 import org.apache.tuscany.core.services.classloading.ClassLoaderRegistryImpl;
+import org.apache.tuscany.core.util.IOHelper;
 import org.apache.tuscany.host.MonitorFactory;
 import org.apache.tuscany.host.RuntimeInfo;
 import org.apache.tuscany.host.management.ManagementService;
 import org.apache.tuscany.host.monitor.FormatterRegistry;
 import org.apache.tuscany.host.runtime.InitializationException;
 import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
 import org.apache.tuscany.spi.builder.Connector;
 import org.apache.tuscany.spi.component.AtomicComponent;
 import org.apache.tuscany.spi.component.Component;
 import org.apache.tuscany.spi.component.ComponentManager;
-import org.apache.tuscany.spi.component.GroupInitializationException;
 import org.apache.tuscany.spi.component.RegistrationException;
-import org.apache.tuscany.spi.component.ScopeContainer;
 import org.apache.tuscany.spi.component.ScopeContainerMonitor;
 import org.apache.tuscany.spi.component.ScopeRegistry;
 import org.apache.tuscany.spi.component.TargetResolutionException;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.deployer.Deployer;
 import org.apache.tuscany.spi.idl.java.JavaServiceContract;
-import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
 import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
 import org.apache.tuscany.spi.services.management.TuscanyManagementService;
 import org.osoa.sca.ComponentContext;
@@ -120,6 +131,7 @@
     protected Component tuscanySystem;
 
     protected ScopeRegistry scopeRegistry;
+    protected Collection<ExtensionActivator> activators;
 
     protected AbstractRuntime(Class<I> runtimeInfoType) {
         this(runtimeInfoType, new NullMonitorFactory());
@@ -190,19 +202,22 @@
     }
 
     public void initialize() throws InitializationException {
-        URI name = TUSCANY_SYSTEM_ROOT.resolve("main");
+        // URI name = TUSCANY_SYSTEM_ROOT.resolve("main");
         Bootstrapper bootstrapper = createBootstrapper();
+        Deployer deployer = bootstrapper.createDeployer();
+        registerSystemComponent(TUSCANY_DEPLOYER, Deployer.class, deployer);
+        registerSystemComponent(WORK_CONTEXT_URI, WorkContext.class, new SimpleWorkContext());
+
+        this.scopeRegistry = bootstrapper.getScopeRegistry();
+        
+        LoaderRegistry loaderRegistry = (LoaderRegistry)((DeployerImpl)deployer).getLoader();
+        BuilderRegistry builderRegistry = (BuilderRegistry)((DeployerImpl)deployer).getBuilder();
+        activators = getInstances(getHostClassLoader(), ExtensionActivator.class);
+        for (ExtensionActivator activator : activators) {
+            activator.start(loaderRegistry, builderRegistry);
+        }
 
         registerBaselineSystemComponents();
-
-        systemComponent = componentManager.getComponent(name);
-        URI uri = systemComponent.getUri();
-        ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
-        try {
-            scopeContainer.startContext(uri, uri);
-        } catch (GroupInitializationException e) {
-            throw new InitializationException(e);
-        }
     }
 
     public void destroy() {
@@ -229,14 +244,7 @@
         resolver = new DefaultAutowireResolver();
         componentManager = new ComponentManagerImpl(tms, resolver);
         Connector connector = new ConnectorImpl(componentManager);
-
-        scopeRegistry = new ScopeRegistryImpl();
-        CompositeScopeContainer scopeContainer = new CompositeScopeContainer(monitorFactory
-            .getMonitor(ScopeContainerMonitor.class));
-        scopeContainer.start();
-        scopeRegistry.register(scopeContainer);
-        return new DefaultBootstrapper(getMonitorFactory(), xmlFactory, componentManager, resolver, connector,
-                                       scopeRegistry);
+        return new DefaultBootstrapper(getMonitorFactory(), xmlFactory, componentManager, resolver, connector);
     }
 
     protected void registerBaselineSystemComponents() throws InitializationException {
@@ -310,5 +318,62 @@
         } catch (TargetResolutionException e) {
             throw new AssertionError(e);
         }
+    }
+
+    /**
+     * Read the service name from a configuration file
+     * 
+     * @param classLoader
+     * @param name The name of the service class
+     * @return A class name which extends/implements the service class
+     * @throws IOException
+     */
+    private static Set<String> getServiceNames(ClassLoader classLoader, String name) throws IOException {
+        Set<String> set = new HashSet<String>();
+        Enumeration<URL> urls = classLoader.getResources("META-INF/services/" + name);
+        while (urls.hasMoreElements()) {
+            URL url = urls.nextElement();
+            String service = getServiceName(url);
+            if (service != null) {
+                set.add(service);
+
+            }
+        }
+        return set;
+    }
+
+    private static String getServiceName(URL url) throws IOException {
+        InputStream is = IOHelper.getInputStream(url);
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new InputStreamReader(is));
+            while (true) {
+                String line = reader.readLine();
+                if (line == null) {
+                    break;
+                } else if (!line.startsWith("#")) {
+                    return line.trim();
+                }
+            }
+        } finally {
+            if (reader != null) {
+                reader.close();
+            }
+        }
+        return null;
+    }
+
+    private static <T> Collection<T> getInstances(final ClassLoader classLoader, Class<T> serviceClass) {
+        List<T> instances = new ArrayList<T>();
+        try {
+            Set<String> services = getServiceNames(classLoader, serviceClass.getName());
+            for (String className : services) {
+                Class cls = Class.forName(className, true, classLoader);
+                instances.add(serviceClass.cast(cls.newInstance())); // NOPMD
+            }
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+        return instances;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message