From 94ef23a1a25f056e0bf8f96d4bb97312ebc86f8b Mon Sep 17 00:00:00 2001 From: nirmal070125 Date: Sat, 6 Aug 2011 18:20:14 +0000 Subject: added support to inclusion, added a test case to demonstrate layout algorithm git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1154566 13f79535-47bb-0310-9956-ffa450edef68 --- .../input/composite_with_compositeService.xml | 4 +- .../output/CalculatorTest_diagram.svg | 2 +- .../output/Calculator_diagram.svg | 2 +- .../output/MyValueComposite2_diagram.svg | 1 + .../output/store_diagram.svg | 2 +- .../output/supplychain_diagram.svg | 2 +- .../tuscany/sca/impl/artifacts/Composite.java | 8 +- .../tuscany/sca/impl/artifacts/DashedWire.java | 83 +++--- .../apache/tuscany/sca/impl/artifacts/Layer.java | 16 +- .../apache/tuscany/sca/impl/artifacts/Link.java | 41 +++ .../tuscany/sca/impl/artifacts/NormalWire.java | 17 +- .../apache/tuscany/sca/impl/artifacts/Text.java | 4 +- .../apache/tuscany/sca/impl/artifacts/Wire.java | 52 ++-- .../tuscany/sca/impl/diagram/DiagramGenerator.java | 306 +++++++++++++-------- .../tuscany/sca/impl/layout/ComponentEntity.java | 2 +- .../tuscany/sca/impl/layout/CompositeEntity.java | 18 ++ .../tuscany/sca/impl/layout/EntityBuilder.java | 45 ++- .../tuscany/sca/impl/layout/LayoutBuilder.java | 33 ++- .../java/org/apache/tuscany/sca/main/Main.java | 2 +- .../tuscany/sca/test/layout/LayoutBuilderTest.java | 144 ++++++++++ 20 files changed, 563 insertions(+), 221 deletions(-) create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Link.java create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java (limited to 'collaboration') 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 1cbc78b56d..722bdeb0a5 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml @@ -8,7 +8,9 @@ name="MyValueComposite2" > - + + + diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/CalculatorTest_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/CalculatorTest_diagram.svg index c029859d70..76052e23f7 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/CalculatorTest_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/CalculatorTest_diagram.svg @@ -1 +1 @@ -CalculatorTestCalculatorServiceComponentsubtractServicedivideServicemultiplyServiceaddServiceAddServiceComponentSubtractServiceComponentMultiplyServiceComponentDivideServiceComponent \ No newline at end of file +CalculatorTestCalculatorServiceComponentCalculatorServiceaddServicesubtractServicemultiplyServicedivideServiceAddServiceComponentAddServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServiceDivideServiceComponentDivideService \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg index 6ba9f5c579..70540cfe70 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg @@ -1 +1 @@ -CalculatorCalculatorServiceComponentsubtractServicedivideServicemultiplyServiceaddServiceAddServiceComponentSubtractServiceComponentMultiplyServiceComponentDivideServiceComponent \ No newline at end of file +CalculatorCalculatorServiceComponentCalculatorServiceaddServicesubtractServicemultiplyServicedivideServiceAddServiceComponentAddServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServiceDivideServiceComponentDivideServiceIncluded Composites \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg new file mode 100755 index 0000000000..9616f4fb2d --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg @@ -0,0 +1 @@ +MyValueComposite2MyValueServiceComponentmyValueServicestockQuoteServicecustomerServicecurrencyStockQuoteMediatorComponentSQMediatorstockQuoteServicecurrencyMyValueServiceCustomerServiceStockQuoteServiceIncluded Composites store , Calculator , supplychain , \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg index b37a777601..46eea2290d 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg @@ -1 +1 @@ -storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogCatalogcurrencyConvertercurrencyCodeShoppingCartCartTotalCurrencyConverterCurrencyConverter +storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogCatalogcurrencyConvertercurrencyCodeShoppingCartCartTotalCurrencyConverterCurrencyConverterIncluded Composites \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg index d74fd8a16c..a56a2c1c79 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg @@ -1 +1 @@ -supplychainCustomerComponentCustomerComponentretailerRetailerComponentRetailerComponentwarehouseWarehouseComponentWarehouseComponentshipperShipperComponentShipperComponentcustomer \ No newline at end of file +supplychainCustomerComponentCustomerComponentretailerRetailerComponentRetailerComponentwarehouseWarehouseComponentWarehouseComponentshipperShipperComponentShipperComponentcustomerIncluded Composites \ No newline at end of file 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; - } + + /** + * + ]]> + + + + */ } 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 refs= new ArrayList(); private ArrayList sers= new ArrayList(); + + 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 refs = e.getReferences(); ArrayList sers = new ArrayList(); String[] orderedRefs = new String[refs.size()]; - for(int i=0;i(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 buildReferenceToMappingServiceList(ArrayList refs, ComponentEntity e) { + + ArrayList sers = new ArrayList(); + + for(int i=0;i promoteAService = new HashMap(); private HashMap promoteAReference = new HashMap(); + private ArrayList includedComposites = new ArrayList(); //private HashSet connectedEntities = new HashSet(); @@ -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 promoteAReference) { this.promoteAReference = promoteAReference; @@ -252,6 +261,15 @@ public class CompositeEntity extends Entity{ } + public ArrayList 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; i2 && 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()); + + } +} -- cgit v1.2.3