You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/03/15 04:47:04 UTC

svn commit: r385966 [1/2] - in /incubator/tuscany/java/sca: container.java/src/main/java/org/apache/tuscany/container/java/builder/ container.java/src/main/java/org/apache/tuscany/container/java/config/ container.java/src/test/java/org/apache/tuscany/c...

Author: jmarino
Date: Tue Mar 14 19:47:01 2006
New Revision: 385966

URL: http://svn.apache.org/viewcvs?rev=385966&view=rev
Log:
changes to allow registration of arbitrarily deep aggregate hierarchies; some JavaDoc cleanup and additions; changes to AggregateImpl to visit components, entry points and external services as opposed to just aggregate parts

Added:
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/SystemBootstrapTestCase.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/AggregateNestingTestCase.java
Removed:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireFactory.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/SystemBootstrapTestCase.java
Modified:
    incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java
    incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java
    incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java
    incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactory.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactoryBuilder.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/WireBuilder.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/AssemblyVisitor.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/client/BootstrapHelper.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ConfigurationContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AggregateContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraAggregateWireIntegrationTestCase.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
    incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/system/context/IntraAggregateWireTestCase.java
    incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/AggregateImpl.java
    incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyContextListener.java

Modified: incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java (original)
+++ incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilder.java Tue Mar 14 19:47:01 2006
@@ -14,9 +14,9 @@
 import org.apache.tuscany.container.java.config.JavaContextFactory;
 import org.apache.tuscany.core.builder.BuilderConfigException;
 import org.apache.tuscany.core.builder.BuilderException;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
 import org.apache.tuscany.core.builder.NoAccessorException;
 import org.apache.tuscany.core.builder.ObjectFactory;
-import org.apache.tuscany.core.builder.ContextFactoryBuilder;
 import org.apache.tuscany.core.builder.impl.ArrayMultiplicityObjectFactory;
 import org.apache.tuscany.core.builder.impl.HierarchicalBuilder;
 import org.apache.tuscany.core.builder.impl.ListMultiplicityObjectFactory;
@@ -58,7 +58,7 @@
 import commonj.sdo.DataObject;
 
 /**
- * Builds runtime configurations for component implementations that map to
+ * Builds context factories for component implementations that map to
  * {@link org.apache.tuscany.container.java.assembly.JavaImplementation}. The logical model is then decorated with the
  * runtime configuration.
  * 
@@ -267,7 +267,6 @@
                 config.setEagerInit(eagerInit);
                 config.setInitInvoker(initInvoker);
                 config.setDestroyInvoker(destroyInvoker);
-                
             } catch (BuilderException e) {
                 e.addContextName(component.getName());
                 throw e;

Modified: incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java (original)
+++ incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/config/JavaContextFactory.java Tue Mar 14 19:47:01 2006
@@ -70,7 +70,7 @@
     // ----------------------------------
 
     /**
-     * Creates the runtime configuration
+     * Creates a new context factory
      * 
      * @param name the SCDL name of the component the context refers to
      * @param ctr the implementation type constructor

Modified: incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java (original)
+++ incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockConfigContext.java Tue Mar 14 19:47:01 2006
@@ -22,10 +22,10 @@
 import org.apache.tuscany.core.builder.impl.AssemblyVisitor;
 import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
 import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.ConfigurationContext;
 import org.apache.tuscany.core.context.ScopeContext;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
 import org.apache.tuscany.model.assembly.Extensible;
 
 /**
@@ -51,17 +51,17 @@
     public void configure(Extensible model) throws ConfigurationException {
     }
 
-    public void build(AggregateContext parent, Extensible model) throws BuilderConfigException {
+    public void build(AssemblyModelObject model) throws BuilderConfigException {
         AssemblyVisitor visitor = new AssemblyVisitor(builders);
         visitor.start(model);
     }
 
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
             ScopeContext targetScopeContext) throws BuilderConfigException {
         wireBuilder.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
     }
 
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
         wireBuilder.completeTargetChain(targetFactory, targetType, targetScopeContext);
     }
 

Modified: incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java (original)
+++ incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java Tue Mar 14 19:47:01 2006
@@ -632,7 +632,7 @@
     }
 
     /**
-     * Creates an aggregate runtime configuration
+     * Creates an aggregate context faxtory
      *
      * @param name             the name of the component
      * @param aggregateContext the containing aggregate context

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactory.java Tue Mar 14 19:47:01 2006
@@ -9,18 +9,26 @@
 import org.apache.tuscany.model.assembly.Scope;
 
 /**
- * Implementations create instances of {@link org.apache.tuscany.core.context.Context} based on a compiled
- * configuration, such as a logical assembly model. For example, implementations of
- * {@link org.apache.tuscany.core.builder.ContextFactoryBuilder} analyze an
- * {@link org.apache.tuscany.model.assembly.AssemblyModelObject} to create implementations of
- * <tt>ContextFactory</tt>.
+ * Implementations serve the dual purpose of creating instances of {@link org.apache.tuscany.core.context.Context} based
+ * on a compiled configuration such as a logical assembly model and holding a
+ * {@link org.apache.tuscany.core.invocation.spi.ProxyFactory} for the instance type associated with the context.
+ * <p>
+ * Context factories are created or "built" in two phases. {@link org.apache.tuscany.core.builder.ContextFactoryBuilder}s
+ * are responsible for analyzing a logical model assembly and producing the appropriate <code>ContextFactory</code>
+ * for the runtime. {@link org.apache.tuscany.core.builder.WireBuilder}s update the proxy configuration associated with
+ * the <code>ProxyFactory</code> attached to the <code>ContextFactory</code>.
+ * <p>
+ * <code>ContextFactory</code> implementations also contain the source and target invocations chains associated with
+ * all instances of a given <code>Context</code> type. For example, two contexts associated with separate sessions for
+ * a component will refer back to the same invocation chains held in the <code>ProxyFactory</code> attached to the
+ * <code>ContextFactory</code>.
  * 
  * @version $Rev: 385747 $ $Date: 2006-03-13 22:12:53 -0800 (Mon, 13 Mar 2006) $
  */
 public interface ContextFactory<T extends Context> {
 
     /**
-     * Creates an instance context based on the current runtime configuration
+     * Creates a <code>Context</code> based on configuration supplied by a logical model assembly
      * 
      * @return a new instance context
      * @throws ContextCreationException if an error occurs creating the context
@@ -28,12 +36,12 @@
     public T createContext() throws ContextCreationException;
 
     /**
-     * Returns the scope identifier associated with the type of contexts produced by the current configuration
+     * Returns the scope identifier associated with the type of contexts produced by the current factory
      */
     public Scope getScope();
 
     /**
-     * Returns the name of the contexts produced by the current configuration
+     * Returns the name of the contexts produced by the current factory
      */
     public String getName();
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactoryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactoryBuilder.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactoryBuilder.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/ContextFactoryBuilder.java Tue Mar 14 19:47:01 2006
@@ -5,26 +5,27 @@
 
 /**
  * Implementations perform the first phase of converting a logical model representing an assembly into a series of
- * runtime or executable artifacts. Specifically, <code>ContextFactoryBuilder</code>s are responsible for
- * analyzing logical model elements and producing {@link ContextFactory}s that are used to generate executable
- * artifacts such as an {@link org.apache.tuscany.core.context.InstanceContext}. In the case of components, the
- * <code>ContextFactory</code> will typically contain configuration for instantiating implementation instances
- * with injected properties and references; invocation chains; and configuration necessary to build proxies to
- * implementation instances.
+ * runtime or executable artifacts. Specifically, <code>ContextFactoryBuilder</code>s are responsible for analyzing
+ * logical model elements and producing {@link ContextFactory}s that are used to generate executable artifacts such as
+ * an {@link org.apache.tuscany.core.context.InstanceContext}. In the case of components, the
+ * <code>ContextFactory</code> will typically contain configuration for instantiating implementation instances with
+ * injected properties and references; invocation chains; and configuration necessary to build proxies to implementation
+ * instances.
  * <p>
- * As the logical model is analyzed, <code>ContextFactoryBuilder</code>s are guaranteed to be called first and
- * are expected to decorate the logical model with initial <code>ContextFactory</code>. Certain implementations
- * may choose to delegate tasks to other builders. For example, a builder may handle component implementation types and
- * set up an initial <code>ContextFactory</code> based on introspected metadata specific to the type. It may
- * then choose to delegate to other builders to handle construction of invocation chains based on policies specified in
- * the logical model. Delegation may be set up by implementing builders as system components and wiring them to other
- * builders. This allows the creation of builders that may modify invocation chains regardless of implementation type,
- * such as generic policy builders.
+ * As the logical model is analyzed, <code>ContextFactoryBuilder</code>s are guaranteed to be called first and are
+ * expected to decorate the logical model with initial <code>ContextFactory</code>. Certain implementations may
+ * choose to delegate tasks to other builders. For example, a builder may handle component implementation types and set
+ * up an initial <code>ContextFactory</code> based on introspected metadata specific to the type. It may then choose
+ * to delegate to other builders to handle construction of invocation chains based on policies specified in the logical
+ * model. Delegation may be set up by implementing builders as system components and wiring them to other builders. This
+ * allows the creation of builders that may modify invocation chains regardless of implementation type, such as generic
+ * policy builders.
  * <p>
  * When this first phase is complete, a logical model will be decorated with essentially independent
- * <code>ContextFactory</code>s. The second phase uses {@link WireBuilder}s to analyze wires represented in
- * the logical model and "connect" the source and target invocation chains held in these
- * <code>ContextFactory</code>s to form a completed wire. <code>WireBuilder<code>s may use a similar delegation strategy and perform various optimizations.
+ * <code>ContextFactory</code>s. The second phase uses {@link WireBuilder}s to analyze wires represented in the
+ * logical model and "connect" the source and target invocation chains held in these <code>ContextFactory</code>s to
+ * form a completed wire.
+ * <code>WireBuilder<code>s may use a similar delegation strategy and perform various optimizations.
  * 
  * @version $Rev$ $Date$
  * @see ContextFactory
@@ -33,10 +34,10 @@
 public interface ContextFactoryBuilder<Y extends Context> {
 
     /**
-     * Builds a runtime configuration for the supplied model object for registration under the supplied context.
+     * Creates or updates a context factory based on configuration contained in the given model object. The model object
+     * is decorated with the factory.
      * 
      * @param object the logical configuration model node
-     * @param context the context that will be the parent of the built context
      * @throws BuilderException
      */
     public void build(AssemblyModelObject object) throws BuilderException;

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/WireBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/WireBuilder.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/WireBuilder.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/WireBuilder.java Tue Mar 14 19:47:01 2006
@@ -25,10 +25,14 @@
  * necessary as a <code>WireBuilder</code> must set a {@link org.apache.tuscany.core.invocation.TargetInvoker} that is
  * responsible for dispatching to an implementation on the source side of the wire.
  * <p>
+ * Runtimes are generally configured with a {@link org.apache.tuscany.core.builder.impl.DefaultWireBuilder} as a
+ * top-most wire builder, which delegates to other builders wired to it as part of a system configuration.
+ * <p>
  * Wire builders may optimize the invocation chains based on certain characteristics of th wire, such as source and
  * target scopes.
  * 
  * @see org.apache.tuscany.core.builder.ContextFactoryBuilder
+ * @see org.apache.tuscany.core.builder.impl.DefaultWireBuilder
  * @version $Rev$ $Date$
  */
 public interface WireBuilder {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/AssemblyVisitor.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/AssemblyVisitor.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/AssemblyVisitor.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/AssemblyVisitor.java Tue Mar 14 19:47:01 2006
@@ -31,8 +31,7 @@
     /**
      * Constructs a visitor
      * 
-     * @param parent the parent context for the object graph
-     * @param builders the collection of builders for creating runtime configurations
+     * @param builders the collection of builders for creating context factories
      */
     public AssemblyVisitor(List<ContextFactoryBuilder> builders) {
         this.builders = builders;

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/builder/impl/DefaultWireBuilder.java Tue Mar 14 19:47:01 2006
@@ -29,7 +29,7 @@
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 
 /**
- * The top-most wire builder configured in a runtime. Responsible for constructing wires from source and target chains,
+ * The top-most <code>WireBuilder</code> configured in a runtime. Responsible for constructing wires from source and target chains,
  * this implementation first bridges the chains and then delegates to any other wire builders.
  * 
  * @version $Rev$ $Date$

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/client/BootstrapHelper.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/client/BootstrapHelper.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/client/BootstrapHelper.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/client/BootstrapHelper.java Tue Mar 14 19:47:01 2006
@@ -126,7 +126,7 @@
 
         // Get the aggregate context representing the component
         AggregateContext context = (AggregateContext) parent.getContext(component.getName());
-        context.registerModelObject(component.getComponentImplementation());
+        //context.registerModelObject(component.getComponentImplementation());
         return context;
     }
 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/AggregateContext.java Tue Mar 14 19:47:01 2006
@@ -42,7 +42,7 @@
      * @see org.apache.tuscany.model.assembly.EntryPoint
      * @see org.apache.tuscany.model.assembly.ExternalService
      */
-    public void registerModelObjects(List<Extensible> models) throws ConfigurationException;
+    public void registerModelObjects(List<? extends Extensible> models) throws ConfigurationException;
 
     /**
      * Adds a runtime artifact represented by the model object to the aggregate context by merging it with existing

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ConfigurationContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ConfigurationContext.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ConfigurationContext.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ConfigurationContext.java Tue Mar 14 19:47:01 2006
@@ -13,20 +13,22 @@
  */
 package org.apache.tuscany.core.context;
 
-import org.apache.tuscany.core.builder.BuilderConfigException;
+import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.builder.WireBuilder;
 import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 import org.apache.tuscany.model.assembly.Extensible;
 
 /**
  * Offers configuration services in the runtime. A ConfigurationContext is able to configure a model and then build the
- * runtime representation corresponding to that model in the live system. <p/> Configuration contexts will typically be
- * hierarchical, delegating to their parent <b>after</b> performing an operation. The parent ConfigurationContext will
- * typically be injected into an implementation of this interface during registration.
+ * runtime representation corresponding to that model in the live system.
+ * <p>
+ * Configuration contexts will typically be hierarchical, delegating to their parent <b>after</b> performing an
+ * operation. The parent ConfigurationContext will typically be injected into an implementation of this interface during
+ * registration.
  * 
  * @version $Rev$ $Date$
  */
-public interface ConfigurationContext {
+public interface ConfigurationContext extends ContextFactoryBuilder, WireBuilder {
 
     /**
      * Adds additional configuration information to a model object.
@@ -35,32 +37,5 @@
      * @throws ConfigurationException
      */
     public void configure(Extensible model) throws ConfigurationException;
-
-    /**
-     * Decorates the supplied model object with a {@link org.apache.tuscany.core.builder.ContextFactory} that can
-     * be used to create the runtime context corresponding to the model.
-     * 
-     * @param parent an AggregrateContext that will ultimately become the parent of the runtime context
-     * @param model the model object that defines the configuration to be built
-     * @throws BuilderConfigException
-     * @see org.apache.tuscany.core.builder.ContextFactory
-     */
-    public void build(AggregateContext parent, Extensible model) throws BuilderConfigException;
-
-    /**
-     * Constructs a wire from a source proxy factory to a corresponding target, potentially performing optimizations
-     * 
-     * @param sourceFactory the proxy factory that will be used to create the injected proxy for a reference
-     * @param targetFactory the proxy factory that contains the invocation chains for the target side of the wire
-     * @param targetType the {@link org.apache.tuscany.core.builder.ContextFactory} implementation type for the
-     *        wire target
-     * @param downScope whether the source is a shorter lived scope than the target. Used in optimization.
-     * @param targetScopeContext the scope context of the target service
-     * @throws BuilderConfigException
-     */
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
-            ScopeContext targetScopeContext) throws BuilderConfigException;
-
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException;
 
 }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractAggregateContext.java Tue Mar 14 19:47:01 2006
@@ -260,7 +260,7 @@
         return parentContext;
     }
 
-    public void registerModelObjects(List<Extensible> models) throws ConfigurationException {
+    public void registerModelObjects(List<? extends Extensible> models) throws ConfigurationException {
         assert (models != null) : "Model object collection was null";
         for (Extensible model : models) {
             registerModelObject(model);
@@ -273,7 +273,7 @@
         if (configurationContext != null) {
             try {
                 configurationContext.configure(model);
-                configurationContext.build(this, model);
+                configurationContext.build(model);
             } catch (ConfigurationException e) {
                 e.addContextName(getName());
                 throw e;
@@ -298,7 +298,7 @@
                 }
                 configuration = (ContextFactory<InstanceContext>) componentImplementation.getContextFactory();
                 if (configuration == null) {
-                    ConfigurationException e = new ConfigurationException("Runtime configuration not set");
+                    ConfigurationException e = new ConfigurationException("Context factory not set");
                     e.addContextName(component.getName());
                     e.addContextName(getName());
                     throw e;
@@ -309,7 +309,7 @@
             for (EntryPoint ep : newModule.getEntryPoints()) {
                 configuration = (ContextFactory<InstanceContext>) ep.getConfiguredReference().getContextFactory();
                 if (configuration == null) {
-                    ConfigurationException e = new ConfigurationException("Runtime configuration not set");
+                    ConfigurationException e = new ConfigurationException("Context factory not set");
                     e.setIdentifier(ep.getName());
                     e.addContextName(getName());
                     throw e;
@@ -320,7 +320,7 @@
             for (ExternalService service : newModule.getExternalServices()) {
                 configuration = (ContextFactory<InstanceContext>) service.getConfiguredService().getContextFactory();
                 if (configuration == null) {
-                    ConfigurationException e = new ConfigurationException("Runtime configuration not set");
+                    ConfigurationException e = new ConfigurationException("Context factory not set");
                     e.setIdentifier(service.getName());
                     e.addContextName(getName());
                     throw e;
@@ -424,7 +424,7 @@
                 throw e;
             }
             if (configuration == null) {
-                ConfigurationException e = new ConfigurationException("Runtime configuration not set");
+                ConfigurationException e = new ConfigurationException("Context factory not set");
                 if (model instanceof Part) {
                     e.setIdentifier(((Part) model).getName());
                 }
@@ -608,7 +608,7 @@
                 }
                 try {
                     boolean downScope = scopeStrategy.downScopeReference(sourceScope, target.getScope());
-                    configurationContext.wire(sourceFactory, targetFactory, target.getClass(), downScope, scopeContexts
+                    configurationContext.connect(sourceFactory, targetFactory, target.getClass(), downScope, scopeContexts
                             .get(target.getScope()));
                 } catch (BuilderConfigException e) {
                     e.addContextName(target.getName());
@@ -623,7 +623,7 @@
         if (source.getTargetProxyFactories() != null) {
             for (ProxyFactory targetFactory : ((Map<String, ProxyFactory>) source.getTargetProxyFactories()).values()) {
                 try {
-                    configurationContext.wire(targetFactory, source.getClass(), scopeContexts.get(sourceScope));
+                    configurationContext.completeTargetChain(targetFactory, source.getClass(), scopeContexts.get(sourceScope));
                 } catch (BuilderConfigException e) {
                     e.addContextName(source.getName());
                     e.addContextName(name);
@@ -655,7 +655,7 @@
                 }
             }
             if (config.getSourceProxyFactories() != null) {
-                for (ProxyFactory targetProxyFactory : (Collection<ProxyFactory>) config.getTargetProxyFactories()) {
+                for (ProxyFactory targetProxyFactory : (Collection<ProxyFactory>) config.getTargetProxyFactories().values()) {
                     targetProxyFactory.initialize();
                 }
             }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AggregateContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AggregateContextImpl.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AggregateContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AggregateContextImpl.java Tue Mar 14 19:47:01 2006
@@ -32,6 +32,7 @@
 import org.apache.tuscany.core.context.TargetException;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 import org.apache.tuscany.core.system.annotation.Autowire;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
 import org.apache.tuscany.model.assembly.Extensible;
 import org.osoa.sca.ModuleContext;
 import org.osoa.sca.RequestContext;
@@ -50,7 +51,7 @@
     // ----------------------------------
 
     @Autowire(required = false)
-    private AutowireContext autowireContext;
+    private AutowireContext autowireContext;    
     
     // ----------------------------------
     // Constructors
@@ -173,10 +174,10 @@
         }
     }
 
-    public void build(AggregateContext parent, Extensible model) throws BuilderConfigException {
+    public void build(AssemblyModelObject model) throws BuilderConfigException {
         if (configurationContext != null) {
             try {
-                configurationContext.build(parent, model);
+                configurationContext.build(model);
             } catch (BuilderConfigException e) {
                 e.addContextName(getName());
                 throw e;
@@ -184,11 +185,11 @@
         }
     }
 
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
             ScopeContext targetScopeContext) throws BuilderConfigException {
         if (configurationContext != null) {
             try {
-                configurationContext.wire(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
+                configurationContext.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
             } catch (BuilderConfigException e) {
                 e.addContextName(getName());
                 throw e;
@@ -196,10 +197,10 @@
         }
     }
 
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
         if (configurationContext != null) {
             try {
-                configurationContext.wire(targetFactory, targetType, targetScopeContext);
+                configurationContext.completeTargetChain(targetFactory, targetType, targetScopeContext);
             } catch (BuilderConfigException e) {
                 e.addContextName(getName());
                 throw e;

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/injection/ContextObjectFactory.java Tue Mar 14 19:47:01 2006
@@ -5,7 +5,7 @@
 import org.apache.tuscany.core.context.AggregateContext;
 
 /**
- * Implementation of ObjectFactory that resolves the current context.
+ * An implementation of <code>ObjectFactory</code> that resolves the current context.
  * 
  * @version $Rev: 380903 $ $Date: 2006-02-25 00:53:26 -0800 (Sat, 25 Feb 2006) $
  */

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/runtime/RuntimeContextImpl.java Tue Mar 14 19:47:01 2006
@@ -19,8 +19,8 @@
 import org.apache.tuscany.common.monitor.MonitorFactory;
 import org.apache.tuscany.common.monitor.impl.NullMonitorFactory;
 import org.apache.tuscany.core.builder.BuilderConfigException;
-import org.apache.tuscany.core.builder.HierarchicalWireBuilder;
 import org.apache.tuscany.core.builder.ContextFactoryBuilder;
+import org.apache.tuscany.core.builder.HierarchicalWireBuilder;
 import org.apache.tuscany.core.builder.WireBuilder;
 import org.apache.tuscany.core.builder.impl.AssemblyVisitor;
 import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
@@ -40,11 +40,12 @@
 import org.apache.tuscany.core.context.impl.AggregateContextImpl;
 import org.apache.tuscany.core.context.impl.EventContextImpl;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl;
+import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl;
 import org.apache.tuscany.core.system.context.SystemAggregateContextImpl;
 import org.apache.tuscany.core.system.context.SystemScopeStrategy;
-import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl;
-import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl;
 import org.apache.tuscany.model.assembly.Aggregate;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
 import org.apache.tuscany.model.assembly.Extensible;
 import org.apache.tuscany.model.scdl.loader.SCDLModelLoader;
 
@@ -182,7 +183,7 @@
         rootContext.registerModelObject(model);
     }
 
-    public void registerModelObjects(List<Extensible> models) throws ConfigurationException {
+    public void registerModelObjects(List<? extends Extensible> models) throws ConfigurationException {
         for (Extensible model : models) {
             registerModelObject(model);
         }
@@ -224,7 +225,7 @@
     // ConfigurationContext methods
     // ----------------------------------
 
-    public synchronized void build(AggregateContext parent, Extensible model) throws BuilderConfigException {
+    public synchronized void build(AssemblyModelObject model) throws BuilderConfigException {
         AssemblyVisitor visitor = new AssemblyVisitor(builders);
         visitor.start(model);
     }
@@ -232,12 +233,12 @@
     public void configure(Extensible model) throws ConfigurationException {
     }
 
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
             ScopeContext targetScopeContext) throws BuilderConfigException {
         wireBuilder.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
     }
 
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
         wireBuilder.completeTargetChain(targetFactory, targetType, targetScopeContext);
     }
 

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/builder/SystemContextFactoryBuilder.java Tue Mar 14 19:47:01 2006
@@ -148,7 +148,6 @@
                 // of app module component context
                 implClass = AggregateContextImpl.class;
                 scope = Scope.AGGREGATE;
-
             }
 
         } else {
@@ -156,15 +155,20 @@
         }
         Set<Field> fields;
         Set<Method> methods;
-        SystemContextFactory config = null;
+        SystemContextFactory contextFactory = null;
         try {
             fields = JavaIntrospectionHelper.getAllFields(implClass);
             methods = JavaIntrospectionHelper.getAllUniqueMethods(implClass);
             String name = component.getName();
             Constructor ctr = implClass.getConstructor((Class[]) null);
-            config = new SystemContextFactory(name, JavaIntrospectionHelper.getDefaultConstructor(implClass),
-                    scope);
-            ContextObjectFactory contextFactory = new ContextObjectFactory(config);
+            if (componentImplementation instanceof Module) {
+                Module module = (Module)componentImplementation;
+                contextFactory = new SystemContextFactory(name, module, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope);
+
+            } else {
+                contextFactory = new SystemContextFactory(name, JavaIntrospectionHelper.getDefaultConstructor(implClass), scope);
+            }
+            ContextObjectFactory contextObjectFactory = new ContextObjectFactory(contextFactory);
 
             List<Injector> injectors = new ArrayList();
 
@@ -183,7 +187,7 @@
                 Map<String, ConfiguredReference> configuredReferences = component.getConfiguredReferences();
                 if (configuredReferences != null) {
                     for (ConfiguredReference reference : configuredReferences.values()) {
-                        Injector injector = createReferenceInjector(reference, fields, methods, config);
+                        Injector injector = createReferenceInjector(reference, fields, methods, contextFactory);
                         injectors.add(injector);
                     }
                 }
@@ -201,27 +205,16 @@
                 }
                 Context context = field.getAnnotation(Context.class);
                 if (context != null) {
-                    Injector injector = new FieldInjector(field, contextFactory);
+                    Injector injector = new FieldInjector(field, contextObjectFactory);
                     injectors.add(injector);
                 }
                 ParentContext parentField = field.getAnnotation(ParentContext.class);
                 if (parentField != null) {
-//                    if (!(parentContext instanceof AggregateContext)) {
-//                        BuilderConfigException e = new BuilderConfigException("Component must be a child of");
-//                        e.setIdentifier(AggregateContext.class.getName());
-//                        throw e;
-//                    }
-                    Injector injector = new FieldInjector(field, contextFactory);
+                    Injector injector = new FieldInjector(field, contextObjectFactory);
                     injectors.add(injector);
                 }
                 Autowire autowire = field.getAnnotation(Autowire.class);
                 if (autowire != null) {
-//                    if (!(parentContext instanceof AutowireContext)) {
-//                        BuilderConfigException e = new BuilderConfigException("Parent context must implement");
-//                        e.setIdentifier(AutowireContext.class.getName());
-//                        throw e;
-//                    }
-//                    AutowireContext ctx = (AutowireContext) parentContext;
                     // for system aggregate context types, only allow autowire of certain types, otherwise we have a
                     // chicken-and-egg problem
                     if (SystemAggregateContext.class.isAssignableFrom(implClass)
@@ -233,14 +226,8 @@
                         e.setIdentifier(field.getType().getName());
                         throw e;
                     }
-
-//                    Object o = ctx.resolveInstance(field.getType());
-//                    if (autowire.required() && o == null) {
-//                        BuilderConfigException e = new BuilderConfigException("No autowire found for field");
-//                        e.setIdentifier(field.getName());
-//                        throw e;
-//                    }
-                    Injector injector = new FieldInjector(field, new AutowireObjectFactory(field.getType(),autowire.required(),config));
+                    Injector injector = new FieldInjector(field, new AutowireObjectFactory(field.getType(), autowire.required(),
+                            contextFactory));
                     injectors.add(injector);
                 }
             }
@@ -263,32 +250,31 @@
                 }
                 Context context = method.getAnnotation(Context.class);
                 if (context != null) {
-                    Injector injector = new MethodInjector(method, contextFactory);
+                    Injector injector = new MethodInjector(method, contextObjectFactory);
                     injectors.add(injector);
                 }
                 ParentContext parentMethod = method.getAnnotation(ParentContext.class);
                 if (parentMethod != null) {
-//                    if (!(parentContext instanceof AggregateContext)) {
-//                        BuilderConfigException e = new BuilderConfigException("Component must be a child of ");
-//                        e.setIdentifier(AggregateContext.class.getName());
-//                        throw e;
-//                    }
-                    Injector injector = new MethodInjector(method, contextFactory);
+                    // if (!(parentContext instanceof AggregateContext)) {
+                    // BuilderConfigException e = new BuilderConfigException("Component must be a child of ");
+                    // e.setIdentifier(AggregateContext.class.getName());
+                    // throw e;
+                    // }
+                    Injector injector = new MethodInjector(method, contextObjectFactory);
                     injectors.add(injector);
                 }
                 Autowire autowire = method.getAnnotation(Autowire.class);
                 if (autowire != null) {
-//                    if (!(parentContext instanceof AutowireContext)) {
-//                        BuilderConfigException e = new BuilderConfigException("Parent context must implement)");
-//                        e.setIdentifier(AutowireContext.class.getName());
-//                        throw e;
-//                    }
+                    // if (!(parentContext instanceof AutowireContext)) {
+                    // BuilderConfigException e = new BuilderConfigException("Parent context must implement)");
+                    // e.setIdentifier(AutowireContext.class.getName());
+                    // throw e;
+                    // }
                     if (method.getParameterTypes() == null || method.getParameterTypes().length != 1) {
                         BuilderConfigException e = new BuilderConfigException("Autowire setter methods must take one parameter");
                         e.setIdentifier(method.getName());
                         throw e;
                     }
-//                    AutowireContext ctx = (AutowireContext) parentContext;
                     Class paramType = method.getParameterTypes()[0];
                     // for system aggregate context types, only allow autowire of certain types, otherwise we have a
                     // chicken-and-egg problem
@@ -299,26 +285,19 @@
                         e.setIdentifier(paramType.getName());
                         throw e;
                     }
-//                    Object o = ctx.resolveInstance(paramType);
-//                    if (autowire.required() && o == null) {
-//                        BuilderConfigException e = new BuilderConfigException("No autowire found for method ");
-//                        e.setIdentifier(method.getName());
-//                        throw e;
-//                    }
-
-                    Injector injector = new MethodInjector(method, new AutowireObjectFactory(paramType,autowire.required(), config));
+                    Injector injector = new MethodInjector(method, new AutowireObjectFactory(paramType, autowire.required(),
+                            contextFactory));
                     injectors.add(injector);
                 }
             }
+            contextFactory.setSetters(injectors);
+            contextFactory.setEagerInit(eagerInit);
+            contextFactory.setInitInvoker(initInvoker);
+            contextFactory.setDestroyInvoker(destroyInvoker);
             // decorate the logical model
-            config.setSetters(injectors);
-            config.setEagerInit(eagerInit);
-            config.setInitInvoker(initInvoker);
-            config.setDestroyInvoker(destroyInvoker);
-            componentImplementation.setContextFactory(config);
+            componentImplementation.setContextFactory(contextFactory);
         } catch (BuilderConfigException e) {
             e.addContextName(component.getName());
-            // e.addContextName(parentContext.getName());
             throw e;
         } catch (NoSuchMethodException e) {
             BuilderConfigException ce = new BuilderConfigException("Class does not have a no-arg constructor", e);

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/config/SystemContextFactory.java Tue Mar 14 19:47:01 2006
@@ -4,9 +4,11 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.tuscany.common.TuscanyRuntimeException;
 import org.apache.tuscany.core.builder.ContextCreationException;
-import org.apache.tuscany.core.builder.ContextResolver;
 import org.apache.tuscany.core.builder.ContextFactory;
+import org.apache.tuscany.core.builder.ContextResolver;
+import org.apache.tuscany.core.config.ConfigurationException;
 import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.InstanceContext;
 import org.apache.tuscany.core.injection.EventInvoker;
@@ -14,10 +16,17 @@
 import org.apache.tuscany.core.injection.PojoObjectFactory;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
 import org.apache.tuscany.core.system.context.SystemComponentContext;
+import org.apache.tuscany.model.assembly.Module;
 import org.apache.tuscany.model.assembly.Scope;
 
 /**
- * A ContextFactory that handles system component implementation types
+ * A <code>ContextFactory</code> that handles system component implementation types, which may be either simple,
+ * leaf types or an aggregates.
+ * <p>
+ * For aggregate types, this factory delegates to an {@link org.apache.tuscany.core.builder.ObjectFactory} to create an
+ * instance of the aggregate implementation and perform injection of configuration and references. Once an aggregate instance is
+ * created, the factory will register the aggregate's children. This process may be done recursively in a lazy fashion,
+ * descending down an aggregate hierarchy as a child aggregate is instantiated.
  * 
  * @version $Rev$ $Date$
  */
@@ -26,8 +35,11 @@
     // the component name as configured in the hosting module
     private String name;
 
+    // if this factory produces aggregates, the module will be the logical model associated with its children
+    private Module module;
+
     private AggregateContext parentContext;
-    
+
     // the implementation type constructor
     private Constructor ctr;
 
@@ -46,7 +58,7 @@
     // the scope of the implementation instance
     private Scope scope;
 
-    // if the component implementation scope is stateless 
+    // if the component implementation scope is stateless
     private boolean stateless;
 
     // if the component implementation is an aggregate context
@@ -61,35 +73,32 @@
      * 
      * @param name the SCDL name of the component the context refers to
      * @param ctr the implementation type constructor
-     * @param setters a collection of <code>Injectors</code> used to configure properties, references and other meta
-     *        data values on implementation instances
-     * @param eagerInit whether the component should be eagerly initialized
-     * @param init an <code>Invoker</code> pointing to a method on the implementation type decorated with
-     *        <code>@Init</code>
-     * @param destroy an <code>Invoker</code> pointing to a method on the implementation type decorated with
-     *        <code>@Destroy</code>
      * @param scope the scope of the component implementation type
      */
-    public SystemContextFactory(String name, Constructor ctr, List<Injector> setters, boolean eagerInit,
-            EventInvoker init, EventInvoker destroy, Scope scope) {
+    public SystemContextFactory(String name, Constructor ctr, Scope scope) {
+        this(name, null, ctr, scope);
+    }
+
+    /**
+     * Creates the runtime configuration
+     * 
+     * @param name the SCDL name of the component the context refers to
+     * @param module if this factory produces aggregagtes, the logical model associated with its children; otherwise
+     *        null
+     * @param ctr the implementation type constructor
+     * @param scope the scope of the component implementation type
+     */
+    public SystemContextFactory(String name, Module module, Constructor ctr, Scope scope) {
         assert (name != null) : "Name was null";
         assert (ctr != null) : "Constructor was null";
-        assert (setters != null) : "Setters were null";
         this.name = name;
+        this.module = module;
         this.ctr = ctr;
         this.isAggregate = AggregateContext.class.isAssignableFrom(ctr.getDeclaringClass());
-        this.setters = setters;
-        this.eagerInit = eagerInit;
-        this.init = init;
-        this.destroy = destroy;
         this.scope = scope;
         stateless = (scope == Scope.INSTANCE);
     }
 
-    public SystemContextFactory(String name, Constructor ctr, Scope scope) {
-        this(name, ctr, null, false, null, null, scope);
-    }
-
     // ----------------------------------
     // Methods
     // ----------------------------------
@@ -104,17 +113,33 @@
 
     public InstanceContext createContext() throws ContextCreationException {
         if (isAggregate) {
-            // aggregate context types are themselves an instance context
-            PojoObjectFactory objectFactory = new PojoObjectFactory(ctr, null, setters);
-            AggregateContext ctx = (AggregateContext) objectFactory.getInstance();
-            ctx.setName(name);
-            return ctx;
+            try {
+                // aggregate context types are themselves an instance context
+                PojoObjectFactory objectFactory = new PojoObjectFactory(ctr, null, setters);
+                AggregateContext ctx = (AggregateContext) objectFactory.getInstance();
+                ctx.setName(name);
+                // the aggregate has been created, now register its children
+                if (module != null) {
+                    try {
+                        ctx.registerModelObject(module);
+                    } catch (ConfigurationException e) {
+                        ContextCreationException cce = new ContextCreationException("Error creating context", e);
+                        cce.setIdentifier(getName());
+                        throw cce;
+                    }
+
+                }
+                return ctx;
+            } catch (TuscanyRuntimeException e) {
+                e.addContextName(name);
+                throw e;
+            }
         } else {
             PojoObjectFactory objectFactory = new PojoObjectFactory(ctr, null, setters);
             return new SystemComponentContext(name, objectFactory, eagerInit, init, destroy, stateless);
         }
     }
-    
+
     public void addTargetProxyFactory(String serviceName, ProxyFactory factory) {
         throw new UnsupportedOperationException();
     }

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAggregateContextImpl.java Tue Mar 14 19:47:01 2006
@@ -30,6 +30,7 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.tuscany.common.TuscanyRuntimeException;
 import org.apache.tuscany.common.monitor.MonitorFactory;
 import org.apache.tuscany.core.builder.BuilderConfigException;
 import org.apache.tuscany.core.builder.ContextFactory;
@@ -70,6 +71,7 @@
 import org.apache.tuscany.core.system.config.SystemObjectContextFactory;
 import org.apache.tuscany.model.assembly.Aggregate;
 import org.apache.tuscany.model.assembly.AggregatePart;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
 import org.apache.tuscany.model.assembly.Component;
 import org.apache.tuscany.model.assembly.EntryPoint;
 import org.apache.tuscany.model.assembly.Extensible;
@@ -309,7 +311,7 @@
         autowireContext = context;
     }
 
-    public void registerModelObjects(List<Extensible> models) throws ConfigurationException {
+    public void registerModelObjects(List<? extends Extensible> models) throws ConfigurationException {
         assert (models != null) : "Model object collection was null";
         for (Extensible model : models) {
             registerModelObject(model);
@@ -322,7 +324,7 @@
         if (configurationContext != null) {
             try {
                 configurationContext.configure(model);
-                configurationContext.build(this, model);
+                configurationContext.build(model);
             } catch (ConfigurationException e) {
                 e.addContextName(getName());
                 throw e;
@@ -338,8 +340,7 @@
             Module newModule = (Module) model;
             module = newModule;
             for (Component component : newModule.getComponents()) {
-                configuration = (ContextFactory<InstanceContext>) component.getComponentImplementation()
-                        .getContextFactory();
+                configuration = (ContextFactory<InstanceContext>) component.getComponentImplementation().getContextFactory();
                 if (configuration == null) {
                     ConfigurationException e = new ConfigurationException("Runtime configuration not set");
                     e.addContextName(component.getName());
@@ -379,8 +380,7 @@
             if (model instanceof Component) {
                 Component component = (Component) model;
                 module.getComponents().add(component);
-                configuration = (ContextFactory<InstanceContext>) component.getComponentImplementation()
-                        .getContextFactory();
+                configuration = (ContextFactory<InstanceContext>) component.getComponentImplementation().getContextFactory();
             } else if (model instanceof EntryPoint) {
                 EntryPoint ep = (EntryPoint) model;
                 module.getEntryPoints().add(ep);
@@ -417,23 +417,28 @@
         autowireIndex.put(service, mapping);
     }
 
-    protected void registerConfiguration(ContextFactory<InstanceContext> configuration) throws ConfigurationException {
-        configuration.prepare(this);
+    protected void registerConfiguration(ContextFactory<InstanceContext> factory) throws ConfigurationException {
+        factory.prepare(this);
         if (lifecycleState == RUNNING) {
-            if (scopeIndex.get(configuration.getName()) != null) {
-                throw new DuplicateNameException(configuration.getName());
+            if (scopeIndex.get(factory.getName()) != null) {
+                throw new DuplicateNameException(factory.getName());
             }
-            ScopeContext scope = scopeContexts.get(configuration.getScope());
-            if (scope == null) {
-                ConfigurationException e = new ConfigurationException("Component has an unknown scope");
-                e.addContextName(configuration.getName());
+            try {
+                ScopeContext scope = scopeContexts.get(factory.getScope());
+                if (scope == null) {
+                    ConfigurationException e = new ConfigurationException("Component has an unknown scope");
+                    e.addContextName(factory.getName());
+                    e.addContextName(getName());
+                    throw e;
+                }
+                scope.registerFactory(factory);
+                scopeIndex.put(factory.getName(), scope);
+            } catch (TuscanyRuntimeException e) {
                 e.addContextName(getName());
                 throw e;
             }
-            scope.registerFactory(configuration);
-            scopeIndex.put(configuration.getName(), scope);
         } else {
-            configurations.add(configuration);
+            configurations.add(factory);
         }
 
     }
@@ -618,8 +623,8 @@
                 EntryPoint ep = (EntryPoint) model;
                 if (ep.getBindings() != null) {
                     if (ep.getBindings().get(0) instanceof SystemBinding) {
-                        ScopeContext scope = scopeContexts.get(((ContextFactory) ep.getConfiguredReference()
-                                .getContextFactory()).getScope());
+                        ScopeContext scope = scopeContexts.get(((ContextFactory) ep.getConfiguredReference().getContextFactory())
+                                .getScope());
                         if (scope == null) {
                             ConfigurationException ce = new ConfigurationException("Scope not found for entry point");
                             ce.setIdentifier(ep.getName());
@@ -644,17 +649,17 @@
         }
     }
 
-    public void build(AggregateContext parent, Extensible model) throws BuilderConfigException {
+    public void build(AssemblyModelObject model) throws BuilderConfigException {
         if (configurationContext != null) {
-            configurationContext.build(parent, model);
+            configurationContext.build(model);
         }
     }
 
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
             ScopeContext targetScopeContext) throws BuilderConfigException {
         if (configurationContext != null) {
             try {
-                configurationContext.wire(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
+                configurationContext.connect(sourceFactory, targetFactory, targetType, downScope, targetScopeContext);
             } catch (BuilderConfigException e) {
                 e.addContextName(getName());
                 throw e;
@@ -662,10 +667,11 @@
         }
     }
 
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext)
+            throws BuilderConfigException {
         if (configurationContext != null) {
             try {
-                configurationContext.wire(targetFactory, targetType, targetScopeContext);
+                configurationContext.completeTargetChain(targetFactory, targetType, targetScopeContext);
             } catch (BuilderConfigException e) {
                 e.addContextName(getName());
                 throw e;

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/system/injection/AutowireObjectFactory.java Tue Mar 14 19:47:01 2006
@@ -22,7 +22,7 @@
 import org.apache.tuscany.core.injection.ObjectCreationException;
 
 /**
- * Implementation of ObjectFactory that returns an instance by resolving against an AutowireContext.
+ * Returns an instance by resolving against an AutowireContext.
  * 
  * @version $Rev: 385139 $ $Date: 2006-03-11 11:03:11 -0800 (Sat, 11 Mar 2006) $
  */
@@ -30,7 +30,7 @@
 
     private ContextResolver resolver;
 
-    private Class interfaze;
+    private Class autowireType;
 
     private boolean required;
 
@@ -38,13 +38,12 @@
      * 
      * @throws FactoryInitException
      */
-    public AutowireObjectFactory(Class<T> implementationType, boolean required, ContextResolver resolver)
-            throws FactoryInitException {
-        assert (implementationType != null) : "Target interface was null";
+    public AutowireObjectFactory(Class<T> autowireType, boolean required, ContextResolver resolver) {
+        assert (autowireType != null) : "Target interface was null";
         assert (resolver != null) : "Context resolver was null";
         this.resolver = resolver;
         this.required = required;
-        interfaze = implementationType;
+        this.autowireType = autowireType;
     }
 
     /**
@@ -52,7 +51,7 @@
      * 
      * @throws FactoryInitException
      */
-    public AutowireObjectFactory(Class<T> implementationType) throws FactoryInitException {
+    public AutowireObjectFactory(Class<T> implementationType) {
         this(implementationType, true, null);
     }
 
@@ -70,12 +69,12 @@
         AutowireContext ctx = (AutowireContext) parent;
         if (ctx == null && required) {
             AutowireResolutionException e = new AutowireResolutionException("Required autowire not found");
-            e.setIdentifier(interfaze.getName());
+            e.setIdentifier(autowireType.getName());
             throw e;
         } else if (ctx == null) {
             return null;
         }
-        return (T) ctx.resolveInstance(interfaze);
+        return (T) ctx.resolveInstance(autowireType);
     }
 
     public void setContextResolver(ContextResolver resolver) {

Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/webapp/TuscanyServletListener.java Tue Mar 14 19:47:01 2006
@@ -152,7 +152,7 @@
 
         // Get the aggregate context representing the system module component
         systemModuleComponentContext = (AggregateContext) systemContext.getContext(SYSTEM_MODULE_COMPONENT);
-        systemModuleComponentContext.registerModelObject(systemModuleComponent.getComponentImplementation());
+        //systemModuleComponentContext.registerModelObject(systemModuleComponent.getComponentImplementation());
         systemModuleComponentContext.fireEvent(EventContext.MODULE_START, null);
 
         // Load the SCDL configuration of the application module
@@ -161,7 +161,7 @@
         // Register it under the root application context
         runtimeContext.getRootContext().registerModelObject(moduleComponent);
         moduleContext=(AggregateContext)runtimeContext.getContext(moduleComponent.getName());
-        moduleContext.registerModelObject(moduleComponent.getComponentImplementation());
+        //moduleContext.registerModelObject(moduleComponent.getComponentImplementation());
 
         moduleContext.fireEvent(EventContext.MODULE_START, null);
     }

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraAggregateWireIntegrationTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraAggregateWireIntegrationTestCase.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraAggregateWireIntegrationTestCase.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/integration/IntraAggregateWireIntegrationTestCase.java Tue Mar 14 19:47:01 2006
@@ -16,6 +16,7 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.tuscany.core.config.ConfigurationException;
 import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.mock.MockFactory;
@@ -26,8 +27,6 @@
 import org.apache.tuscany.core.system.assembly.SystemImplementation;
 import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl;
 import org.apache.tuscany.core.system.context.SystemAggregateContextImpl;
-import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.model.assembly.Component;
 import org.apache.tuscany.model.assembly.Module;
 import org.apache.tuscany.model.assembly.ModuleComponent;
 import org.apache.tuscany.model.assembly.Scope;
@@ -45,12 +44,12 @@
     public void testWireConstruction2() throws Exception {
         RuntimeContext runtime = MockFactory.createCoreRuntime();
         ModuleComponent moduleComponent = createSystemAggregateComponent("test.system");
-        Module module = MockFactory.createSystemModuleWithWiredComponents(Scope.MODULE, Scope.MODULE);
+        Module module = MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE, Scope.MODULE);
         moduleComponent.setModuleImplementation(module);
         runtime.getSystemContext().registerModelObject(moduleComponent);
         AggregateContext context = (AggregateContext) runtime.getSystemContext().getContext("test.system").getImplementationInstance();
         context.fireEvent(EventContext.MODULE_START, null);
-        context.registerModelObject(module);
+        //context.registerModelObject(module);
         Source source = (Source) context.getContext("source").getImplementationInstance();
         Assert.assertNotNull(source);
         Target targetRef = source.getTarget();
@@ -91,7 +90,7 @@
         AggregateContext context = (AggregateContext) runtime.getSystemContext().getContext("test.system").getImplementationInstance();
 
         context.fireEvent(EventContext.MODULE_START, null);
-        context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents(Scope.MODULE,Scope.MODULE));
+        context.registerModelObject(MockFactory.createSystemModuleWithWiredComponents("system.module",Scope.MODULE,Scope.MODULE));
         Source source = (Source) context.getContext("source").getImplementationInstance();
         Assert.assertNotNull(source);
         Target targetRef = source.getTarget();

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockConfigContext.java Tue Mar 14 19:47:01 2006
@@ -20,10 +20,10 @@
 import org.apache.tuscany.core.builder.ContextFactoryBuilder;
 import org.apache.tuscany.core.builder.impl.AssemblyVisitor;
 import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.ConfigurationContext;
 import org.apache.tuscany.core.context.ScopeContext;
 import org.apache.tuscany.core.invocation.spi.ProxyFactory;
+import org.apache.tuscany.model.assembly.AssemblyModelObject;
 import org.apache.tuscany.model.assembly.Extensible;
 
 /**
@@ -42,16 +42,16 @@
     public void configure(Extensible model) throws ConfigurationException {
     }
 
-    public void build(AggregateContext parent, Extensible model) throws BuilderConfigException {
+    public void build(AssemblyModelObject model) throws BuilderConfigException {
         AssemblyVisitor visitor = new AssemblyVisitor(builders);
         visitor.start(model);
     }
 
-    public void wire(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
+    public void connect(ProxyFactory sourceFactory, ProxyFactory targetFactory, Class targetType, boolean downScope,
             ScopeContext targetScopeContext) throws BuilderConfigException {
     }
 
-    public void wire(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
+    public void completeTargetChain(ProxyFactory targetFactory, Class targetType, ScopeContext targetScopeContext) throws BuilderConfigException {
     }
 
 }

Modified: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java?rev=385966&r1=385965&r2=385966&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java (original)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/mock/MockFactory.java Tue Mar 14 19:47:01 2006
@@ -44,6 +44,7 @@
 import org.apache.tuscany.model.assembly.EntryPoint;
 import org.apache.tuscany.model.assembly.ExternalService;
 import org.apache.tuscany.model.assembly.Module;
+import org.apache.tuscany.model.assembly.ModuleComponent;
 import org.apache.tuscany.model.assembly.Multiplicity;
 import org.apache.tuscany.model.assembly.Reference;
 import org.apache.tuscany.model.assembly.Scope;
@@ -53,7 +54,7 @@
 
 /**
  * Generates test components, modules, and runtime artifacts
- *
+ * 
  * @version $Rev$ $Date$
  */
 public class MockFactory {
@@ -105,10 +106,10 @@
 
     /**
      * Creates a basic entry point with no configured reference using the system binding
-     *
-     * @param name     the name of the entry point
+     * 
+     * @param name the name of the entry point
      * @param interfaz the inteface exposed by the entry point
-     * @param refName  the name of the entry point reference
+     * @param refName the name of the entry point reference
      */
     public static EntryPoint createEPSystemBinding(String name, Class interfaz, String refName) {
         return createEPSystemBinding(name, interfaz, refName, null);
@@ -116,11 +117,11 @@
 
     /**
      * Creates an entry point wired to the given target (e.g. component, external service) using the system binding
-     *
-     * @param name     the name of the entry point
+     * 
+     * @param name the name of the entry point
      * @param interfaz the inteface exposed by the entry point
-     * @param refName  the name of the entry point reference
-     * @param target   the target the entry point is wired to
+     * @param refName the name of the entry point reference
+     * @param target the target the entry point is wired to
      */
     public static EntryPoint createEPSystemBinding(String name, Class interfaz, String refName, AggregatePart target) {
         JavaServiceContract contract = systemFactory.createJavaServiceContract();
@@ -170,10 +171,10 @@
     /**
      * Creates an entry point that should be wired to the given target (e.g. component, external service) using the
      * system binding. The system assembly process should resolve the target name to an actual target configuration.
-     *
-     * @param name          the name of the entry point
-     * @param interfaz      the inteface exposed by the entry point
-     * @param refName       the name of the entry point reference
+     * 
+     * @param name the name of the entry point
+     * @param interfaz the inteface exposed by the entry point
+     * @param refName the name of the entry point reference
      * @param componentName the name of the target to resolve
      */
     public static EntryPoint createEntryPointWithStringRef(String name, Class interfaz, String refName, String componentName) {
@@ -238,7 +239,8 @@
         module.setName("system.module");
 
         // create test component
-        Component component = systemFactory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
+        Component component = systemFactory.createSystemComponent("TestService1", ModuleScopeSystemComponent.class,
+                ModuleScopeSystemComponentImpl.class, Scope.MODULE);
         module.getComponents().add(component);
 
         // create the entry point
@@ -251,11 +253,11 @@
 
     /**
      * Creates a test system module with source and target components wired together.
-     *
+     * 
      * @see org.apache.tuscany.core.mock.component.Source
      * @see org.apache.tuscany.core.mock.component.Target
      */
-    public static Module createSystemModuleWithWiredComponents(Scope sourceScope, Scope targetScope) {
+    public static Module createSystemModuleWithWiredComponents(String moduleName, Scope sourceScope, Scope targetScope) {
 
         // create the target component
         Component target = systemFactory.createSystemComponent("target", Target.class, TargetImpl.class, targetScope);
@@ -273,24 +275,24 @@
         configuredReferences.put(configuredReference.getName(), configuredReference);
 
         // wire multiplicity using a setter
-        references.add(systemFactory.createReference("setTargets", Target.class,Multiplicity.ONE_N));
+        references.add(systemFactory.createReference("setTargets", Target.class, Multiplicity.ONE_N));
         configuredReference = systemFactory.createConfiguredReference("setTargets", "target");
         configuredReferences.put(configuredReference.getName(), configuredReference);
 
         // wire multiplicity using a field
-        references.add(systemFactory.createReference("targetsThroughField", Target.class,Multiplicity.ONE_N));
+        references.add(systemFactory.createReference("targetsThroughField", Target.class, Multiplicity.ONE_N));
         configuredReference = systemFactory.createConfiguredReference("targetsThroughField", "target");
         configuredReferences.put(configuredReference.getName(), configuredReference);
 
         // wire multiplicity using a setter
-        references.add(systemFactory.createReference("setArrayOfTargets", Target.class,Multiplicity.ONE_N));
+        references.add(systemFactory.createReference("setArrayOfTargets", Target.class, Multiplicity.ONE_N));
         configuredReference = systemFactory.createConfiguredReference("setArrayOfTargets", "target");
         configuredReferences.put(configuredReference.getName(), configuredReference);
 
         source.initialize(assemblyContext);
 
         Module module = systemFactory.createModule();
-        module.setName("system.module");
+        module.setName(moduleName);
         module.getComponents().add(source);
         module.getComponents().add(target);
         module.initialize(assemblyContext);
@@ -298,6 +300,20 @@
     }
 
     /**
+     * Creates a test system module component with source and target components wired together.
+     * 
+     * @see org.apache.tuscany.core.mock.component.Source
+     * @see org.apache.tuscany.core.mock.component.Target
+     */
+    public static ModuleComponent createSystemModuleComponentWithWiredComponents(String moduleComponentName, Scope sourceScope,
+            Scope targetScope) {
+        ModuleComponent mc = systemFactory.createModuleComponent();
+        mc.setName(moduleComponentName);
+        mc.setComponentImplementation(createSystemModuleWithWiredComponents(moduleComponentName+".module", sourceScope, targetScope));
+        return mc;
+    }
+
+    /**
      * Creates a test system module component with a module-scoped component and entry point
      */
     public static Module createSystemChildModule() {
@@ -305,7 +321,8 @@
         module.setName("system.test.module");
 
         // create test component
-        Component component = systemFactory.createSystemComponent("TestService2", ModuleScopeSystemComponent.class, ModuleScopeSystemComponentImpl.class, Scope.MODULE);
+        Component component = systemFactory.createSystemComponent("TestService2", ModuleScopeSystemComponent.class,
+                ModuleScopeSystemComponentImpl.class, Scope.MODULE);
         module.getComponents().add(component);
 
         // create the entry point