You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2007/05/24 16:57:39 UTC

svn commit: r541314 - in /incubator/tuscany/sandbox/slaws/disitributed-changes: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apac...

Author: slaws
Date: Thu May 24 07:57:37 2007
New Revision: 541314

URL: http://svn.apache.org/viewvc?view=rev&rev=541314
Log:
start playing with changes for distributed runtime

Added:
    incubator/tuscany/sandbox/slaws/disitributed-changes/
    incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java   (with props)
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/resources/
    incubator/tuscany/sandbox/slaws/disitributed-changes/src/test/

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml Thu May 24 07:57:37 2007
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    * 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.    
+-->
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-sca</artifactId>
+        <version>1.0-incubating-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+    <artifactId>distributed-changes</artifactId>
+    <name>Apache Tuscany Calculator Sample</name>
+
+    <repositories>
+       <repository>
+          <id>apache.incubator</id>
+          <url>http://people.apache.org/repo/m2-incubating-repository</url>
+       </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-host-embedded</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-java-runtime</artifactId>
+            <version>1.0-incubating-SNAPSHOT</version>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.2</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+       <finalName>${artifactId}</finalName>
+    </build>
+</project>

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java Thu May 24 07:57:37 2007
@@ -0,0 +1,147 @@
+/*
+ * 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.sca.assembly;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a component. A component is a configured instance of an
+ * implementation.
+ * 
+ * @version $Rev$ $Date$
+ */
+public interface Component extends Base, IntentAttachPoint, PolicySetAttachPoint, Visitable {
+    
+    /**
+     * Returns the runtimeId of the component.
+     *  
+     * @return the runtimeId of the component
+     */    
+    public String getRuntimeId();
+    
+    /**
+     * Sets the runtimeId of the component.
+     *  
+     * @param runtimeId the runtimeId of the component
+     */    
+    public void setRuntimeId(String runtimeId);
+    
+    /**
+     * Returns the URI of the component.
+     *  
+     * @return the URI of the component
+     */
+    String getURI();
+    
+    /**
+     * Returns the URI of the component.
+     *  
+     * @return the URI of the component
+     */
+    void setURI(String uri);
+
+    /**
+     * Returns the name of the component.
+     * 
+     * @return the name of the component
+     */
+    String getName();
+
+    /**
+     * Sets the name of the component.
+     * 
+     * @param name the name of the component
+     */
+    void setName(String name);
+
+    /**
+     * Returns the component implementation.
+     * 
+     * @return the component implementation
+     */
+    Implementation getImplementation();
+
+    /**
+     * Sets the component implementation
+     * 
+     * @param implementation the component implementation
+     */
+    void setImplementation(Implementation implementation);
+
+    /**
+     * Returns a list of references used by the component.
+     * 
+     * @return a list of references used by the component
+     */
+    List<ComponentReference> getReferences();
+
+    /**
+     * Returns a list of services exposed by the component.
+     * 
+     * @return a list of services exposed by the component
+     */
+    List<ComponentService> getServices();
+
+    /**
+     * Returns a list of properties for the component.
+     * 
+     * @return a list of properties
+     */
+    List<ComponentProperty> getProperties();
+
+    /**
+     * Returns a constraining type defining the shape of the component.
+     * 
+     * @return a constraining type
+     */
+    ConstrainingType getConstrainingType();
+
+    /**
+     * Sets a constraining type defining the shape of the component.
+     * 
+     * @param constrainingType the constraining type
+     */
+    void setConstrainingType(ConstrainingType constrainingType);
+
+    /**
+     * Returns true if the component references should be autowired.
+     * 
+     * @return whether component references should be autowired.
+     */
+    boolean isAutowire();
+
+    /**
+     * Sets whether component references should be autowired.
+     * 
+     * @param autowire whether component references should be autowired
+     */
+    void setAutowire(boolean autowire);
+
+    /**
+     * Returns a clone of the component.
+     * 
+     * @return a clone of the component
+     * @throws CloneNotSupportedException
+     */
+    Object clone() throws CloneNotSupportedException;
+
+}

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/Component.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java Thu May 24 07:57:37 2007
@@ -0,0 +1,169 @@
+/*
+ * 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.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Visitor;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a component.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ComponentImpl extends BaseImpl implements Component, Cloneable {
+    private ConstrainingType constrainingType;
+    private Implementation implementation;
+    private String name;
+    private String uri;
+    private List<ComponentProperty> properties = new ArrayList<ComponentProperty>();
+    private List<ComponentReference> references = new ArrayList<ComponentReference>();
+    private List<ComponentService> services = new ArrayList<ComponentService>();
+    private List<Intent> requiredIntents = new ArrayList<Intent>();
+    private List<PolicySet> policySets = new ArrayList<PolicySet>();
+    private boolean autowire;
+    private String runtimeId;
+    
+    /**
+     * Constructs a new component.
+     */
+    protected ComponentImpl() {
+    }
+    
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        ComponentImpl clone = (ComponentImpl)super.clone();
+
+        clone.properties = new ArrayList<ComponentProperty>();
+        for (ComponentProperty property: getProperties()) {
+            clone.properties.add((ComponentProperty)property.clone());
+        }
+        clone.references = new ArrayList<ComponentReference>();
+        for (ComponentReference reference: getReferences()) {
+            clone.references.add((ComponentReference)reference.clone());
+        }
+        clone.services = new ArrayList<ComponentService>();
+        for (ComponentService service: getServices()) {
+            clone.services.add((ComponentService)service.clone());
+        }
+        return clone;
+    }
+    
+    public String getRuntimeId() {
+        return runtimeId;
+    }
+    
+    public void setRuntimeId(String runtimeId) {
+        System.out.println(">>> RuntimeId set to: " + runtimeId);           
+        this.runtimeId = runtimeId;
+    }    
+    
+    public String getURI() {
+        return uri;
+    }
+    
+    public void setURI(String uri) {
+        System.out.println(">>> Component uri set to: " + uri);           
+        this.uri = uri;
+    }
+
+    public ConstrainingType getConstrainingType() {
+        return constrainingType;
+    }
+
+    public Implementation getImplementation() {
+        return implementation;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public List<ComponentProperty> getProperties() {
+        return properties;
+    }
+
+    public List<ComponentReference> getReferences() {
+        return references;
+    }
+
+    public List<ComponentService> getServices() {
+        return services;
+    }
+
+    public void setConstrainingType(ConstrainingType constrainingType) {
+        this.constrainingType = constrainingType;
+    }
+
+    public void setImplementation(Implementation implementation) {
+        this.implementation = implementation;
+    }
+
+    public void setName(String name) {
+        System.out.println(">>> Component name set to: " + name);         
+        this.name = name;
+    }
+
+    public List<Intent> getRequiredIntents() {
+        return requiredIntents;
+    }
+
+    public List<PolicySet> getPolicySets() {
+        return policySets;
+    }
+
+    public boolean isAutowire() {
+        return autowire;
+    }
+
+    public void setAutowire(boolean autowire) {
+        this.autowire = autowire;
+    }
+
+    public boolean accept(Visitor visitor) {
+        if (!super.accept(visitor)) {
+            return false;
+        }
+        for (ComponentProperty property : properties) {
+            if (!visitor.visit(property)) {
+                return false;
+            }
+        }
+        for (ComponentReference reference : references) {
+            if (!visitor.visit(reference)) {
+                return false;
+            }
+        }
+        for (ComponentService service : services) {
+            if (!visitor.visit(service)) {
+                return false;
+            }
+        }
+        return true;
+    }
+}

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java Thu May 24 07:57:37 2007
@@ -0,0 +1,504 @@
+/*
+ * 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.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * A composite processor.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class CompositeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor<Composite> {
+    
+    /**
+     * Construct a new composite processor
+     * @param assemblyFactory
+     * @param policyFactory
+     * @param extensionProcessor 
+     */
+    public CompositeProcessor(AssemblyFactory factory, PolicyFactory policyFactory,
+                              InterfaceContractMapper interfaceContractMapper,
+                              StAXArtifactProcessor extensionProcessor) {
+        super(factory, policyFactory, extensionProcessor);
+    }
+
+    public Composite read(XMLStreamReader reader) throws ContributionReadException {
+        Composite composite = null;
+        Composite include = null;
+        Component component = null;
+        Property property = null;
+        ComponentService componentService = null;
+        ComponentReference componentReference = null;
+        ComponentProperty componentProperty = null;
+        CompositeService compositeService = null;
+        CompositeReference compositeReference = null;
+        Contract contract = null;
+        Wire wire = null;
+        Callback callback = null;
+        QName name = null;
+        
+        try {
+    
+            // Read the composite document
+            while (reader.hasNext()) {
+                int event = reader.getEventType();
+                switch (event) {
+                    case START_ELEMENT:
+                        name = reader.getName();
+    
+                        if (COMPOSITE_QNAME.equals(name)) {
+    
+                            // Read a <composite>
+                            composite = assemblyFactory.createComposite();
+                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
+                            composite.setLocal(getBoolean(reader, LOCAL));
+                            composite.setConstrainingType(getConstrainingType(reader));
+                            readPolicies(composite, reader);
+    
+                        } else if (INCLUDE_QNAME.equals(name)) {
+    
+                            // Read an <include>
+                            include = assemblyFactory.createComposite();
+                            include.setUnresolved(true);
+                            composite.getIncludes().add(include);
+    
+                        } else if (SERVICE_QNAME.equals(name)) {
+                            if (component != null) {
+    
+                                // Read a <component><service>
+                                componentService = assemblyFactory.createComponentService();
+                                contract = componentService;
+                                componentService.setName(getString(reader, NAME));
+                                component.getServices().add(componentService);
+                                readPolicies(contract, reader);
+                            } else {
+    
+                                // Read a <composite><service>
+                                compositeService = assemblyFactory.createCompositeService();
+                                contract = compositeService;
+                                compositeService.setName(getString(reader, NAME));
+    
+                                ComponentService promoted = assemblyFactory.createComponentService();
+                                promoted.setUnresolved(true);
+                                promoted.setName(getString(reader, PROMOTE));
+                                compositeService.setPromotedService(promoted);
+    
+                                composite.getServices().add(compositeService);
+                                readPolicies(contract, reader);
+                            }
+    
+                        } else if (REFERENCE_QNAME.equals(name)) {
+                            if (component != null) {
+                                // Read a <component><reference>
+                                componentReference = assemblyFactory.createComponentReference();
+                                contract = componentReference;
+                                componentReference.setName(getString(reader, NAME));
+                                readMultiplicity(componentReference, reader);
+                                componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
+                                readTargets(componentReference, reader);
+                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+                                component.getReferences().add(componentReference);
+                                readPolicies(contract, reader);
+                            } else {
+                                // Read a <composite><reference>
+                                compositeReference = assemblyFactory.createCompositeReference();
+                                contract = compositeReference;
+                                compositeReference.setName(getString(reader, NAME));
+                                readMultiplicity(compositeReference, reader);
+                                readTargets(compositeReference, reader);
+                                readPromotes(compositeReference, reader);
+                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+                                composite.getReferences().add(compositeReference);
+                                readPolicies(contract, reader);
+                            }
+    
+                        } else if (PROPERTY_QNAME.equals(name)) {
+                            if (component != null) {
+                                // Read a <component><property>
+                                componentProperty = assemblyFactory.createComponentProperty();
+                                property = componentProperty;
+                                componentProperty.setSource(getString(reader, SOURCE));
+                                componentProperty.setFile(getString(reader, FILE));
+                                readPolicies(property, reader);
+                                readProperty(componentProperty, reader);
+                                component.getProperties().add(componentProperty);
+                            } else {
+    
+                                // Read a <composite><property>
+                                property = assemblyFactory.createProperty();
+                                readPolicies(property, reader);
+                                readProperty(property, reader);
+                                composite.getProperties().add(property);
+                            }
+    
+                        } else if (COMPONENT_QNAME.equals(name)) {
+    
+                            // Read a <component>
+                            component = assemblyFactory.createComponent();
+                            component.setName(getString(reader, NAME));
+                            component.setRuntimeId(getString(reader, RUNTIME_ID));
+                            component.setConstrainingType(getConstrainingType(reader));
+                            composite.getComponents().add(component);
+                            readPolicies(component, reader);
+    
+                        } else if (WIRE_QNAME.equals(name)) {
+    
+                            // Read a <wire>
+                            wire = assemblyFactory.createWire();
+                            ComponentReference source = assemblyFactory.createComponentReference();
+                            source.setUnresolved(true);
+                            source.setName(getString(reader, SOURCE));
+                            wire.setSource(source);
+    
+                            ComponentService target = assemblyFactory.createComponentService();
+                            target.setUnresolved(true);
+                            target.setName(getString(reader, TARGET));
+                            wire.setTarget(target);
+    
+                            composite.getWires().add(wire);
+                            readPolicies(wire, reader);
+    
+                        } else if (CALLBACK_QNAME.equals(name)) {
+    
+                            // Read a <callback>
+                            callback = assemblyFactory.createCallback();
+                            contract.setCallback(callback);
+                            readPolicies(callback, reader);
+    
+                        } else if (OPERATION_QNAME.equals(name)) {
+    
+                            // Read an <operation>
+                            Operation operation = assemblyFactory.createOperation();
+                            operation.setName(getString(reader, NAME));
+                            operation.setUnresolved(true);
+                            if (callback != null) {
+                                readPolicies(callback, operation, reader);
+                            } else {
+                                readPolicies(contract, operation, reader);
+                            }
+                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
+                            
+                            // Read an implementation.composite
+                            Composite implementation = assemblyFactory.createComposite();
+                            implementation.setName(getQName(reader, NAME));
+                            implementation.setUnresolved(true);
+                            component.setImplementation(implementation);
+                            
+                        } else {
+    
+                            // Read an extension element
+                            Object extension = extensionProcessor.read(reader);
+                            if (extension != null) {
+                                if (extension instanceof InterfaceContract) {
+    
+                                    // <service><interface> and
+                                    // <reference><interface>
+                                    contract.setInterfaceContract((InterfaceContract)extension);
+    
+                                } else if (extension instanceof Binding) {
+                                    // <service><binding> and <reference><binding>
+                                    contract.getBindings().add((Binding)extension);
+    
+                                } else if (extension instanceof Implementation) {
+    
+                                    // <component><implementation>
+                                    component.setImplementation((Implementation)extension);
+                                } else {
+                                    
+                                    // FIXME: We need to decide where to host the extensions
+                                    composite.getExtensions().add(extension);
+                                }
+                            }
+                        }
+                        break;
+    
+                    case XMLStreamConstants.CHARACTERS:
+    
+                        // Read an <include>qname</include>
+                        if (include != null && INCLUDE_QNAME.equals(name)) {
+                            include.setName(getQNameValue(reader, reader.getText().trim()));
+                        }
+    
+                        break;
+    
+                    case END_ELEMENT:
+                        name = reader.getName();
+    
+                        // Clear current state when reading reaching end element
+                        if (SERVICE_QNAME.equals(name)) {
+                            componentService = null;
+                            compositeService = null;
+                            contract = null;
+                        } else if (INCLUDE_QNAME.equals(name)) {
+                            include = null;
+                        } else if (REFERENCE_QNAME.equals(name)) {
+                            componentReference = null;
+                            compositeReference = null;
+                            contract = null;
+                        } else if (PROPERTY_QNAME.equals(name)) {
+                            componentProperty = null;
+                            property = null;
+                        } else if (COMPONENT_QNAME.equals(name)) {
+                            component = null;
+                        } else if (WIRE_QNAME.equals(name)) {
+                            wire = null;
+                        } else if (CALLBACK_QNAME.equals(name)) {
+                            callback = null;
+                        }
+                        break;
+                }
+    
+                // Read the next element
+                if (reader.hasNext()) {
+                    reader.next();
+                }
+            }
+            return composite;
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionReadException(e);
+        }
+    }
+    
+    public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException {
+
+        try {
+            writeStartDocument(writer, COMPOSITE,
+                new XAttr(CONSTRAINING_TYPE, getConstrainingTypeAttr(composite)),
+                new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
+                new XAttr(NAME, composite.getName().getLocalPart()));
+    
+            for (Service service : composite.getServices()) {
+                CompositeService compositeService = (CompositeService)service;
+                ComponentService promotedService = compositeService.getPromotedService();
+                String promote = promotedService != null ? promotedService.getName() : null;
+                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote));
+
+                extensionProcessor.write(service.getInterfaceContract(), writer);
+                
+                for (Binding binding: service.getBindings()) {
+                    extensionProcessor.write(binding, writer);
+                }
+                
+                if (service.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Component component : composite.getComponents()) {
+                writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()));
+    
+                for (ComponentService service : component.getServices()) {
+                    writeStart(writer, SERVICE, new XAttr(NAME, service.getName()));
+
+                    extensionProcessor.write(service.getInterfaceContract(), writer);
+
+                    for (Binding binding: service.getBindings()) {
+                        extensionProcessor.write(binding, writer);
+                    }
+                    
+                    if (service.getCallback() != null) {
+                        writeStart(writer, CALLBACK);
+                        writeEnd(writer);
+                    }
+                    writeEnd(writer);
+                }
+    
+                for (ComponentReference reference : component.getReferences()) {
+                    // TODO handle multivalued target attribute
+                    String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName();
+                    writeStart(writer, REFERENCE,
+                               new XAttr(NAME, reference.getName()),
+                               new XAttr(TARGET,target));
+                    
+                    extensionProcessor.write(reference.getInterfaceContract(), writer);
+                    
+                    for (Binding binding: reference.getBindings()) {
+                        extensionProcessor.write(binding, writer);
+                    }
+                    
+                    if (reference.getCallback() != null) {
+                        writeStart(writer, CALLBACK);
+                        writeEnd(writer);
+                    }
+                    writeEnd(writer);
+                }
+    
+                for (ComponentProperty property : component.getProperties()) {
+                    writeStart(writer, PROPERTY, new XAttr(NAME, property.getName()));
+                    writeEnd(writer);
+                }
+
+                // Write the component implementation
+                Implementation implementation = component.getImplementation();
+                if (implementation instanceof Composite) {
+                    writeStart(writer, IMPLEMENTATION_COMPOSITE, 
+                       new XAttr(NAME, composite.getName()));
+                    writeEnd(writer);
+                } else {
+                    extensionProcessor.write(component.getImplementation(), writer);
+                }
+    
+                writeEnd(writer);
+            }
+    
+            for (Reference reference : composite.getReferences()) {
+                // TODO handle multivalued promote attribute
+                CompositeReference compositeReference = (CompositeReference)reference;
+                String promote;
+                if (!compositeReference.getPromotedReferences().isEmpty())
+                    promote = compositeReference.getPromotedReferences().get(0).getName();
+                else
+                    promote = null;
+                writeStart(writer, REFERENCE,
+                           new XAttr(NAME, reference.getName()),
+                           new XAttr(PROMOTE, promote));
+
+                extensionProcessor.write(reference.getInterfaceContract(), writer);
+                
+                for (Binding binding: reference.getBindings()) {
+                    extensionProcessor.write(binding, writer);
+                }
+                
+                if (reference.getCallback() != null) {
+                    writeStart(writer, CALLBACK);
+                    writeEnd(writer);
+                }
+                writeEnd(writer);
+            }
+    
+            for (Property property : composite.getProperties()) {
+                writeStart(writer, PROPERTY, new XAttr(NAME, property.getName()));
+                writeEnd(writer);
+            }
+    
+            writeEndDocument(writer);
+            
+        } catch (XMLStreamException e) {
+            throw new ContributionWriteException(e);
+        }
+    }
+    
+    public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {
+        
+        // Resolve constraining type
+        ConstrainingType constrainingType = composite.getConstrainingType(); 
+        constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); 
+        composite.setConstrainingType(constrainingType);
+        
+        // Resolve includes in the composite
+        for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
+            Composite include = composite.getIncludes().get(i);
+            include = resolver.resolveModel(Composite.class, include);
+            composite.getIncludes().set(i, include);
+        }
+
+        // resolve and extensions to the standard SCDL that appear in the 
+        // SCDL. 
+        for (int i = 0, n = composite.getExtensions().size(); i < n; i++) {
+            Object model = composite.getExtensions().get(i);
+            extensionProcessor.resolve(model, resolver);
+        }
+        
+        // Resolve component implementations, services and references 
+        for (Component component: composite.getComponents()) {
+            constrainingType = component.getConstrainingType(); 
+            constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); 
+            component.setConstrainingType(constrainingType);
+
+            Implementation implementation = component.getImplementation();
+            implementation = resolveImplementation(implementation, resolver);
+            component.setImplementation(implementation);
+            
+            resolveContracts(component.getServices(), resolver);
+            resolveContracts(component.getReferences(), resolver);
+        }
+        
+        // Resolve composite services and references
+        resolveContracts(composite.getServices(), resolver);
+        resolveContracts(composite.getReferences(), resolver);
+    }
+
+    public QName getArtifactType() {
+        return COMPOSITE_QNAME;
+    }
+    
+    public Class<Composite> getModelType() {
+        return Composite.class;
+    }
+    
+    /**
+     * Read list of refence targets
+     * @param reference
+     * @param reader
+     */
+    protected void readPromotes(CompositeReference reference, XMLStreamReader reader) {
+        String value = reader.getAttributeValue(null, Constants.PROMOTE);
+        ComponentReference promoted = null;
+        if (value != null) {
+            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+                promoted = assemblyFactory.createComponentReference();
+                promoted.setUnresolved(true);
+                promoted.setName(tokens.nextToken());
+                reference.getPromotedReferences().add(promoted);
+            }
+        }
+    }
+}

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java Thu May 24 07:57:37 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.sca.assembly.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Constants used in SCA assembly XML files.
+ */
+public interface Constants {
+    String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+    String COMPONENT_TYPE = "componentType";
+    QName COMPONENT_TYPE_QNAME = new QName(SCA10_NS, COMPONENT_TYPE);
+    String SERVICE = "service";
+    QName SERVICE_QNAME = new QName(SCA10_NS, SERVICE);
+    String REFERENCE = "reference";
+    QName REFERENCE_QNAME = new QName(SCA10_NS, REFERENCE);
+    String PROPERTY = "property";
+    QName PROPERTY_QNAME = new QName(SCA10_NS, PROPERTY);
+    String CONSTRAINING_TYPE = "constrainingType";
+    QName CONSTRAINING_TYPE_QNAME = new QName(SCA10_NS, CONSTRAINING_TYPE);
+    String COMPOSITE = "composite";
+    QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE);
+    String INCLUDE = "include";
+    QName INCLUDE_QNAME = new QName(SCA10_NS, INCLUDE);
+    String COMPONENT = "component";
+    QName COMPONENT_QNAME = new QName(SCA10_NS, COMPONENT);
+    String WIRE = "wire";
+    QName WIRE_QNAME = new QName(SCA10_NS, WIRE);
+    String NAME = "name";
+    String TARGET_NAMESPACE = "targetNamespace";
+    String LOCAL = "local";
+    String AUTOWIRE = "autowire";
+    String REQUIRES = "requires";
+    String POLICY_SETS = "policySets";
+    String OPERATION = "operation";
+    QName OPERATION_QNAME = new QName(SCA10_NS, OPERATION);
+    String CALLBACK = "callback";
+    QName CALLBACK_QNAME = new QName(SCA10_NS, CALLBACK);
+    String PROMOTE = "promote";
+    String TARGET = "target";
+    String WIRED_BY_IMPL = "wiredByImpl";
+    String MULTIPLICITY = "multiplicity";
+    String TYPE = "type";
+    String ELEMENT = "element";
+    String MANY = "many";
+    String MUST_SUPPLY = "mustSupply";
+    String SOURCE = "source";
+    String FILE = "file";
+    String URI = "uri";
+    String ZERO_ONE = "0..1";
+    String ZERO_N = "0..n";
+    String ONE_ONE = "1..1";
+    String ONE_N = "1..n";
+    String IMPLEMENTATION_COMPOSITE = "implementation.composite";
+    QName IMPLEMENTATION_COMPOSITE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_COMPOSITE);
+    String RUNTIME_ID = "runtimeId";
+}

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java?view=auto&rev=541314
==============================================================================
--- incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java (added)
+++ incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java Thu May 24 07:57:37 2007
@@ -0,0 +1,612 @@
+/*
+ * 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.sca.core.runtime;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor;
+import org.apache.tuscany.sca.assembly.builder.Problem;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.core.invocation.InvocationChainImpl;
+import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.scope.ScopeRegistry;
+import org.apache.tuscany.sca.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeActivatorImpl implements CompositeActivator {
+
+    private final AssemblyFactory assemblyFactory;
+    private final SCABindingFactory scaBindingFactory;
+    private final InterfaceContractMapper interfaceContractMapper;
+    private final ScopeRegistry scopeRegistry;
+    private final WorkScheduler workScheduler;
+    private final RuntimeWireProcessor wireProcessor;
+    private final ProviderFactoryExtensionPoint providerFactories;
+
+    /**
+     * @param assemblyFactory
+     * @param interfaceContractMapper
+     * @param workContext
+     * @param workScheduler
+     * @param wirePostProcessorRegistry
+     */
+    public CompositeActivatorImpl(AssemblyFactory assemblyFactory,
+                                     SCABindingFactory scaBindingFactory,
+                                     InterfaceContractMapper interfaceContractMapper,
+                                     ScopeRegistry scopeRegistry,
+                                     WorkScheduler workScheduler,
+                                     RuntimeWireProcessor wireProcessor,
+                                     ProviderFactoryExtensionPoint providerFactories) {
+        super();
+        this.assemblyFactory = assemblyFactory;
+        this.scaBindingFactory = scaBindingFactory;
+        this.interfaceContractMapper = interfaceContractMapper;
+        this.scopeRegistry = scopeRegistry;
+        this.workScheduler = workScheduler;
+        this.wireProcessor = wireProcessor;
+        this.providerFactories = providerFactories;
+    }
+
+    /**
+     * Configure a composite
+     * 
+     * @param composite
+     * @throws IncompatibleInterfaceContractException 
+     */
+    @SuppressWarnings("unchecked")
+    protected void configureComposite(Composite composite) throws IncompatibleInterfaceContractException {
+        for (Component component : composite.getComponents()) {
+
+            for (ComponentService service : component.getServices()) {
+                for (Binding binding : service.getBindings()) {
+                    BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories
+                        .getProviderFactory(binding.getClass());
+                    if (providerFactory != null) {
+                        ServiceBindingProvider bindingProvider = providerFactory
+                            .createServiceBindingProvider((RuntimeComponent)component,
+                                                          (RuntimeComponentService)service,
+                                                          binding);
+                        if (bindingProvider != null) {
+                            ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider);
+                        }
+                    } else {
+                        throw new IllegalStateException("Provider factory not found for class: " + binding.getClass()
+                                                            .getName());
+                    }
+                }
+            }
+            for (ComponentReference reference : component.getReferences()) {
+                for (Binding binding : reference.getBindings()) {
+                    BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories
+                        .getProviderFactory(binding.getClass());
+                    if (providerFactory != null) {
+                        ReferenceBindingProvider bindingProvider = providerFactory
+                            .createReferenceBindingProvider((RuntimeComponent)component,
+                                                            (RuntimeComponentReference)reference,
+                                                            binding);
+                        if (bindingProvider != null) {
+                            ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider);
+                        }
+                    } else {
+                        throw new IllegalStateException("Provider factory not found for class: " + binding.getClass()
+                                                            .getName());
+                    }
+                }
+            }
+
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                configureComposite((Composite)implementation);
+            } else if (implementation != null) {
+                ImplementationProviderFactory providerFactory = (ImplementationProviderFactory)providerFactories
+                    .getProviderFactory(implementation.getClass());
+                if (providerFactory != null) {
+                    ImplementationProvider implementationProvider = providerFactory
+                        .createImplementationProvider((RuntimeComponent)component, implementation);
+                    if (implementationProvider != null) {
+                        ((RuntimeComponent)component).setImplementationProvider(implementationProvider);
+                    }
+                } else {
+                    throw new IllegalStateException("Provider factory not found for class: " + implementation
+                                                        .getClass().getName());
+                }
+                setScopeContainer(component);
+            }
+        }
+    }
+
+    /**
+     * Start a composite
+     */
+    protected void startComposite(Composite composite) {
+        for (Component component : composite.getComponents()) {
+
+            for (ComponentService service : component.getServices()) {
+                for (Binding binding : service.getBindings()) {
+                    ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service)
+                        .getBindingProvider(binding);
+                    if (bindingProvider != null) {
+                        bindingProvider.start();
+                    }
+                }
+            }
+            for (ComponentReference reference : component.getReferences()) {
+                for (Binding binding : reference.getBindings()) {
+                    ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference)
+                        .getBindingProvider(binding);
+                    if (bindingProvider != null) {
+                        bindingProvider.start();
+                    }
+                }
+            }
+
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                startComposite((Composite)implementation);
+            } else {
+                ImplementationProvider implementationProvider = ((RuntimeComponent)component)
+                    .getImplementationProvider();
+                if (implementationProvider != null) {
+                    implementationProvider.start();
+                }
+            }
+
+            if (component instanceof ScopedRuntimeComponent) {
+                ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+                if (runtimeComponent.getScopeContainer() != null) {
+                    runtimeComponent.getScopeContainer().start();
+                }
+            }
+
+        }
+    }
+
+    public void stop(Composite composite) {
+        for (Component component : composite.getComponents()) {
+
+            for (ComponentService service : component.getServices()) {
+                for (Binding binding : service.getBindings()) {
+                    ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service)
+                        .getBindingProvider(binding);
+                    if (bindingProvider != null) {
+                        bindingProvider.stop();
+                    }
+                }
+            }
+            for (ComponentReference reference : component.getReferences()) {
+                for (Binding binding : reference.getBindings()) {
+                    ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference)
+                        .getBindingProvider(binding);
+                    if (bindingProvider != null) {
+                        bindingProvider.stop();
+                    }
+                }
+            }
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                stop((Composite)implementation);
+            } else {
+                ImplementationProvider implementationProvider = ((RuntimeComponent)component)
+                    .getImplementationProvider();
+                if (implementationProvider != null) {
+                    implementationProvider.stop();
+                }
+            }
+
+            if (component instanceof ScopedRuntimeComponent) {
+                ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+                if (runtimeComponent.getScopeContainer() != null) {
+                    runtimeComponent.getScopeContainer().stop();
+                }
+            }
+
+        }
+
+    }
+
+    /**
+     * Create runtime wires for the composite
+     * 
+     * @param composite
+     * @throws IncompatibleInterfaceContractException
+     */
+    protected void createRuntimeWires(Composite composite) throws IncompatibleInterfaceContractException {
+        for (Component component : composite.getComponents()) {
+            Implementation implementation = component.getImplementation();
+            if (implementation instanceof Composite) {
+                // Recursively create runtime wires
+                createRuntimeWires((Composite)implementation);
+            } else {
+                // Create outbound wires for the component references
+                for (ComponentReference reference : component.getReferences()) {
+                    for (Binding binding : reference.getBindings()) {
+                        createWires(component, reference, binding);
+                    }
+                }
+                // Create inbound wires for the component services
+                for (ComponentService service : component.getServices()) {
+                    for (Binding binding : service.getBindings()) {
+                        createWires(component, service, binding);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Get the effective interface contract for a reference binding
+     * 
+     * @param reference
+     * @param binding
+     * @return
+     */
+    private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
+        InterfaceContract interfaceContract = reference.getInterfaceContract();
+        ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+        if (provider != null) {
+            InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+            if (bindingContract != null) {
+                interfaceContract = bindingContract;
+            }
+        }
+        return interfaceContract;
+    }
+
+    /**
+     * Create the runtime wires for a reference binding
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     */
+    private void createWires(Component component, ComponentReference reference, Binding binding) {
+        if (!(reference instanceof RuntimeComponentReference)) {
+            return;
+        }
+        RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+        InterfaceContract bindingContract = getInterfaceContract(reference, binding);
+
+        if (!(binding instanceof SCABinding)) {
+            InterfaceContract sourceContract = reference.getInterfaceContract();
+
+            // Component Reference --> External Service
+            EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component,
+                                                                     (RuntimeComponentReference)reference, binding,
+                                                                     sourceContract);
+
+            EndpointReference wireTarget = new EndpointReferenceImpl(null, null, binding, bindingContract);
+            RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget);
+
+            for (Operation operation : sourceContract.getInterface().getOperations()) {
+                Operation targetOperation = interfaceContractMapper.map(bindingContract.getInterface(), operation);
+                InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                if (operation.isNonBlocking()) {
+                    chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                }
+                addBindingInterceptor(component, reference, binding, chain, operation, false);
+                wire.getInvocationChains().add(chain);
+            }
+            if (sourceContract.getCallbackInterface() != null) {
+                for (Operation operation : sourceContract.getCallbackInterface().getOperations()) {
+                    Operation targetOperation = interfaceContractMapper.map(bindingContract.getCallbackInterface(),
+                                                                            operation);
+                    InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                    if (operation.isNonBlocking()) {
+                        chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                    }
+                    addBindingInterceptor(component, reference, binding, chain, operation, true);
+                    wire.getCallbackInvocationChains().add(chain);
+                }
+            }
+            runtimeRef.getRuntimeWires().add(wire);
+            wireProcessor.process(wire);
+        }
+        for (ComponentService service : reference.getTargets()) {
+            Component target = null;
+            SCABinding scaBinding = service.getBinding(SCABinding.class);
+            if (scaBinding != null) {
+                target = scaBinding.getComponent();
+            }
+
+            // FIXME: [rfeng] Ignore unresolved services
+            if (service.isUnresolved()) {
+                continue;
+            }
+
+            // FIXME: [rfeng] We might need a better way to get the impl interface contract
+            InterfaceContract targetContract = service.getService().getInterfaceContract();
+
+            EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component,
+                                                                     (RuntimeComponentReference)reference, binding,
+                                                                     bindingContract);
+
+            EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)target,
+                                                                     (RuntimeComponentService)service, binding,
+                                                                     targetContract);
+            
+            String sourceRuntimeId = component.getRuntimeId();
+            String targetRuntimeId = target.getRuntimeId();
+            
+            System.out.println(">>> " + 
+                               sourceRuntimeId +
+                               " wires to " +
+                               targetRuntimeId );
+            
+            if ( !sourceRuntimeId.equals(targetRuntimeId)) {
+                System.out.println(">>>>> Swap SCA binding for disitributed binding for wire between " +
+                                   component.getName() +
+                                   " and " +
+                                   component.getName());
+            }
+
+            RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget);
+
+            for (Operation operation : bindingContract.getInterface().getOperations()) {
+                Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+                InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                if (operation.isNonBlocking()) {
+                    chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                }
+                addBindingInterceptor(component, reference, binding, chain, operation, false);
+                if (target != null) {
+                    addImplementationInterceptor(target, service, chain, targetOperation, false);
+                }
+                wire.getInvocationChains().add(chain);
+            }
+            if (bindingContract.getCallbackInterface() != null) {
+                if (reference.getName().startsWith("$self$.")) {
+                    // No callback is needed
+                    continue;
+                }
+                for (Operation operation : bindingContract.getCallbackInterface().getOperations()) {
+                    Operation targetOperation = interfaceContractMapper.map(targetContract.getCallbackInterface(),
+                                                                            operation);
+                    InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+                    if (operation.isNonBlocking()) {
+                        chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+                    }
+                    addBindingInterceptor(component, reference, binding, chain, operation, true);
+                    addImplementationInterceptor(component, null, chain, targetOperation, true);
+                    wire.getCallbackInvocationChains().add(chain);
+                }
+            }
+
+            runtimeRef.getRuntimeWires().add(wire);
+            if (!wire.getCallbackInvocationChains().isEmpty()) {
+                if (wire.getTarget().getContract() != null) {
+                    ((RuntimeComponentService) wire.getTarget().getContract()).getCallbackWires().add(wire);
+                }
+            }
+            wireProcessor.process(wire);
+        }
+    }
+
+    /**
+     * Get the effective interface contract for the service binding
+     * 
+     * @param service
+     * @param binding
+     * @return
+     */
+    private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) {
+        InterfaceContract interfaceContract = service.getInterfaceContract();
+
+        ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
+        if (provider != null) {
+            InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+            if (bindingContract != null) {
+                interfaceContract = bindingContract;
+            }
+        }
+        return interfaceContract;
+    }
+
+    /**
+     * Create runtime wires for a service binding
+     * 
+     * @param component
+     * @param service
+     * @param binding
+     */
+    private void createWires(Component component, ComponentService service, Binding binding) {
+        if (!(service instanceof RuntimeComponentService)) {
+            return;
+        }
+        RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+
+        // FIXME: [rfeng] We might need a better way to get the impl interface contract
+        InterfaceContract targetContract = service.getService().getInterfaceContract();
+
+        InterfaceContract sourceContract = getInterfaceContract(service, binding);
+
+        EndpointReference wireSource = new EndpointReferenceImpl(null, null, binding, sourceContract);
+
+        EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)component,
+                                                                 (RuntimeComponentService)service, binding,
+                                                                 targetContract);
+
+        RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget);
+
+        for (Operation operation : sourceContract.getInterface().getOperations()) {
+            Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+            InvocationChain chain = new InvocationChainImpl(operation, targetOperation);
+            /* lresende */
+            if (operation.isNonBlocking()) {
+                chain.addInterceptor(new NonBlockingInterceptor(workScheduler));
+            }
+
+            addImplementationInterceptor(component, service, chain, targetOperation, false);
+            wire.getInvocationChains().add(chain);
+        }
+        // if (sourceContract.getCallbackInterface() != null) {
+        // for (Operation operation :
+        // sourceContract.getCallbackInterface().getOperations()) {
+        // Operation targetOperation =
+        // interfaceContractMapper.map(targetContract.getCallbackInterface(),
+        // operation);
+        // InvocationChain chain = new InvocationChainImpl(operation,
+        // targetOperation);
+        // if (operation.isNonBlocking()) {
+        // chain.addInterceptor(new NonBlockingInterceptor(workScheduler,
+        // workContext));
+        // }
+        // addImplementationInterceptor(component, service, chain, operation,
+        // true);
+        // wire.getCallbackInvocationChains().add(chain);
+        // }
+        // }
+
+        runtimeService.getRuntimeWires().add(wire);
+        wireProcessor.process(wire);
+    }
+
+    /**
+     * Add the interceptor for a component implementation
+     * 
+     * @param component
+     * @param service
+     * @param chain
+     * @param operation
+     * @param isCallback
+     */
+    private void addImplementationInterceptor(Component component,
+                                              ComponentService service,
+                                              InvocationChain chain,
+                                              Operation operation,
+                                              boolean isCallback) {
+        ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider();
+        if (provider != null) {
+            Invoker invoker = null;
+            if (!isCallback) {
+                invoker = provider.createInvoker((RuntimeComponentService)service, operation);
+            } else {
+                invoker = provider.createCallbackInvoker(operation);
+            }
+            chain.addInvoker(invoker);
+        }
+    }
+
+    /**
+     * Add the interceptor for a binding
+     * 
+     * @param component
+     * @param reference
+     * @param binding
+     * @param chain
+     * @param operation
+     * @param isCallback
+     */
+    private void addBindingInterceptor(Component component,
+                                       ComponentReference reference,
+                                       Binding binding,
+                                       InvocationChain chain,
+                                       Operation operation,
+                                       boolean isCallback) {
+        ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+        if (provider != null) {
+            Invoker invoker = provider.createInvoker(operation, isCallback);
+            if (invoker != null) {
+                chain.addInvoker(invoker);
+            }
+        }
+    }
+
+    private void setScopeContainer(Component component) {
+        if (!(component instanceof ScopedRuntimeComponent)) {
+            return;
+        }
+        ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+        runtimeComponent.setScopeContainer(scopeRegistry.getScopeContainer(runtimeComponent));
+    }
+
+    protected void buildComposite(Composite composite) throws CompositeBuilderException {
+
+        CompositeBuilderMonitor monitor = new CompositeBuilderMonitor() {
+
+            public void problem(Problem problem) {
+                // Uncommenting the following two lines can be useful to detect
+                // and troubleshoot SCA assembly XML composite configuration
+                // problems.
+
+                System.out.println("Composite assembly problem: " + problem.getMessage());
+            }
+        };
+
+        CompositeBuilderImpl builder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, monitor);
+
+        builder.build(composite);
+
+        // if (!problems.isEmpty()) {
+        // throw new VariantRuntimeException(new RuntimeException("Problems in
+        // the composite..."));
+        // }
+    }
+
+    public void activate(Composite composite) throws ActivationException {
+        try {
+            buildComposite(composite);
+            configureComposite(composite);
+            createRuntimeWires(composite);
+        } catch (Exception e) {
+            throw new ActivationException(e);
+        }
+    }
+
+    public void deactivate(Composite composite) throws ActivationException {
+    }
+
+    public void start(Composite composite) throws ActivationException {
+        try {
+            startComposite(composite);
+        } catch (Exception e) {
+            throw new ActivationException(e);
+        }
+    }
+
+}

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/slaws/disitributed-changes/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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