summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src')
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java8
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java83
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Layer.java16
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Link.java41
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/NormalWire.java17
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Text.java4
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java52
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java306
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java18
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java45
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java33
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java144
14 files changed, 555 insertions, 216 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
index 66f99a739b..e42baa68ee 100644
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
@@ -51,9 +51,9 @@ public class Composite extends Artifact{
return rectangle;
}
- //OBSOLETE
- public Element addElement(Document document, String svgNs, int x, int y) {
- return null;
- }
+// //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/DashedWire.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/DashedWire.java
index c9381c9d50..9fc9144f5f 100755
--- 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
@@ -24,54 +24,61 @@ import org.w3c.dom.Element;
public class DashedWire extends Wire{
-
- public Element addElement(Document document, String svgNs,
- Reference aReference1, Reference aReference2){
+ @Override
+ public Element addElement(Document document, String svgNs, Object a,
+ Object b, int changingFactor, String color) {
Element polyline = document.createElementNS(svgNs, "polyline");
- int x1=aReference1.getxCoordinate()+aReference1.getHeight()*3/2;
- int y1=aReference1.getyCoordinate()+aReference1.getHeight()/2;
+ int x1=0,x2=0,y1=0,y2=0;
- 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");
+ if(a instanceof Service && b instanceof Service){
+
+ Service aService1 = (Service)a;
+ Service aService2 = (Service)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;
+
+ }
- return polyline;
- }
+ else if(a instanceof Reference && b instanceof Reference){
+
+ Reference aReference1 = (Reference)a;
+ Reference aReference2 = (Reference)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);
- 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;
- }
+
+ /**
+ * <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/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
index 36d3d29f20..22ec76ff09 100755
--- 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
@@ -23,7 +23,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
- * Structure of a "Composite" element in SCA, as a SVG element
+ * Structure of a "Outermost layer" : not a SCA artifact
*
*/
public class Layer extends Artifact{
@@ -50,10 +50,14 @@ public class Layer extends Artifact{
return rectangle;
}
-
- //OBSOLETE
- public Element addElement(Document document, String svgNs, int x, int y) {
- return null;
- }
+ 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/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Link.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Link.java
new file mode 100755
index 0000000000..e03edfd0e2
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/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.impl.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/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
index 5ceece65bc..54fe2f5d04 100755
--- 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
@@ -24,9 +24,12 @@ import org.w3c.dom.Element;
public class NormalWire extends Wire{
-
- public Element addElement(Document document, String svgNs,
- Reference aReference, Service aService){
+ @Override
+ public Element addElement(Document document, String svgNs, Object a,
+ Object b, int changingFactor, String color) {
+
+ Reference aReference = (Reference)a;
+ Service aService = (Service)b;
Element polyline = document.createElementNS(svgNs, "polyline");
int x1=aReference.getxCoordinate()+aReference.getHeight()*3/2;
@@ -34,12 +37,8 @@ public class NormalWire extends Wire{
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");
+
+ polyline = setWireAttributes(x1, y1, x2, y2, polyline, changingFactor, color);
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 7457084eb6..40edf226c0 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
@@ -29,9 +29,9 @@ public class Text {
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, "text-anchor", "middle");
text.setAttributeNS(null, "dominant-baseline", "mathematical");
- text.setAttributeNS(null, "font-size", "20");
+ text.setAttributeNS(null, "font-size", "15");
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 9c91ccc361..e173365f4a 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
@@ -23,26 +23,42 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
public abstract class Wire {
-
-
+
public abstract Element addElement(Document document, String svgNs,
- Reference aReference, Service aService); //{
+ 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");
-// 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;
-// }
+ 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 742575f501..57b9ffea40 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
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.impl.diagram;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Map.Entry;
@@ -28,6 +29,7 @@ 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.Link;
import org.apache.tuscany.sca.impl.artifacts.NormalWire;
import org.apache.tuscany.sca.impl.artifacts.Property;
import org.apache.tuscany.sca.impl.artifacts.Reference;
@@ -42,69 +44,77 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class DiagramGenerator {
-
+
private CompositeEntity comp;
-// private Entity[] entities;
-// private int height, width;
private Document doc;
-// private String compositeName;
private String svgNS ;
private Element svgRoot;
private ArrayList<Reference> refs= new ArrayList<Reference>();
private ArrayList<Service> sers= new ArrayList<Service>();
+
+ 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 compositeName
- * with a given height and a width and consisting of entities.
+ * Constructor to generate a SVG diagram for a given CompositeEntity
+ * Object.
*/
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);
// 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: comp.getComponentList()){
-
+
+ for(ComponentEntity ent: comp.getComponentList()){
+
addComponent(ent);
- addService(ent);
- addReference(ent);
- addProperties(ent);
+ addComponentService(ent);
+ addComponentReference(ent);
+ addComponentProperties(ent);
}
-
- addCompositeService(comp);
- addCompositeReference(comp);
- addCompositeProperties(comp);
-
+
+ addCompositeService();
+ addCompositeReference();
+ addCompositeProperties();
+
addComponentConnections();
addReferencePromotion();
addServicePromotion();
+ addInclusions();
+
return doc;
}
-
-
private void addLayer() {
@@ -112,7 +122,7 @@ public class DiagramGenerator {
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();
@@ -120,10 +130,10 @@ public class DiagramGenerator {
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);
}
@@ -137,27 +147,54 @@ public class DiagramGenerator {
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);
}
}
}
-
+ private void addInclusions() {
+ Layer inclusionLayer = new Layer();
+ int constant = 5;
+ int x0 = comp.getX()+constant;
+ int y0 = comp.getY()+comp.getHeight()-(Component.DEFAULT_HEIGHT/2+constant);
+ int height = 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, "");
+
+ for(String includedComposite : comp.getIncludedComposites()){
+
+ Link link = new Link();
+ Element aLink = link.addElement(doc, svgNS, includedComposite+comp.getFileNameSuffix(), includedComposite);
+ text.appendChild(aLink);
+
+ }
+ svgRoot.appendChild(text);
+ }
+
/**
* Connects references to services.
*/
private void addComponentConnections() {
for(Entity ent: comp.getComponentList()){
- if(ent instanceof ComponentEntity){
-
+ //if(ent instanceof ComponentEntity){
+
for(Iterator it= ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator();
- it.hasNext();){
+ it.hasNext();){
Entry entry = (Entry) it.next();
String ref = (String)entry.getKey();
String ser = (String)entry.getValue();
@@ -169,28 +206,48 @@ public class DiagramGenerator {
addWire(r,s);
}
}
- }
+ //}
}
}
- private void addWire(Reference r, Service 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(Reference r, Service s) {
+
Wire edge = new NormalWire();
- Element wire = edge.addElement(doc, svgNS, r, s);
+ Element wire = edge.addElement(doc, svgNS, r, s, getChangingFactor(), getColor());
svgRoot.appendChild(wire);
}
-
+
private void addWire(Service s1, Service s2) {
DashedWire edge = new DashedWire();
- Element wire = edge.addElement(doc, svgNS, s1, s2);
+ Element wire = edge.addElement(doc, svgNS, s1, s2, getChangingFactor(), getColor());
svgRoot.appendChild(wire);
}
-
+
private void addWire(Reference r1, Reference r2) {
DashedWire edge = new DashedWire();
- Element wire = edge.addElement(doc, svgNS, r1, r2);
+ Element wire = edge.addElement(doc, svgNS, r1, r2, getChangingFactor(), getColor());
svgRoot.appendChild(wire);
}
@@ -207,7 +264,7 @@ public class DiagramGenerator {
private Reference getRef(String ref) {
for(Reference r: refs){
-
+
if(r.getContainerName().equals(ref) || r.getName().equals(ref)){
return r;
}
@@ -215,7 +272,7 @@ public class DiagramGenerator {
return null;
}
- private void addProperties(Entity ent) {
+ private void addComponentProperties(ComponentEntity ent) {
int propLen = ent.getPropLength();
int x= ent.getX() + Property.SPACING_FOR_COMPONENT;
int y= ent.getY()-propLen/2;
@@ -224,18 +281,19 @@ public class DiagramGenerator {
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_COMPONENT);
-
+
pro.setName(prop);
pro.setContainerName(ent.getName());
}
}
- private void addReference(Entity ent) {
+ private void addComponentReference(ComponentEntity ent) {
+
int refHeight = ent.getRefHeight();
int x=(ent.getX()+ent.getWidth())-(refHeight*2/3);
int y=ent.getY() + Reference.SPACING_FOR_COMPONENT;
@@ -246,40 +304,30 @@ public class DiagramGenerator {
Element text = Text.addTextElement(doc, svgNS, x, y+refHeight/2, ref);
svgRoot.appendChild(polygon);
svgRoot.appendChild(text);
-
+
y += (refHeight + Reference.SPACING_FOR_COMPONENT);
-
+
refer.setName(ref);
refer.setContainerName(ent.getName());
refs.add(refer);
-
+
}
}
- private String[] setRefOrder(Entity e){
-
+ /**
+ * 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()];
- for(int i=0;i<refs.size();i++){
- sers.add(i, "");
- }
-
- if(e instanceof ComponentEntity){
- for(Iterator it= ((ComponentEntity)e).getReferenceToServiceMap().entrySet().iterator();it.hasNext();){
- Entry entry = (Entry) it.next();
- String ref = (String)entry.getKey();
- String ser = (String)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));
+ //sers = new ArrayList<String>(e.getReferenceToServiceMap().values());
- }
- }
+ sers = buildReferenceToMappingServiceList(refs, e);
for(String eName: e.getAdjacentEntities()){
for(Entity ent: comp.getComponentList()){
@@ -289,11 +337,11 @@ public class DiagramGenerator {
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);
+ //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 "+ 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;
@@ -301,7 +349,7 @@ public class DiagramGenerator {
else{
for(int i=ent.getLevel();i<orderedRefs.length;i++){
if(orderedRefs[i]== null){
-
+
orderedRefs[i] = refs.get(sers.indexOf(s));
break;
}
@@ -317,7 +365,7 @@ public class DiagramGenerator {
}
}
}
-
+
//adding references which are not connected to any service
for(String ref : refs){
for(int i=0; i<orderedRefs.length ; i++){
@@ -330,18 +378,44 @@ public class DiagramGenerator {
}
}
}
-
+
return orderedRefs;
}
-
- private void addService(Entity ent) {
+
+ 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 it= e.getReferenceToServiceMap().entrySet().iterator();
+ it.hasNext();){
+
+ Entry entry = (Entry) it.next();
+ String ref = (String)entry.getKey();
+ String ser = (String)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() + Service.SPACING_FOR_COMPONENT;
System.out.println("''''''"+ent.getName() +" '''''' "+ ent.getServices().size());
for(String ser: ent.getServices()){
-
+
Service serve= new Service();
Element polygon = serve.addElement(doc, svgNS, x, y, serHeight);
Element text;
@@ -349,20 +423,20 @@ public class DiagramGenerator {
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_COMPONENT);
-
+
serve.setName(ser);
serve.setContainerName(ent.getName());
sers.add(serve);
}
}
-
- private void addCompositeService(CompositeEntity comp) {
-
+
+ private void addCompositeService() {
+
int serHeight = comp.getSerHeight();
int x= comp.getX()-(serHeight*2/3);
int y= comp.getY() + Service.SPACING_FOR_COMPOSITE;
@@ -370,7 +444,7 @@ public class DiagramGenerator {
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;
@@ -378,20 +452,20 @@ public class DiagramGenerator {
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) {
-
+ private void addCompositeReference() {
+
int refHeight = comp.getRefHeight();
int x=(comp.getX()+comp.getWidth())-(refHeight*2/3);
int y=comp.getY() + Reference.SPACING_FOR_COMPOSITE;
@@ -402,18 +476,18 @@ public class DiagramGenerator {
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) {
+
+ private void addCompositeProperties() {
int propLen = comp.getPropLength();
int x= comp.getX() + Property.SPACING_FOR_COMPOSITE;
int y= comp.getY()-propLen/2;
@@ -422,47 +496,47 @@ public class DiagramGenerator {
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),
+ Element text = Text.addTextElement(doc, svgNS, ent.getX(),
ent.getY()+(ent.getHeight()+Component.TEXT_SPACING), ent.getName());
-
+
svgRoot.appendChild(com);
svgRoot.appendChild(text);
-
+
comp.setName(ent.getName());
}
private void addComposite() {
Composite composite = new Composite();
-
+
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(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 f85a83bdb7..7507b4ab57 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,7 +48,7 @@ public class ComponentEntity extends Entity{
public ComponentEntity(){
- super.setStartPosition(200);
+ 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
index 0adffcc44e..810c0a8f09 100755
--- 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
@@ -43,12 +43,14 @@ public class CompositeEntity extends Entity{
// 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.svg";
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 ArrayList<String> includedComposites = new ArrayList<String>();
//private HashSet<String> connectedEntities = new HashSet<String>();
@@ -201,6 +203,13 @@ public class CompositeEntity extends Entity{
promoteAReference.put(compositeRef, componentRef);
return true;
}
+
+ public boolean addToIncludedComposites(String composite){
+
+ includedComposites.add(composite);
+
+ return true;
+ }
public void setPromoteAReference(HashMap<String, String> promoteAReference) {
this.promoteAReference = promoteAReference;
@@ -252,6 +261,15 @@ public class CompositeEntity extends Entity{
}
+ public ArrayList<String> getIncludedComposites() {
+ return includedComposites;
+ }
+
+ public String getFileNameSuffix() {
+ return fileNameSuffix;
+ }
+
+
// public int getNoOfRefs(){
// return references.size();
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 4157f93409..07ee0d7c75 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
@@ -63,7 +63,7 @@ public class EntityBuilder {
composite = new CompositeEntity(compositeName);
- setParent(comps, composite);
+ setParent(comps);
//System.out.println("ComponentEntity "+comps[0].getLevel());
int[][] conns = buildConnectionMatrix(comps);
@@ -72,21 +72,25 @@ public class EntityBuilder {
composite.setConnections(conns);
LayoutBuilder buildLayout = new LayoutBuilder(comps , conns);
- buildLayout.buildEntities();
+ buildLayout.placeEntities();
System.out.println("conns "+conns[0][0]);
- buildCompositeService(docEle, composite);
- buildCompositeReference(docEle, composite);
- buildCompositeProperty(docEle, composite);
+ buildCompositeService(docEle);
+ buildCompositeReference(docEle);
+ buildCompositeProperty(docEle);
+
+ addInclusions(docEle);
composite.setAttributes();
return composite;
}
+
+
// private void assignCoordinates() {
//
// for(Entity ent: elts){
@@ -95,15 +99,14 @@ public class EntityBuilder {
// }
// }
- private void setParent(ComponentEntity[] comps, Entity parent) {
+ private void setParent(ComponentEntity[] comps) {
for(ComponentEntity comp: comps){
- comp.setParent(parent);
+ comp.setParent(composite);
}
}
- private void buildCompositeService(Element docEle,
- CompositeEntity composite) {
+ private void buildCompositeService(Element docEle) {
NodeList nl = docEle.getElementsByTagName("service");
System.err.println("^^^^^^^^^ "+nl.getLength());
@@ -136,8 +139,7 @@ public class EntityBuilder {
}
}
- private void buildCompositeReference(Element docEle,
- CompositeEntity composite) {
+ private void buildCompositeReference(Element docEle) {
NodeList nl = docEle.getElementsByTagName("reference");
//System.out.println("^^^^^^^^^ "+nl.getLength());
@@ -170,8 +172,7 @@ public class EntityBuilder {
}
}
- private void buildCompositeProperty(Element docEle,
- CompositeEntity composite) {
+ private void buildCompositeProperty(Element docEle) {
NodeList nl = docEle.getElementsByTagName("property");
//System.out.println("^^^^^^^^^ "+nl.getLength());
@@ -188,6 +189,24 @@ public class EntityBuilder {
}
}
}
+
+ 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) {
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
index 07f432d6a3..c2acdf8f89 100755
--- 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
@@ -25,7 +25,6 @@ public class LayoutBuilder {
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
@@ -62,7 +61,7 @@ public class LayoutBuilder {
*
*
*/
- public Entity[] buildEntities(){
+ public Entity[] placeEntities(){
/**
* Finding the starting entity
@@ -73,19 +72,29 @@ public class LayoutBuilder {
if( isConnected(ent.getId()) ){
setPosition(ent, 0, 0);
startEnt = ent;
- System.out.println("startEnt "+ent.getName());
+ //System.out.println("startEnt "+ent.getId());
break;
}
}
assignPositions(startEnt);
+ assignPositionsOfIdleEntities();
assignCoordinates();
return elts;
}
+ private void assignPositionsOfIdleEntities() {
+
+ for(Entity ent: elts){
+ if(!ent.isPossitionSet()){
+ this.setPosition(ent, ++currentMaxLevel, 0);
+ }
+ }
+ }
+
private void assignCoordinates() {
for(Entity ent: elts){
@@ -102,10 +111,10 @@ public class LayoutBuilder {
if( entConns[i] == 1 ){
Entity nextEnt = findEntity(i);
- if(nextEnt.isPossitionSet()){
- currentMaxLevel = nextEnt.getLevel()+1; // for diagram clearness purpose
- }
- else if(nextEnt != null){
+// if(nextEnt.isPossitionSet()){
+// currentMaxLevel = nextEnt.getLevel()+1; // for diagram clearness purpose
+// }
+ if(nextEnt != null && !nextEnt.isPossitionSet()){
setPosition(nextEnt, currentMaxLevel, ent.getLane()+1);
assignPositions(nextEnt);
}
@@ -131,7 +140,7 @@ public class LayoutBuilder {
private boolean isConnected(int id) {
int[] entConns = conns[id];
- System.out.println("entConns "+entConns.length);
+ //System.out.println("entConns "+entConns.length);
for(int i=0; i<entConns.length; i++){
if(entConns[i] == 1){
@@ -149,4 +158,12 @@ public class LayoutBuilder {
ent.setPossitionSet(true);
}
+ public Entity getStartEnt() {
+ return startEnt;
+ }
+
+ public void setStartEnt(Entity startEnt) {
+ this.startEnt = startEnt;
+ }
+
}
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 0ab086b92a..4dc0799d8d 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
@@ -55,7 +55,7 @@ public class Main {
DiagramGenerator dg = new DiagramGenerator(comp);
Document svg =dg.buildSVGDocument();
- File outFile = new File(outFileDir+comp.getName()+"_diagram.svg");
+ File outFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix());
XMLWriter writer = new XMLWriter();
writer.fileWriter(svg, outFile);
}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java
new file mode 100755
index 0000000000..3c3e96c0f2
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java
@@ -0,0 +1,144 @@
+package org.apache.tuscany.sca.test.layout;
+
+import static org.junit.Assert.*;
+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(2, 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());
+
+ }
+}