From 3dd877e74fd7d6acfab5f0e09cf7df8024f42586 Mon Sep 17 00:00:00 2001 From: nirmal070125 Date: Tue, 26 Jul 2011 13:00:55 +0000 Subject: Refactored the code a bit git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1151079 13f79535-47bb-0310-9956-ffa450edef68 --- .../input/composite_with_compositeService.xml | 89 +++++++ .../output/store_diagram.svg | 2 +- .../tuscany/sca/impl/artifacts/Artifact.java | 4 +- .../tuscany/sca/impl/artifacts/Component.java | 3 - .../tuscany/sca/impl/artifacts/Composite.java | 2 - .../tuscany/sca/impl/artifacts/Property.java | 12 +- .../tuscany/sca/impl/artifacts/Reference.java | 13 +- .../apache/tuscany/sca/impl/artifacts/Service.java | 15 +- .../tuscany/sca/impl/diagram/DiagramGenerator.java | 118 ++++---- .../tuscany/sca/impl/layout/ComponentEntity.java | 251 +++++++++++++++++ .../org/apache/tuscany/sca/impl/layout/Entity.java | 296 +++++++-------------- .../tuscany/sca/impl/layout/EntityBuilder.java | 69 ++--- .../java/org/apache/tuscany/sca/main/Main.java | 6 +- 13 files changed, 563 insertions(+), 317 deletions(-) create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.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 new file mode 100755 index 0000000000..4dc8353a53 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_with_compositeService.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + EURO + + + + + + + + + + + + + + + + + + + + EURO + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 db517b9b29..5cf0528cc6 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg @@ -1 +1 @@ -storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogCatalogcurrencyConvertercurrencyCodeShoppingCartCartTotalCurrencyConverter \ No newline at end of file +storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogCatalogcurrencyConvertercurrencyCodeShoppingCartCartTotalCurrencyConverter \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java index 849d440c2d..a2093dbf10 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java @@ -47,8 +47,8 @@ public abstract class Artifact { public abstract Element addElement(Document document, String svgNs, int x, int y, int height, int width); - public abstract Element addElement(Document document, String svgNs, - int x, int y); +// public abstract Element addElement(Document document, String svgNs, +// int x, int y); public int getHeight() { return height; diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java index 9254657547..6b69c488f1 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java @@ -62,7 +62,4 @@ public class Component extends Artifact{ } - - - } 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 8b04759bee..66f99a739b 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 @@ -56,6 +56,4 @@ public class Composite extends Artifact{ return null; } - - } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java index ea6b0b9eeb..0b437ecb1c 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java @@ -24,8 +24,10 @@ import org.w3c.dom.Element; public class Property extends Artifact{ - public static final int MAXIMUM_HEIGHT = 20 ; //default value - public static final int SPACING = 20 ; //default value + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT = 20 ; + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE = 60 ; + public static final int SPACING_FOR_COMPONENT = 20 ; + public static final int SPACING_FOR_COMPOSITE = 60 ; /** @@ -62,11 +64,5 @@ public class Property extends Artifact{ return addElement(document, svgNs, x, y, height, height); } - - public Element addElement(Document document, String svgNs, int x, int y) { - - - return addElement(document, svgNs, x, y, MAXIMUM_HEIGHT); - } } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java index f89fc2ab5f..6538dd0caa 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java @@ -24,8 +24,11 @@ import org.w3c.dom.Element; public class Reference extends Artifact { - public static final int MAXIMUM_HEIGHT = 30 ; //default value - public static final int SPACING = 10 ; //default value + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT = 30 ; + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE = 90 ; + public static final int SPACING_FOR_COMPONENT = 10 ; + public static final int SPACING_FOR_COMPOSITE = 30 ; + /** @@ -70,10 +73,4 @@ public class Reference extends Artifact { return this.addElement(document, svgNs, x, y, height, height*3/2); } - - public Element addElement(Document document, String svgNs, int x, int y) { - - return this.addElement(document, svgNs, x, y, MAXIMUM_HEIGHT); - } - } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java index 37adb65f39..0faf5fd789 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java @@ -24,8 +24,10 @@ import org.w3c.dom.Element; public class Service extends Artifact{ - public static final int MAXIMUM_HEIGHT = 30 ; //default value - public static final int SPACING = 10 ; //default value + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT = 30 ; + public static final int DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE = 90 ; + public static final int SPACING_FOR_COMPONENT = 10 ; + public static final int SPACING_FOR_COMPOSITE = 30 ; /** @@ -77,14 +79,5 @@ public class Service extends Artifact{ return this.addElement(document, svgNs, x, y, height, height*3/2); } - /** - * Use default height - */ - public Element addElement(Document document, String svgNs, int x, int y) { - - return this.addElement(document, svgNs, x, y, MAXIMUM_HEIGHT); - } - - } 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 39addafe40..031ff25e95 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 @@ -31,6 +31,7 @@ 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.Entity; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; @@ -38,15 +39,19 @@ import org.w3c.dom.Element; public class DiagramGenerator { - Entity[] entities; - int height, width; - Document doc; - String compositeName; - String svgNS ; - Element svgRoot; - ArrayList refs= new ArrayList(); - ArrayList sers= new ArrayList(); + 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(); + /** + * 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; @@ -54,6 +59,9 @@ public class DiagramGenerator { this.compositeName = compositeName; } + /** + * Draws the diagram. + */ public Document buildSVGDocument(){ DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; @@ -63,6 +71,7 @@ public class DiagramGenerator { svgRoot = doc.getDocumentElement(); addComposite(); + for(Entity ent: entities){ addComponent(ent); addService(ent); @@ -70,23 +79,36 @@ public class DiagramGenerator { addProperties(ent); } + addConnections(); + + return doc; + } + + /** + * Connects references to services. + */ + private void addConnections() { + for(Entity ent: entities){ - for(Iterator it= ent.getReferenceToServiceMap().entrySet().iterator();it.hasNext();){ - Entry entry = (Entry) it.next(); - String ref = (String)entry.getKey(); - String ser = (String)entry.getValue(); + if(ent instanceof ComponentEntity){ - Reference r = getRef(ref); - Service s = getSer(ser); - - if(r != null && s != null){ - addWire(r,s); + for(Iterator it= ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator(); + it.hasNext();){ + Entry entry = (Entry) it.next(); + String ref = (String)entry.getKey(); + String ser = (String)entry.getValue(); + + Reference r = getRef(ref); + Service s = getSer(ser); + + if(r != null && s != null){ + addWire(r,s); + } } } } - return doc; } - + private void addWire(Reference r, Service s) { Wire edge = new Wire(); @@ -117,7 +139,7 @@ public class DiagramGenerator { private void addProperties(Entity ent) { int propLen = ent.getPropLength(); - int x=ent.getX()+Property.SPACING; + int x= ent.getX() + Property.SPACING_FOR_COMPONENT; int y= ent.getY()-propLen/2; for(String prop: ent.getProperties()){ @@ -128,17 +150,17 @@ public class DiagramGenerator { svgRoot.appendChild(property); svgRoot.appendChild(text); - x += (propLen + Property.SPACING); + x += (propLen + Property.SPACING_FOR_COMPONENT); pro.setName(prop); - pro.setContainerName(ent.getComponentName()); + pro.setContainerName(ent.getName()); } } private void addReference(Entity ent) { int refHeight = ent.getRefHeight(); int x=(ent.getX()+ent.getWidth())-(refHeight*2/3); - int y=ent.getY()+Reference.SPACING; + int y=ent.getY() + Reference.SPACING_FOR_COMPONENT; for(String ref: setRefOrder(ent)){ Reference refer= new Reference(); @@ -147,10 +169,10 @@ public class DiagramGenerator { svgRoot.appendChild(polygon); svgRoot.appendChild(text); - y += (refHeight + Reference.SPACING); + y += (refHeight + Reference.SPACING_FOR_COMPONENT); refer.setName(ref); - refer.setContainerName(ent.getComponentName()); + refer.setContainerName(ent.getName()); refs.add(refer); } @@ -166,33 +188,35 @@ public class DiagramGenerator { 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)); - + 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)); + + } } for(String eName: e.getAdjacentEntities()){ for(Entity ent: entities){ - if(ent.getComponentName().equals(eName)){ + if(ent.getName().equals(eName)){ for(String s : sers){ for(String s1: ent.getServices()){ //System.err.println("XXXXX "+ s1 +" ::: "+s); - if(s1.equals(s) || s.equals(ent.getComponentName())){ + if(s1.equals(s) || s.equals(ent.getName())){ System.err.println("|||||||| "+ sers.size()+ " ||| " + refs.size()+"|| "+orderedRefs.length); if(orderedRefs[ent.getLevel()] == null){ - System.err.println("XXXXX "+ sers.get(1)+ " ::::::: "+refs.get(1)); + //System.err.println("XXXXX "+ sers.get(1)+ " ::::::: "+refs.get(1)); // System.err.println("XXXXX "+ sers.get(2)+ " ::::::: "+refs.get(2)); // System.err.println("XXXXX "+ sers.get(3)+ " ::::::: "+refs.get(3)); - System.err.println("XXXXX "+ refs.get(sers.indexOf(s))+" ::: "+ent.getLevel()+" ::: "+ent.getComponentName()); + System.err.println("XXXXX "+ refs.get(sers.indexOf(s))+" ::: "+ent.getLevel()+" ::: "+ent.getName()); orderedRefs[ent.getLevel()] = refs.get(sers.indexOf(s)); break; } @@ -221,10 +245,12 @@ public class DiagramGenerator { private void addService(Entity ent) { int serHeight = ent.getSerHeight(); - int x=ent.getX()-(serHeight*2/3); - int y=ent.getY()+Service.SPACING; + 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; @@ -236,10 +262,10 @@ public class DiagramGenerator { svgRoot.appendChild(polygon); svgRoot.appendChild(text); - y += (serHeight + Service.SPACING); + y += (serHeight + Service.SPACING_FOR_COMPONENT); serve.setName(ser); - serve.setContainerName(ent.getComponentName()); + serve.setContainerName(ent.getName()); sers.add(serve); } } @@ -250,12 +276,12 @@ public class DiagramGenerator { 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), - ent.getY()+(ent.getHeight()+Component.TEXT_SPACING), ent.getComponentName()); + ent.getY()+(ent.getHeight()+Component.TEXT_SPACING), ent.getName()); svgRoot.appendChild(com); svgRoot.appendChild(text); - comp.setName(ent.getComponentName()); + comp.setName(ent.getName()); } private void addComposite() { 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 new file mode 100755 index 0000000000..4feaaff635 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java @@ -0,0 +1,251 @@ +/* + * 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.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 ComponentEntity extends Entity{ + +// private String componentName; +// private int X, Y, level=-1, lane=-1, refHeight, serHeight, propLength; +// private final int height= Component.DEFAULT_HEIGHT, width= Component.DEFAULT_WIDTH; +// public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / (Service.MAXIMUM_HEIGHT+Service.SPACING); +// public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers +// public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING); + + private HashMap referenceToServiceMap = new HashMap(); + //private HashSet connectedEntities = new HashSet(); + + + public ComponentEntity(){ + + setHeight(Component.DEFAULT_HEIGHT); + setWidth(Component.DEFAULT_WIDTH); + + setDefaultNoOfSers( + Component.DEFAULT_HEIGHT / + (Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Service.SPACING_FOR_COMPONENT)); + setDefaultNoOfRefs( + Component.DEFAULT_HEIGHT / + (Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Reference.SPACING_FOR_COMPONENT)); + setDefaultNoOfProps( + Component.DEFAULT_WIDTH / + (Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Property.SPACING_FOR_COMPONENT)); + } + + public void referenceHeight(){ + if(getDefaultNoOfRefs() < getNoOfRefs()){ + + setRefHeight((Component.DEFAULT_HEIGHT / getNoOfRefs()) - Reference.SPACING_FOR_COMPONENT); + } + else + setRefHeight(Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + } + + public void serviceHeight(){ + if(getDefaultNoOfSers() < getNoOfSers()){ + + setSerHeight((Component.DEFAULT_HEIGHT / getNoOfSers()) - Service.SPACING_FOR_COMPONENT); + } + else + setSerHeight(Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + } + + public void propertyLength(){ + if(getDefaultNoOfProps() < getNoOfProps()){ + + setPropLength((Component.DEFAULT_WIDTH / getNoOfProps()) - Property.SPACING_FOR_COMPONENT); + } + else + setPropLength(Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + } + + /** + * 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 getReferenceToServiceMap() { + return referenceToServiceMap; + } + + public void setReferenceToServiceMap( + HashMap referenceToServiceMap) { + this.referenceToServiceMap = referenceToServiceMap; + } + + +// public int getNoOfRefs(){ +// return references.size(); +// } +// +// public int getNoOfSers(){ +// return services.size(); +// } +// +// public int getNoOfProps(){ +// return properties.size(); +// } +// +// public int getNoOfAdjacentUnits(){ +// return adjacentEntities.size(); +// } +// +// /** +// * Put a value to referenceToServiceMap +// * @param ref +// * @param ser +// * @return successfully added or not +// */ +// //assumption there can not be two services for the same reference +// public boolean addToRefToSerMap(String ref, String ser){ +// //ref = ref.toLowerCase(); +// //ser = ser.toLowerCase(); +// +// if (referenceToServiceMap.containsKey(ref)) +// return false; +// +// referenceToServiceMap.put(ref, ser); +// return true; +// } +// +// /** +// * Retrieve a service name for a given reference +// * @param ref +// * @return service name +// */ +// public String getSerOfRef(String ref){ +// //ref = ref.toLowerCase(); +// +// if (!referenceToServiceMap.containsKey(ref)) +// return null; +// +// return referenceToServiceMap.get(ref); +// } +// +// public void addAService(String serName){ +// //serName = serName.toLowerCase(); +// services.add(serName); +// +// } +// +// public void addAReference(String refName){ +// //refName = refName.toLowerCase(); +// references.add(refName); +// +// } +// +// public void addAProperty(String propName){ +// //propName = propName.toLowerCase(); +// properties.add(propName); +// +// } +// +// public void addAnAdjacentEntity(String x){ +//// System.out.println("eee "+x); +// adjacentEntities.add(x); +// +// } +// +// public void addAnConnectedEntity(String x){ +//// System.out.println("eee "+x); +// adjacentEntities.add(x); +// +// } +// +// public HashMap getReferenceToServiceMap() { +// return referenceToServiceMap; +// } +// public void setReferenceToServiceMap( +// HashMap referenceToServiceMap) { +// this.referenceToServiceMap = referenceToServiceMap; +// } +// public ArrayList getProperties() { +// return properties; +// } +// public void setProperties(ArrayList properties) { +// this.properties = properties; +// } +// public HashSet getAdjacentEntities() { +// return adjacentEntities; +// } +// public void setAdjacentEntities(HashSet adjacentEntities) { +// this.adjacentEntities = adjacentEntities; +// } +// public void setServices(ArrayList services) { +// this.services = services; +// } +// +// public ArrayList getServices() { +// return services; +// } +// +// public ArrayList getReferences() { +// return references; +// } + +// public void setConnectedEntities(HashSet connectedEntities) { +// this.connectedEntities = connectedEntities; +// } +// +// public HashSet 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 3a2a48f108..711a5b5394 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 @@ -1,93 +1,116 @@ -/* - * 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.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 Entity { - - private String componentName; - private int X, Y, level=-1, lane=-1, refHeight, serHeight, propLength; - private final int height= Component.DEFAULT_HEIGHT, width= Component.DEFAULT_WIDTH; - public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / (Service.MAXIMUM_HEIGHT+Service.SPACING); - public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers - public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING); - - private HashMap referenceToServiceMap = new HashMap(); - +public abstract class Entity { + + private String name; // a unique name + 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 int height; // height of the entity + private int width; // width of the entity + private int refHeight; // height of a reference element + private int serHeight; // height of a service element + private int propLength; // length of a property element + private int defaultNoOfSers; // default # of service elements + private int defaultNoOfRefs; // default # of reference elements + private int defaultNoOfProps; // default # of property elements + private ArrayList references = new ArrayList(); - private ArrayList refProperties = new ArrayList(); private ArrayList services = new ArrayList(); - private ArrayList serProperties = new ArrayList(); private ArrayList properties = new ArrayList(); - private ArrayList propProperties = new ArrayList(); private HashSet adjacentEntities = new HashSet(); - private HashSet connectedEntities = new HashSet(); + public abstract void referenceHeight(); + public abstract void serviceHeight(); + public abstract void propertyLength(); - public Entity(){ - - + public String getName() { + return name; } - - public void referenceHeight(){ - if(Entity.defaultNoOfRefs < getNoOfRefs()){ - - refHeight = (Component.DEFAULT_HEIGHT / getNoOfRefs()) - Reference.SPACING; - } - else - refHeight = Reference.MAXIMUM_HEIGHT; + public void setName(String name) { + this.name = name; } - - public void serviceHeight(){ - if(Entity.defaultNoOfSers < getNoOfSers()){ - - serHeight = (Component.DEFAULT_HEIGHT / getNoOfSers()) - Service.SPACING; - } - else - serHeight = Service.MAXIMUM_HEIGHT; + public int getX() { + return x; } - - public void propertyLength(){ - if(Entity.defaultNoOfProps < getNoOfProps()){ - - propLength = (Component.DEFAULT_WIDTH / getNoOfProps()) - Property.SPACING; - } - else - propLength = Property.MAXIMUM_HEIGHT; + public void setX(int x) { + this.x = x; + } + public int getY() { + return y; + } + public void setY(int y) { + this.y = y; + } + public int getLevel() { + return level; + } + public void setLevel(int level) { + this.level = level; + } + public int getLane() { + return lane; + } + public void setLane(int lane) { + this.lane = lane; + } + public int getHeight() { + return height; } + public void setHeight(int height) { + this.height = height; + } + public int getWidth() { + return width; + } + public void setWidth(int width) { + this.width = width; + } + public int getRefHeight() { + return refHeight; + } + public void setRefHeight(int refHeight) { + this.refHeight = refHeight; + } + public int getSerHeight() { + return serHeight; + } + public void setSerHeight(int serHeight) { + this.serHeight = serHeight; + } + public int getPropLength() { + return propLength; + } + public void setPropLength(int propLength) { + this.propLength = propLength; + } + public int getDefaultNoOfSers() { + return defaultNoOfSers; + } + public void setDefaultNoOfSers(int defaultNoOfSers) { + this.defaultNoOfSers = defaultNoOfSers; + } + public int getDefaultNoOfRefs() { + return defaultNoOfRefs; + } + public void setDefaultNoOfRefs(int defaultNoOfRefs) { + this.defaultNoOfRefs = defaultNoOfRefs; + } + public int getDefaultNoOfProps() { + return defaultNoOfProps; + } + public void setDefaultNoOfProps(int defaultNoOfProps) { + this.defaultNoOfProps = defaultNoOfProps; + } + public int getNoOfRefs(){ return references.size(); @@ -105,37 +128,6 @@ public class Entity { 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(); @@ -167,20 +159,7 @@ public class Entity { } - public void setComponentName(String componentName) { - this.componentName = componentName; - } - public String getComponentName() { - return componentName; - } - public HashMap getReferenceToServiceMap() { - return referenceToServiceMap; - } - public void setReferenceToServiceMap( - HashMap referenceToServiceMap) { - this.referenceToServiceMap = referenceToServiceMap; - } public ArrayList getProperties() { return properties; } @@ -200,93 +179,10 @@ public class Entity { public ArrayList getServices() { return services; } - - public int getX() { - return X; - } - - public void setX(int x) { - X = x; - } - - public int getY() { - return Y; - } - - public void setY(int y) { - Y = y; - } - - public int getLevel() { - return level; - } - - public void setLevel(int level) { - this.level = level; - } - - public int getLane() { - return lane; - } - - public void setLane(int lane) { - this.lane = lane; - } - - public ArrayList getRefProperties() { - return refProperties; - } public ArrayList getReferences() { return references; } - - public void setRefProperties(ArrayList refProperties) { - this.refProperties = refProperties; - } - - public ArrayList getSerProperties() { - return serProperties; - } - - public void setSerProperties(ArrayList serProperties) { - this.serProperties = serProperties; - } - - public ArrayList getPropProperties() { - return propProperties; - } - - public void setPropProperties(ArrayList propProperties) { - this.propProperties = propProperties; - } - - public int getRefHeight() { - return refHeight; - } - - public int getSerHeight() { - return serHeight; - } - - public int getPropLength() { - return propLength; - } - - public void setConnectedEntities(HashSet connectedEntities) { - this.connectedEntities = connectedEntities; - } - - public HashSet getConnectedEntities() { - return connectedEntities; - } - - public int getHeight() { - return height; - } - - public int getWidth() { - return width; - } - + + } 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 2d753221db..e8c7bf76e8 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 @@ -37,9 +37,9 @@ public class EntityBuilder { private HashMap> connectedEntities = new HashMap>(); private int totalWidth=0; private int totalHeight=0; - private Entity startEnt = null; + private ComponentEntity startEnt = null; private String compositeName; - Entity[] elts = null; + ComponentEntity[] elts = null; /** * Constructor which initiates the DOM document @@ -76,7 +76,7 @@ public class EntityBuilder { * * @return */ - public Entity[] buildEntities(){ + public ComponentEntity[] buildEntities(){ //get the root element Element docEle = dom.getDocumentElement(); @@ -86,12 +86,12 @@ public class EntityBuilder { //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("component"); if(nl != null && nl.getLength() > 0 ) { - elts = new Entity[nl.getLength()]; + elts = new ComponentEntity[nl.getLength()]; for(int i = 0 ; i < nl.getLength();i++) { - elts[i] = new Entity(); + elts[i] = new ComponentEntity(); Element nVal = (Element)nl.item(i); //System.out.println(nVal.hasAttribute("name")); - elts[i].setComponentName(nVal.getAttribute("name")); + elts[i].setName(nVal.getAttribute("name")); setServices(nVal, elts[i]); setReferences(nVal, elts[i]); setProperties(nVal, elts[i]); @@ -131,8 +131,8 @@ public class EntityBuilder { reference = null; } - Entity e = findEntity(referenceComp); - System.out.println("^^^^^^^^^ "+e.getComponentName()); + ComponentEntity e = findEntity(referenceComp); + System.out.println("^^^^^^^^^ "+e.getName()); if(e != null){ createConnection(e, reference, serviceComp, service); } @@ -148,17 +148,17 @@ public class EntityBuilder { } - private Entity findEntity(String componentName) { + private ComponentEntity findEntity(String componentName) { - for(Entity e: elts){ - if(e.getComponentName().equals(componentName)){ + for(ComponentEntity e: elts){ + if(e.getName().equals(componentName)){ return e; } } return null; } - private void setReferences(Element nVal, Entity ent) { + private void setReferences(Element nVal, ComponentEntity ent) { NodeList nl = nVal.getElementsByTagName("reference"); if(nl != null && nl.getLength() > 0 ) { @@ -188,10 +188,10 @@ public class EntityBuilder { } } - private void createConnection(Entity ent, String reference, + private void createConnection(ComponentEntity ent, String reference, String serviceComp, String service) { - String referenceComp = ent.getComponentName(); + String referenceComp = ent.getName(); if(reference != null && service != null){ @@ -220,10 +220,10 @@ public class EntityBuilder { } } - private void calculateProperties(Entity[] elts) { + private void calculateProperties(ComponentEntity[] elts) { int level=0, lane=0; - for(Entity ent: elts){ + for(ComponentEntity ent: elts){ level = max(level, ent.getLevel()); lane = max(lane, ent.getLane()); @@ -241,22 +241,22 @@ public class EntityBuilder { } - private void print(Entity[] elts) { + private void print(ComponentEntity[] elts) { - for(Entity ent: elts){ - System.out.println(ent.getComponentName()+" : "+ent.getLevel()+" : " + for(ComponentEntity ent: elts){ + System.out.println(ent.getName()+" : "+ent.getLevel()+" : " +ent.getLane()+" : "+ent.getX()+" : "+ent.getY()); } } - private void positionEntities(Entity[] ents){ + private void positionEntities(ComponentEntity[] ents){ - for(Entity ent: 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.getComponentName()); + System.err.println(ent.getName()); break; } } @@ -267,16 +267,16 @@ public class EntityBuilder { } - private void assignPositions(Entity[] ents, Entity ent){ + private void assignPositions(ComponentEntity[] ents, ComponentEntity ent){ int i=0; if(ent.getAdjacentEntities().size()>0){ - System.out.println(ent.getComponentName()); + System.out.println(ent.getName()); for(String name: ent.getAdjacentEntities()){ //System.out.println("eee "+name); - for(Entity aEnt: ents){ + for(ComponentEntity aEnt: ents){ i++; - if(name.equalsIgnoreCase(aEnt.getComponentName())){ + if(name.equalsIgnoreCase(aEnt.getName())){ int lane = ent.getLane()+1; if(levelCount.size()<= lane){ levelCount.add(lane, 1); @@ -300,14 +300,14 @@ public class EntityBuilder { else{ - ArrayList conns = connectedEntities.get(ent.getComponentName()); + ArrayList conns = connectedEntities.get(ent.getName()); System.err.println(conns.size()); if(conns.size()>0){ for(String conn: conns){ - System.err.println("conn "+conn +" : "+ent.getComponentName()); - for(Entity e: ents){ - if(e.getLane() == -1 && e.getComponentName().equals(conn)){ + 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); @@ -323,7 +323,7 @@ public class EntityBuilder { } } - private void setPosition(Entity ent, int x, int y, int level, int lane){ + private void setPosition(ComponentEntity ent, int x, int y, int level, int lane){ ent.setX(x); ent.setY(y); ent.setLevel(level); @@ -352,7 +352,7 @@ public class EntityBuilder { connectedEntities.put(ent1, list); } - private void setServices(Element nVal, Entity ent) { + private void setServices(Element nVal, ComponentEntity ent) { NodeList nl = nVal.getElementsByTagName("service"); if(nl != null && nl.getLength() > 0 ) { @@ -361,6 +361,7 @@ public class EntityBuilder { ent.addAService(elt.getAttribute("name")); } } + else{ NodeList nl1 = nVal.getElementsByTagName("implementation.java"); if(nl1 != null && nl1.getLength() > 0 ) { @@ -372,9 +373,11 @@ public class EntityBuilder { } } + } + } - private void setProperties(Element nVal, Entity ent) { + private void setProperties(Element nVal, ComponentEntity ent) { NodeList nl = nVal.getElementsByTagName("property"); if(nl != null && nl.getLength() > 0 ) { 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 3f62f38cb5..dd5762bc5e 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 @@ -24,7 +24,7 @@ import java.io.File; 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.Entity; +import org.apache.tuscany.sca.impl.layout.ComponentEntity; import org.apache.tuscany.sca.impl.layout.EntityBuilder; import org.w3c.dom.Document; @@ -38,9 +38,9 @@ public class Main { public static void main(String[] args) throws Exception { XMLReader reader = new XMLReader(); - Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite3.xml"); + Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite.xml"); EntityBuilder eb = new EntityBuilder(doc); - Entity[] ents =eb.buildEntities(); + ComponentEntity[] ents =eb.buildEntities(); DiagramGenerator dg = new DiagramGenerator(ents, eb.getTotalHeight(), eb.getTotalWidth(), eb.getCompositeName()); Document svg =dg.buildSVGDocument(); File outFile = new File(outFileDir+eb.getCompositeName()+"_diagram.svg"); -- cgit v1.2.3