summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-15 18:53:59 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-15 18:53:59 +0000
commit2f21f4e89ac9e46e807daaab1c61d61291df37b1 (patch)
treed21fa51b39de9235c4254e21668f83ea2ce49e98
parent5e5b75bc00d3fd9e8f640b8afb67b1fb50d46089 (diff)
Copy the composite diagram generator into modules
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171222 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/META-INF/MANIFEST.MF23
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/Calculator.xml49
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/MyValueComposite2.xml91
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite.xml59
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite1.xml47
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite2.xml64
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite3.xml50
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite_idle.xml31
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/composite_with_compositeService.xml100
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/store.xml64
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/input/supplychain.xml47
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/CalculatorTest_diagram.svg1
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.html22
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.svg1
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/IdleTest_diagram.svg1
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.html10
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.svg1
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.html10
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.svg1
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.html22
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.svg1
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/pom.xml187
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java120
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java59
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java57
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java26
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java81
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java60
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java41
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java45
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java58
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java86
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java95
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java38
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java86
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java604
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/html/HTMLWrapper.java90
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java236
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java374
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java259
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java733
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilder.java183
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java359
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java279
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java33
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilderTestCase.java141
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java141
47 files changed, 5166 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/composite-diagram/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..2139ef9842
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.diagram.artifacts;version="2.0.0",
+ org.apache.tuscany.sca.diagram.generator;version="2.0.0",
+ org.apache.tuscany.sca.diagram.html;version="2.0.0",
+ org.apache.tuscany.sca.diagram.layout;version="2.0.0",
+ org.apache.tuscany.sca.diagram.main;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Composite Diagram
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Composite Diagram
+Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0"
+ javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.transform,
+ javax.xml.transform.dom,
+ javax.xml.transform.stream,
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.diagram
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/Calculator.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/Calculator.xml
new file mode 100755
index 0000000000..345b9065a9
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/Calculator.xml
@@ -0,0 +1,49 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Calculator">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/MyValueComposite2.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/MyValueComposite2.xml
new file mode 100755
index 0000000000..722bdeb0a5
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/MyValueComposite2.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!-- MyValueComposite Wires examples -->
+
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+
+ targetNamespace="http://foo.com"
+
+ name="MyValueComposite2" >
+
+ <include name="store"/>
+ <include name="Calculator"/>
+ <include name="supplychain"/>
+
+ <service name="MyValueService" promote="MyValueServiceComponent">
+
+ <interface.java interface="services.myvalue.MyValueService"/>
+
+ <binding.ws port="http://www.myvalue.org/MyValueService#
+
+ wsdl.endpoint(MyValueService/MyValueServiceSOAP)"/>
+
+ </service>
+
+
+
+ <component name="MyValueServiceComponent">
+
+ <implementation.java
+
+ class="services.myvalue.MyValueServiceImpl"/>
+
+ <property name="currency">EURO</property>
+
+ <service name="myValueService"/>
+
+ <reference name="customerService"/>
+
+ <reference name="stockQuoteService"/>
+
+ </component>
+
+
+
+ <wire source="MyValueServiceComponent/stockQuoteService"
+
+ target="StockQuoteMediatorComponent"/>
+
+
+
+ <component name="StockQuoteMediatorComponent">
+
+ <implementation.java class="services.myvalue.SQMediatorImpl"/>
+
+ <property name="currency">EURO</property>
+
+ <reference name="stockQuoteService"/>
+
+ </component>
+
+
+
+ <reference name="CustomerService"
+
+ promote="MyValueServiceComponent/customerService">
+
+ <interface.java interface="services.customer.CustomerService"/>
+
+ <binding.sca/>
+
+ </reference>
+
+
+
+ <reference name="StockQuoteService"
+
+ promote="StockQuoteMediatorComponent">
+
+ <interface.java
+
+ interface="services.stockquote.StockQuoteService"/>
+
+ <binding.ws port="http://www.stockquote.org/StockQuoteService#
+
+ wsdl.endpoint(StockQuoteService/StockQuoteServiceSOAP)"/>
+
+ </reference>
+
+
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite.xml
new file mode 100755
index 0000000000..49c33cf2d8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite.xml
@@ -0,0 +1,59 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Calculator">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+ <component name="StockQuoteMediatorComponent">
+
+ <implementation.java class="services.myvalue.SQMediatorImpl"/>
+
+ <property name="currency">EURO</property>
+
+ <reference name="stockQuoteService"/>
+
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite1.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite1.xml
new file mode 100755
index 0000000000..1964db7fbb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite1.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://supplychain"
+ xmlns:sp="http://supplychain"
+ name="supplychain">
+
+ <component name="CustomerComponent">
+ <implementation.java class="supplychain.CustomerComponentImpl" />
+ <reference name="retailer" target="RetailerComponent"/>
+ </component>
+
+ <component name="RetailerComponent">
+ <implementation.java class="supplychain.RetailerComponentImpl" />
+ <reference name="warehouse" target="WarehouseComponent"/>
+ </component>
+
+ <component name="WarehouseComponent">
+ <implementation.java class="supplychain.WarehouseComponentImpl" />
+ <reference name="shipper" target="ShipperComponent"/>
+ </component>
+
+ <component name="ShipperComponent">
+ <implementation.java class="supplychain.ShipperComponentImpl" />
+ <reference name="customer" />
+ </component>
+
+ <wire source="ShipperComponent/customer" target="CustomerComponent" />
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite2.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite2.xml
new file mode 100755
index 0000000000..fc32186344
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite2.xml
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://store"
+ name="store">
+
+ <component name="Store">
+ <t:implementation.widget location="uiservices/store.html"/>
+ <service name="Widget">
+ <t:binding.http uri="/store"/>
+ </service>
+ <reference name="catalog" target="Catalog">
+ <t:binding.jsonrpc/>
+ </reference>
+ <reference name="shoppingCart" target="ShoppingCart/Cart">
+ <t:binding.atom/>
+ </reference>
+ <reference name="shoppingTotal" target="ShoppingCart/Total">
+ <t:binding.jsonrpc/>
+ </reference>
+ </component>
+
+ <component name="Catalog">
+ <implementation.java class="services.FruitsCatalogImpl"/>
+ <property name="currencyCode">USD</property>
+ <service name="Catalog">
+ <t:binding.jsonrpc/>
+ </service>
+ <reference name="currencyConverter" target="CurrencyConverter"/>
+ </component>
+
+ <component name="ShoppingCart">
+ <implementation.java class="services.ShoppingCartImpl"/>
+ <service name="Cart">
+ <t:binding.atom uri="/ShoppingCart/Cart"/>
+ </service>
+ <service name="Total">
+ <t:binding.jsonrpc/>
+ </service>
+ </component>
+
+ <component name="CurrencyConverter">
+ <implementation.java class="services.CurrencyConverterImpl"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite3.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite3.xml
new file mode 100755
index 0000000000..9997ba42bc
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite3.xml
@@ -0,0 +1,50 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="CalculatorTest">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ <!-- reference name="dividetestService" target="AddServiceComponent" / -->
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite_idle.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite_idle.xml
new file mode 100755
index 0000000000..99517f639f
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite_idle.xml
@@ -0,0 +1,31 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="IdleTest">
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/composite_with_compositeService.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/composite_with_compositeService.xml
new file mode 100755
index 0000000000..e619d39c1c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/composite_with_compositeService.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<!-- MyValueComposite Wires examples -->
+
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+
+ targetNamespace="http://foo.com"
+
+ name="MyValueComposite2" >
+
+ <include name="store"/>
+ <include name="Calculator"/>
+ <include name="supplychain"/>
+
+ <service name="MyValueService" promote="MyValueServiceComponent">
+
+ <interface.java interface="services.myvalue.MyValueService"/>
+
+ <binding.ws port="http://www.myvalue.org/MyValueService#
+
+ wsdl.endpoint(MyValueService/MyValueServiceSOAP)"/>
+
+ </service>
+
+
+
+ <component name="MyValueServiceComponent">
+
+ <implementation.java
+
+ class="services.myvalue.MyValueServiceImpl"/>
+
+ <property name="currency">EURO</property>
+
+ <service name="myValueService"/>
+
+ <reference name="customerService"/>
+
+ <reference name="stockQuoteService"/>
+
+ </component>
+
+
+
+ <wire source="MyValueServiceComponent/stockQuoteService"
+
+ target="StockQuoteMediatorComponent"/>
+
+
+
+ <component name="StockQuoteMediatorComponent">
+
+ <implementation.java class="services.myvalue.SQMediatorImpl"/>
+
+ <property name="currency">EURO</property>
+
+ <reference name="stockQuoteService"/>
+
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+
+
+
+ <reference name="CustomerService"
+
+ promote="MyValueServiceComponent/customerService StockQuoteMediatorComponent">
+
+ <interface.java interface="services.customer.CustomerService"/>
+
+ <binding.sca/>
+
+ </reference>
+
+ <property name="currency">EURO</property>
+
+ <reference name="StockQuoteService"
+
+ promote="StockQuoteMediatorComponent">
+
+ <interface.java
+
+ interface="services.stockquote.StockQuoteService"/>
+
+ <binding.ws port="http://www.stockquote.org/StockQuoteService#
+
+ wsdl.endpoint(StockQuoteService/StockQuoteServiceSOAP)"/>
+
+ </reference>
+
+
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/store.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/store.xml
new file mode 100755
index 0000000000..fc32186344
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/store.xml
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://store"
+ name="store">
+
+ <component name="Store">
+ <t:implementation.widget location="uiservices/store.html"/>
+ <service name="Widget">
+ <t:binding.http uri="/store"/>
+ </service>
+ <reference name="catalog" target="Catalog">
+ <t:binding.jsonrpc/>
+ </reference>
+ <reference name="shoppingCart" target="ShoppingCart/Cart">
+ <t:binding.atom/>
+ </reference>
+ <reference name="shoppingTotal" target="ShoppingCart/Total">
+ <t:binding.jsonrpc/>
+ </reference>
+ </component>
+
+ <component name="Catalog">
+ <implementation.java class="services.FruitsCatalogImpl"/>
+ <property name="currencyCode">USD</property>
+ <service name="Catalog">
+ <t:binding.jsonrpc/>
+ </service>
+ <reference name="currencyConverter" target="CurrencyConverter"/>
+ </component>
+
+ <component name="ShoppingCart">
+ <implementation.java class="services.ShoppingCartImpl"/>
+ <service name="Cart">
+ <t:binding.atom uri="/ShoppingCart/Cart"/>
+ </service>
+ <service name="Total">
+ <t:binding.jsonrpc/>
+ </service>
+ </component>
+
+ <component name="CurrencyConverter">
+ <implementation.java class="services.CurrencyConverterImpl"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/input/supplychain.xml b/sca-java-2.x/trunk/modules/composite-diagram/input/supplychain.xml
new file mode 100755
index 0000000000..1964db7fbb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/input/supplychain.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://supplychain"
+ xmlns:sp="http://supplychain"
+ name="supplychain">
+
+ <component name="CustomerComponent">
+ <implementation.java class="supplychain.CustomerComponentImpl" />
+ <reference name="retailer" target="RetailerComponent"/>
+ </component>
+
+ <component name="RetailerComponent">
+ <implementation.java class="supplychain.RetailerComponentImpl" />
+ <reference name="warehouse" target="WarehouseComponent"/>
+ </component>
+
+ <component name="WarehouseComponent">
+ <implementation.java class="supplychain.WarehouseComponentImpl" />
+ <reference name="shipper" target="ShipperComponent"/>
+ </component>
+
+ <component name="ShipperComponent">
+ <implementation.java class="supplychain.ShipperComponentImpl" />
+ <reference name="customer" />
+ </component>
+
+ <wire source="ShipperComponent/customer" target="CustomerComponent" />
+
+</composite> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/CalculatorTest_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/CalculatorTest_diagram.svg
new file mode 100755
index 0000000000..76052e23f7
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/CalculatorTest_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="central" fill="#E5E5D0" width="1400" rx="20" ry="20" height="1340" stroke="#919191"/><rect x="200" y="100" alignment-baseline="central" fill="#E5E5E5" width="1000" rx="20" ry="20" height="1140" stroke="#919191"/><text x="700" font-size="20" y="120" dominant-baseline="mathematical">CalculatorTest</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="20" y="350" dominant-baseline="mathematical">CalculatorServiceComponent</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="20" y="225" dominant-baseline="mathematical">CalculatorService</text><polygon fill="#BF3EFF" points="586,210 608,210 619,221 608,232 586,232 597,221 " stroke="#68228B"/><text x="586" font-size="20" y="221" dominant-baseline="mathematical">addService</text><polygon fill="#BF3EFF" points="586,242 608,242 619,253 608,264 586,264 597,253 " stroke="#68228B"/><text x="586" font-size="20" y="253" dominant-baseline="mathematical">subtractService</text><polygon fill="#BF3EFF" points="586,274 608,274 619,285 608,296 586,296 597,285 " stroke="#68228B"/><text x="586" font-size="20" y="285" dominant-baseline="mathematical">multiplyService</text><polygon fill="#BF3EFF" points="586,306 608,306 619,317 608,328 586,328 597,317 " stroke="#68228B"/><text x="586" font-size="20" y="317" dominant-baseline="mathematical">divideService</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="20" y="350" dominant-baseline="mathematical">AddServiceComponent</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="20" y="225" dominant-baseline="mathematical">AddService</text><rect x="800" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="20" y="610" dominant-baseline="mathematical">SubtractServiceComponent</text><polygon fill="#00CD66" points="780,470 810,470 825,485 810,500 780,500 795,485 " stroke="#008B45"/><text x="780" font-size="20" y="485" dominant-baseline="mathematical">SubtractService</text><rect x="800" y="720" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="20" y="870" dominant-baseline="mathematical">MultiplyServiceComponent</text><polygon fill="#00CD66" points="780,730 810,730 825,745 810,760 780,760 795,745 " stroke="#008B45"/><text x="780" font-size="20" y="745" dominant-baseline="mathematical">MultiplyService</text><rect x="800" y="980" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="20" y="1130" dominant-baseline="mathematical">DivideServiceComponent</text><polygon fill="#00CD66" points="780,990 810,990 825,1005 810,1020 780,1020 795,1005 " stroke="#008B45"/><text x="780" font-size="20" y="1005" dominant-baseline="mathematical">DivideService</text><polyline fill="none" stroke-width="2" points="619,221 639,221 639,225 795,225" stroke="black"/><polyline fill="none" stroke-width="2" points="619,317 639,317 639,1005 795,1005" stroke="black"/><polyline fill="none" stroke-width="2" points="619,285 639,285 639,745 795,745" stroke="black"/><polyline fill="none" stroke-width="2" points="619,253 639,253 639,485 795,485" stroke="black"/></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.html b/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.html
new file mode 100755
index 0000000000..9788bbce0a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.html
@@ -0,0 +1,22 @@
+<html>
+<head>
+<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>
+<h2 align='center'>Calculator</h2>
+</br>
+<script type="text/javascript" src="/media/798D-18B1/GSoC-2011/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/resources/rgbcolor.js"></script>
+<script type="text/javascript" src="/media/798D-18B1/GSoC-2011/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/resources/canvg-1.0.js"></script>
+<script type="text/javascript">
+window.onload = function() {
+//load '../path/to/your.svg' in the canvas with id = 'canvas'
+canvg('canvas', 'Calculator_diagram.svg')
+//load a svg snippet in the canvas with id = 'drawingArea'
+canvg(document.getElementById('drawingArea'), '<svg>...</svg>')
+canvg('canvas', 'Calculator_diagram.svg', {})
+}
+</script>
+</head>
+<body>
+<canvas id="canvas" width="1400px" height="1340px">
+</canvas>
+</body>
+</html> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.svg
new file mode 100755
index 0000000000..7c7622b974
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/Calculator_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1400 1340" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1400" rx="20" ry="20" height="1340" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1000" rx="20" ry="20" height="1140" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">Calculator</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">CalculatorServiceComponent</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">CalculatorService</text><polygon fill="#BF3EFF" points="586,210 608,210 619,221 608,232 586,232 597,221 " stroke="#68228B"/><text x="586" font-size="15" y="209" dominant-baseline="mathematical">addService</text><polygon fill="#BF3EFF" points="586,242 608,242 619,253 608,264 586,264 597,253 " stroke="#68228B"/><text x="586" font-size="15" y="241" dominant-baseline="mathematical">subtractService</text><polygon fill="#BF3EFF" points="586,274 608,274 619,285 608,296 586,296 597,285 " stroke="#68228B"/><text x="586" font-size="15" y="273" dominant-baseline="mathematical">multiplyService</text><polygon fill="#BF3EFF" points="586,306 608,306 619,317 608,328 586,328 597,317 " stroke="#68228B"/><text x="586" font-size="15" y="305" dominant-baseline="mathematical">divideService</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">AddServiceComponent</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">AddService</text><rect x="800" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="610" dominant-baseline="mathematical">SubtractServiceComponent</text><polygon fill="#00CD66" points="780,470 810,470 825,485 810,500 780,500 795,485 " stroke="#008B45"/><text x="780" font-size="15" y="469" dominant-baseline="mathematical">SubtractService</text><rect x="800" y="720" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="870" dominant-baseline="mathematical">MultiplyServiceComponent</text><polygon fill="#00CD66" points="780,730 810,730 825,745 810,760 780,760 795,745 " stroke="#008B45"/><text x="780" font-size="15" y="729" dominant-baseline="mathematical">MultiplyService</text><rect x="800" y="980" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="1130" dominant-baseline="mathematical">DivideServiceComponent</text><polygon fill="#00CD66" points="780,990 810,990 825,1005 810,1020 780,1020 795,1005 " stroke="#008B45"/><text x="780" font-size="15" y="989" dominant-baseline="mathematical">DivideService</text><rect x="400" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="610" dominant-baseline="mathematical">StockQuoteMediatorComponent</text><rect fill="#EEEE00" x="420" width="20" height="20" y="450" stroke="#EEC900"/><text x="420" font-size="15" y="449" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="380,470 410,470 425,485 410,500 380,500 395,485 " stroke="#008B45"/><text x="380" font-size="15" y="469" dominant-baseline="mathematical">SQMediator</text><polygon fill="#BF3EFF" points="580,470 610,470 625,485 610,500 580,500 595,485 " stroke="#68228B"/><text x="580" font-size="15" y="469" dominant-baseline="mathematical">stockQuoteService</text><polyline fill="none" stroke-width="2" points="619,221 639,221 639,225 795,225" stroke="black"/><polyline fill="none" stroke-width="2" points="619,317 644,317 644,1005 795,1005" stroke="black"/><polyline fill="none" stroke-width="2" points="619,285 649,285 649,745 795,745" stroke="black"/><polyline fill="none" stroke-width="2" points="619,253 654,253 654,485 795,485" stroke="black"/></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/IdleTest_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/IdleTest_diagram.svg
new file mode 100755
index 0000000000..a18d9c11a2
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/IdleTest_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1000" rx="20" ry="20" height="560" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="600" rx="20" ry="20" height="360" stroke="#919191"/><text x="500" font-size="15" y="120" dominant-baseline="mathematical">IdleTest</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">AddServiceComponent</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">AddService</text></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.html b/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.html
new file mode 100755
index 0000000000..0c91f6ae0a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>
+<h2 align='center'>MyValueComposite2</h2>
+</br>
+</head>
+<body>
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1400 1080" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1400" rx="20" ry="20" height="1080" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1000" rx="20" ry="20" height="880" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">MyValueComposite2</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">MyValueServiceComponent</text><rect fill="#EEEE00" x="420" width="20" height="20" y="190" stroke="#EEC900"/><text x="420" font-size="15" y="189" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">myValueService</text><polygon fill="#BF3EFF" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#68228B"/><text x="580" font-size="15" y="209" dominant-baseline="mathematical">stockQuoteService</text><polygon fill="#BF3EFF" points="580,250 610,250 625,265 610,280 580,280 595,265 " stroke="#68228B"/><text x="580" font-size="15" y="249" dominant-baseline="mathematical">customerService</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">StockQuoteMediatorComponent</text><rect fill="#EEEE00" x="820" width="20" height="20" y="190" stroke="#EEC900"/><text x="820" font-size="15" y="189" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">SQMediator</text><polygon fill="#BF3EFF" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#68228B"/><text x="980" font-size="15" y="209" dominant-baseline="mathematical">stockQuoteService</text><rect x="400" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="610" dominant-baseline="mathematical">SubtractServiceComponent</text><polygon fill="#00CD66" points="380,470 410,470 425,485 410,500 380,500 395,485 " stroke="#008B45"/><text x="380" font-size="15" y="469" dominant-baseline="mathematical">SubtractService</text><rect x="400" y="720" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="870" dominant-baseline="mathematical">MultiplyServiceComponent</text><polygon fill="#00CD66" points="380,730 410,730 425,745 410,760 380,760 395,745 " stroke="#008B45"/><text x="380" font-size="15" y="729" dominant-baseline="mathematical">MultiplyService</text><rect fill="#EEEE00" x="670" width="60" height="60" y="70" stroke="#EEC900"/><text x="670" font-size="15" y="69" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="140,495 230,495 275,540 230,585 140,585 185,540 " stroke="#008B45"/><text x="140" font-size="15" y="494" dominant-baseline="mathematical">MyValueService</text><polygon fill="#BF3EFF" points="1140,425 1230,425 1275,470 1230,515 1140,515 1185,470 " stroke="#68228B"/><text x="1140" font-size="15" y="424" dominant-baseline="mathematical">CustomerService</text><polygon fill="#BF3EFF" points="1140,565 1230,565 1275,610 1230,655 1140,655 1185,610 " stroke="#68228B"/><text x="1140" font-size="15" y="564" dominant-baseline="mathematical">StockQuoteService</text><polyline fill="none" stroke-width="2" points="625,225 795,225" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="1025,225 1050,225 1050,610 1185,610" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="625,265 655,265 655,470 1185,470" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="1025,225 1060,225 1060,470 1185,470" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="275,540 315,540 315,225 395,225" stroke="black"/><rect x="205" y="910" alignment-baseline="middle" fill="#E5E5C0" width="990" rx="20" ry="20" height="65" stroke="#919191"/><text x="210" font-size="15" y="920" dominant-baseline="mathematical">Included Composites</text><text x="210" font-size="15" y="945" dominant-baseline="mathematical"><a xlink:href="store_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> store ,</a><a xlink:href="Calculator_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> Calculator ,</a><a xlink:href="supplychain_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> supplychain ,</a></text></svg>
+</body>
+</html> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.svg
new file mode 100755
index 0000000000..f731eb05aa
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/MyValueComposite2_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1400 1080" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1400" rx="20" ry="20" height="1080" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1000" rx="20" ry="20" height="880" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">MyValueComposite2</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">MyValueServiceComponent</text><rect fill="#EEEE00" x="420" width="20" height="20" y="190" stroke="#EEC900"/><text x="420" font-size="15" y="189" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">myValueService</text><polygon fill="#BF3EFF" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#68228B"/><text x="580" font-size="15" y="209" dominant-baseline="mathematical">stockQuoteService</text><polygon fill="#BF3EFF" points="580,250 610,250 625,265 610,280 580,280 595,265 " stroke="#68228B"/><text x="580" font-size="15" y="249" dominant-baseline="mathematical">customerService</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">StockQuoteMediatorComponent</text><rect fill="#EEEE00" x="820" width="20" height="20" y="190" stroke="#EEC900"/><text x="820" font-size="15" y="189" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">SQMediator</text><polygon fill="#BF3EFF" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#68228B"/><text x="980" font-size="15" y="209" dominant-baseline="mathematical">stockQuoteService</text><rect x="400" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="610" dominant-baseline="mathematical">SubtractServiceComponent</text><polygon fill="#00CD66" points="380,470 410,470 425,485 410,500 380,500 395,485 " stroke="#008B45"/><text x="380" font-size="15" y="469" dominant-baseline="mathematical">SubtractService</text><rect x="400" y="720" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="870" dominant-baseline="mathematical">MultiplyServiceComponent</text><polygon fill="#00CD66" points="380,730 410,730 425,745 410,760 380,760 395,745 " stroke="#008B45"/><text x="380" font-size="15" y="729" dominant-baseline="mathematical">MultiplyService</text><rect fill="#EEEE00" x="670" width="60" height="60" y="70" stroke="#EEC900"/><text x="670" font-size="15" y="69" dominant-baseline="mathematical">currency</text><polygon fill="#00CD66" points="140,495 230,495 275,540 230,585 140,585 185,540 " stroke="#008B45"/><text x="140" font-size="15" y="494" dominant-baseline="mathematical">MyValueService</text><polygon fill="#BF3EFF" points="1140,425 1230,425 1275,470 1230,515 1140,515 1185,470 " stroke="#68228B"/><text x="1140" font-size="15" y="424" dominant-baseline="mathematical">CustomerService</text><polygon fill="#BF3EFF" points="1140,565 1230,565 1275,610 1230,655 1140,655 1185,610 " stroke="#68228B"/><text x="1140" font-size="15" y="564" dominant-baseline="mathematical">StockQuoteService</text><polyline fill="none" stroke-width="2" points="625,225 795,225" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="1025,225 1050,225 1050,610 1185,610" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="625,265 655,265 655,470 1185,470" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="1025,225 1060,225 1060,470 1185,470" stroke="black"/><polyline fill="none" stroke-dasharray="3 3" stroke-width="2" points="275,540 315,540 315,225 395,225" stroke="black"/><rect x="205" y="910" alignment-baseline="middle" fill="#E5E5C0" width="990" rx="20" ry="20" height="65" stroke="#919191"/><text x="210" font-size="15" y="920" dominant-baseline="mathematical">Included Composites</text><text x="210" font-size="15" y="945" dominant-baseline="mathematical"><a xlink:href="store_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> store ,</a><a xlink:href="Calculator_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> Calculator ,</a><a xlink:href="supplychain_diagram.svg" xlink:actuate="onRequest" xlink:type="simple" xlink:show="new" xmlns:xlink="http://www.w3.org/1999/xlink"> supplychain ,</a></text></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.html b/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.html
new file mode 100755
index 0000000000..9be38f99ad
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>
+<h2 align='center'>store</h2>
+</br>
+</head>
+<body>
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1800 820" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1800" rx="20" ry="20" height="820" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1400" rx="20" ry="20" height="620" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">store</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">Store</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">Widget</text><polygon fill="#BF3EFF" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#68228B"/><text x="580" font-size="15" y="209" dominant-baseline="mathematical">catalog</text><polygon fill="#BF3EFF" points="580,250 610,250 625,265 610,280 580,280 595,265 " stroke="#68228B"/><text x="580" font-size="15" y="249" dominant-baseline="mathematical">shoppingCart</text><polygon fill="#BF3EFF" points="580,290 610,290 625,305 610,320 580,320 595,305 " stroke="#68228B"/><text x="580" font-size="15" y="289" dominant-baseline="mathematical">shoppingTotal</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">Catalog</text><rect fill="#EEEE00" x="820" width="20" height="20" y="190" stroke="#EEC900"/><text x="820" font-size="15" y="189" dominant-baseline="mathematical">currencyCode</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">Catalog</text><polygon fill="#BF3EFF" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#68228B"/><text x="980" font-size="15" y="209" dominant-baseline="mathematical">currencyConverter</text><rect x="800" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="610" dominant-baseline="mathematical">ShoppingCart</text><polygon fill="#00CD66" points="780,470 810,470 825,485 810,500 780,500 795,485 " stroke="#008B45"/><text x="780" font-size="15" y="469" dominant-baseline="mathematical">Cart</text><polygon fill="#00CD66" points="780,510 810,510 825,525 810,540 780,540 795,525 " stroke="#008B45"/><text x="780" font-size="15" y="509" dominant-baseline="mathematical">Total</text><rect x="1200" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1200" font-size="15" y="350" dominant-baseline="mathematical">CurrencyConverter</text><polygon fill="#00CD66" points="1180,210 1210,210 1225,225 1210,240 1180,240 1195,225 " stroke="#008B45"/><text x="1180" font-size="15" y="209" dominant-baseline="mathematical">CurrencyConverter</text><polyline fill="none" stroke-width="2" points="625,305 645,305 645,525 795,525" stroke="black"/><polyline fill="none" stroke-width="2" points="625,265 650,265 650,485 795,485" stroke="black"/><polyline fill="none" stroke-width="2" points="625,225 795,225" stroke="black"/><polyline fill="none" stroke-width="2" points="1025,225 1195,225" stroke="black"/></svg>
+</body>
+</html> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.svg
new file mode 100755
index 0000000000..2bce7c1173
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/store_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 1800 820" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="1800" rx="20" ry="20" height="820" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1400" rx="20" ry="20" height="620" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">store</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">Store</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">Widget</text><polygon fill="#BF3EFF" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#68228B"/><text x="580" font-size="15" y="209" dominant-baseline="mathematical">catalog</text><polygon fill="#BF3EFF" points="580,250 610,250 625,265 610,280 580,280 595,265 " stroke="#68228B"/><text x="580" font-size="15" y="249" dominant-baseline="mathematical">shoppingCart</text><polygon fill="#BF3EFF" points="580,290 610,290 625,305 610,320 580,320 595,305 " stroke="#68228B"/><text x="580" font-size="15" y="289" dominant-baseline="mathematical">shoppingTotal</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">Catalog</text><rect fill="#EEEE00" x="820" width="20" height="20" y="190" stroke="#EEC900"/><text x="820" font-size="15" y="189" dominant-baseline="mathematical">currencyCode</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">Catalog</text><polygon fill="#BF3EFF" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#68228B"/><text x="980" font-size="15" y="209" dominant-baseline="mathematical">currencyConverter</text><rect x="800" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="610" dominant-baseline="mathematical">ShoppingCart</text><polygon fill="#00CD66" points="780,470 810,470 825,485 810,500 780,500 795,485 " stroke="#008B45"/><text x="780" font-size="15" y="469" dominant-baseline="mathematical">Cart</text><polygon fill="#00CD66" points="780,510 810,510 825,525 810,540 780,540 795,525 " stroke="#008B45"/><text x="780" font-size="15" y="509" dominant-baseline="mathematical">Total</text><rect x="1200" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1200" font-size="15" y="350" dominant-baseline="mathematical">CurrencyConverter</text><polygon fill="#00CD66" points="1180,210 1210,210 1225,225 1210,240 1180,240 1195,225 " stroke="#008B45"/><text x="1180" font-size="15" y="209" dominant-baseline="mathematical">CurrencyConverter</text><polyline fill="none" stroke-width="2" points="625,305 645,305 645,525 795,525" stroke="black"/><polyline fill="none" stroke-width="2" points="625,265 650,265 650,485 795,485" stroke="black"/><polyline fill="none" stroke-width="2" points="625,225 795,225" stroke="black"/><polyline fill="none" stroke-width="2" points="1025,225 1195,225" stroke="black"/></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.html b/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.html
new file mode 100755
index 0000000000..227ebd720b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.html
@@ -0,0 +1,22 @@
+<html>
+<head>
+<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>
+<h2 align='center'>supplychain</h2>
+</br>
+<script type="text/javascript" src="/media/798D-18B1/GSoC-2011/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/resources/rgbcolor.js"></script>
+<script type="text/javascript" src="/media/798D-18B1/GSoC-2011/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/resources/canvg-1.0.js"></script>
+<script type="text/javascript">
+window.onload = function() {
+//load '../path/to/your.svg' in the canvas with id = 'canvas'
+canvg('canvas', 'supplychain_diagram.svg')
+//load a svg snippet in the canvas with id = 'drawingArea'
+canvg(document.getElementById('drawingArea'), '<svg>...</svg>')
+canvg('canvas', 'supplychain_diagram.svg', {})
+}
+</script>
+</head>
+<body>
+<canvas id="canvas" width="2200px" height="560px">
+</canvas>
+</body>
+</html> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.svg b/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.svg
new file mode 100755
index 0000000000..466028c02e
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/output/supplychain_diagram.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" viewBox="0 0 2200 560" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" alignment-baseline="middle" fill="#E5E5D0" width="2200" rx="20" ry="20" height="560" stroke="#919191"/><rect x="200" y="100" alignment-baseline="middle" fill="#E5E5E5" width="1800" rx="20" ry="20" height="360" stroke="#919191"/><text x="220" font-size="15" y="120" dominant-baseline="mathematical">supplychain</text><rect x="400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="400" font-size="15" y="350" dominant-baseline="mathematical">CustomerComponent</text><polygon fill="#00CD66" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#008B45"/><text x="380" font-size="15" y="209" dominant-baseline="mathematical">CustomerComponent</text><polygon fill="#BF3EFF" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#68228B"/><text x="580" font-size="15" y="209" dominant-baseline="mathematical">retailer</text><rect x="800" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="800" font-size="15" y="350" dominant-baseline="mathematical">RetailerComponent</text><polygon fill="#00CD66" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#008B45"/><text x="780" font-size="15" y="209" dominant-baseline="mathematical">RetailerComponent</text><polygon fill="#BF3EFF" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#68228B"/><text x="980" font-size="15" y="209" dominant-baseline="mathematical">warehouse</text><rect x="1200" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1200" font-size="15" y="350" dominant-baseline="mathematical">WarehouseComponent</text><polygon fill="#00CD66" points="1180,210 1210,210 1225,225 1210,240 1180,240 1195,225 " stroke="#008B45"/><text x="1180" font-size="15" y="209" dominant-baseline="mathematical">WarehouseComponent</text><polygon fill="#BF3EFF" points="1380,210 1410,210 1425,225 1410,240 1380,240 1395,225 " stroke="#68228B"/><text x="1380" font-size="15" y="209" dominant-baseline="mathematical">shipper</text><rect x="1600" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1600" font-size="15" y="350" dominant-baseline="mathematical">ShipperComponent</text><polygon fill="#00CD66" points="1580,210 1610,210 1625,225 1610,240 1580,240 1595,225 " stroke="#008B45"/><text x="1580" font-size="15" y="209" dominant-baseline="mathematical">ShipperComponent</text><polygon fill="#BF3EFF" points="1780,210 1810,210 1825,225 1810,240 1780,240 1795,225 " stroke="#68228B"/><text x="1780" font-size="15" y="209" dominant-baseline="mathematical">customer</text><polyline fill="none" stroke-width="2" points="625,225 795,225" stroke="black"/><polyline fill="none" stroke-width="2" points="1025,225 1195,225" stroke="black"/><polyline fill="none" stroke-width="2" points="1425,225 1595,225" stroke="black"/><polyline fill="none" stroke-width="2" points="1825,225 1860,225 1860,155 360,155 360,225 395,225" stroke="black"/></svg> \ No newline at end of file
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/pom.xml b/sca-java-2.x/trunk/modules/composite-diagram/pom.xml
new file mode 100644
index 0000000000..ee360ddfb1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/pom.xml
@@ -0,0 +1,187 @@
+<?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. <groupId>org.apache.tuscany.sca</groupId>
+-->
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-composite-diagram</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <name>Apache Tuscany SCA Composite Diagram Generator Application</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+
+ <!--
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-anim</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-awt-util</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-css</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-ext</artifactId>
+ <version>1.7</version>
+ </dependency>
+ -->
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-dom</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-parser</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-svg-dom</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-svggen</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-util</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-xml</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlgraphics</groupId>
+ <artifactId>batik-codec</artifactId>
+ <version>1.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis-ext</artifactId>
+ <version>1.3.04</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <directory>${basedir}/target</directory>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+<!--
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.1</version>
+ <executions>
+ <execution>
+ <id>${project.artifactId}-fetch-deps</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.outputDirectory}</outputDirectory>
+ <stripVersion>true</stripVersion>
+ <excludeTransitive>true</excludeTransitive>
+ <excludeArtifactIds>junit</excludeArtifactIds>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.tuscany.sca.diagram.main.Main</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+</project>
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java
new file mode 100644
index 0000000000..0a16a797c2
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Artifact.java
@@ -0,0 +1,120 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public abstract class Artifact {
+
+ private String name;
+ private String containerName;
+ private int height;
+ private int width;
+ private int xCoordinate;
+ private int yCoordinate;
+ private Document doc;
+ private String svgNs;
+ private static final String ROUND_CORNER = "20";
+
+ /**
+ * Abstract method
+ * @param document DOM document
+ * @param svgNs namespace URI
+ * @param x x-coordinate
+ * @param y y-coordinate
+ * @param height height of the shape
+ * @param width width of the shape
+ * @return DOM Element
+ */
+ public abstract Element addElement(Document document, String svgNs, int x, int y, int height, int width);
+
+ // public abstract Element addElement(Document document, String svgNs,
+ // int x, int y);
+
+ public int getHeight() {
+ return height;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public int getxCoordinate() {
+ return xCoordinate;
+ }
+
+ public void setxCoordinate(int xCoordinate) {
+ this.xCoordinate = xCoordinate;
+ }
+
+ public int getyCoordinate() {
+ return yCoordinate;
+ }
+
+ public void setyCoordinate(int yCoordinate) {
+ this.yCoordinate = yCoordinate;
+ }
+
+ public Document getDoc() {
+ return doc;
+ }
+
+ public void setDoc(Document doc) {
+ this.doc = doc;
+ }
+
+ public String getSvgNs() {
+ return svgNs;
+ }
+
+ public void setSvgNs(String svgNs) {
+ this.svgNs = svgNs;
+ }
+
+ public static String getRoundCorner() {
+ return ROUND_CORNER;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setContainerName(String containerName) {
+ this.containerName = containerName;
+ }
+
+ public String getContainerName() {
+ return containerName;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
new file mode 100755
index 0000000000..96a1d6ad1c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ComponentArtifact.java
@@ -0,0 +1,59 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ComponentArtifact extends Artifact {
+
+ /**
+ * Create an element with specified height and width
+ */
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ Element rectangle = document.createElementNS(svgNs, "rect");
+ rectangle.setAttributeNS(null, "x", x + "");
+ rectangle.setAttributeNS(null, "y", y + "");
+ rectangle.setAttributeNS(null, "rx", getRoundCorner());
+ rectangle.setAttributeNS(null, "ry", getRoundCorner());
+ rectangle.setAttributeNS(null, "width", width + "");
+ rectangle.setAttributeNS(null, "height", height + "");
+ rectangle.setAttributeNS(null, "fill", "#3D59AB");
+ rectangle.setAttributeNS(null, "stroke", "#104E8B");
+ rectangle.setAttributeNS(null, "fill-opacity", "0.75");
+ return rectangle;
+ }
+
+ /**
+ * Create an element with default height and width
+ */
+ public Element addElement(Document document, String svgNs, int x, int y) {
+
+ return addElement(document, svgNs, x, y, Constant.COMPONENT_DEFAULT_HEIGHT, Constant.COMPONENT_DEFAULT_WIDTH);
+
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
new file mode 100755
index 0000000000..38285cac2a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/CompositeArtifact.java
@@ -0,0 +1,57 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Structure of a "Composite" element in SCA, as a SVG element
+ *
+ */
+public class CompositeArtifact extends Artifact {
+
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ Element rectangle = document.createElementNS(svgNs, "rect");
+ rectangle.setAttributeNS(null, "x", x + "");
+ rectangle.setAttributeNS(null, "y", y + "");
+ rectangle.setAttributeNS(null, "rx", getRoundCorner());
+ rectangle.setAttributeNS(null, "ry", getRoundCorner());
+ rectangle.setAttributeNS(null, "width", width + "");
+ rectangle.setAttributeNS(null, "height", height + "");
+ rectangle.setAttributeNS(null, "fill", "#E5E5E5");
+ rectangle.setAttributeNS(null, "stroke", "#919191");
+ rectangle.setAttributeNS(null, "alignment-baseline", "middle");
+
+ return rectangle;
+ }
+
+ // //OBSOLETE
+ // public Element addElement(Document document, String svgNs, int x, int y) {
+ // return null;
+ // }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
new file mode 100755
index 0000000000..52e9e3e054
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Constant.java
@@ -0,0 +1,26 @@
+package org.apache.tuscany.sca.diagram.artifacts;
+
+public final class Constant {
+
+ public static final int COMPONENT_DEFAULT_WIDTH = 200;
+ public static final int COMPONENT_DEFAULT_HEIGHT = 130;
+ public static final int COMPONENT_TEXT_SPACING = 20;
+
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY = 20;
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY = 60;
+ public static final int SPACING_FOR_COMPONENT_OF_PROPERTY = 20;
+ public static final int SPACING_FOR_COMPOSITE_OF_PROPERTY = 60;
+
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE = 30;
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE = 90;
+ public static final int SPACING_FOR_COMPONENT_OF_REFERENCE = 10;
+ public static final int SPACING_FOR_COMPOSITE_OF_REFERENCE = 50;
+
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE = 30;
+ public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE = 90;
+ public static final int SPACING_FOR_COMPONENT_OF_SERVICE = 10;
+ public static final int SPACING_FOR_COMPOSITE_OF_SERVICE = 50;
+
+ public static final int SPACING_FOR_TEXT = 1;
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java
new file mode 100755
index 0000000000..4f9c741ab6
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/DashedWire.java
@@ -0,0 +1,81 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class DashedWire extends WireArtifact {
+
+ @Override
+ public Element addElement(Document document, String svgNs, Object a, Object b, int changingFactor, String color) {
+
+ Element polyline = document.createElementNS(svgNs, "polyline");
+ int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
+
+ if (a instanceof ServiceArtifact && b instanceof ServiceArtifact) {
+
+ ServiceArtifact aService1 = (ServiceArtifact)a;
+ ServiceArtifact aService2 = (ServiceArtifact)b;
+
+ x1 = aService1.getxCoordinate() + aService1.getHeight() * 3 / 2;
+ y1 = aService1.getyCoordinate() + aService1.getHeight() / 2;
+
+ x2 = aService2.getxCoordinate() + aService2.getHeight() / 2;
+ y2 = aService2.getyCoordinate() + aService2.getHeight() / 2;
+
+ }
+
+ else if (a instanceof ReferenceArtifact && b instanceof ReferenceArtifact) {
+
+ ReferenceArtifact aReference1 = (ReferenceArtifact)a;
+ ReferenceArtifact aReference2 = (ReferenceArtifact)b;
+
+ x1 = aReference1.getxCoordinate() + aReference1.getHeight() * 3 / 2;
+ y1 = aReference1.getyCoordinate() + aReference1.getHeight() / 2;
+
+ x2 = aReference2.getxCoordinate() + aReference2.getHeight() / 2;
+ y2 = aReference2.getyCoordinate() + aReference2.getHeight() / 2;
+
+ }
+
+ polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color);
+
+ polyline.setAttributeNS(null, "stroke-dasharray", "3 3");
+
+ return polyline;
+ }
+
+ /**
+ * <script type="text/ecmascript"><![CDATA[
+ <SCRIPT LANGUAGE="JavaScript">
+
+ var test = document.open("store_diagram.svg");
+
+ </SCRIPT>
+ ]]></script>
+
+ <!--rect x="0" y="0" alignment-baseline="central" fill="#E5E5D0" width="1400" rx="20" ry="20" height="560" stroke="#919191"/><rect x="200" y="100" alignment-baseline="central" fill="#E5E5E5" width="1000" rx="20" ry="20" height="360" stroke="#919191"/><text x="700" font-size="20" dominant-baseline="mathematical" y="120" text-anchor="middle">
+
+ <a xlink:href="store_diagram.svg" xlink:show="new">MyValueComposite2</a></text-->
+
+ */
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
new file mode 100755
index 0000000000..fa2d44f89f
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Layer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Structure of a "Outermost layer" : not a SCA artifact
+ *
+ */
+public class Layer extends Artifact {
+
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ Element rectangle = document.createElementNS(svgNs, "rect");
+ rectangle.setAttributeNS(null, "x", x + "");
+ rectangle.setAttributeNS(null, "y", y + "");
+ rectangle.setAttributeNS(null, "rx", getRoundCorner());
+ rectangle.setAttributeNS(null, "ry", getRoundCorner());
+ rectangle.setAttributeNS(null, "width", width + "");
+ rectangle.setAttributeNS(null, "height", height + "");
+ rectangle.setAttributeNS(null, "fill", "#E5E5D0");
+ rectangle.setAttributeNS(null, "stroke", "#919191");
+ rectangle.setAttributeNS(null, "alignment-baseline", "middle");
+
+ return rectangle;
+ }
+
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width, String fillColor) {
+
+ Element rect = addElement(document, svgNs, x, y, height, width);
+ rect.setAttributeNS(null, "fill", fillColor);
+
+ return rect;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
new file mode 100755
index 0000000000..a0cbee344c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Link.java
@@ -0,0 +1,41 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An "a" element to link two SVG diagrams: not a SCA artifact
+ *
+ */
+public class Link {
+
+ public Element addElement(Document document, String svgNs, String fileName, String compName) {
+
+ Element link = document.createElementNS(svgNs, "a");
+ link.setAttributeNS(null, "xlink:href", fileName);
+ link.setAttributeNS(null, "xlink:show", "new");
+ link.setTextContent(" " + compName + " ,");
+
+ return link;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java
new file mode 100755
index 0000000000..7611c004aa
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/NormalWire.java
@@ -0,0 +1,45 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class NormalWire extends WireArtifact {
+
+ @Override
+ public Element addElement(Document document, String svgNs, Object a, Object b, int changingFactor, String color) {
+
+ ReferenceArtifact aReference = (ReferenceArtifact)a;
+ ServiceArtifact aService = (ServiceArtifact)b;
+
+ Element polyline = document.createElementNS(svgNs, "polyline");
+ int x1 = aReference.getxCoordinate() + aReference.getHeight() * 3 / 2;
+ int y1 = aReference.getyCoordinate() + aReference.getHeight() / 2;
+
+ int x2 = aService.getxCoordinate() + aService.getHeight() / 2;
+ int y2 = aService.getyCoordinate() + aService.getHeight() / 2;
+
+ polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color);
+
+ return polyline;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java
new file mode 100755
index 0000000000..4b13c0de64
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/PropertyArtifact.java
@@ -0,0 +1,58 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class PropertyArtifact extends Artifact {
+
+ /**
+ * Property is a square.
+ * ___
+ * | |
+ * |___|
+ *
+ */
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ Element rectangle = document.createElementNS(svgNs, "rect");
+ rectangle.setAttributeNS(null, "x", x + "");
+ rectangle.setAttributeNS(null, "y", y + "");
+ rectangle.setAttributeNS(null, "width", height + "");
+ rectangle.setAttributeNS(null, "height", height + "");
+ rectangle.setAttributeNS(null, "fill", "#EEEE00");
+ rectangle.setAttributeNS(null, "stroke", "#EEC900");
+ //rectangle.setAttributeNS(null, "fill-opacity", "0.75");
+
+ return rectangle;
+ }
+
+ public Element addElement(Document document, String svgNs, int x, int y, int height) {
+
+ return addElement(document, svgNs, x, y, height, height);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java
new file mode 100755
index 0000000000..87ecba2af7
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ReferenceArtifact.java
@@ -0,0 +1,86 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ReferenceArtifact extends Artifact {
+
+ /**
+ * In a Reference the (x,y) coordinates refers to the top corner edge of the polygon
+ * (x,y)______
+ * \ \
+ * \ \
+ * / /
+ * /____ /
+ */
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ int halfOfHeight = height / 2;
+
+ Element polygon = document.createElementNS(svgNs, "polygon");
+ polygon.setAttributeNS(null, "points", "" + x
+ + ","
+ + y
+ + " "
+ + ""
+ + (x + 2 * halfOfHeight)
+ + ","
+ + (y)
+ + " "
+ + ""
+ + (x + 3 * halfOfHeight)
+ + ","
+ + (y + halfOfHeight)
+ + " "
+ + ""
+ + (x + 2 * halfOfHeight)
+ + ","
+ + (y + 2 * halfOfHeight)
+ + " "
+ + ""
+ + (x)
+ + ","
+ + (y + 2 * halfOfHeight)
+ + " "
+ + ""
+ + (x + halfOfHeight)
+ + ","
+ + (y + halfOfHeight)
+ + " ");
+
+ polygon.setAttributeNS(null, "fill", "#BF3EFF");
+ polygon.setAttributeNS(null, "stroke", "#68228B");
+
+ return polygon;
+ }
+
+ public Element addElement(Document document, String svgNs, int x, int y, int height) {
+
+ return this.addElement(document, svgNs, x, y, height, height * 3 / 2);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java
new file mode 100755
index 0000000000..d7c312f729
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ServiceArtifact.java
@@ -0,0 +1,95 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ServiceArtifact extends Artifact {
+
+ /**
+ * In a Service the (x,y) coordinates refers to the top corner edge of the polygon
+ * (x,y)______
+ * \ \
+ * \ \
+ * / /
+ * /____ /
+ */
+ public Element addElement(Document document, String svgNs, int x, int y, int height, int width) {
+
+ this.setHeight(height);
+ this.setWidth(width);
+ this.setxCoordinate(x);
+ this.setyCoordinate(y);
+
+ int halfOfHeight = height / 2;
+
+ Element polygon = document.createElementNS(svgNs, "polygon");
+ polygon.setAttributeNS(null, "points", "" + x
+ + ","
+ + y
+ + " "
+ + ""
+ + (x + 2 * halfOfHeight)
+ + ","
+ + (y)
+ + " "
+ + ""
+ + (x + 3 * halfOfHeight)
+ + ","
+ + (y + halfOfHeight)
+ + " "
+ + ""
+ + (x + 2 * halfOfHeight)
+ + ","
+ + (y + 2 * halfOfHeight)
+ + " "
+ + ""
+ + (x)
+ + ","
+ + (y + 2 * halfOfHeight)
+ + " "
+ + ""
+ + (x + halfOfHeight)
+ + ","
+ + (y + halfOfHeight)
+ + " ");
+
+ polygon.setAttributeNS(null, "fill", "#00CD66");
+ polygon.setAttributeNS(null, "stroke", "#008B45");
+
+ return polygon;
+ }
+
+ /**
+ * Width is 3/2 times of the height
+ * @param document
+ * @param svgNs
+ * @param x
+ * @param y
+ * @param height
+ * @return
+ */
+ public Element addElement(Document document, String svgNs, int x, int y, int height) {
+
+ return this.addElement(document, svgNs, x, y, height, height * 3 / 2);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java
new file mode 100644
index 0000000000..ec4563254a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Text.java
@@ -0,0 +1,38 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class Text {
+
+ public static Element addTextElement(Document document, String svgNs, int x, int y, String content) {
+ Element text = document.createElementNS(svgNs, "text");
+ text.setAttributeNS(null, "x", x + "");
+ text.setAttributeNS(null, "y", y + "");
+ //text.setAttributeNS(null, "text-anchor", "middle");
+ text.setAttributeNS(null, "dominant-baseline", "mathematical");
+ text.setAttributeNS(null, "font-size", "15");
+ text.setTextContent(content);
+
+ return text;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java
new file mode 100755
index 0000000000..0b3e83b9c2
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/WireArtifact.java
@@ -0,0 +1,86 @@
+/*
+ * 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.diagram.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public abstract class WireArtifact {
+
+ public abstract Element addElement(Document document,
+ String svgNs,
+ Object a,
+ Object b,
+ int changingFactor,
+ String color);
+
+ public Element setWireAttributes(int x1, int y1, int x2, int y2, Element polyline, int changingFactor, String color) {
+
+ if (y1 == y2 && x2 > x1) {
+ polyline.setAttributeNS(null, "points", x1 + "," + y1 + " " + x2 + "," + y2);
+ } else if (y1 == y2 && x1 > x2) {
+ polyline.setAttributeNS(null, "points", x1 + ","
+ + y1
+ + " "
+ + (x1 + changingFactor)
+ + ","
+ + y1
+ + " "
+ + (x1 + changingFactor)
+ + ","
+ + (y1 - (changingFactor * 2))
+ + " "
+ + (x2 - changingFactor)
+ + ","
+ + (y1 - (changingFactor * 2))
+ + " "
+ + (x2 - changingFactor)
+ + ","
+ + (y1)
+ + " "
+ + (x2)
+ + ","
+ + (y1));
+
+ } else {
+ polyline.setAttributeNS(null, "points", x1 + ","
+ + y1
+ + " "
+ + (x1 + changingFactor)
+ + ","
+ + y1
+ + " "
+ + (x1 + changingFactor)
+ + ","
+ + y2
+ + " "
+ + x2
+ + ","
+ + y2);
+ }
+
+ polyline.setAttributeNS(null, "stroke", color);
+ polyline.setAttributeNS(null, "stroke-width", "2");
+ polyline.setAttributeNS(null, "fill", "none");
+
+ return polyline;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
new file mode 100755
index 0000000000..5d4a40fcfb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
@@ -0,0 +1,604 @@
+/*
+ * 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.diagram.generator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.tuscany.sca.diagram.artifacts.ComponentArtifact;
+import org.apache.tuscany.sca.diagram.artifacts.CompositeArtifact;
+import org.apache.tuscany.sca.diagram.artifacts.Constant;
+import org.apache.tuscany.sca.diagram.artifacts.DashedWire;
+import org.apache.tuscany.sca.diagram.artifacts.Layer;
+import org.apache.tuscany.sca.diagram.artifacts.Link;
+import org.apache.tuscany.sca.diagram.artifacts.NormalWire;
+import org.apache.tuscany.sca.diagram.artifacts.PropertyArtifact;
+import org.apache.tuscany.sca.diagram.artifacts.ReferenceArtifact;
+import org.apache.tuscany.sca.diagram.artifacts.ServiceArtifact;
+import org.apache.tuscany.sca.diagram.artifacts.Text;
+import org.apache.tuscany.sca.diagram.artifacts.WireArtifact;
+import org.apache.tuscany.sca.diagram.layout.ComponentEntity;
+import org.apache.tuscany.sca.diagram.layout.CompositeEntity;
+import org.apache.tuscany.sca.diagram.layout.Entity;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class DiagramGenerator {
+
+ private CompositeEntity comp;
+ private Document doc;
+ private String svgNS;
+ private Element svgRoot;
+ private ArrayList<ReferenceArtifact> refs = new ArrayList<ReferenceArtifact>();
+ private ArrayList<ServiceArtifact> sers = new ArrayList<ServiceArtifact>();
+ private int diagramHeight, diagramWidth;
+
+ private boolean isHtml;
+
+ private int lastUsedChangingFactor = 0;
+
+ enum changingFactor {
+ a(20), b(25), c(30), d(35), e(40), f(15);
+
+ private final int val;
+
+ private changingFactor(int x) {
+ val = x;
+ }
+
+ public int getVal() {
+ return val;
+ }
+
+ };
+
+ enum color {
+ black
+ }//, violet, red, green};
+
+ private int previousWireColor = 0;
+
+ /**
+ * Constructor to generate a SVG diagram for a given CompositeEntity
+ * Object.
+ */
+ public DiagramGenerator(CompositeEntity comp, boolean isHtml) {
+
+ this.comp = comp;
+ this.isHtml = isHtml;
+
+ }
+
+ /**
+ * Draws the diagram.
+ */
+ public Document buildSVGDocument() {
+
+ DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
+ svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
+ doc = impl.createDocument(svgNS, "svg", null);
+
+ // Get the root element (the 'svg' element).
+ svgRoot = doc.getDocumentElement();
+
+ setDiagramHeight(comp.getHeight() + 200);
+ setDiagramWidth(comp.getWidth() + 400);
+
+ svgRoot.setAttributeNS(null, "viewBox", "0 0 " + getDiagramWidth() + " " + getDiagramHeight());
+
+ addLayer();
+ addComposite();
+
+ for (ComponentEntity ent : comp.getComponentList()) {
+
+ addComponent(ent);
+ addComponentProperties(ent);
+ addComponentService(ent);
+ addComponentReference(ent);
+ }
+
+ addCompositeProperties();
+ addCompositeService();
+ addCompositeReference();
+
+ addComponentConnections();
+ addReferencePromotion();
+ addServicePromotion();
+
+ addInclusions();
+
+ return doc;
+ }
+
+ private void addLayer() {
+
+ Layer outerLayer = new Layer();
+ Element layerElt = outerLayer.addElement(doc, svgNS, 0, 0, getDiagramHeight(), getDiagramWidth());
+ svgRoot.appendChild(layerElt);
+ }
+
+ private void addReferencePromotion() {
+
+ for (Iterator<Entry<String, ArrayList<String>>> it = comp.getPromoteAReference().entrySet().iterator(); it
+ .hasNext();) {
+ Entry<String, ArrayList<String>> entry = it.next();
+ String compositeRef = entry.getKey();
+ ArrayList<String> componentRef = entry.getValue();
+
+ ReferenceArtifact r1 = getRef(compositeRef);
+
+ for (String ref : componentRef) {
+
+ ReferenceArtifact r2 = getRef(ref);
+
+ if (r1 != null && r2 != null) {
+ addWire(r2, r1);
+ }
+ }
+
+ }
+ }
+
+ private void addServicePromotion() {
+
+ for (Iterator<Entry<String, String>> it = comp.getPromoteAService().entrySet().iterator(); it.hasNext();) {
+ Entry<String, String> entry = it.next();
+ String compositeSer = entry.getKey();
+ String componentSer = entry.getValue();
+
+ ServiceArtifact s1 = getSer(compositeSer);
+ ServiceArtifact s2 = getSer(componentSer);
+
+ if (s1 != null && s2 != null) {
+ addWire(s1, s2);
+ }
+ }
+ }
+
+ private void addInclusions() {
+
+ if (!comp.getIncludedComposites().isEmpty()) {
+
+ Layer inclusionLayer = new Layer();
+ int constant = 5;
+ int x0 = comp.getX() + constant;
+ int y0 = comp.getY() + comp.getHeight() - (Constant.COMPONENT_DEFAULT_HEIGHT / 2 + constant);
+ int height = Constant.COMPONENT_DEFAULT_HEIGHT / 2;
+ int width = comp.getWidth() - constant * 2;
+
+ Element layerElt = inclusionLayer.addElement(doc, svgNS, x0, y0, height, width, "#E5E5C0");
+
+ Element text = Text.addTextElement(doc, svgNS, x0 + constant, y0 + constant * 2, "Included Composites");
+
+ svgRoot.appendChild(layerElt);
+ svgRoot.appendChild(text);
+
+ text = Text.addTextElement(doc, svgNS, x0 + constant, y0 + constant * 7, "");
+
+ String ext;
+
+ if (isHtml) {
+ ext = ".html";
+ } else {
+ ext = ".svg";
+ }
+
+ for (String includedComposite : comp.getIncludedComposites()) {
+
+ Link link = new Link();
+ Element aLink =
+ link.addElement(doc, svgNS, includedComposite + comp.getFileNameSuffix() + ext, includedComposite);
+ text.appendChild(aLink);
+
+ }
+ svgRoot.appendChild(text);
+ }
+ }
+
+ /**
+ * Connects references to services.
+ */
+ private void addComponentConnections() {
+
+ for (Entity ent : comp.getComponentList()) {
+ //if(ent instanceof ComponentEntity){
+
+ for (Iterator<Entry<String, String>> it =
+ ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
+ Entry<String, String> entry = it.next();
+ String ref = entry.getKey();
+ String ser = entry.getValue();
+
+ ReferenceArtifact r = getRef(ref);
+ ServiceArtifact s = getSer(ser);
+
+ if (r != null && s != null) {
+ addWire(r, s);
+ }
+ }
+ //}
+ }
+ }
+
+ /**
+ * This is to remove overlapping of wire elements
+ */
+ private String getColor() {
+
+ previousWireColor = previousWireColor % color.values().length;
+ return color.values()[previousWireColor++].toString();
+ }
+
+ /**
+ * This is to remove overlapping of wire elements
+ */
+ private int getChangingFactor() {
+
+ lastUsedChangingFactor = lastUsedChangingFactor % changingFactor.values().length;
+ return changingFactor.values()[lastUsedChangingFactor++].getVal();
+
+ }
+
+ private void addWire(ReferenceArtifact r, ServiceArtifact s) {
+
+ WireArtifact edge = new NormalWire();
+ Element wire = edge.addElement(doc, svgNS, r, s, getChangingFactor(), getColor());
+ svgRoot.appendChild(wire);
+ }
+
+ private void addWire(ServiceArtifact s1, ServiceArtifact s2) {
+
+ DashedWire edge = new DashedWire();
+ Element wire = edge.addElement(doc, svgNS, s1, s2, getChangingFactor(), getColor());
+ svgRoot.appendChild(wire);
+ }
+
+ private void addWire(ReferenceArtifact r1, ReferenceArtifact r2) {
+
+ DashedWire edge = new DashedWire();
+ Element wire = edge.addElement(doc, svgNS, r1, r2, getChangingFactor(), getColor());
+ svgRoot.appendChild(wire);
+ }
+
+ private ServiceArtifact getSer(String ser) {
+
+ for (ServiceArtifact s : sers) {
+ if (s.getContainerName().equals(ser) || s.getName().equals(ser)) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ private ReferenceArtifact getRef(String ref) {
+
+ for (ReferenceArtifact r : refs) {
+
+ if (r.getContainerName().equals(ref) || r.getName().equals(ref)) {
+ return r;
+ }
+ }
+ return null;
+ }
+
+ private void addComponentProperties(ComponentEntity ent) {
+ int propLen = ent.getPropLength();
+ int x = ent.getX() + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY;
+ int y = ent.getY() - propLen / 2;
+
+ for (String prop : ent.getProperties()) {
+ PropertyArtifact pro = new PropertyArtifact();
+ Element property = pro.addElement(doc, svgNS, x, y, propLen);
+ Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, prop);
+
+ svgRoot.appendChild(property);
+ svgRoot.appendChild(text);
+
+ x += (propLen + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY);
+
+ pro.setName(prop);
+ pro.setContainerName(ent.getName());
+ }
+ }
+
+ private void addComponentReference(ComponentEntity ent) {
+
+ int refHeight = ent.getRefHeight();
+ int x = (ent.getX() + ent.getWidth()) - (refHeight * 2 / 3);
+ int y = ent.getY() + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE;
+
+ for (String ref : setRefOrder(ent)) {
+ ReferenceArtifact refer = new ReferenceArtifact();
+ Element polygon = refer.addElement(doc, svgNS, x, y, refHeight);
+ Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ref);
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (refHeight + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE);
+
+ refer.setName(ref);
+ refer.setContainerName(ent.getName());
+ refs.add(refer);
+
+ }
+ }
+
+ /**
+ * This method is used to organize the Component References,
+ * in a manner where they are stay approximately in-line with the
+ * connecting Service. This would enhance the clearness of the diagram.
+ */
+ private String[] setRefOrder(ComponentEntity e) {
+
+ ArrayList<String> refs = e.getReferences();
+ ArrayList<String> sers = new ArrayList<String>();
+ String[] orderedRefs = new String[refs.size()];
+
+ //sers = new ArrayList<String>(e.getReferenceToServiceMap().values());
+
+ sers = buildReferenceToMappingServiceList(refs, e);
+
+ for (String eName : e.getAdjacentEntities()) {
+ for (Entity ent : comp.getComponentList()) {
+
+ if (ent.getName().equals(eName)) {
+ for (String s : sers) {
+ for (String s1 : ent.getServices()) {
+ //System.err.println("XXXXX "+ s1 +" ::: "+s);
+ if (s1.equals(s) || s.equals(ent.getName())) {
+ //System.err.println("|||||||| "+ sers.size()+ " ||| " + refs.size()+"|| "+orderedRefs.length);
+ if (orderedRefs[ent.getLevel()] == null) {
+ //System.err.println("XXXXX "+ sers.get(1)+ " ::::::: "+refs.get(1));
+ // System.err.println("XXXXX "+ sers.get(2)+ " ::::::: "+refs.get(2));
+ // System.err.println("XXXXX "+ sers.get(3)+ " ::::::: "+refs.get(3));
+ //System.err.println("XXXXX "+ refs.get(sers.indexOf(s))+" ::: "+ent.getLevel()+" ::: "+ent.getName());
+ orderedRefs[ent.getLevel()] = refs.get(sers.indexOf(s));
+ break;
+ } else {
+ for (int i = ent.getLevel(); i < orderedRefs.length; i++) {
+ if (orderedRefs[i] == null) {
+
+ orderedRefs[i] = refs.get(sers.indexOf(s));
+ break;
+ }
+ // else{
+ // if(i==orderedRefs.length)
+ // System.out.println("GRRR");
+ // }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //adding references which are not connected to any service
+ for (String ref : refs) {
+ for (int i = 0; i < orderedRefs.length; i++) {
+ if (ref.equals(orderedRefs[i])) {
+ break;
+ } else if (orderedRefs[i] == null) {
+ orderedRefs[i] = ref;
+ break;
+ }
+ }
+ }
+
+ return orderedRefs;
+ }
+
+ private ArrayList<String> buildReferenceToMappingServiceList(ArrayList<String> refs, ComponentEntity e) {
+
+ ArrayList<String> sers = new ArrayList<String>();
+
+ for (int i = 0; i < refs.size(); i++) {
+ sers.add(i, "");
+ }
+
+ for (Iterator<Entry<String, String>> it = e.getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
+
+ Entry<String, String> entry = it.next();
+ String ref = entry.getKey();
+ String ser = entry.getValue();
+ //System.out.println("---------"+ref);
+ int idx = refs.indexOf(ref);
+ //System.out.println("---------"+sers.get(idx));
+ sers.remove(idx);
+ sers.add(idx, ser);
+ //System.out.println(refs.get(idx)+"---"+sers.get(idx));
+
+ }
+
+ return sers;
+ }
+
+ private void addComponentService(ComponentEntity ent) {
+ int serHeight = ent.getSerHeight();
+ int x = ent.getX() - (serHeight * 2 / 3);
+ int y = ent.getY() + Constant.SPACING_FOR_COMPONENT_OF_SERVICE;
+
+ //System.out.println("''''''"+ent.getName() +" '''''' "+ ent.getServices().size());
+ for (String ser : ent.getServices()) {
+
+ ServiceArtifact serve = new ServiceArtifact();
+ Element polygon = serve.addElement(doc, svgNS, x, y, serHeight);
+ Element text;
+ if (!ser.endsWith("Impl"))
+ text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ser);
+ else
+ text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, "");
+
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (serHeight + Constant.SPACING_FOR_COMPONENT_OF_SERVICE);
+
+ serve.setName(ser);
+ serve.setContainerName(ent.getName());
+ sers.add(serve);
+ }
+ }
+
+ private void addCompositeService() {
+
+ int serHeight = comp.getSerHeight();
+ int x = comp.getX() - (serHeight * 2 / 3);
+ int y =
+ comp.getY() + getStartingPoint(comp.getHeight(), serHeight, Constant.SPACING_FOR_COMPOSITE_OF_SERVICE, comp
+ .getServices().size());
+
+ //int y= comp.getY() + Constant.SPACING_FOR_COMPOSITE_OF_SERVICE;
+
+ //System.err.println(serHeight);
+ //System.out.println("''''''"+((CompositeEntity)comp).getName() +" '''''' "+ comp.getServices().size());
+ for (String ser : comp.getServices()) {
+
+ ServiceArtifact serve = new ServiceArtifact();
+ Element polygon = serve.addElement(doc, svgNS, x, y, serHeight);
+ Element text;
+ if (!ser.endsWith("Impl"))
+ text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ser);
+ else
+ text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, "");
+
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (serHeight + Constant.SPACING_FOR_COMPOSITE_OF_SERVICE);
+
+ serve.setName(ser);
+ serve.setContainerName(comp.getName());
+ sers.add(serve);
+ }
+ }
+
+ private void addCompositeReference() {
+
+ int refHeight = comp.getRefHeight();
+
+ int x = (comp.getX() + comp.getWidth()) - (refHeight * 2 / 3);
+ int y =
+ comp.getY() + getStartingPoint(comp.getHeight(),
+ refHeight,
+ Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE,
+ comp.getReferences().size());
+
+ for (String ref : comp.getReferences()) {
+ ReferenceArtifact refer = new ReferenceArtifact();
+ Element polygon = refer.addElement(doc, svgNS, x, y, refHeight);
+ Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ref);
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (refHeight + Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE);
+
+ refer.setName(ref);
+ refer.setContainerName(comp.getName());
+ refs.add(refer);
+
+ }
+
+ }
+
+ //Algorithm to position in center
+ private int getStartingPoint(int compDim, int artifactDim, int gap, int artifactQty) {
+
+ int x = (compDim - artifactQty * artifactDim - (artifactQty - 1) * gap) / 2;
+ return x;
+ }
+
+ private void addCompositeProperties() {
+ int propLen = comp.getPropLength();
+
+ int x =
+ comp.getX() + getStartingPoint(comp.getWidth(), propLen, Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY, comp
+ .getProperties().size());
+ //int x= comp.getX() + Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY;
+ int y = comp.getY() - propLen / 2;
+
+ for (String prop : comp.getProperties()) {
+ PropertyArtifact pro = new PropertyArtifact();
+ Element property = pro.addElement(doc, svgNS, x, y, propLen);
+ Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, prop);
+
+ svgRoot.appendChild(property);
+ svgRoot.appendChild(text);
+
+ x += (propLen + Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY);
+
+ pro.setName(prop);
+ pro.setContainerName(comp.getName());
+ }
+ }
+
+ private void addComponent(Entity ent) {
+
+ ComponentArtifact comp = new ComponentArtifact();
+ //System.err.println(ent.getX());
+ Element com = comp.addElement(doc, svgNS, ent.getX(), ent.getY(), ent.getHeight(), ent.getWidth());
+ Element text =
+ Text.addTextElement(doc,
+ svgNS,
+ ent.getX(),
+ ent.getY() + (ent.getHeight() + Constant.COMPONENT_TEXT_SPACING),
+ ent.getName());
+
+ svgRoot.appendChild(com);
+ svgRoot.appendChild(text);
+
+ comp.setName(ent.getName());
+ }
+
+ private void addComposite() {
+
+ CompositeArtifact composite = new CompositeArtifact();
+
+ Element composi = composite.addElement(doc, svgNS, comp.getX(), comp.getY(), comp.getHeight(), comp.getWidth());
+ Element text = Text.addTextElement(doc, svgNS, comp.getX() + 20, comp.getY() + 20, comp.getName());
+
+ svgRoot.appendChild(composi);
+ svgRoot.appendChild(text);
+
+ composite.setName(comp.getName());
+
+ }
+
+ public void setDiagramHeight(int diagramHeight) {
+ this.diagramHeight = diagramHeight;
+ }
+
+ public int getDiagramHeight() {
+ return diagramHeight;
+ }
+
+ public void setDiagramWidth(int diagramWidth) {
+ this.diagramWidth = diagramWidth;
+ }
+
+ public int getDiagramWidth() {
+ return diagramWidth;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/html/HTMLWrapper.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/html/HTMLWrapper.java
new file mode 100755
index 0000000000..cf399bf23c
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/html/HTMLWrapper.java
@@ -0,0 +1,90 @@
+/*
+ * 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.diagram.html;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
+public class HTMLWrapper {
+
+ private File htmlFilePath;
+ private String compositeName;
+ private String svg;
+
+ /**
+ *
+ * @param svg
+ * @param compositeName
+ * @param htmlFilePath
+ */
+ public HTMLWrapper(String svg, String compositeName, File htmlFilePath) {
+
+ this.svg = svg;
+ this.compositeName = compositeName;
+ this.htmlFilePath = htmlFilePath;
+ }
+
+ public String buildHTML() throws Exception {
+ String content =
+ "" + "<html>\n"
+ + "<head>\n"
+ + "<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>\n"
+ + "<h2 align='center'>"
+ + compositeName
+ + "</h2>\n"
+ + "</br>\n"
+ +
+ // "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+RGB_FILE+"\"></script>\n" +
+ // "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+CANVG_FILE+"\"></script>\n" +
+ // "<script type=\"text/javascript\">\n" +
+ // "window.onload = function() {\n" +
+ // "//load '../path/to/your.svg' in the canvas with id = 'canvas'\n" +
+ // "canvg('canvas', '"+svgFileName+"')\n" +
+ // "//load a svg snippet in the canvas with id = 'drawingArea'\n" +
+ // "canvg(document.getElementById('drawingArea'), '<svg>...</svg>')\n" +
+ // "canvg('canvas', '"+svgFileName+"', {})\n" +
+ // "}\n" +
+ // "</script>\n" +
+ "</head>\n"
+ + "<body>\n"
+ + svg
+ + "\n"
+ +
+ // "<canvas id=\"canvas\" width=\""+compositeWidth+"px\" height=\""+compositeHeight+"px\">\n" +
+ // "</canvas>\n" +
+ "</body>\n"
+ + "</html>";
+
+ fileWriter(content);
+
+ return content;
+
+ }
+
+ private void fileWriter(String content) throws Exception {
+
+ FileWriter fileWriter = new FileWriter(htmlFilePath);
+ BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
+ bufferedWriter.append(content);
+ bufferedWriter.close();
+
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
new file mode 100755
index 0000000000..626394fd44
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/ComponentEntity.java
@@ -0,0 +1,236 @@
+/*
+ * 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.diagram.layout;
+
+import java.util.HashMap;
+
+import org.apache.tuscany.sca.diagram.artifacts.Constant;
+
+/**
+ * Represents an unit (a component including its references, services, properties
+ * and adjacent units) in the diagram.
+ *
+ */
+public class ComponentEntity extends Entity {
+
+ // private String componentName;
+ // private int X, Y, level=-1, lane=-1, refHeight, serHeight, propLength;
+ // private final int height= Component.DEFAULT_HEIGHT, width= Component.DEFAULT_WIDTH;
+ // public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / (Service.MAXIMUM_HEIGHT+Service.SPACING);
+ // public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers
+ // public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING);
+
+ private HashMap<String, String> referenceToServiceMap = new HashMap<String, String>();
+
+ //private HashSet<String> connectedEntities = new HashSet<String>();
+
+ public ComponentEntity() {
+
+ setStartPosition(200);
+ setHeight(Constant.COMPONENT_DEFAULT_HEIGHT);
+ setWidth(Constant.COMPONENT_DEFAULT_WIDTH);
+
+ setDefaultNoOfSers(Constant.COMPONENT_DEFAULT_HEIGHT / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE + Constant.SPACING_FOR_COMPONENT_OF_SERVICE));
+ setDefaultNoOfRefs(Constant.COMPONENT_DEFAULT_HEIGHT / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE));
+ setDefaultNoOfProps(Constant.COMPONENT_DEFAULT_WIDTH / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY));
+ }
+
+ public void referenceHeight() {
+ if (getDefaultNoOfRefs() < getNoOfRefs()) {
+
+ setRefHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfRefs()) - Constant.SPACING_FOR_COMPONENT_OF_REFERENCE);
+ } else
+ setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE);
+ }
+
+ public void serviceHeight() {
+ if (getDefaultNoOfSers() < getNoOfSers()) {
+
+ setSerHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfSers()) - Constant.SPACING_FOR_COMPONENT_OF_SERVICE);
+ } else
+ setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE);
+ }
+
+ public void propertyLength() {
+ if (getDefaultNoOfProps() < getNoOfProps()) {
+
+ setPropLength((Constant.COMPONENT_DEFAULT_WIDTH / getNoOfProps()) - Constant.SPACING_FOR_COMPONENT_OF_PROPERTY);
+ } else
+ setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY);
+ }
+
+ /**
+ * Put a value to referenceToServiceMap
+ * @param ref
+ * @param ser
+ * @return successfully added or not
+ */
+ //assumption there can not be two services for the same reference
+ public boolean addToRefToSerMap(String ref, String ser) {
+ //ref = ref.toLowerCase();
+ //ser = ser.toLowerCase();
+
+ if (referenceToServiceMap.containsKey(ref))
+ return false;
+
+ referenceToServiceMap.put(ref, ser);
+ return true;
+ }
+
+ /**
+ * Retrieve a service name for a given reference
+ * @param ref
+ * @return service name
+ */
+ public String getSerOfRef(String ref) {
+ //ref = ref.toLowerCase();
+
+ if (!referenceToServiceMap.containsKey(ref))
+ return null;
+
+ return referenceToServiceMap.get(ref);
+ }
+
+ public HashMap<String, String> getReferenceToServiceMap() {
+ return referenceToServiceMap;
+ }
+
+ public void setReferenceToServiceMap(HashMap<String, String> referenceToServiceMap) {
+ this.referenceToServiceMap = referenceToServiceMap;
+ }
+
+ // public int getNoOfRefs(){
+ // return references.size();
+ // }
+ //
+ // public int getNoOfSers(){
+ // return services.size();
+ // }
+ //
+ // public int getNoOfProps(){
+ // return properties.size();
+ // }
+ //
+ // public int getNoOfAdjacentUnits(){
+ // return adjacentEntities.size();
+ // }
+ //
+ // /**
+ // * Put a value to referenceToServiceMap
+ // * @param ref
+ // * @param ser
+ // * @return successfully added or not
+ // */
+ // //assumption there can not be two services for the same reference
+ // public boolean addToRefToSerMap(String ref, String ser){
+ // //ref = ref.toLowerCase();
+ // //ser = ser.toLowerCase();
+ //
+ // if (referenceToServiceMap.containsKey(ref))
+ // return false;
+ //
+ // referenceToServiceMap.put(ref, ser);
+ // return true;
+ // }
+ //
+ // /**
+ // * Retrieve a service name for a given reference
+ // * @param ref
+ // * @return service name
+ // */
+ // public String getSerOfRef(String ref){
+ // //ref = ref.toLowerCase();
+ //
+ // if (!referenceToServiceMap.containsKey(ref))
+ // return null;
+ //
+ // return referenceToServiceMap.get(ref);
+ // }
+ //
+ // public void addAService(String serName){
+ // //serName = serName.toLowerCase();
+ // services.add(serName);
+ //
+ // }
+ //
+ // public void addAReference(String refName){
+ // //refName = refName.toLowerCase();
+ // references.add(refName);
+ //
+ // }
+ //
+ // public void addAProperty(String propName){
+ // //propName = propName.toLowerCase();
+ // properties.add(propName);
+ //
+ // }
+ //
+ // public void addAnAdjacentEntity(String x){
+ //// System.out.println("eee "+x);
+ // adjacentEntities.add(x);
+ //
+ // }
+ //
+ // public void addAnConnectedEntity(String x){
+ //// System.out.println("eee "+x);
+ // adjacentEntities.add(x);
+ //
+ // }
+ //
+ // public HashMap<String, String> getReferenceToServiceMap() {
+ // return referenceToServiceMap;
+ // }
+ // public void setReferenceToServiceMap(
+ // HashMap<String, String> referenceToServiceMap) {
+ // this.referenceToServiceMap = referenceToServiceMap;
+ // }
+ // public ArrayList<String> getProperties() {
+ // return properties;
+ // }
+ // public void setProperties(ArrayList<String> properties) {
+ // this.properties = properties;
+ // }
+ // public HashSet<String> getAdjacentEntities() {
+ // return adjacentEntities;
+ // }
+ // public void setAdjacentEntities(HashSet<String> adjacentEntities) {
+ // this.adjacentEntities = adjacentEntities;
+ // }
+ // public void setServices(ArrayList<String> services) {
+ // this.services = services;
+ // }
+ //
+ // public ArrayList<String> getServices() {
+ // return services;
+ // }
+ //
+ // public ArrayList<String> getReferences() {
+ // return references;
+ // }
+
+ // public void setConnectedEntities(HashSet<String> connectedEntities) {
+ // this.connectedEntities = connectedEntities;
+ // }
+ //
+ // public HashSet<String> getConnectedEntities() {
+ // return connectedEntities;
+ // }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
new file mode 100755
index 0000000000..258dcbcaa3
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/CompositeEntity.java
@@ -0,0 +1,374 @@
+/*
+ * 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.diagram.layout;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.tuscany.sca.diagram.artifacts.Constant;
+
+/**
+ * Represents an unit (a component including its references, services, properties
+ * and adjacent units) in the diagram.
+ *
+ */
+public class CompositeEntity extends Entity {
+
+ // private String componentName;
+ // private int X, Y, level=-1, lane=-1, refHeight, serHeight, propLength;
+ // private final int height= Component.DEFAULT_HEIGHT, width= Component.DEFAULT_WIDTH;
+ // public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / (Service.MAXIMUM_HEIGHT+Service.SPACING);
+ // public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers
+ // public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING);
+
+ private final String fileNameSuffix = "_diagram";
+ private int maxInternalLevel = 0;
+ private int maxInternalLane = 0;
+ private ComponentEntity[] componentList;
+ private int[][] connections;
+ private HashMap<String, String> promoteAService = new HashMap<String, String>();
+ private HashMap<String, ArrayList<String>> promoteAReference = new HashMap<String, ArrayList<String>>();
+ private ArrayList<String> includedComposites = new ArrayList<String>();
+
+ //private HashSet<String> connectedEntities = new HashSet<String>();
+
+ public CompositeEntity(String name) {
+
+ setStartPosition(200);
+ setLevel(0);
+ setLane(0);
+
+ setX(getStartPosition());
+ setY(getStartPosition() / 2);
+
+ setName(name);
+ //componentList = comps;
+ //setConnections(conns);
+
+ }
+
+ public void referenceHeight() {
+ //System.err.println(getDefaultNoOfRefs() + " kkkkkkk "+getNoOfRefs());
+
+ if (getDefaultNoOfRefs() < getNoOfRefs()) {
+
+ setRefHeight((getHeight() / getNoOfRefs()) - Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE);
+ } else
+ setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE);
+ }
+
+ public void serviceHeight() {
+ if (getDefaultNoOfSers() < getNoOfSers()) {
+ setSerHeight((getHeight() / getNoOfSers()) - Constant.SPACING_FOR_COMPOSITE_OF_SERVICE);
+ } else
+ setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE);
+ }
+
+ public void propertyLength() {
+ if (getDefaultNoOfProps() < getNoOfProps()) {
+
+ setPropLength((getWidth() / getNoOfProps()) - Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY);
+ } else
+ setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY);
+ }
+
+ // /**
+ // * Put a value to referenceToServiceMap
+ // * @param ref
+ // * @param ser
+ // * @return successfully added or not
+ // */
+ // //assumption there can not be two services for the same reference
+ // public boolean addToRefToSerMap(String ref, String ser){
+ // //ref = ref.toLowerCase();
+ // //ser = ser.toLowerCase();
+ //
+ // if (referenceToServiceMap.containsKey(ref))
+ // return false;
+ //
+ // referenceToServiceMap.put(ref, ser);
+ // return true;
+ // }
+ //
+ // /**
+ // * Retrieve a service name for a given reference
+ // * @param ref
+ // * @return service name
+ // */
+ // public String getSerOfRef(String ref){
+ // //ref = ref.toLowerCase();
+ //
+ // if (!referenceToServiceMap.containsKey(ref))
+ // return null;
+ //
+ // return referenceToServiceMap.get(ref);
+ // }
+ //
+ // public HashMap<String, String> getReferenceToServiceMap() {
+ // return referenceToServiceMap;
+ // }
+ //
+ // public void setReferenceToServiceMap(
+ // HashMap<String, String> referenceToServiceMap) {
+ // this.referenceToServiceMap = referenceToServiceMap;
+ // }
+
+ public void calcHeight(int initPoint) {
+ setHeight((Constant.COMPONENT_DEFAULT_HEIGHT * getSpaceFactor()) * (maxInternalLevel + 1) + initPoint);
+ }
+
+ public void calcWidth(int initPoint) {
+ //System.err.println("maxInternalLane "+maxInternalLane);
+ setWidth((Constant.COMPONENT_DEFAULT_WIDTH * getSpaceFactor()) * (maxInternalLane + 1) + initPoint);
+ }
+
+ private int max(int a, int b) {
+ if (a >= b)
+ return a;
+ return b;
+ }
+
+ public void setMaxInternalProperties() {
+
+ for (ComponentEntity ent : componentList) {
+
+ maxInternalLevel = max(maxInternalLevel, ent.getLevel());
+ maxInternalLane = max(maxInternalLane, ent.getLane());
+
+ }
+ //System.out.println("++++++ "+maxInternalLevel+" +++++ "+maxInternalLane);
+ }
+
+ public int getMaxInternalLevel() {
+ return maxInternalLevel;
+ }
+
+ public int getMaxInternalLane() {
+ return maxInternalLane;
+ }
+
+ public boolean addToPromoteAService(String compositeSer, String componentSer) {
+ //ref = ref.toLowerCase();
+ //ser = ser.toLowerCase();
+
+ if (promoteAService.containsKey(compositeSer))
+ return false;
+
+ promoteAService.put(compositeSer, componentSer);
+ return true;
+ }
+
+ public void setPromoteAService(HashMap<String, String> promoteAService) {
+ this.promoteAService = promoteAService;
+ }
+
+ public HashMap<String, String> getPromoteAService() {
+ return promoteAService;
+ }
+
+ public boolean addToPromoteAReference(String compositeRef, String componentRef) {
+ ArrayList<String> list;
+
+ if (promoteAReference.containsKey(compositeRef)) {
+ list = promoteAReference.get(compositeRef);
+ } else {
+ list = new ArrayList<String>();
+ }
+
+ list.add(componentRef);
+ promoteAReference.put(compositeRef, list);
+ return true;
+ }
+
+ public boolean addToIncludedComposites(String composite) {
+
+ includedComposites.add(composite);
+
+ return true;
+ }
+
+ public void setPromoteAReference(HashMap<String, ArrayList<String>> promoteAReference) {
+ this.promoteAReference = promoteAReference;
+ }
+
+ public HashMap<String, ArrayList<String>> getPromoteAReference() {
+ return promoteAReference;
+ }
+
+ public ComponentEntity[] getComponentList() {
+ return componentList;
+ }
+
+ public void setComponentList(ComponentEntity[] componentList) {
+ this.componentList = componentList;
+ }
+
+ public void setConnections(int[][] connections) {
+ this.connections = connections;
+ }
+
+ public int[][] getConnections() {
+ return connections;
+ }
+
+ public void setAttributes() {
+
+ setMaxInternalProperties();
+
+ //System.out.println("++++++ "+this.maxInternalLevel);
+
+ calcHeight(getY());
+ calcWidth(getX());
+
+ setDefaultNoOfSers(getHeight() / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE + Constant.SPACING_FOR_COMPOSITE_OF_SERVICE));
+ setDefaultNoOfRefs(getHeight() / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE + Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE));
+ setDefaultNoOfProps(getWidth() / (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY + Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY));
+
+ referenceHeight();
+ serviceHeight();
+ propertyLength();
+ }
+
+ public ArrayList<String> getIncludedComposites() {
+ return includedComposites;
+ }
+
+ public String getFileNameSuffix() {
+ return fileNameSuffix;
+ }
+
+ // public int getNoOfRefs(){
+ // return references.size();
+ // }
+ //
+ // public int getNoOfSers(){
+ // return services.size();
+ // }
+ //
+ // public int getNoOfProps(){
+ // return properties.size();
+ // }
+ //
+ // public int getNoOfAdjacentUnits(){
+ // return adjacentEntities.size();
+ // }
+ //
+ // /**
+ // * Put a value to referenceToServiceMap
+ // * @param ref
+ // * @param ser
+ // * @return successfully added or not
+ // */
+ // //assumption there can not be two services for the same reference
+ // public boolean addToRefToSerMap(String ref, String ser){
+ // //ref = ref.toLowerCase();
+ // //ser = ser.toLowerCase();
+ //
+ // if (referenceToServiceMap.containsKey(ref))
+ // return false;
+ //
+ // referenceToServiceMap.put(ref, ser);
+ // return true;
+ // }
+ //
+ // /**
+ // * Retrieve a service name for a given reference
+ // * @param ref
+ // * @return service name
+ // */
+ // public String getSerOfRef(String ref){
+ // //ref = ref.toLowerCase();
+ //
+ // if (!referenceToServiceMap.containsKey(ref))
+ // return null;
+ //
+ // return referenceToServiceMap.get(ref);
+ // }
+ //
+ // public void addAService(String serName){
+ // //serName = serName.toLowerCase();
+ // services.add(serName);
+ //
+ // }
+ //
+ // public void addAReference(String refName){
+ // //refName = refName.toLowerCase();
+ // references.add(refName);
+ //
+ // }
+ //
+ // public void addAProperty(String propName){
+ // //propName = propName.toLowerCase();
+ // properties.add(propName);
+ //
+ // }
+ //
+ // public void addAnAdjacentEntity(String x){
+ //// System.out.println("eee "+x);
+ // adjacentEntities.add(x);
+ //
+ // }
+ //
+ // public void addAnConnectedEntity(String x){
+ //// System.out.println("eee "+x);
+ // adjacentEntities.add(x);
+ //
+ // }
+ //
+ // public HashMap<String, String> getReferenceToServiceMap() {
+ // return referenceToServiceMap;
+ // }
+ // public void setReferenceToServiceMap(
+ // HashMap<String, String> referenceToServiceMap) {
+ // this.referenceToServiceMap = referenceToServiceMap;
+ // }
+ // public ArrayList<String> getProperties() {
+ // return properties;
+ // }
+ // public void setProperties(ArrayList<String> properties) {
+ // this.properties = properties;
+ // }
+ // public HashSet<String> getAdjacentEntities() {
+ // return adjacentEntities;
+ // }
+ // public void setAdjacentEntities(HashSet<String> adjacentEntities) {
+ // this.adjacentEntities = adjacentEntities;
+ // }
+ // public void setServices(ArrayList<String> services) {
+ // this.services = services;
+ // }
+ //
+ // public ArrayList<String> getServices() {
+ // return services;
+ // }
+ //
+ // public ArrayList<String> getReferences() {
+ // return references;
+ // }
+
+ // public void setConnectedEntities(HashSet<String> connectedEntities) {
+ // this.connectedEntities = connectedEntities;
+ // }
+ //
+ // public HashSet<String> getConnectedEntities() {
+ // return connectedEntities;
+ // }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
new file mode 100755
index 0000000000..582b8ed37b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
@@ -0,0 +1,259 @@
+package org.apache.tuscany.sca.diagram.layout;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+
+public abstract class Entity {
+
+ private int id = -1; //a unique integer id (0..n)
+ private String name; // a unique name
+ private int spaceFactor = 2; //which determines the free space surrounded by this
+ private int x; // x coordinate
+ private int y; // y coordinate
+ private int level = -1; // corresponding row which this entity is placed
+ private int lane = -1; // corresponding column which this entity is placed
+ private boolean isPossitionSet = false;
+ private int height; // height of the entity
+ private int width; // width of the entity
+ private int refHeight; // height of a reference element
+ private int serHeight; // height of a service element
+ private int propLength; // length of a property element
+ private int defaultNoOfSers; // default # of service elements
+ private int defaultNoOfRefs; // default # of reference elements
+ private int defaultNoOfProps; // default # of property elements
+ private int startPosition = 0;
+ private Entity parent = null;
+
+ private ArrayList<String> references = new ArrayList<String>();
+
+ private ArrayList<String> services = new ArrayList<String>();
+
+ private ArrayList<String> properties = new ArrayList<String>();
+
+ private HashSet<String> adjacentEntities = new HashSet<String>();
+
+ public abstract void referenceHeight();
+
+ public abstract void serviceHeight();
+
+ public abstract void propertyLength();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public void setX(int init) {
+ this.x = init + width * spaceFactor * lane;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public void setY(int init) {
+ this.y = init + height * spaceFactor * level;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
+ public int getLane() {
+ return lane;
+ }
+
+ public void setLane(int lane) {
+ this.lane = lane;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public int getRefHeight() {
+ return refHeight;
+ }
+
+ public void setRefHeight(int refHeight) {
+ this.refHeight = refHeight;
+ }
+
+ public int getSerHeight() {
+ return serHeight;
+ }
+
+ public void setSerHeight(int serHeight) {
+ this.serHeight = serHeight;
+ }
+
+ public int getPropLength() {
+ return propLength;
+ }
+
+ public void setPropLength(int propLength) {
+ this.propLength = propLength;
+ }
+
+ public int getDefaultNoOfSers() {
+ return defaultNoOfSers;
+ }
+
+ public void setDefaultNoOfSers(int defaultNoOfSers) {
+ this.defaultNoOfSers = defaultNoOfSers;
+ }
+
+ public int getDefaultNoOfRefs() {
+ return defaultNoOfRefs;
+ }
+
+ public void setDefaultNoOfRefs(int defaultNoOfRefs) {
+ this.defaultNoOfRefs = defaultNoOfRefs;
+ }
+
+ public int getDefaultNoOfProps() {
+ return defaultNoOfProps;
+ }
+
+ public void setDefaultNoOfProps(int defaultNoOfProps) {
+ this.defaultNoOfProps = defaultNoOfProps;
+ }
+
+ public int getNoOfRefs() {
+ return references.size();
+ }
+
+ public int getNoOfSers() {
+ return services.size();
+ }
+
+ public int getNoOfProps() {
+ return properties.size();
+ }
+
+ public int getNoOfAdjacentUnits() {
+ return adjacentEntities.size();
+ }
+
+ public void addAService(String serName) {
+ //serName = serName.toLowerCase();
+ services.add(serName);
+
+ }
+
+ public void addAReference(String refName) {
+ //refName = refName.toLowerCase();
+ references.add(refName);
+
+ }
+
+ public void addAProperty(String propName) {
+ //propName = propName.toLowerCase();
+ properties.add(propName);
+
+ }
+
+ public void addAnAdjacentEntity(String x) {
+ // System.out.println("eee "+x);
+ adjacentEntities.add(x);
+
+ }
+
+ public void addAnConnectedEntity(String x) {
+ // System.out.println("eee "+x);
+ adjacentEntities.add(x);
+
+ }
+
+ public ArrayList<String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(ArrayList<String> properties) {
+ this.properties = properties;
+ }
+
+ public HashSet<String> getAdjacentEntities() {
+ return adjacentEntities;
+ }
+
+ public void setAdjacentEntities(HashSet<String> adjacentEntities) {
+ this.adjacentEntities = adjacentEntities;
+ }
+
+ public void setServices(ArrayList<String> services) {
+ this.services = services;
+ }
+
+ public ArrayList<String> getServices() {
+ return services;
+ }
+
+ public ArrayList<String> getReferences() {
+ return references;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setPossitionSet(boolean isPossitionSet) {
+ this.isPossitionSet = isPossitionSet;
+ }
+
+ public boolean isPossitionSet() {
+ return isPossitionSet;
+ }
+
+ public int getSpaceFactor() {
+ return spaceFactor;
+ }
+
+ public void setSpaceFactor(int spaceFactor) {
+ this.spaceFactor = spaceFactor;
+ }
+
+ public void setStartPosition(int startPosition) {
+ this.startPosition = startPosition;
+ }
+
+ public int getStartPosition() {
+ return startPosition;
+ }
+
+ public void setParent(Entity parent) {
+ this.parent = parent;
+ }
+
+ public Entity getParent() {
+ return parent;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
new file mode 100755
index 0000000000..33ff1209cb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
@@ -0,0 +1,733 @@
+/*
+ * 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.diagram.layout;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class EntityBuilder {
+
+ private Document dom;
+
+ //components connected to each other are tracked using following map
+ private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
+ private int totalWidth = 0;
+ private int totalHeight = 0;
+
+ CompositeEntity composite = null;
+
+ /**
+ * Constructor which initiates the DOM document
+ * @param aDom DOM document
+ */
+ public EntityBuilder(Document aDom) {
+ dom = aDom;
+ }
+
+ public CompositeEntity buildCompositeEntity() {
+
+ //get the root element
+ Element docEle = dom.getDocumentElement();
+
+ String compositeName;
+ compositeName = docEle.getAttribute("name");
+ //System.out.println("compositeName "+compositeName);
+
+ ComponentEntity[] comps = buildComponentEntities(docEle);
+
+ composite = new CompositeEntity(compositeName);
+
+ setParent(comps);
+
+ //System.out.println("ComponentEntity "+comps[0].getLevel());
+ int[][] conns = buildConnectionMatrix(comps);
+
+ composite.setComponentList(comps);
+ composite.setConnections(conns);
+
+ LayoutBuilder buildLayout = new LayoutBuilder(comps, conns);
+ buildLayout.placeEntities();
+
+ //System.out.println("conns "+conns[0][0]);
+
+ buildCompositeService(docEle);
+ buildCompositeReference(docEle);
+ buildCompositeProperty(docEle);
+
+ addInclusions(docEle);
+
+ composite.setAttributes();
+
+ return composite;
+ }
+
+ // private void assignCoordinates() {
+ //
+ // for(Entity ent: elts){
+ // ent.setX(ent.getParent().getX() + ent.getStartPosition());
+ // ent.setY(ent.getParent().getY() + ent.getStartPosition()/2);
+ // }
+ // }
+
+ private void setParent(ComponentEntity[] comps) {
+
+ for (ComponentEntity comp : comps) {
+ comp.setParent(composite);
+ }
+ }
+
+ private void buildCompositeService(Element docEle) {
+
+ NodeList nl = docEle.getElementsByTagName("service");
+ //System.err.println("^^^^^^^^^ "+nl.getLength());
+ if (nl != null && nl.getLength() > 0) {
+
+ for (int i = 0; i < nl.getLength(); i++) {
+
+ Element elt = (Element)nl.item(i);
+
+ if (elt.getParentNode().getNodeName().equals("composite")) {
+ String compositeSer = elt.getAttribute("name");
+ composite.addAService(compositeSer);
+
+ String target = elt.getAttribute("promote");
+
+ String service, serviceComp;
+ String[] arr1 = extractComp(target);
+ serviceComp = arr1[0];
+ service = arr1[1];
+
+ if (service == null) {
+ composite.addToPromoteAService(compositeSer, serviceComp);
+ } else {
+ composite.addToPromoteAService(compositeSer, service);
+ }
+ }
+
+ }
+ }
+ }
+
+ private void buildCompositeReference(Element docEle) {
+
+ NodeList nl = docEle.getElementsByTagName("reference");
+ //System.out.println("^^^^^^^^^ "+nl.getLength());
+ if (nl != null && nl.getLength() > 0) {
+
+ for (int i = 0; i < nl.getLength(); i++) {
+
+ Element elt = (Element)nl.item(i);
+
+ if (elt.getParentNode().getNodeName().equals("composite")) {
+ String compositeRef = elt.getAttribute("name");
+ composite.addAReference(compositeRef);
+
+ String targetStr = elt.getAttribute("promote");
+
+ String[] targets = targetStr.split(" ");
+
+ for (String target : targets) {
+
+ String reference, referenceComp;
+ String[] arr1 = extractComp(target);
+ referenceComp = arr1[0];
+ reference = arr1[1];
+
+ if (reference == null) {
+ composite.addToPromoteAReference(compositeRef, referenceComp);
+ } else {
+ composite.addToPromoteAReference(compositeRef, reference);
+ }
+ }
+
+ }
+ }
+ }
+ }
+
+ private void buildCompositeProperty(Element docEle) {
+
+ NodeList nl = docEle.getElementsByTagName("property");
+ //System.out.println("^^^^^^^^^ "+nl.getLength());
+ if (nl != null && nl.getLength() > 0) {
+
+ for (int i = 0; i < nl.getLength(); i++) {
+
+ Element elt = (Element)nl.item(i);
+
+ if (elt.getParentNode().getNodeName().equals("composite")) {
+ String compositeProp = elt.getAttribute("name");
+ composite.addAProperty(compositeProp);
+ }
+ }
+ }
+ }
+
+ private void addInclusions(Element docEle) {
+
+ NodeList nl = docEle.getElementsByTagName("include");
+ //System.out.println("^^^^^^^^^ "+nl.getLength());
+ if (nl != null && nl.getLength() > 0) {
+
+ for (int i = 0; i < nl.getLength(); i++) {
+
+ Element elt = (Element)nl.item(i);
+
+ if (elt.getParentNode().getNodeName().equals("composite")) {
+ String compToBeIncluded = elt.getAttribute("name");
+ composite.addToIncludedComposites(compToBeIncluded);
+ }
+ }
+ }
+ }
+
+ private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
+
+ int[][] connections = new int[comps.length][comps.length];
+ connections = initConnections(connections);
+
+ // //sec. 5.4 in the spec
+ // NodeList nl = docEle.getElementsByTagName("wire");
+ // //System.out.println("^^^^^^^^^ "+nl.getLength());
+ // if(nl != null && nl.getLength() > 0 ) {
+ //
+ // for(int i = 0 ; i < nl.getLength();i++) {
+ //
+ // Element elt = (Element)nl.item(i);
+ //
+ // String source = elt.getAttribute("source");
+ // String target = elt.getAttribute("target");
+ //
+ // String service, serviceComp, reference, referenceComp;
+ //
+ // String[] arr1 = extractComp(target);
+ // serviceComp = arr1[0];
+ // service = arr1[1];
+ //
+ // String[] arr2 = extractComp(source);
+ // referenceComp = arr2[0];
+ // reference = arr2[1];
+
+ // //System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+ // if(target.contains("/")){
+ // String[] arr = target.split("/");
+ // serviceComp = arr[0];
+ // service = arr[1];
+ // }
+ // else{
+ // serviceComp = target;
+ // service = null;
+ // }
+ //
+ // if(source.contains("/")){
+ // String[] arr = source.split("/");
+ // referenceComp = arr[0];
+ // reference = arr[1];
+ // }
+ // else{
+ // referenceComp = source;
+ // reference = null;
+ // }
+ // //sec. 5.4 in the spec
+ // NodeList nl = docEle.getElementsByTagName("wire");
+ // //System.out.println("^^^^^^^^^ "+nl.getLength());
+ // if(nl != null && nl.getLength() > 0 ) {
+ //
+ // for(int i = 0 ; i < nl.getLength();i++) {
+ //
+ // Element elt = (Element)nl.item(i);
+ //
+ // String source = elt.getAttribute("source");
+ // String target = elt.getAttribute("target");
+ //
+ // String service, serviceComp, reference, referenceComp;
+ //
+ // String[] arr1 = extractComp(target);
+ // serviceComp = arr1[0];
+ // service = arr1[1];
+ //
+ // String[] arr2 = extractComp(source);
+ // referenceComp = arr2[0];
+ // reference = arr2[1];
+
+ for (Entity ent : comps) {
+ for (String name : ent.getAdjacentEntities()) {
+ ComponentEntity e2 = findEntity(comps, name);
+ if (ent != null && e2 != null) {
+ //System.out.println("^^^^^^^^^ "+e2.getName());
+ connections[ent.getId()][e2.getId()] = 1;
+ }
+ }
+
+ }
+ // ComponentEntity e1 = findEntity(comps, referenceComp);
+ // ComponentEntity e2 = findEntity(comps, serviceComp);
+ //
+ // System.out.println("^^^^^^^^^ "+e1.getName());
+ // if(e1 != null && e2 != null){
+ // System.out.println("^^^^^^^^^ "+e1.getId());
+ // connections[e1.getId()][e2.getId()] = 1;
+ // createConnection(e1, reference, serviceComp, service);
+ // }
+ // }
+ // }
+ //
+ return connections;
+ }
+
+ private String[] extractComp(String str) {
+
+ String[] arr = new String[2];
+
+ if (str.contains("/")) {
+ arr = str.split("/");
+ } else {
+ arr[0] = str;
+ arr[1] = null;
+ }
+ return arr;
+ }
+
+ private int[][] initConnections(int[][] connections) {
+
+ for (int i = 0; i < connections.length; i++) {
+ for (int j = 0; j < connections.length; j++) {
+ connections[i][j] = 0;
+ }
+ }
+ return connections;
+ }
+
+ public ComponentEntity[] buildComponentEntities(Element docEle) {
+
+ ComponentEntity[] elts = null;
+
+ // //get the root element
+ // Element docEle = dom.getDocumentElement();
+ // compositeName = docEle.getAttribute("name");
+ // System.out.println("compositeName "+compositeName);
+
+ //get a nodelist of elements
+ NodeList nl = docEle.getElementsByTagName("component");
+ if (nl != null && nl.getLength() > 0) {
+ elts = new ComponentEntity[nl.getLength()];
+
+ for (int i = 0; i < nl.getLength(); i++) {
+ elts[i] = new ComponentEntity();
+ Element nVal = (Element)nl.item(i);
+ //System.out.println(nVal.hasAttribute("name"));
+ elts[i].setId(i);
+ elts[i].setName(nVal.getAttribute("name"));
+
+ setServices(nVal, elts[i]);
+ setReferences(nVal, elts[i]);
+ setProperties(nVal, elts[i]);
+
+ elts[i].referenceHeight();
+ elts[i].serviceHeight();
+ elts[i].propertyLength();
+ }
+ }
+
+ buildWires(docEle, elts);
+ // //sec. 5.4 in the spec
+ // nl = docEle.getElementsByTagName("wire");
+ // System.out.println("^^^^^^^^^ "+nl.getLength());
+ // if(nl != null && nl.getLength() > 0 ) {
+ // for(int i = 0 ; i < nl.getLength();i++) {
+ // Element elt = (Element)nl.item(i);
+ // String source = elt.getAttribute("source");
+ // String target = elt.getAttribute("target");
+ // String service, serviceComp, reference, referenceComp;
+ //
+ // System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+ // if(target.contains("/")){
+ // String[] arr = target.split("/");
+ // serviceComp = arr[0];
+ // service = arr[1];
+ // }
+ // else{
+ // serviceComp = target;
+ // service = null;
+ // }
+ //
+ // if(source.contains("/")){
+ // String[] arr = source.split("/");
+ // referenceComp = arr[0];
+ // reference = arr[1];
+ // }
+ // else{
+ // referenceComp = source;
+ // reference = null;
+ // }
+ //
+ // ComponentEntity e = findEntity(referenceComp);
+ // System.out.println("^^^^^^^^^ "+e.getName());
+ // if(e != null){
+ // createConnection(e, reference, serviceComp, service);
+ // }
+ // }
+ // }
+ //
+ // positionEntities(elts);
+ //
+ // calculateProperties(elts);
+ // print(elts);
+
+ return elts;
+
+ }
+
+ private void buildWires(Element docEle, ComponentEntity[] elts) {
+
+ //sec. 5.4 in the spec
+ NodeList nl = docEle.getElementsByTagName("wire");
+ //System.out.println("^^^^^^^^^ "+nl.getLength());
+ if (nl != null && nl.getLength() > 0) {
+
+ for (int i = 0; i < nl.getLength(); i++) {
+
+ Element elt = (Element)nl.item(i);
+
+ String source = elt.getAttribute("source");
+ String target = elt.getAttribute("target");
+
+ String service, serviceComp, reference, referenceComp;
+
+ String[] arr1 = extractComp(target);
+ serviceComp = arr1[0];
+ service = arr1[1];
+
+ String[] arr2 = extractComp(source);
+ referenceComp = arr2[0];
+ reference = arr2[1];
+
+ // //System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+ // if(target.contains("/")){
+ // String[] arr = target.split("/");
+ // serviceComp = arr[0];
+ // service = arr[1];
+ // }
+ // else{
+ // serviceComp = target;
+ // service = null;
+ // }
+ //
+ // if(source.contains("/")){
+ // String[] arr = source.split("/");
+ // referenceComp = arr[0];
+ // reference = arr[1];
+ // }
+ // else{
+ // referenceComp = source;
+ // reference = null;
+ // }
+ //
+ ComponentEntity e1 = findEntity(elts, referenceComp);
+ //ComponentEntity e2 = findEntity(comps, serviceComp);
+
+ //System.out.println("^^^^^^^^^ "+e1.getName());
+ if (e1 != null) {
+ //System.out.println("^^^^^^^^^ "+e1.getId());
+ //connections[e1.getId()][e2.getId()] = 1;
+ createConnection(e1, reference, serviceComp, service);
+ }
+ }
+ }
+
+ }
+
+ private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
+
+ for (ComponentEntity e : elts) {
+ if (e.getName().equals(componentName)) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ private void setReferences(Element nVal, ComponentEntity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("reference");
+ if (nl != null && nl.getLength() > 0) {
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element elt = (Element)nl.item(i);
+ String target = elt.getAttribute("target");
+ String ref = elt.getAttribute("name");
+ if (target.contains("/")) {
+ String[] arr = target.split("/");
+ createConnection(ent, ref, arr[0], arr[1]);
+ // ent.addToRefToSerMap(ref, arr[1]);
+ // ent.addAnAdjacentEntity(arr[0]);
+ // addToConnectedEntities(ent.getComponentName(), arr[0]);
+ // addToConnectedEntities(arr[0], ent.getComponentName());
+ } else if (!target.equals("")) {
+ createConnection(ent, ref, target, null);
+ // ent.addToRefToSerMap(ref, target);
+ // ent.addAnAdjacentEntity(target);
+ // addToConnectedEntities(ent.getComponentName(), target);
+ // addToConnectedEntities(target, ent.getComponentName());
+ }
+
+ ent.addAReference(ref);
+
+ }
+ }
+ }
+
+ private void createConnection(ComponentEntity ent, String reference, String serviceComp, String service) {
+
+ String referenceComp = ent.getName();
+
+ if (reference != null && service != null) {
+
+ ent.addToRefToSerMap(reference, service);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else if (reference == null && service != null) {
+ ent.addToRefToSerMap(referenceComp, service);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else if (reference != null && service == null) {
+ ent.addToRefToSerMap(reference, serviceComp);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else {
+ ent.addToRefToSerMap(referenceComp, serviceComp);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ }
+ }
+
+ // private void calculateProperties(ComponentEntity[] elts) {
+ // int level=0, lane=0;
+ //
+ // for(ComponentEntity ent: elts){
+ // level = max(level, ent.getLevel());
+ // lane = max(lane, ent.getLane());
+ //
+ // }
+ // totalHeight += spaceY*(level+1) + initPoint;
+ // totalWidth += spaceX*(lane+1) + initPoint;
+ //
+ // System.err.println(totalHeight + " :: "+totalWidth);
+ // }
+
+ // private int max(int a, int b){
+ // if(a>=b)
+ // return a;
+ // return b;
+ // }
+
+ @SuppressWarnings("unused")
+ private void print(ComponentEntity[] elts) {
+
+ for (ComponentEntity ent : elts) {
+ System.out.println(ent.getName() + " : "
+ + ent.getLevel()
+ + " : "
+ + ent.getLane()
+ + " : "
+ + ent.getX()
+ + " : "
+ + ent.getY());
+ }
+ }
+
+ // private void positionEntities(ComponentEntity[] ents){
+ //
+ // for(ComponentEntity ent: ents){
+ // if(ent.getAdjacentEntities().size() != 0 || ents.length==1){
+ // setPosition(ent, initPoint, initPoint, 0, 0);
+ // levelCount.add(0, 1);
+ // startEnt = ent;
+ // System.err.println(ent.getName());
+ // break;
+ // }
+ // }
+ //
+ //
+ // if(startEnt != null)
+ // assignPositions(ents, startEnt);
+ //
+ // }
+ //
+ // private void assignPositions(ComponentEntity[] ents, ComponentEntity ent){
+ // int i=0;
+ // if(ent.getAdjacentEntities().size()>0){
+ //
+ // System.out.println(ent.getName());
+ // for(String name: ent.getAdjacentEntities()){
+ // //System.out.println("eee "+name);
+ // for(ComponentEntity aEnt: ents){
+ // i++;
+ // if(name.equalsIgnoreCase(aEnt.getName())){
+ // int lane = ent.getLane()+1;
+ // if(levelCount.size()<= lane){
+ // levelCount.add(lane, 1);
+ // setPosition(aEnt, ent.getX()+spaceX, ent.getY(), 0, lane);
+ // }
+ // else{
+ // int level = levelCount.get(lane);
+ // levelCount.add(lane, level+1);
+ // setPosition(aEnt, ent.getX()+spaceX, ent.getY()+spaceY*level, level, lane);
+ // }
+ // if(i<ents.length)
+ // assignPositions(ents, aEnt);
+ //// else
+ //// System.out.println(i+ " <<<<< "+ents.length);
+ // break;
+ // }
+ //
+ // }
+ // }
+ // }
+ //
+ //
+ // else{
+ // ArrayList<String> conns = connectedEntities.get(ent.getName());
+ // System.err.println(conns.size());
+ // if(conns.size()>0){
+ //
+ // for(String conn: conns){
+ // System.err.println("conn "+conn +" : "+ent.getName());
+ // for(ComponentEntity e: ents){
+ // if(e.getLane() == -1 && e.getName().equals(conn)){
+ //
+ // int lane = ent.getLane()-1;
+ // System.err.println(lane);
+ // int level = levelCount.get(lane);
+ // levelCount.add(lane, level+1);
+ // setPosition(e, ent.getX()-spaceX, ent.getY()+spaceY*level, level, lane);
+ //
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ // private void setPosition(ComponentEntity ent, int x, int y, int level, int lane){
+ // ent.setX(x);
+ // ent.setY(y);
+ // ent.setLevel(level);
+ // ent.setLane(lane);
+ // }
+ //
+ //
+ // private String[] splitValues(String str){
+ // return str.split("/");
+ // }
+
+ private void addToConnectedEntities(String ent1, String ent2) {
+ //System.err.println(ent1+" : "+ent2);
+ ArrayList<String> list;
+ if (connectedEntities.containsKey(ent1)) {
+ list = connectedEntities.get(ent1);
+
+ } else {
+ list = new ArrayList<String>();
+
+ }
+ list.add(ent2);
+ connectedEntities.put(ent1, list);
+ }
+
+ private void setServices(Element nVal, ComponentEntity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("service");
+ if (nl != null && nl.getLength() > 0) {
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element elt = (Element)nl.item(i);
+ ent.addAService(elt.getAttribute("name"));
+ }
+ } else {
+
+ NodeList nl1 = nVal.getElementsByTagName("implementation.java");
+ if (nl1 != null && nl1.getLength() > 0) {
+ for (int i = 0; i < nl1.getLength(); i++) {
+ Element elt = (Element)nl1.item(i);
+ //System.out.println(elt.getAttribute("class"));
+ String serName = extractServiceName(elt.getAttribute("class"));
+ ent.addAService(serName);
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ *
+ * This will extract the service name part from the class attribute of
+ * implementation.java element.
+ * eg: if class = "NirmalServiceImpl", returning service name would be "NirmalService"
+ */
+ private String extractServiceName(String classAttr) {
+ if (classAttr != null) {
+ String[] x = classAttr.split("\\.");
+ String name = x[x.length - 1];
+ if (name.endsWith("Impl")) {
+ return name.substring(0, name.length() - 4);
+ } else {
+ return name;
+ }
+ }
+ return "";
+ }
+
+ private void setProperties(Element nVal, ComponentEntity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("property");
+ if (nl != null && nl.getLength() > 0) {
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element elt = (Element)nl.item(i);
+ ent.addAProperty(elt.getAttribute("name"));
+ }
+ }
+ }
+
+ // public void setCompositeName(String compositeName) {
+ // this.compositeName = compositeName;
+ // }
+ //
+ // public String getCompositeName() {
+ // return compositeName;
+ // }
+
+ public int getTotalWidth() {
+ return totalWidth;
+ }
+
+ public int getTotalHeight() {
+ return totalHeight;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilder.java
new file mode 100755
index 0000000000..87b358479a
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilder.java
@@ -0,0 +1,183 @@
+/*
+ * 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.diagram.layout;
+
+public class LayoutBuilder {
+
+ private Entity[] elts = null;
+ private int[][] conns = null;
+ private Entity startEnt = null;
+ private int currentMaxLevel = 0;
+
+ /**
+ * Constructor which takes set of entities and their connection matrix
+ */
+ public LayoutBuilder(Entity[] entities, int[][] connections) {
+ elts = entities;
+ conns = connections;
+ }
+
+ /**
+ * Layout Building Algorithm
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Here we position (i.e. assigning a level and a lane) all Entities
+ * in a unique cell of a grid.
+ *
+ * lane0 lane1 lane2 lane3 ....
+ * _______________________________
+ * level0 | | | | |
+ * |_______|_______|_______|_______|
+ * level1 | | | | |
+ * |_______|_______|_______|_______|
+ * level2 | | | | |
+ *
+ * 1) Determining the Entity at level0, lane0 (starting entity)
+ * -First Entity in the list of Entities which has one or more adjacent Entities
+ * -If there is only one Entity it will eventually chosen
+ *
+ * 2) Get connected Entities of starting Entity.
+ * * If there are connected entities;
+ * *For each connected Entity;
+ * *We assign a corresponding level and a lane
+ * *Then recurse the procedure for connections of the assigned Entity
+ *
+ *
+ */
+ public Entity[] placeEntities() {
+
+ /**
+ * Finding the starting entity
+ */
+ for (int i = 0; i < elts.length; i++) {
+ //System.out.println("ELts "+elts.length);
+ Entity ent = elts[i];
+ if (isConnected(ent.getId())) {
+ setPosition(ent, 0, 0);
+ startEnt = ent;
+ //System.out.println("startEnt "+ent.getId());
+ break;
+ }
+
+ }
+
+ if (startEnt != null) {
+ assignPositions(startEnt);
+ }
+
+ assignPositionsOfOtherConncetedEntities();//such as a different cluster of components
+ assignPositionsOfIdleEntities();
+ assignCoordinates();
+
+ return elts;
+
+ }
+
+ private void assignPositionsOfIdleEntities() {
+
+ for (Entity ent : elts) {
+ if (!ent.isPossitionSet()) {
+
+ setPosition(ent, currentMaxLevel++, 0);
+ }
+ }
+ }
+
+ private void assignPositionsOfOtherConncetedEntities() {
+
+ for (Entity ent : elts) {
+ if (!ent.isPossitionSet() && isConnected(ent.getId())) {
+ assignPositions(ent);
+ }
+ }
+ }
+
+ private void assignCoordinates() {
+
+ for (Entity ent : elts) {
+ ent.setX(ent.getParent().getX() + ent.getStartPosition());
+ ent.setY(ent.getParent().getY() + ent.getStartPosition() / 2);
+ }
+ }
+
+ private void assignPositions(Entity ent) {
+ int id = ent.getId();
+ int[] entConns = conns[id];
+
+ for (int i = 0; i < entConns.length; i++) {
+ if (entConns[i] == 1) {
+ Entity nextEnt = findEntity(i);
+
+ // if(nextEnt.isPossitionSet()){
+ // currentMaxLevel = nextEnt.getLevel()+1; // for diagram clearness purpose
+ // }
+ if (nextEnt != null && !nextEnt.isPossitionSet()) {
+ setPosition(nextEnt, currentMaxLevel, ent.getLane() + 1);
+ assignPositions(nextEnt);
+ }
+ }
+
+ }
+ currentMaxLevel = ent.getLevel() + 1;
+ }
+
+ private Entity findEntity(int i) {
+
+ for (Entity ent : elts) {
+ if (ent.getId() == i) {
+ return ent;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * If there's at least 1 connection, this will return true
+ */
+ private boolean isConnected(int id) {
+ int[] entConns = conns[id];
+
+ //System.out.println("entConns "+entConns.length);
+ for (int i = 0; i < entConns.length; i++) {
+
+ if (entConns[i] == 1) {
+ return true;
+ }
+
+ }
+
+ return false;
+ }
+
+ private void setPosition(Entity ent, int level, int lane) {
+ ent.setLevel(level);
+ ent.setLane(lane);
+ ent.setPossitionSet(true);
+ }
+
+ public Entity getStartEnt() {
+ return startEnt;
+ }
+
+ public void setStartEnt(Entity startEnt) {
+ this.startEnt = startEnt;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java
new file mode 100755
index 0000000000..1a9b59e486
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/TuscanyCompositeEntityBuilder.java
@@ -0,0 +1,359 @@
+/*
+ * 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.diagram.layout;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+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.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+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;
+
+public class TuscanyCompositeEntityBuilder {
+
+ private Composite tuscanyComp;
+ //components connected to each other are tracked using following map
+ private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
+ private int totalWidth = 0;
+ private int totalHeight = 0;
+
+ CompositeEntity composite = null;
+
+ /**
+ * Constructor which initiates the DOM document
+ * @param aDom DOM document
+ */
+ public TuscanyCompositeEntityBuilder(Composite comp) {
+ tuscanyComp = comp;
+ }
+
+ public CompositeEntity buildCompositeEntity() {
+
+ String compositeName;
+ compositeName = tuscanyComp.getName().getLocalPart();
+ System.out.println("compositeName " + compositeName);
+
+ ComponentEntity[] comps = buildComponentEntities();
+
+ buildWires(tuscanyComp.getWires(), comps);
+
+ composite = new CompositeEntity(compositeName);
+
+ setParent(comps);
+
+ System.out.println("ComponentEntity " + comps[0].getId());
+ int[][] conns = buildConnectionMatrix(comps);
+ System.out.println("ComponentEntity " + conns[0][0]);
+
+ composite.setComponentList(comps);
+ composite.setConnections(conns);
+
+ LayoutBuilder buildLayout = new LayoutBuilder(comps, conns);
+ buildLayout.placeEntities();
+
+ System.out.println("conns " + conns[0][0]);
+
+ buildCompositeService();
+ buildCompositeReference();
+ buildCompositeProperty();
+
+ addInclusions();
+
+ composite.setAttributes();
+
+ return composite;
+ }
+
+ private void setParent(ComponentEntity[] comps) {
+
+ for (ComponentEntity comp : comps) {
+ comp.setParent(composite);
+ }
+ }
+
+ private void buildCompositeService() {
+
+ List<Service> sers = tuscanyComp.getServices();
+
+ for (int i = 0; i < sers.size(); i++) {
+ Service compositeSer = sers.get(i);
+ composite.addAService(compositeSer.getName());
+ String service = ((CompositeService)compositeSer).getPromotedService().getName();
+
+ composite.addToPromoteAService(compositeSer.getName(), service);
+ }
+
+ }
+
+ private void buildCompositeReference() {
+
+ List<Reference> refs = tuscanyComp.getReferences();
+
+ for (int i = 0; i < refs.size(); i++) {
+ Reference compositeRef = refs.get(i);
+ composite.addAReference(compositeRef.getName());
+
+ List<ComponentReference> promotedRefs = ((CompositeReference)compositeRef).getPromotedReferences();
+
+ for (ComponentReference ref : promotedRefs) {
+ String reference = ref.getName();
+
+ composite.addToPromoteAReference(compositeRef.getName(), reference);
+ }
+
+ }
+
+ }
+
+ private void buildCompositeProperty() {
+
+ List<Property> props = tuscanyComp.getProperties();
+
+ for (int i = 0; i < props.size(); i++) {
+ Property compositeProp = props.get(i);
+ composite.addAProperty(compositeProp.getName());
+ }
+
+ }
+
+ private void addInclusions() {
+
+ List<Composite> includes = tuscanyComp.getIncludes();
+
+ for (int i = 0; i < includes.size(); i++) {
+ Composite anInclude = includes.get(i);
+ composite.addToIncludedComposites(anInclude.getName().getLocalPart());
+ }
+
+ }
+
+ private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
+
+ int[][] connections = new int[comps.length][comps.length];
+ connections = initConnections(connections);
+
+ for (Entity ent : comps) {
+ for (String name : ent.getAdjacentEntities()) {
+ ComponentEntity e2 = findEntity(comps, name);
+ if (ent != null && e2 != null) {
+ //System.out.println("^^^^^^^^^ "+e2.getName());
+ connections[ent.getId()][e2.getId()] = 1;
+ }
+ }
+
+ }
+
+ return connections;
+ }
+
+ private String extractComp(ComponentEntity[] elts, String str, boolean isReference) {
+
+ if (isReference) {
+ for (ComponentEntity elt : elts) {
+ for (String ref : elt.getReferences()) {
+ if (ref.equals(str)) {
+ return elt.getName();
+ }
+ }
+ }
+ } else {
+ for (ComponentEntity elt : elts) {
+ for (String ser : elt.getServices()) {
+ if (ser.equals(str)) {
+ return elt.getName();
+ }
+ }
+ }
+ }
+ return "";
+
+ }
+
+ private int[][] initConnections(int[][] connections) {
+
+ for (int i = 0; i < connections.length; i++) {
+ for (int j = 0; j < connections.length; j++) {
+ connections[i][j] = 0;
+ }
+ }
+ return connections;
+ }
+
+ public ComponentEntity[] buildComponentEntities() {
+
+ ComponentEntity[] elts = null;
+
+ List<Component> components = tuscanyComp.getComponents();
+
+ elts = new ComponentEntity[components.size()];
+
+ for (int i = 0; i < components.size(); i++) {
+ Component aComp = components.get(i);
+
+ elts[i] = new ComponentEntity();
+ elts[i].setId(i);
+ elts[i].setName(aComp.getName());
+
+ setServices(aComp.getServices(), elts[i]);
+ setReferences(aComp.getReferences(), elts[i]);
+ setProperties(aComp.getProperties(), elts[i]);
+
+ elts[i].referenceHeight();
+ elts[i].serviceHeight();
+ elts[i].propertyLength();
+ }
+
+ return elts;
+
+ }
+
+ private void buildWires(List<Wire> wires, ComponentEntity[] elts) {
+
+ for (int i = 0; i < wires.size(); i++) {
+ String service, serviceComp, reference, referenceComp;
+ Wire aWire = wires.get(i);
+
+ reference = aWire.getSource().getName();
+ service = aWire.getTarget().getName();
+
+ referenceComp = extractComp(elts, reference, true);
+ serviceComp = extractComp(elts, service, false);
+
+ ComponentEntity e1 = findEntity(elts, referenceComp);
+
+ //System.out.println("^^^^^^^^^ "+e1.getName());
+ if (e1 != null) {
+ //System.out.println("^^^^^^^^^ "+e1.getId());
+ //connections[e1.getId()][e2.getId()] = 1;
+ createConnection(e1, reference, serviceComp, service);
+ }
+ }
+
+ }
+
+ private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
+
+ for (ComponentEntity e : elts) {
+ if (e.getName().equals(componentName)) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ private void setReferences(List<ComponentReference> refs, ComponentEntity ent) {
+
+ for (int i = 0; i < refs.size(); i++) {
+ ent.addAReference(refs.get(i).getName());
+ }
+
+ }
+
+ private void createConnection(ComponentEntity ent, String reference, String serviceComp, String service) {
+
+ String referenceComp = ent.getName();
+
+ if (reference != null && service != null) {
+
+ ent.addToRefToSerMap(reference, service);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else if (reference == null && service != null) {
+ ent.addToRefToSerMap(referenceComp, service);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else if (reference != null && service == null) {
+ ent.addToRefToSerMap(reference, serviceComp);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ } else {
+ ent.addToRefToSerMap(referenceComp, serviceComp);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private void print(ComponentEntity[] elts) {
+
+ for (ComponentEntity ent : elts) {
+ System.out.println(ent.getName() + " : "
+ + ent.getLevel()
+ + " : "
+ + ent.getLane()
+ + " : "
+ + ent.getX()
+ + " : "
+ + ent.getY());
+ }
+ }
+
+ private void addToConnectedEntities(String ent1, String ent2) {
+ System.err.println(ent1 + " : " + ent2);
+ ArrayList<String> list;
+ if (connectedEntities.containsKey(ent1)) {
+ list = connectedEntities.get(ent1);
+
+ } else {
+ list = new ArrayList<String>();
+
+ }
+ list.add(ent2);
+ connectedEntities.put(ent1, list);
+ }
+
+ private void setServices(List<ComponentService> sers, ComponentEntity ent) {
+
+ for (int i = 0; i < sers.size(); i++) {
+ ent.addAService(sers.get(i).getName());
+ }
+
+ }
+
+ private void setProperties(List<ComponentProperty> props, ComponentEntity ent) {
+
+ for (int i = 0; i < props.size(); i++) {
+ ent.addAProperty(props.get(i).getName());
+ }
+
+ }
+
+ public int getTotalWidth() {
+ return totalWidth;
+ }
+
+ public int getTotalHeight() {
+ return totalHeight;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
new file mode 100755
index 0000000000..2ce360a9c3
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
@@ -0,0 +1,279 @@
+/*
+ * 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.diagram.main;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.batik.transcoder.Transcoder;
+import org.apache.batik.transcoder.TranscoderException;
+import org.apache.batik.transcoder.TranscoderInput;
+import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.JPEGTranscoder;
+import org.apache.batik.transcoder.image.PNGTranscoder;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.tuscany.sca.diagram.generator.DiagramGenerator;
+import org.apache.tuscany.sca.diagram.html.HTMLWrapper;
+import org.apache.tuscany.sca.diagram.layout.CompositeEntity;
+import org.apache.tuscany.sca.diagram.layout.EntityBuilder;
+import org.w3c.dom.Document;
+
+public class Main {
+
+ static Options getCommandLineOptions() {
+ Options options = new Options();
+ Option opt1 = new Option("s", "svg", false, "Generate SVG diagrams");
+ options.addOption(opt1);
+ Option opt2 = new Option("h", "html", false, "Generate HTML documents");
+ options.addOption(opt2);
+
+ Option opt3 = new Option("j", "jpeg", false, "Generate JPEG diagrams");
+ options.addOption(opt3);
+
+ Option opt4 = new Option("o", "output", true, "Output directory");
+ options.addOption(opt4);
+
+ return options;
+ }
+
+ /**
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ CommandLineParser parser = new PosixParser();
+ Options options = getCommandLineOptions();
+ CommandLine cli = null;
+ boolean help = false;
+ try {
+ cli = parser.parse(options, args);
+ if (cli.getArgList().size() == 0) {
+ help = true;
+ }
+ } catch (ParseException e) {
+ System.out.println(e);
+ help = true;
+ }
+
+ // Print out the options and quit
+ if (help) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("<-h> <-s> <-o outputDirectory> file1 file2 ...: ", options);
+ return;
+ }
+
+ boolean isHtml = false;
+ boolean isSvg = false;
+ boolean isJpeg = false;
+ isSvg = cli.hasOption('s');
+ isHtml = cli.hasOption('h');
+ isJpeg = cli.hasOption('j');
+
+ if (!isSvg && !isHtml && !isJpeg) {
+ isSvg = true;
+ isHtml = true;
+ }
+
+ String outFileDir;
+
+ if (cli.hasOption('o')) {
+ outFileDir = cli.getOptionValue('o');
+ } else {
+ outFileDir = ".";
+ }
+ File dir = new File(outFileDir);
+ String[] compositeFiles = cli.getArgs();
+ generate(dir, isSvg, isHtml, false, compositeFiles);
+ }
+
+ public static void generate(File dir, boolean isSvg, boolean isHtml, boolean isJpeg, String... compositeFiles)
+ throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ for (String str : compositeFiles) {
+
+ if (str != null) {
+
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(str);
+
+ EntityBuilder eb = new EntityBuilder(doc);
+ CompositeEntity comp = eb.buildCompositeEntity();
+
+ DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
+ Document svg = dg.buildSVGDocument();
+
+ if (isJpeg) {
+ String jpgFileName = comp.getName() + comp.getFileNameSuffix() + ".jpg";
+ svgToJPEG(svg, new File(dir, jpgFileName));
+ }
+
+ String svgContent = extractSvg(svg);
+
+ if (isSvg) {
+ writeSVG(dir, svgContent, comp);
+ }
+
+ if (isHtml) {
+ writeHTML(dir, svgContent, comp);
+ }
+
+ }
+ }
+ }
+
+ private static void writeHTML(File dir, String svg, CompositeEntity comp) throws Exception {
+
+ File htmlFile = new File(dir, comp.getName() + comp.getFileNameSuffix() + ".html");
+ HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile);
+ html.buildHTML();
+
+ // System.err.println("--------------HTML Output for " + comp.getName() + "--------------\n");
+ // System.out.println(content);
+ // System.err.println("--------------------------------------------------------------\n");
+
+ }
+
+ private static File writeSVG(File dir, String svg, CompositeEntity comp) throws Exception {
+
+ String svgFileName = comp.getName() + comp.getFileNameSuffix() + ".svg";
+ File svgFile = new File(dir, svgFileName);
+ FileWriter fw = new FileWriter(svgFile);
+ fw.write(svg);
+ fw.close();
+ return svgFile;
+ }
+
+ private static String extractSvg(Document svg) throws Exception {
+
+ // Set up the output transformer
+ TransformerFactory transfac = TransformerFactory.newInstance();
+ Transformer trans = transfac.newTransformer();
+
+ // Print the DOM node
+
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ DOMSource source = new DOMSource(svg);
+ trans.transform(source, result);
+ String svgString = sw.toString();
+
+ return svgString;
+ }
+
+ public static void svgToJPEG(File svg, File jpeg) throws IOException, TranscoderException {
+ // Create the transcoder input.
+ TranscoderInput input = new TranscoderInput(svg.toURI().toString());
+ // Create the transcoder output.
+ OutputStream ostream = new FileOutputStream(jpeg);
+ TranscoderOutput output = new TranscoderOutput(ostream);
+
+ // Create a JPEG transcoder
+ Transcoder t = new JPEGTranscoder();
+
+ // Set the transcoding hints.
+ t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+ // Save the image.
+ t.transcode(input, output);
+
+ // Flush and close the stream.
+ ostream.flush();
+ ostream.close();
+ }
+
+ public static void svgToJPEG(Document svg, File jpeg) throws IOException, TranscoderException {
+ // Create the transcoder input.
+ TranscoderInput input = new TranscoderInput(svg);
+ // Create the transcoder output.
+ OutputStream ostream = new FileOutputStream(jpeg);
+ TranscoderOutput output = new TranscoderOutput(ostream);
+
+ // Create a JPEG transcoder
+ Transcoder t = new JPEGTranscoder();
+
+ // Set the transcoding hints.
+ t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+ // Save the image.
+ t.transcode(input, output);
+
+ // Flush and close the stream.
+ ostream.flush();
+ ostream.close();
+ }
+
+ public static void svgToJPEG(InputStream svg, OutputStream jpeg) throws IOException, TranscoderException {
+ // Create the transcoder input.
+ TranscoderInput input = new TranscoderInput(svg);
+
+ TranscoderOutput output = new TranscoderOutput(jpeg);
+
+ // Create a JPEG transcoder
+ Transcoder t = new JPEGTranscoder();
+
+ // Set the transcoding hints.
+ t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+ // Save the image.
+ t.transcode(input, output);
+
+ // Flush and close the stream.
+ svg.close();
+ jpeg.flush();
+ jpeg.close();
+ }
+
+ public static void svgToPNG(InputStream svg, OutputStream png) throws IOException, TranscoderException {
+ // Create the transcoder input.
+ TranscoderInput input = new TranscoderInput(svg);
+
+ TranscoderOutput output = new TranscoderOutput(png);
+
+ // Create a JPEG transcoder
+ Transcoder t = new PNGTranscoder();
+
+ // Save the image.
+ t.transcode(input, output);
+
+ // Flush and close the stream.
+ svg.close();
+ png.flush();
+ png.close();
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
new file mode 100644
index 0000000000..ee0feb86bb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
@@ -0,0 +1,33 @@
+/**********************************************************************
+ * NAME:
+ * DiagramGeneratorTestCase
+ *
+ * AUTHOR:
+ * rfeng
+ *
+ * DESCRIPTION:
+ *
+ *
+ * Copyright (c) Shutterfly, Inc. 2010. All Rights reserved.
+ **********************************************************************/
+
+package org.apache.tuscany.sca.diagram.layout;
+
+import java.io.File;
+
+import org.apache.tuscany.sca.diagram.main.Main;
+import org.junit.Test;
+
+public class DiagramGeneratorTestCase {
+
+ @Test
+ public final void test() throws Exception {
+ for (File xml : new File("input").listFiles()) {
+ if (xml.getName().endsWith(".xml")) {
+ System.out.println(xml);
+ Main.generate(new File("target"), true, false, false, xml.toString());
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilderTestCase.java b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilderTestCase.java
new file mode 100755
index 0000000000..992a47c1dd
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/LayoutBuilderTestCase.java
@@ -0,0 +1,141 @@
+package org.apache.tuscany.sca.diagram.layout;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.diagram.layout.ComponentEntity;
+import org.apache.tuscany.sca.diagram.layout.CompositeEntity;
+import org.apache.tuscany.sca.diagram.layout.Entity;
+import org.apache.tuscany.sca.diagram.layout.LayoutBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LayoutBuilderTestCase {
+
+ LayoutBuilder lb;
+ Entity[] ents;
+ Entity parent;
+ int[][] conns;
+
+ @Before
+ public void setUp() throws Exception {
+ parent = new CompositeEntity("composite");
+ parent.setX(200);
+ parent.setY(100);
+
+ ents = new Entity[5];
+ for (int i = 0; i < ents.length; i++) {
+ ents[i] = new ComponentEntity();
+ ents[i].setId(i);
+ ents[i].setParent(parent);
+ }
+
+ }
+
+ @Test
+ public void testPlaceEntities() throws Exception {
+ //setUp();
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(200, ents[0].getStartPosition());
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ //int x = Math.getExponent(Math.random());
+ if (i == j - 1)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(0, lb.getStartEnt().getId());
+
+ Assert.assertEquals(0, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(0, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(1, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(3, ents[3].getLane());
+ Assert.assertEquals(4, ents[4].getLane());
+
+ }
+
+ @Test
+ public void testPlaceEntities1() throws Exception {
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ //int x = Math.getExponent(Math.random());
+ if (i == j - 1 || i == j - 4)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+ conns[3][4] = 0;
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(0, lb.getStartEnt().getId());
+
+ Assert.assertEquals(0, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(1, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(1, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(3, ents[3].getLane());
+ Assert.assertEquals(1, ents[4].getLane());
+
+ }
+
+ @Test
+ public void testPlaceEntities2() throws Exception {
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ if (i * j > 2 && i * j <= 6)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(1, lb.getStartEnt().getId());
+
+ Assert.assertEquals(1, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(1, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(0, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(1, ents[3].getLane());
+ Assert.assertEquals(1, ents[4].getLane());
+
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java
new file mode 100755
index 0000000000..36ea55f5d1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java
@@ -0,0 +1,141 @@
+package org.apache.tuscany.sca.layout;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.impl.layout.ComponentEntity;
+import org.apache.tuscany.sca.impl.layout.CompositeEntity;
+import org.apache.tuscany.sca.impl.layout.Entity;
+import org.apache.tuscany.sca.impl.layout.LayoutBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LayoutBuilderTest {
+
+ LayoutBuilder lb;
+ Entity[] ents;
+ Entity parent;
+ int[][] conns;
+
+ @Before
+ public void setUp() throws Exception {
+ parent = new CompositeEntity("composite");
+ parent.setX(200);
+ parent.setY(100);
+
+ ents = new Entity[5];
+ for (int i = 0; i < ents.length; i++) {
+ ents[i] = new ComponentEntity();
+ ents[i].setId(i);
+ ents[i].setParent(parent);
+ }
+
+ }
+
+ @Test
+ public void testPlaceEntities() throws Exception {
+ //setUp();
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(200, ents[0].getStartPosition());
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ //int x = Math.getExponent(Math.random());
+ if (i == j - 1)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(0, lb.getStartEnt().getId());
+
+ Assert.assertEquals(0, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(0, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(1, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(3, ents[3].getLane());
+ Assert.assertEquals(4, ents[4].getLane());
+
+ }
+
+ @Test
+ public void testPlaceEntities1() throws Exception {
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ //int x = Math.getExponent(Math.random());
+ if (i == j - 1 || i == j - 4)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+ conns[3][4] = 0;
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(0, lb.getStartEnt().getId());
+
+ Assert.assertEquals(0, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(1, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(1, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(3, ents[3].getLane());
+ Assert.assertEquals(1, ents[4].getLane());
+
+ }
+
+ @Test
+ public void testPlaceEntities2() throws Exception {
+
+ conns = new int[5][5];
+ for (int i = 0; i < conns.length; i++) {
+ for (int j = 0; j < conns.length; j++) {
+ if (i * j > 2 && i * j <= 6)
+ conns[i][j] = 1;
+ else
+ conns[i][j] = 0;
+ }
+ }
+
+ lb = new LayoutBuilder(ents, conns);
+
+ ents = lb.placeEntities();
+
+ Assert.assertEquals(5, ents.length);
+ Assert.assertEquals(1, lb.getStartEnt().getId());
+
+ Assert.assertEquals(1, ents[0].getLevel());
+ Assert.assertEquals(0, ents[1].getLevel());
+ Assert.assertEquals(0, ents[2].getLevel());
+ Assert.assertEquals(0, ents[3].getLevel());
+ Assert.assertEquals(1, ents[4].getLevel());
+
+ Assert.assertEquals(0, ents[0].getLane());
+ Assert.assertEquals(0, ents[1].getLane());
+ Assert.assertEquals(2, ents[2].getLane());
+ Assert.assertEquals(1, ents[3].getLane());
+ Assert.assertEquals(1, ents[4].getLane());
+
+ }
+}