Author: nash
Date: Fri Jul 4 09:54:33 2008
New Revision: 674090
URL: http://svn.apache.org/viewvc?rev=674090&view=rev
Log:
Add itest/builder
Added:
tuscany/java/sca/itest/builder/
tuscany/java/sca/itest/builder/pom.xml
tuscany/java/sca/itest/builder/src/
tuscany/java/sca/itest/builder/src/main/
tuscany/java/sca/itest/builder/src/main/java/
tuscany/java/sca/itest/builder/src/main/java/org/
tuscany/java/sca/itest/builder/src/main/java/org/apache/
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/ComponentDImpl.java
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3.java
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3a.java
tuscany/java/sca/itest/builder/src/main/resources/
tuscany/java/sca/itest/builder/src/main/resources/META-INF/
tuscany/java/sca/itest/builder/src/main/resources/META-INF/sca-contribution.xml
tuscany/java/sca/itest/builder/src/main/resources/scenario1.composite
tuscany/java/sca/itest/builder/src/main/resources/scenario1a.composite
tuscany/java/sca/itest/builder/src/test/
tuscany/java/sca/itest/builder/src/test/java/
tuscany/java/sca/itest/builder/src/test/java/org/
tuscany/java/sca/itest/builder/src/test/java/org/apache/
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java
Added: tuscany/java/sca/itest/builder/pom.xml
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/pom.xml?rev=674090&view=auto
==============================================================================
--- tuscany/java/sca/itest/builder/pom.xml (added)
+++ tuscany/java/sca/itest/builder/pom.xml Fri Jul 4 09:54:33 2008
@@ -0,0 +1,99 @@
+<?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-itest</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>itest-builder</artifactId>
+ <name>Apache Tuscany SCA Builder Integration Test</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-monitor-logging</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-workspace-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-ws-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ </build>
+</project>
Added:
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/ComponentDImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/ComponentDImpl.java?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/ComponentDImpl.java
(added)
+++
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/ComponentDImpl.java
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.itest.builder;
+
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Implementation class for ComponentD.
+ *
+ * @version $Rev$ $Date$
+ */
[EMAIL PROTECTED](interfaces={Service3.class, Service3a.class})
+public class ComponentDImpl implements Service3, Service3a {
+
+ public String getGreetings(String name) {
+ return "Hello, " + name + "!";
+ }
+
+ public String getGreetings2(String name) {
+ return "Goodbye, " + name + "!";
+ }
+
+}
Added:
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3.java?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3.java
(added)
+++
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3.java
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.itest.builder;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Interface for Service3 in ComponentD.
+ *
+ * @version $Rev$ $Date$
+ */
[EMAIL PROTECTED]
+public interface Service3 {
+
+ String getGreetings(String name);
+
+}
Added:
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3a.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3a.java?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3a.java
(added)
+++
tuscany/java/sca/itest/builder/src/main/java/org/apache/tuscany/sca/itest/builder/Service3a.java
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.itest.builder;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Interface for Service3a in ComponentD.
+ *
+ * @version $Rev$ $Date$
+ */
[EMAIL PROTECTED]
+public interface Service3a {
+
+ String getGreetings2(String name);
+
+}
Added:
tuscany/java/sca/itest/builder/src/main/resources/META-INF/sca-contribution.xml
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/resources/META-INF/sca-contribution.xml?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/main/resources/META-INF/sca-contribution.xml
(added)
+++
tuscany/java/sca/itest/builder/src/main/resources/META-INF/sca-contribution.xml
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,24 @@
+<?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.
+-->
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://scenario1"
+ xmlns:tns="http://scenario1">
+ <deployable composite="tns:CompositeA" />
+</contribution>
Added: tuscany/java/sca/itest/builder/src/main/resources/scenario1.composite
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/resources/scenario1.composite?rev=674090&view=auto
==============================================================================
--- tuscany/java/sca/itest/builder/src/main/resources/scenario1.composite
(added)
+++ tuscany/java/sca/itest/builder/src/main/resources/scenario1.composite Fri
Jul 4 09:54:33 2008
@@ -0,0 +1,22 @@
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://scenario1"
+ xmlns:tns="http://scenario1"
+ name="CompositeA">
+
+ <service name="Service1" promote="ComponentB/Service2">
+ <!-- bindings and/or interfaces may or may not be specified explicitly
here -->
+ <binding.ws />
+ </service>
+
+ <component name="ComponentB">
+ <implementation.composite name="tns:CompositeC" />
+ <service name="Service2">
+ <!-- bindings and/or interfaces may or may not be specified
explicitly here -->
+ </service>
+ <service name="Service2a">
+ <!-- bindings and/or interfaces may or may not be specified
explicitly here -->
+ </service>
+ </component>
+
+</composite>
+
Added: tuscany/java/sca/itest/builder/src/main/resources/scenario1a.composite
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/main/resources/scenario1a.composite?rev=674090&view=auto
==============================================================================
--- tuscany/java/sca/itest/builder/src/main/resources/scenario1a.composite
(added)
+++ tuscany/java/sca/itest/builder/src/main/resources/scenario1a.composite Fri
Jul 4 09:54:33 2008
@@ -0,0 +1,24 @@
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://scenario1"
+ xmlns:tns="http://scenario1"
+ name="CompositeC">
+
+ <service name="Service2" promote="ComponentD/Service3">
+ <!-- bindings and/or interfaces may or may not be specified explicitly
here -->
+ </service>
+ <service name="Service2a" promote="ComponentD/Service3a">
+ <!-- bindings and/or interfaces may or may not be specified explicitly
here -->
+ </service>
+
+ <component name="ComponentD">
+ <implementation.java
class="org.apache.tuscany.sca.itest.builder.ComponentDImpl"/>
+ <service name="Service3">
+ <!-- bindings and/or interfaces may or may not be specified
explicitly here -->
+ </service>
+ <service name="Service3a">
+ <!-- bindings and/or interfaces may or may not be specified
explicitly here -->
+ </service>
+ </component>
+</composite>
+
+
Added:
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
(added)
+++
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/BuilderTestCase.java
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,133 @@
+/*
+ * 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.itest.builder;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamWriter;
+import junit.framework.TestCase;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+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.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+
+/**
+ * Load and build some composites and inspect the results.
+ *
+ * @version $Rev$ $Date$
+ */
+public class BuilderTestCase extends TestCase {
+ private CustomCompositeBuilder customBuilder;
+
+ @Override
+ protected void setUp() throws Exception {
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ }
+
+ public void testScenario1() throws Exception {
+ customBuilder = new CustomCompositeBuilder();
+
customBuilder.loadContribution("src/main/resources/scenario1.composite",
+ "TestContribution",
"src/main/resources/");
+ printResults();
+ }
+
+ private void printResults() throws Exception {
+ for (Problem problem : customBuilder.getMonitor().getProblems()) {
+ if (problem.getCause() != null) {
+ problem.getCause().printStackTrace();
+ }
+ }
+ Composite domainComposite = customBuilder.getDomainComposite();
+ printComposite(domainComposite);
+ }
+
+ private void printComposite(Composite composite) throws Exception {
+ // process implementation composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ printComposite((Composite)implementation);
+ }
+ }
+
+ // write out the SCDL
+ writeSCDL(composite);
+
+ // find all the component service bindings
+ for (Component component : composite.getComponents()) {
+ for (ComponentService componentService : component.getServices()) {
+ for (Binding binding : componentService.getBindings()) {
+ if (binding instanceof WebServiceBinding) {
+ writeWSDL(component, componentService,
((WebServiceBinding)binding).getWSDLDocument());
+ }
+ }
+ }
+ }
+ }
+
+ private void writeSCDL(Composite composite) throws Exception {
+ // Print out a composite
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ XMLStreamWriter writer =
customBuilder.getOutputFactory().createXMLStreamWriter(bos);
+ customBuilder.getModelProcessor().write(composite, writer);
+
+ // Parse and write again to pretty format it
+ DocumentBuilder documentBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = documentBuilder.parse(new
ByteArrayInputStream(bos.toByteArray()));
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+ format.setIndent(2);
+ XMLSerializer serializer = new XMLSerializer(System.out, format);
+ System.out.println("-->Runtime SCDL model for composite " +
composite.getName());
+ serializer.serialize(document);
+ }
+
+ private void writeWSDL(Component component, ComponentService service,
Definition definition) {
+ if (definition == null) {
+ System.out.println("-->No generated WSDL for " +
component.getName() + "/" + service.getName());
+ } else {
+ try {
+ System.out.println("-->Generated WSDL for " +
component.getName() + "/" + service.getName());
+ WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
+ writer.writeWSDL(definition, System.out);
+ } catch (WSDLException e) {
+ // ignore
+ }
+ }
+ }
+
+
+}
Added:
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java?rev=674090&view=auto
==============================================================================
---
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java
(added)
+++
tuscany/java/sca/itest/builder/src/test/java/org/apache/tuscany/sca/itest/builder/CustomCompositeBuilder.java
Fri Jul 4 09:54:33 2008
@@ -0,0 +1,201 @@
+/*
+ * 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.itest.builder;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import
org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import
org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import
org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import
org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.workspace.Workspace;
+import org.apache.tuscany.sca.workspace.WorkspaceFactory;
+import org.apache.tuscany.sca.workspace.builder.ContributionDependencyBuilder;
+import
org.apache.tuscany.sca.workspace.builder.impl.ContributionDependencyBuilderImpl;
+
+public class CustomCompositeBuilder {
+ private URLArtifactProcessor<Contribution> contributionProcessor;
+ private ModelResolverExtensionPoint modelResolvers;
+ private ModelFactoryExtensionPoint modelFactories;
+ private WorkspaceFactory workspaceFactory;
+ private AssemblyFactory assemblyFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Object> xmlProcessor;
+ private ContributionDependencyBuilder contributionDependencyBuilder;
+ private CompositeBuilder domainCompositeBuilder;
+ private static Workspace workspace;
+ private List<SCADefinitions> policyDefinitions;
+ private Monitor monitor;
+ private Composite domainComposite;
+
+ private void init() {
+
+ // Create extension point registry
+ ExtensionPointRegistry extensionPoints = new
DefaultExtensionPointRegistry();
+
+ // Create a monitor
+ UtilityExtensionPoint utilities =
extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory =
utilities.getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+
+ // Initialize the Tuscany module activators
+ ModuleActivatorExtensionPoint moduleActivators =
extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
+ for (ModuleActivator activator :
moduleActivators.getModuleActivators()) {
+ activator.start(extensionPoints);
+ }
+
+ // Get XML input/output factories
+ modelFactories =
extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ XMLInputFactory inputFactory =
modelFactories.getFactory(XMLInputFactory.class);
+ outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+
+ // Get contribution workspace and assembly model factories
+ workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class);
+ assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+
+ // Create XML artifact processors
+ StAXArtifactProcessorExtensionPoint xmlProcessorExtensions =
extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ xmlProcessor = new
ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory,
outputFactory, monitor);
+
+ // Create contribution content processor
+ URLArtifactProcessorExtensionPoint docProcessorExtensions =
extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ contributionProcessor =
docProcessorExtensions.getProcessor(Contribution.class);
+
+ // Get the model resolvers
+ modelResolvers =
extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
+
+ // Create a contribution dependency builder
+ contributionDependencyBuilder = new
ContributionDependencyBuilderImpl(monitor);
+
+ // Create a composite builder
+ SCABindingFactory scaBindingFactory =
modelFactories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory =
modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ InterfaceContractMapper contractMapper =
utilities.getUtility(InterfaceContractMapper.class);
+ domainCompositeBuilder = new CompositeBuilderImpl(assemblyFactory,
scaBindingFactory, attachPointTypeFactory, contractMapper, monitor);
+ }
+
+ public void loadContribution(String compositeURL, String sourceURI, String
sourceURL) throws Exception {
+ init();
+
+ // Create workspace model
+ workspace = workspaceFactory.createWorkspace();
+ workspace.setModelResolver(new ExtensibleModelResolver(workspace,
modelResolvers, modelFactories));
+
+ // Read the test contribution
+ URI artifactURI = URI.create(sourceURI);
+ URL artifactURL = new File(sourceURL).toURI().toURL();
+ URL contributionURL = new File(compositeURL).toURI().toURL();
+ Contribution testContribution =
contributionProcessor.read(contributionURL, artifactURI, artifactURL);
+ workspace.getContributions().add(testContribution);
+
+ // Build the contribution dependencies
+ Map<Contribution, List<Contribution>> contributionDependencies = new
HashMap<Contribution, List<Contribution>>();
+ Set<Contribution> resolved = new HashSet<Contribution>();
+ for (Contribution contribution: workspace.getContributions()) {
+ List<Contribution> dependencies =
contributionDependencyBuilder.buildContributionDependencies(contribution,
workspace);
+
+ // Resolve contributions
+ for (Contribution dependency: dependencies) {
+ if (!resolved.contains(dependency)) {
+ resolved.add(dependency);
+ contributionProcessor.resolve(dependency,
workspace.getModelResolver());
+ }
+ }
+
+ contributionDependencies.put(contribution, dependencies);
+ }
+
+ // Create a composite model for the domain
+ domainComposite = assemblyFactory.createComposite();
+ domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
+
+ // Add all deployables to it, normally the domain administrator would
select
+ // the deployables to include
+ domainComposite.getIncludes().addAll(workspace.getDeployables());
+
+ // Build the domain composite and wire the components included in it
+ domainCompositeBuilder.build(domainComposite);
+ }
+
+ /**
+ * Returns the delegating model processor.
+ * @return the delegating model processor
+ */
+ public StAXArtifactProcessor<Object> getModelProcessor() {
+ return xmlProcessor;
+ }
+
+ /**
+ * Returns the XML output factory.
+ * @return the XML output factory
+ */
+ public XMLOutputFactory getOutputFactory() {
+ return outputFactory;
+ }
+
+ /**
+ * Returns the domain composite.
+ * @return the domain composite model object
+ */
+ public Composite getDomainComposite() {
+ return domainComposite;
+ }
+
+ /**
+ * Returns the monitor.
+ * @return the monitor instance
+ */
+ public Monitor getMonitor() {
+ return monitor;
+ }
+
+}