summaryrefslogtreecommitdiffstats
path: root/collaboration
diff options
context:
space:
mode:
authornirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-08-04 19:40:01 +0000
committernirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-08-04 19:40:01 +0000
commit46f968e7e04f3626785098da089c6d385e198fdf (patch)
treef9dffcb5bb7d366853c6e2726ab9c2d09e0230f5 /collaboration
parent145673fce295ef2075f9ee82d23dfeb23504d464 (diff)
Provide support to composite services and references + few design changes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1153978 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration')
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java77
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Layer.java59
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/NormalWire.java48
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java2
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java36
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java199
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java1
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java373
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java44
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java661
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java152
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java20
15 files changed, 1473 insertions, 205 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml
index 4dc8353a53..1cbc78b56d 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml
@@ -30,7 +30,7 @@
<property name="currency">EURO</property>
- <service name="MyValueService"/>
+ <service name="myValueService"/>
<reference name="customerService"/>
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
index 5cf0528cc6..b37a777601 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
@@ -1 +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="#E5E5E5" width="1400" rx="20" ry="20" height="720" stroke="#919191"/><text x="700" font-size="10" dominant-baseline="mathematical" y="20" text-anchor="middle">store</text><rect x="200" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="250" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">Store</text><polygon fill="#00CD66" points="180,210 210,210 225,225 210,240 180,240 195,225 " stroke="#008B45"/><text x="180" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">Widget</text><polygon fill="#BF3EFF" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#68228B"/><text x="380" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">catalog</text><polygon fill="#BF3EFF" points="380,250 410,250 425,265 410,280 380,280 395,265 " stroke="#68228B"/><text x="380" font-size="10" dominant-baseline="mathematical" y="265" text-anchor="middle">shoppingCart</text><polygon fill="#BF3EFF" points="380,290 410,290 425,305 410,320 380,320 395,305 " stroke="#68228B"/><text x="380" font-size="10" dominant-baseline="mathematical" y="305" text-anchor="middle">shoppingTotal</text><rect x="600" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="650" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">Catalog</text><polygon fill="#00CD66" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#008B45"/><text x="580" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">Catalog</text><polygon fill="#BF3EFF" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#68228B"/><text x="780" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">currencyConverter</text><rect fill="#EEEE00" x="620" width="20" height="20" y="190" stroke="#EEC900"/><text x="620" font-size="10" dominant-baseline="mathematical" y="190" text-anchor="middle">currencyCode</text><rect x="600" y="460" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="650" font-size="10" dominant-baseline="mathematical" y="610" text-anchor="middle">ShoppingCart</text><polygon fill="#00CD66" points="580,470 610,470 625,485 610,500 580,500 595,485 " stroke="#008B45"/><text x="580" font-size="10" dominant-baseline="mathematical" y="485" text-anchor="middle">Cart</text><polygon fill="#00CD66" points="580,510 610,510 625,525 610,540 580,540 595,525 " stroke="#008B45"/><text x="580" font-size="10" dominant-baseline="mathematical" y="525" text-anchor="middle">Total</text><rect x="1000" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1050" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">CurrencyConverter</text><polygon fill="#00CD66" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#008B45"/><text x="980" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle"></text><polyline stroke-width="2" points="425,305 595,525" stroke="black"/><polyline stroke-width="2" points="425,265 595,485" stroke="black"/><polyline stroke-width="2" points="425,225 595,225" stroke="black"/><polyline stroke-width="2" points="825,225 995,225" stroke="black"/></svg> \ No newline at end of file
+<?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" overflow="visible"><rect x="0" y="0" alignment-baseline="central" fill="#E5E5E5" width="1450" rx="20" ry="20" height="770" stroke="#919191"/><text x="725" font-size="20" dominant-baseline="mathematical" y="20" text-anchor="middle">store</text><rect x="250" y="250" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="300" font-size="20" dominant-baseline="mathematical" y="400" text-anchor="middle">Store</text><polygon fill="#00CD66" points="230,260 260,260 275,275 260,290 230,290 245,275 " stroke="#008B45"/><text x="230" font-size="20" dominant-baseline="mathematical" y="275" text-anchor="middle">Widget</text><polygon fill="#BF3EFF" points="430,260 460,260 475,275 460,290 430,290 445,275 " stroke="#68228B"/><text x="430" font-size="20" dominant-baseline="mathematical" y="275" text-anchor="middle">catalog</text><polygon fill="#BF3EFF" points="430,300 460,300 475,315 460,330 430,330 445,315 " stroke="#68228B"/><text x="430" font-size="20" dominant-baseline="mathematical" y="315" text-anchor="middle">shoppingCart</text><polygon fill="#BF3EFF" points="430,340 460,340 475,355 460,370 430,370 445,355 " stroke="#68228B"/><text x="430" font-size="20" dominant-baseline="mathematical" y="355" text-anchor="middle">shoppingTotal</text><rect x="650" y="250" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="700" font-size="20" dominant-baseline="mathematical" y="400" text-anchor="middle">Catalog</text><polygon fill="#00CD66" points="630,260 660,260 675,275 660,290 630,290 645,275 " stroke="#008B45"/><text x="630" font-size="20" dominant-baseline="mathematical" y="275" text-anchor="middle">Catalog</text><polygon fill="#BF3EFF" points="830,260 860,260 875,275 860,290 830,290 845,275 " stroke="#68228B"/><text x="830" font-size="20" dominant-baseline="mathematical" y="275" text-anchor="middle">currencyConverter</text><rect fill="#EEEE00" x="670" width="20" height="20" y="240" stroke="#EEC900"/><text x="670" font-size="20" dominant-baseline="mathematical" y="240" text-anchor="middle">currencyCode</text><rect x="650" y="510" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="700" font-size="20" dominant-baseline="mathematical" y="660" text-anchor="middle">ShoppingCart</text><polygon fill="#00CD66" points="630,520 660,520 675,535 660,550 630,550 645,535 " stroke="#008B45"/><text x="630" font-size="20" dominant-baseline="mathematical" y="535" text-anchor="middle">Cart</text><polygon fill="#00CD66" points="630,560 660,560 675,575 660,590 630,590 645,575 " stroke="#008B45"/><text x="630" font-size="20" dominant-baseline="mathematical" y="575" text-anchor="middle">Total</text><rect x="1050" y="250" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1100" font-size="20" dominant-baseline="mathematical" y="400" text-anchor="middle">CurrencyConverter</text><polygon fill="#00CD66" points="1030,260 1060,260 1075,275 1060,290 1030,290 1045,275 " stroke="#008B45"/><text x="1030" font-size="20" dominant-baseline="mathematical" y="275" text-anchor="middle">CurrencyConverter</text><polyline stroke-width="2" points="475,355 645,575" stroke="black"/><polyline stroke-width="2" points="475,315 645,535" stroke="black"/><polyline stroke-width="2" points="475,275 645,275" stroke="black"/><polyline stroke-width="2" points="875,275 1045,275" stroke="black"/></svg>
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
index cf0569359f..d74fd8a16c 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
@@ -1 +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="#E5E5E5" width="1800" rx="20" ry="20" height="460" stroke="#919191"/><text x="900" font-size="10" dominant-baseline="mathematical" y="20" text-anchor="middle">supplychain</text><rect x="200" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="250" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">CustomerComponent</text><polygon fill="#00CD66" points="180,210 210,210 225,225 210,240 180,240 195,225 " stroke="#008B45"/><text x="180" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle"></text><polygon fill="#BF3EFF" points="380,210 410,210 425,225 410,240 380,240 395,225 " stroke="#68228B"/><text x="380" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">retailer</text><rect x="600" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="650" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">RetailerComponent</text><polygon fill="#00CD66" points="580,210 610,210 625,225 610,240 580,240 595,225 " stroke="#008B45"/><text x="580" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle"></text><polygon fill="#BF3EFF" points="780,210 810,210 825,225 810,240 780,240 795,225 " stroke="#68228B"/><text x="780" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">warehouse</text><rect x="1000" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1050" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">WarehouseComponent</text><polygon fill="#00CD66" points="980,210 1010,210 1025,225 1010,240 980,240 995,225 " stroke="#008B45"/><text x="980" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle"></text><polygon fill="#BF3EFF" points="1180,210 1210,210 1225,225 1210,240 1180,240 1195,225 " stroke="#68228B"/><text x="1180" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">shipper</text><rect x="1400" y="200" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="1450" font-size="10" dominant-baseline="mathematical" y="350" text-anchor="middle">ShipperComponent</text><polygon fill="#00CD66" points="1380,210 1410,210 1425,225 1410,240 1380,240 1395,225 " stroke="#008B45"/><text x="1380" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle"></text><polygon fill="#BF3EFF" points="1580,210 1610,210 1625,225 1610,240 1580,240 1595,225 " stroke="#68228B"/><text x="1580" font-size="10" dominant-baseline="mathematical" y="225" text-anchor="middle">customer</text><polyline stroke-width="2" points="425,225 595,225" stroke="black"/><polyline stroke-width="2" points="825,225 995,225" stroke="black"/><polyline stroke-width="2" points="1225,225 1395,225" stroke="black"/><polyline stroke-width="2" points="1625,225 195,225" stroke="black"/></svg> \ No newline at end of file
+<?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="2200" rx="20" ry="20" height="560" stroke="#919191"/><rect x="200" y="100" alignment-baseline="central" fill="#E5E5E5" width="1800" rx="20" ry="20" height="360" stroke="#919191"/><text x="1100" font-size="20" dominant-baseline="mathematical" y="120" text-anchor="middle">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="450" font-size="20" dominant-baseline="mathematical" y="350" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="850" font-size="20" dominant-baseline="mathematical" y="350" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="1250" font-size="20" dominant-baseline="mathematical" y="350" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="1650" font-size="20" dominant-baseline="mathematical" y="350" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">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="20" dominant-baseline="mathematical" y="225" text-anchor="middle">customer</text><polyline stroke-width="2" points="625,225 795,225" stroke="black"/><polyline stroke-width="2" points="1025,225 1195,225" stroke="black"/><polyline stroke-width="2" points="1425,225 1595,225" stroke="black"/><polyline stroke-width="2" points="1825,225 395,225" stroke="black"/></svg> \ No newline at end of file
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java
new file mode 100755
index 0000000000..c9381c9d50
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java
@@ -0,0 +1,77 @@
+/*
+ * 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.impl.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class DashedWire extends Wire{
+
+
+ public Element addElement(Document document, String svgNs,
+ Reference aReference1, Reference aReference2){
+
+ Element polyline = document.createElementNS(svgNs, "polyline");
+ int x1=aReference1.getxCoordinate()+aReference1.getHeight()*3/2;
+ int y1=aReference1.getyCoordinate()+aReference1.getHeight()/2;
+
+ int x2=aReference2.getxCoordinate()+aReference2.getHeight()/2;
+ int y2=aReference2.getyCoordinate()+aReference2.getHeight()/2;
+ //polyline.setAttributeNS(null,"class", "Connect");
+ polyline.setAttributeNS(null, "points", x1+","+
+ y1+" "+x2+","+y2
+ );
+ polyline.setAttributeNS(null, "stroke", "black");
+ polyline.setAttributeNS(null, "stroke-dasharray", "3 3");
+ polyline.setAttributeNS(null, "stroke-width", "2");
+
+ return polyline;
+ }
+
+ public Element addElement(Document document, String svgNs,
+ Service aService1, Service aService2){
+
+ Element polyline = document.createElementNS(svgNs, "polyline");
+ int x1=aService1.getxCoordinate()+aService1.getHeight()*3/2;
+ int y1=aService1.getyCoordinate()+aService1.getHeight()/2;
+
+ int x2=aService2.getxCoordinate()+aService2.getHeight()/2;
+ int y2=aService2.getyCoordinate()+aService2.getHeight()/2;
+ //polyline.setAttributeNS(null,"class", "Connect");
+ polyline.setAttributeNS(null, "points", x1+","+
+ y1+" "+x2+","+y2
+ );
+ polyline.setAttributeNS(null, "stroke", "black");
+ polyline.setAttributeNS(null, "stroke-dasharray", "3 3");
+ polyline.setAttributeNS(null, "stroke-width", "2");
+
+ return polyline;
+ }
+
+
+ @Override
+ public Element addElement(Document document, String svgNs,
+ Reference aReference, Service aService) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Layer.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Layer.java
new file mode 100755
index 0000000000..36d3d29f20
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Layer.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.impl.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Structure of a "Composite" element in SCA, as a SVG element
+ *
+ */
+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", "central");
+
+ return rectangle;
+ }
+
+ //OBSOLETE
+ public Element addElement(Document document, String svgNs, int x, int y) {
+ return null;
+ }
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/NormalWire.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/NormalWire.java
new file mode 100755
index 0000000000..5ceece65bc
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/NormalWire.java
@@ -0,0 +1,48 @@
+/*
+ * 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.impl.artifacts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class NormalWire extends Wire{
+
+
+ public Element addElement(Document document, String svgNs,
+ Reference aReference, Service aService){
+
+ 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.setAttributeNS(null,"class", "Connect");
+ polyline.setAttributeNS(null, "points", x1+","+
+ y1+" "+x2+","+y2
+ );
+ polyline.setAttributeNS(null, "stroke", "black");
+ polyline.setAttributeNS(null, "stroke-width", "2");
+
+ return polyline;
+ }
+
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java
index fabbf40873..7457084eb6 100644
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java
@@ -31,7 +31,7 @@ public class Text {
text.setAttributeNS(null, "y", y+"");
text.setAttributeNS(null, "text-anchor", "middle");
text.setAttributeNS(null, "dominant-baseline", "mathematical");
- text.setAttributeNS(null, "font-size", "10");
+ text.setAttributeNS(null, "font-size", "20");
text.setTextContent(content);
return text;
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
index 59ef48895a..9c91ccc361 100644
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
@@ -22,27 +22,27 @@ package org.apache.tuscany.sca.impl.artifacts;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class Wire {
+public abstract class Wire {
- public Element addElement(Document document, String svgNs,
- Reference aReference, Service aService){
+ public abstract Element addElement(Document document, String svgNs,
+ Reference aReference, Service aService); //{
- 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.setAttributeNS(null,"class", "Connect");
- polyline.setAttributeNS(null, "points", x1+","+
- y1+" "+x2+","+y2
- );
- polyline.setAttributeNS(null, "stroke", "black");
- polyline.setAttributeNS(null, "stroke-width", "2");
-
- return polyline;
- }
+// 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.setAttributeNS(null,"class", "Connect");
+// polyline.setAttributeNS(null, "points", x1+","+
+// y1+" "+x2+","+y2
+// );
+// polyline.setAttributeNS(null, "stroke", "black");
+// polyline.setAttributeNS(null, "stroke-width", "2");
+//
+// return polyline;
+// }
}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
index 031ff25e95..742575f501 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
@@ -26,12 +26,16 @@ import java.util.Map.Entry;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.tuscany.sca.impl.artifacts.Component;
import org.apache.tuscany.sca.impl.artifacts.Composite;
+import org.apache.tuscany.sca.impl.artifacts.DashedWire;
+import org.apache.tuscany.sca.impl.artifacts.Layer;
+import org.apache.tuscany.sca.impl.artifacts.NormalWire;
import org.apache.tuscany.sca.impl.artifacts.Property;
import org.apache.tuscany.sca.impl.artifacts.Reference;
import org.apache.tuscany.sca.impl.artifacts.Service;
import org.apache.tuscany.sca.impl.artifacts.Text;
import org.apache.tuscany.sca.impl.artifacts.Wire;
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.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
@@ -39,10 +43,11 @@ import org.w3c.dom.Element;
public class DiagramGenerator {
- private Entity[] entities;
- private int height, width;
+ private CompositeEntity comp;
+// private Entity[] entities;
+// private int height, width;
private Document doc;
- private String compositeName;
+// private String compositeName;
private String svgNS ;
private Element svgRoot;
private ArrayList<Reference> refs= new ArrayList<Reference>();
@@ -52,17 +57,20 @@ public class DiagramGenerator {
* Constructor to generate a SVG diagram for compositeName
* with a given height and a width and consisting of entities.
*/
- public DiagramGenerator(Entity[] entities, int height, int width, String compositeName) {
- this.entities = entities;
- this.height = height;
- this.width = width;
- this.compositeName = compositeName;
+ public DiagramGenerator(CompositeEntity comp) {
+ this.comp = comp;
+// this.entities = comp.getComponentList();
+// this.height = comp.getHeight();
+// this.width = comp.getWidth();
+// this.compositeName = comp.getName();
+// comp.getServices();
}
/**
* Draws the diagram.
*/
public Document buildSVGDocument(){
+
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
doc = impl.createDocument(svgNS, "svg", null);
@@ -70,26 +78,82 @@ public class DiagramGenerator {
// Get the root element (the 'svg' element).
svgRoot = doc.getDocumentElement();
+// svgRoot.setAttributeNS(null, "width", ""+(width+400));
+// svgRoot.setAttributeNS(null, "height", ""+(height+200));
+
+ addLayer();
addComposite();
- for(Entity ent: entities){
+
+ for(Entity ent: comp.getComponentList()){
+
addComponent(ent);
addService(ent);
addReference(ent);
addProperties(ent);
}
- addConnections();
+ addCompositeService(comp);
+ addCompositeReference(comp);
+ addCompositeProperties(comp);
+
+ addComponentConnections();
+ addReferencePromotion();
+ addServicePromotion();
return doc;
}
+
+
+ private void addLayer() {
+
+ Layer outerLayer = new Layer();
+ Element layerElt = outerLayer.addElement(doc, svgNS, 0, 0, comp.getHeight()+200, comp.getWidth()+400);
+ svgRoot.appendChild(layerElt);
+ }
+
+ private void addReferencePromotion() {
+
+ for(Iterator it= comp.getPromoteAReference().entrySet().iterator();
+ it.hasNext();){
+ Entry entry = (Entry) it.next();
+ String compositeRef = (String)entry.getKey();
+ String componentRef = (String)entry.getValue();
+
+ Reference r1 = getRef(compositeRef);
+ Reference r2 = getRef(componentRef);
+
+ if(r1 != null && r2 != null){
+ addWire(r2, r1);
+ }
+ }
+ }
+
+ private void addServicePromotion() {
+
+ for(Iterator it= comp.getPromoteAService().entrySet().iterator();
+ it.hasNext();){
+ Entry entry = (Entry) it.next();
+ String compositeSer = (String)entry.getKey();
+ String componentSer = (String)entry.getValue();
+
+ Service s1 = getSer(compositeSer);
+ Service s2 = getSer(componentSer);
+
+ if(s1 != null && s2 != null){
+ addWire(s1, s2);
+ }
+ }
+ }
+
+
/**
* Connects references to services.
*/
- private void addConnections() {
+ private void addComponentConnections() {
- for(Entity ent: entities){
+ for(Entity ent: comp.getComponentList()){
if(ent instanceof ComponentEntity){
for(Iterator it= ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator();
@@ -111,10 +175,24 @@ public class DiagramGenerator {
private void addWire(Reference r, Service s) {
- Wire edge = new Wire();
+ Wire edge = new NormalWire();
Element wire = edge.addElement(doc, svgNS, r, s);
svgRoot.appendChild(wire);
}
+
+ private void addWire(Service s1, Service s2) {
+
+ DashedWire edge = new DashedWire();
+ Element wire = edge.addElement(doc, svgNS, s1, s2);
+ svgRoot.appendChild(wire);
+ }
+
+ private void addWire(Reference r1, Reference r2) {
+
+ DashedWire edge = new DashedWire();
+ Element wire = edge.addElement(doc, svgNS, r1, r2);
+ svgRoot.appendChild(wire);
+ }
private Service getSer(String ser) {
@@ -204,7 +282,7 @@ public class DiagramGenerator {
}
for(String eName: e.getAdjacentEntities()){
- for(Entity ent: entities){
+ for(Entity ent: comp.getComponentList()){
if(ent.getName().equals(eName)){
for(String s : sers){
@@ -240,6 +318,19 @@ public class DiagramGenerator {
}
}
+ //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;
}
@@ -269,10 +360,83 @@ public class DiagramGenerator {
sers.add(serve);
}
}
+
+ private void addCompositeService(CompositeEntity comp) {
+
+ int serHeight = comp.getSerHeight();
+ int x= comp.getX()-(serHeight*2/3);
+ int y= comp.getY() + Service.SPACING_FOR_COMPOSITE;
+ System.err.println(serHeight);
+ System.out.println("''''''"+((CompositeEntity)comp).getName() +" '''''' "+ comp.getServices().size());
+ for(String ser: comp.getServices()){
+
+ Service serve= new Service();
+ Element polygon = serve.addElement(doc, svgNS, x, y, serHeight);
+ Element text;
+ if(!ser.endsWith("Impl"))
+ text = Text.addTextElement(doc, svgNS, x, y+serHeight/2, ser);
+ else
+ text = Text.addTextElement(doc, svgNS, x, y+serHeight/2, "");
+
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (serHeight + Service.SPACING_FOR_COMPOSITE);
+
+ serve.setName(ser);
+ serve.setContainerName(comp.getName());
+ sers.add(serve);
+ }
+ }
+
+ private void addCompositeReference(CompositeEntity comp) {
+
+ int refHeight = comp.getRefHeight();
+ int x=(comp.getX()+comp.getWidth())-(refHeight*2/3);
+ int y=comp.getY() + Reference.SPACING_FOR_COMPOSITE;
+
+ for(String ref: comp.getReferences()){
+ Reference refer= new Reference();
+ Element polygon = refer.addElement(doc, svgNS, x, y, refHeight);
+ Element text = Text.addTextElement(doc, svgNS, x, y+refHeight/2, ref);
+ svgRoot.appendChild(polygon);
+ svgRoot.appendChild(text);
+
+ y += (refHeight + Reference.SPACING_FOR_COMPOSITE);
+
+ refer.setName(ref);
+ refer.setContainerName(comp.getName());
+ refs.add(refer);
+
+ }
+
+ }
+
+ private void addCompositeProperties(CompositeEntity comp) {
+ int propLen = comp.getPropLength();
+ int x= comp.getX() + Property.SPACING_FOR_COMPOSITE;
+ int y= comp.getY()-propLen/2;
+
+ for(String prop: comp.getProperties()){
+ Property pro = new Property();
+ Element property = pro.addElement(doc, svgNS, x, y, propLen);
+ Element text = Text.addTextElement(doc, svgNS, x, y, prop);
+
+ svgRoot.appendChild(property);
+ svgRoot.appendChild(text);
+
+ x += (propLen + Property.SPACING_FOR_COMPOSITE);
+
+ pro.setName(prop);
+ pro.setContainerName(comp.getName());
+ }
+ }
+
private void addComponent(Entity ent) {
Component comp = new Component();
+ 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.getWidth()/4),
@@ -287,13 +451,14 @@ public class DiagramGenerator {
private void addComposite() {
Composite composite = new Composite();
- Element composi = composite.addElement(doc, svgNS, 0, 0, height, width);
- Element text = Text.addTextElement(doc, svgNS, width/2, 20, compositeName);
+
+ Element composi = composite.addElement(doc, svgNS, comp.getX(), comp.getY(), comp.getHeight(), comp.getWidth());
+ Element text = Text.addTextElement(doc, svgNS, comp.getX() +comp.getWidth()/2, comp.getY() +20, comp.getName());
svgRoot.appendChild(composi);
svgRoot.appendChild(text);
- composite.setName(compositeName);
+ composite.setName(comp.getName());
}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java
index 4feaaff635..f85a83bdb7 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java
@@ -48,6 +48,7 @@ public class ComponentEntity extends Entity{
public ComponentEntity(){
+ super.setStartPosition(200);
setHeight(Component.DEFAULT_HEIGHT);
setWidth(Component.DEFAULT_WIDTH);
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java
new file mode 100755
index 0000000000..0adffcc44e
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java
@@ -0,0 +1,373 @@
+/*
+ * 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.impl.layout;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.apache.tuscany.sca.impl.artifacts.Component;
+import org.apache.tuscany.sca.impl.artifacts.Composite;
+import org.apache.tuscany.sca.impl.artifacts.Property;
+import org.apache.tuscany.sca.impl.artifacts.Reference;
+import org.apache.tuscany.sca.impl.artifacts.Service;
+
+/**
+ * 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 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, String> promoteAReference = new HashMap<String, 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()) - Reference.SPACING_FOR_COMPOSITE);
+ }
+ else
+ setRefHeight(Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE);
+ }
+
+ public void serviceHeight(){
+ if(getDefaultNoOfSers() < getNoOfSers()){
+ setSerHeight((getHeight() / getNoOfSers()) - Service.SPACING_FOR_COMPOSITE);
+ }
+ else
+ setSerHeight(Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE);
+ }
+
+ public void propertyLength(){
+ if(getDefaultNoOfProps() < getNoOfProps()){
+
+ setPropLength((getWidth() / getNoOfProps()) - Property.SPACING_FOR_COMPOSITE);
+ }
+ else
+ setPropLength(Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE);
+ }
+
+// /**
+// * 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((Component.DEFAULT_HEIGHT * getSpaceFactor()) * (maxInternalLevel + 1) + initPoint);
+ }
+
+ public void calcWidth(int initPoint) {
+ System.err.println("maxInternalLane "+maxInternalLane);
+ setWidth((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){
+ //ref = ref.toLowerCase();
+ //ser = ser.toLowerCase();
+
+ if (promoteAReference.containsKey(compositeRef))
+ return false;
+
+ promoteAReference.put(compositeRef, componentRef);
+ return true;
+ }
+
+ public void setPromoteAReference(HashMap<String, String> promoteAReference) {
+ this.promoteAReference = promoteAReference;
+ }
+
+ public HashMap<String, 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()/
+ (Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Service.SPACING_FOR_COMPOSITE));
+ setDefaultNoOfRefs(
+ getHeight()/
+ (Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Reference.SPACING_FOR_COMPOSITE));
+ setDefaultNoOfProps(
+ getWidth()/
+ (Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Property.SPACING_FOR_COMPOSITE));
+
+ referenceHeight();
+ serviceHeight();
+ propertyLength();
+ }
+
+
+
+// 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/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
index 711a5b5394..b9a38a0deb 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
@@ -6,11 +6,14 @@ 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
@@ -19,6 +22,9 @@ public abstract class Entity {
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>();
@@ -41,14 +47,14 @@ public abstract class Entity {
public int getX() {
return x;
}
- public void setX(int x) {
- this.x = x;
+ public void setX(int init) {
+ this.x = init + width * spaceFactor * lane;
}
public int getY() {
return y;
}
- public void setY(int y) {
- this.y = y;
+ public void setY(int init) {
+ this.y = init + height * spaceFactor * level;
}
public int getLevel() {
return level;
@@ -183,6 +189,36 @@ public abstract class Entity {
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/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
index e8c7bf76e8..4157f93409 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
@@ -38,8 +38,9 @@ public class EntityBuilder {
private int totalWidth=0;
private int totalHeight=0;
private ComponentEntity startEnt = null;
- private String compositeName;
- ComponentEntity[] elts = null;
+ //private String compositeName;
+
+ CompositeEntity composite = null;
/**
* Constructor which initiates the DOM document
@@ -49,6 +50,263 @@ public class EntityBuilder {
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, composite);
+
+ //System.out.println("ComponentEntity "+comps[0].getLevel());
+ int[][] conns = buildConnectionMatrix(comps);
+
+ composite.setComponentList(comps);
+ composite.setConnections(conns);
+
+ LayoutBuilder buildLayout = new LayoutBuilder(comps , conns);
+ buildLayout.buildEntities();
+
+
+ System.out.println("conns "+conns[0][0]);
+
+
+ buildCompositeService(docEle, composite);
+ buildCompositeReference(docEle, composite);
+ buildCompositeProperty(docEle, composite);
+
+ 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, Entity parent) {
+
+ for(ComponentEntity comp: comps){
+ comp.setParent(parent);
+ }
+ }
+
+ private void buildCompositeService(Element docEle,
+ CompositeEntity composite) {
+
+ 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,
+ CompositeEntity composite) {
+
+ 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 target = elt.getAttribute("promote");
+
+ 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,
+ CompositeEntity composite) {
+
+ 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 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;
+ }
+
/**
* Layout Building Algorithm
* ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -76,79 +334,146 @@ public class EntityBuilder {
*
* @return
*/
- public ComponentEntity[] buildEntities(){
+ public ComponentEntity[] buildComponentEntities(Element docEle){
- //get the root element
- Element docEle = dom.getDocumentElement();
- compositeName = docEle.getAttribute("name");
- System.out.println("compositeName "+compositeName);
+ 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
- nl = docEle.getElementsByTagName("wire");
- System.out.println("^^^^^^^^^ "+nl.getLength());
+ 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;
- System.out.println("^^^^^^^^^ "+source+" ::: "+target);
- if(target.contains("/")){
- String[] arr = target.split("/");
- serviceComp = arr[0];
- service = arr[1];
- }
- else{
- serviceComp = target;
- service = null;
- }
+ String[] arr1 = extractComp(target);
+ serviceComp = arr1[0];
+ service = arr1[1];
- if(source.contains("/")){
- String[] arr = source.split("/");
- referenceComp = arr[0];
- reference = arr[1];
- }
- else{
- referenceComp = source;
- reference = null;
- }
+ 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);
- ComponentEntity e = findEntity(referenceComp);
- System.out.println("^^^^^^^^^ "+e.getName());
- if(e != null){
- createConnection(e, reference, serviceComp, service);
+ System.out.println("^^^^^^^^^ "+e1.getName());
+ if(e1 != null){
+ System.out.println("^^^^^^^^^ "+e1.getId());
+ //connections[e1.getId()][e2.getId()] = 1;
+ createConnection(e1, reference, serviceComp, service);
}
}
}
- positionEntities(elts);
-
- calculateProperties(elts);
- print(elts);
-
- return elts;
-
}
-
- private ComponentEntity findEntity(String componentName) {
+
+ private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
for(ComponentEntity e: elts){
if(e.getName().equals(componentName)){
@@ -192,13 +517,13 @@ public class EntityBuilder {
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);
+
+ ent.addToRefToSerMap(reference, service);
+ ent.addAnAdjacentEntity(serviceComp);
+ addToConnectedEntities(referenceComp, serviceComp);
+ addToConnectedEntities(serviceComp, referenceComp);
}
else if(reference == null && service != null){
ent.addToRefToSerMap(referenceComp, service);
@@ -220,25 +545,25 @@ public class EntityBuilder {
}
}
- 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 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;
- }
+// private int max(int a, int b){
+// if(a>=b)
+// return a;
+// return b;
+// }
private void print(ComponentEntity[] elts) {
@@ -249,91 +574,91 @@ public class EntityBuilder {
}
}
- 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 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("/");
+// }
@@ -368,7 +693,7 @@ public class EntityBuilder {
for(int i = 0 ; i < nl1.getLength();i++) {
Element elt = (Element)nl1.item(i);
System.out.println(elt.getAttribute("class"));
- String serName = elt.getAttribute("class").split("\\.")[1];
+ String serName = extractServiceName(elt.getAttribute("class"));
ent.addAService(serName);
}
}
@@ -377,6 +702,26 @@ public class EntityBuilder {
}
+ /**
+ *
+ * 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");
@@ -388,13 +733,13 @@ public class EntityBuilder {
}
}
- public void setCompositeName(String compositeName) {
- this.compositeName = compositeName;
- }
-
- public String getCompositeName() {
- return compositeName;
- }
+// public void setCompositeName(String compositeName) {
+// this.compositeName = compositeName;
+// }
+//
+// public String getCompositeName() {
+// return compositeName;
+// }
public int getTotalWidth() {
return totalWidth;
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java
new file mode 100755
index 0000000000..07f432d6a3
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java
@@ -0,0 +1,152 @@
+/*
+ * 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.impl.layout;
+
+public class LayoutBuilder {
+
+ private Entity[] elts = null;
+ private int[][] conns = null;
+ private Entity startEnt = null;
+ private int currentMaxLevel= 0;
+ private int startPosition = 250;
+
+ /**
+ * 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[] buildEntities(){
+
+ /**
+ * Finding the starting entity
+ */
+ for(int i = 0 ; i < elts.length; i++) {
+
+ Entity ent = elts[i];
+ if( isConnected(ent.getId()) ){
+ setPosition(ent, 0, 0);
+ startEnt = ent;
+ System.out.println("startEnt "+ent.getName());
+ break;
+ }
+
+ }
+
+ assignPositions(startEnt);
+ assignCoordinates();
+
+ return elts;
+
+ }
+
+ 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
+ }
+ else if(nextEnt != null){
+ 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);
+ }
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
index dd5762bc5e..0ab086b92a 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
@@ -25,7 +25,9 @@ import org.apache.tuscany.sca.impl.diagram.DiagramGenerator;
import org.apache.tuscany.sca.impl.io.XMLReader;
import org.apache.tuscany.sca.impl.io.XMLWriter;
import org.apache.tuscany.sca.impl.layout.ComponentEntity;
+import org.apache.tuscany.sca.impl.layout.CompositeEntity;
import org.apache.tuscany.sca.impl.layout.EntityBuilder;
+import org.apache.tuscany.sca.impl.layout.LayoutBuilder;
import org.w3c.dom.Document;
public class Main {
@@ -38,12 +40,22 @@ public class Main {
public static void main(String[] args) throws Exception {
XMLReader reader = new XMLReader();
- Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite.xml");
+ Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite_with_compositeService.xml");//composite1.xml composite_with_compositeService.xml");
EntityBuilder eb = new EntityBuilder(doc);
- ComponentEntity[] ents =eb.buildEntities();
- DiagramGenerator dg = new DiagramGenerator(ents, eb.getTotalHeight(), eb.getTotalWidth(), eb.getCompositeName());
+ CompositeEntity comp =eb.buildCompositeEntity();
+ System.out.println("comp "+comp.getName());
+
+// ComponentEntity[] ents = comp.getComponentList();
+// int[][] conns = comp.getConnections();
+// System.out.println("entConns "+conns.length);
+// LayoutBuilder buildLayout = new LayoutBuilder(ents , conns);
+// buildLayout.buildEntities();
+
+ //DiagramGenerator dg = new DiagramGenerator(ents, eb.getTotalHeight(), eb.getTotalWidth(), eb.getCompositeName());
+ DiagramGenerator dg = new DiagramGenerator(comp);
Document svg =dg.buildSVGDocument();
- File outFile = new File(outFileDir+eb.getCompositeName()+"_diagram.svg");
+
+ File outFile = new File(outFileDir+comp.getName()+"_diagram.svg");
XMLWriter writer = new XMLWriter();
writer.fileWriter(svg, outFile);
}