summaryrefslogtreecommitdiffstats
path: root/collaboration
diff options
context:
space:
mode:
authornirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-06-07 05:17:25 +0000
committernirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-06-07 05:17:25 +0000
commitc6406ddd51887ba702991e960512161a92697d5e (patch)
tree2610fc623f82de99962d08f7b337548777ac2045 /collaboration
parenta0a513f7e7cf5a91b3ca15f7ea279c88220e2aca (diff)
Work up to date: not stable
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1132863 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration')
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/component.svg1
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/reference.svg1
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/service.svg1
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/test.svg1
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java13
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java19
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java5
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java32
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java58
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java62
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java28
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java246
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java155
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/PropertyAllocator.java26
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java62
15 files changed, 616 insertions, 94 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/component.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/component.svg
new file mode 100755
index 0000000000..c1acd47edd
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/component.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="100" font-size="20" dominant-baseline="mathematical" y="70" text-anchor="middle">SCA Component</text></svg> \ No newline at end of file
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/reference.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/reference.svg
new file mode 100755
index 0000000000..00a4f8e33e
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/reference.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><polygon fill="#BF3EFF" points="45,15 30,30 0,30 15,15 0,0 30,0 " stroke="#68228B"/></svg> \ No newline at end of file
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/service.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/service.svg
new file mode 100755
index 0000000000..07f0a65b0b
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/service.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><polygon fill="#00CD66" points="15,15 0,0 30,0 45,15 30,30 0,30 " stroke="#008B45"/></svg> \ No newline at end of file
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/test.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/test.svg
new file mode 100755
index 0000000000..c1acd47edd
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/test.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" preserveAspectRatio="xMidYMid meet" version="1.0"><rect x="0" y="0" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="100" font-size="20" dominant-baseline="mathematical" y="70" text-anchor="middle">SCA Component</text></svg> \ 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 2b3ed336f5..9a14ecf929 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
@@ -32,9 +32,22 @@ public abstract class Artifact {
private String svgNs;
private static final String ROUND_CORNER = "20" ;
+ /**
+ * Abstract method
+ * @param document DOM document
+ * @param svgNs namespace URI
+ * @param x x-coordinate
+ * @param y y-coordinate
+ * @param height height of the shape
+ * @param width width of the shape
+ * @return DOM Element
+ */
public abstract Element addElement(Document document, String svgNs,
int x, int y, int height, int width);
+ public abstract Element addElement(Document document, String svgNs,
+ int x, int y);
+
public int getHeight() {
return height;
}
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 8af5dba7b2..8e7d20146e 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
@@ -24,8 +24,8 @@ import org.w3c.dom.Element;
public class Component extends Artifact{
-// private static final String WIDTH = "200" ;
-// private static final String HEIGHT = "130" ;
+ public static final int DEFAULT_WIDTH = 200 ;
+ public static final int DEFAULT_HEIGHT = 130 ;
// public Element addElement(Document document,
@@ -60,7 +60,9 @@ public class Component extends Artifact{
// return rectangle;
// }
-
+ /**
+ * Create an element with specified height and width
+ */
public Element addElement(Document document, String svgNs, int x, int y,
int height, int width) {
@@ -81,6 +83,17 @@ public class Component extends Artifact{
rectangle.setAttributeNS(null, "fill-opacity", "0.75");
return rectangle;
}
+
+ /**
+ * Create an element with default height and width
+ */
+ public Element addElement(Document document, String svgNs, int x, int y) {
+
+ return addElement(document, svgNs, x, y, DEFAULT_HEIGHT, DEFAULT_WIDTH);
+
+ }
+
+
}
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 539a18e768..48491efe69 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
@@ -77,6 +77,11 @@ public class Composite extends Artifact{
return rectangle;
}
+
+ //OBSOLETE
+ public Element addElement(Document document, String svgNs, int x, int y) {
+ return null;
+ }
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java
index c751db9b77..0d236ccfaa 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,7 +24,8 @@ import org.w3c.dom.Element;
public class Property extends Artifact{
-// private static final String WIDTH = "20" ;
+ public static final int MAXIMUM_HEIGHT = 20 ; //default value
+ public static final int SPACING = 20 ; //default value
// public static Element addPropertyElement(Document document,
// String svgNs, int x, int y) {
@@ -40,17 +41,18 @@ public class Property extends Artifact{
// return rectangle;
// }
-
+ /**
+ * Property is a square.
+ * ___
+ * | |
+ * |___|
+ *
+ */
public Element addElement(Document document, String svgNs, int x, int y,
int height, int width) {
- return this.addElement(document, svgNs, x, y, height);
- }
-
- public Element addElement(Document document, String svgNs, int x, int y,
- int height) {
this.setHeight(height);
- this.setWidth(height);
+ this.setWidth(width);
this.setxCoordinate(x);
this.setyCoordinate(y);
@@ -65,5 +67,19 @@ public class Property extends Artifact{
return rectangle;
}
+
+
+ public Element addElement(Document document, String svgNs, int x, int y,
+ int height) {
+
+ 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 5f49b39ba2..6a3f7ff9d1 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,6 +24,9 @@ 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
+
//private static final int COMMON_LENGTH = 20 ;
// public static Element addReferenceElement(Document document, String svgNs, int midX, int midY) {
@@ -46,45 +49,33 @@ public class Reference extends Artifact {
// }
//
-
- public Element addElement(Document document, String svgNs, int x, int y,
- int height, int width) {
- return this.addElement(document, svgNs, x, y, height);
- }
-
/**
- * In a Reference the (x,y) coordinates refers to the outer edge of the polygon
- * ______
- * \ \
- * \ \ ___ outer edge
- * / /
- * /____ /
- *
- * @param document
- * @param svgNs
- * @param x
- * @param y
- * @param height
- * @return
+ * In a Reference the (x,y) coordinates refers to the top corner edge of the polygon
+ * (x,y)______
+ * \ \
+ * \ \
+ * / /
+ * /____ /
*/
public Element addElement(Document document, String svgNs, int x, int y,
- int height) {
+ int height, int width) {
+
this.setHeight(height);
- this.setWidth(height);
+ this.setWidth(width);
this.setxCoordinate(x);
this.setyCoordinate(y);
- int length = height/2;
+ int halfOfHeight = height/2;
Element polygon = document.createElementNS(svgNs, "polygon");
polygon.setAttributeNS(null, "points",
""+ x +","+y+" " +
- ""+ (x-length) +","+(y+length)+" " +
- ""+ (x-length*3) +","+(y+length)+" " +
- ""+ (x-length*2) +","+(y)+" " +
- ""+ (x-length*3) +","+(y-length)+" " +
- ""+ (x-length) +","+(y-length)+" "
+ ""+ (x+2*halfOfHeight) +","+(y)+" " +
+ ""+ (x+3*halfOfHeight) +","+(y-halfOfHeight)+" " +
+ ""+ (x+2*halfOfHeight) +","+(y-2*halfOfHeight)+" " +
+ ""+ (x) +","+(y-2*halfOfHeight)+" " +
+ ""+ (x+halfOfHeight) +","+(y-halfOfHeight)+" "
);
polygon.setAttributeNS(null, "fill", "#BF3EFF");
@@ -92,5 +83,18 @@ public class Reference extends Artifact {
return polygon;
}
+
+
+ public Element addElement(Document document, String svgNs, int x, int y,
+ int height) {
+
+ return this.addElement(document, svgNs, x, y, height, height*3/2);
+ }
+
+
+ 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 997ea90448..986cc1b99c 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,7 +24,8 @@ import org.w3c.dom.Element;
public class Service extends Artifact{
-// private static final int COMMON_LENGTH = 20 ;
+ public static final int MAXIMUM_HEIGHT = 30 ; //default value
+ public static final int SPACING = 10 ; //default value
// public static Element addServiceElement(Document document, String svgNs, int midX, int midY) {
// // Create the rectangle.
@@ -43,45 +44,32 @@ public class Service extends Artifact{
// return polygon;
// }
-
- public Element addElement(Document document, String svgNs, int x, int y,
- int height, int width) {
- return this.addElement(document, svgNs, x, y, height);
- }
-
/**
- * In a Service the (x,y) coordinates refers to the inner edge of the polygon
- * ______
+ * In a Service the (x,y) coordinates refers to the top corner edge of the polygon
+ * (x,y)______
* \ \
- * inner edge ____ \ \
+ * \ \
* / /
* /____ /
- *
- * @param document
- * @param svgNs
- * @param x
- * @param y
- * @param height
- * @return
*/
public Element addElement(Document document, String svgNs, int x, int y,
- int height) {
+ int height, int width) {
this.setHeight(height);
- this.setWidth(height);
+ this.setWidth(width);
this.setxCoordinate(x);
this.setyCoordinate(y);
- int length = height/2;
+ int halfOfHeight = height/2;
Element polygon = document.createElementNS(svgNs, "polygon");
polygon.setAttributeNS(null, "points",
""+ x +","+y+" " +
- ""+ (x-length) +","+(y-length)+" " +
- ""+ (x+length) +","+(y-length)+" " +
- ""+ (x+(length*2)) +","+y+" " +
- ""+ (x+length) +","+(y+length)+" " +
- ""+ (x-length) +","+(y+length)+" "
+ ""+ (x+2*halfOfHeight) +","+(y)+" " +
+ ""+ (x+3*halfOfHeight) +","+(y-halfOfHeight)+" " +
+ ""+ (x+2*halfOfHeight) +","+(y-2*halfOfHeight)+" " +
+ ""+ (x) +","+(y-2*halfOfHeight)+" " +
+ ""+ (x+halfOfHeight) +","+(y-halfOfHeight)+" "
);
polygon.setAttributeNS(null, "fill", "#00CD66");
@@ -90,5 +78,29 @@ public class Service extends Artifact{
return polygon;
}
+ /**
+ * Width is 3/2 times of the height
+ * @param document
+ * @param svgNs
+ * @param x
+ * @param y
+ * @param height
+ * @return
+ */
+ public Element addElement(Document document, String svgNs, int x, int y,
+ int height) {
+
+ return this.addElement(document, svgNs, x, y, height, height*3/2);
+ }
+
+ /**
+ * 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/io/XMLReader.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
new file mode 100755
index 0000000000..92099a7104
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
@@ -0,0 +1,28 @@
+package org.apache.tuscany.sca.impl.io;
+
+import java.io.IOException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class XMLReader {
+
+ //get the factory
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ private Document dom;
+
+ public Document parseXMLFile(String file) throws Exception
+ {
+ //Using factory get an instance of document builder
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ //parse using builder to get DOM representation of the XML file
+ dom = db.parse(file);
+
+ return dom;
+ }
+}
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
new file mode 100755
index 0000000000..34c750bbce
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
@@ -0,0 +1,246 @@
+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.
+ * @author nirmal
+ *
+ */
+public class Entity {
+
+ private String componentName;
+ private int X, Y, level, lane, refHeight, serHeight, propLength;
+
+ public static final int defaultNoOfSers= Component.DEFAULT_HEIGHT / (Service.MAXIMUM_HEIGHT+Service.SPACING);
+ public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers
+ public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING);
+
+ private HashMap<String, String> referenceToServiceMap = new HashMap<String, String>();
+
+ private ArrayList<String> references = new ArrayList<String>();
+ private ArrayList<String> refProperties = new ArrayList<String>();
+
+ private ArrayList<String> services = new ArrayList<String>();
+ private ArrayList<String> serProperties = new ArrayList<String>();
+
+ private ArrayList<String> properties = new ArrayList<String>();
+ private ArrayList<String> propProperties = new ArrayList<String>();
+
+ private HashSet<String> adjacentEntities = new HashSet<String>();
+
+
+ public Entity(){
+
+
+ }
+
+ public void referenceHeight(){
+ if(Entity.defaultNoOfRefs < getNoOfRefs()){
+
+ refHeight = (Component.DEFAULT_HEIGHT / getNoOfRefs()) - Reference.SPACING;
+ }
+ else
+ refHeight = Reference.MAXIMUM_HEIGHT;
+ }
+
+ public void serviceHeight(){
+ if(Entity.defaultNoOfSers < getNoOfSers()){
+
+ serHeight = (Component.DEFAULT_HEIGHT / getNoOfSers()) - Service.SPACING;
+ }
+ else
+ serHeight = Service.MAXIMUM_HEIGHT;
+ }
+
+ public void propertyLength(){
+ if(Entity.defaultNoOfProps < getNoOfProps()){
+
+ propLength = (Component.DEFAULT_WIDTH / getNoOfProps()) - Property.SPACING;
+ }
+ else
+ propLength = Property.MAXIMUM_HEIGHT;
+ }
+
+ 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){
+
+ adjacentEntities.add(x);
+
+ }
+
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public HashMap<String, String> getReferenceToServiceMap() {
+ return referenceToServiceMap;
+ }
+ public void setReferenceToServiceMap(
+ HashMap<String, String> referenceToServiceMap) {
+ this.referenceToServiceMap = referenceToServiceMap;
+ }
+ public ArrayList<String> getProperties() {
+ return properties;
+ }
+ public void setProperties(ArrayList<String> properties) {
+ this.properties = properties;
+ }
+ public HashSet<String> getAdjacentEntities() {
+ return adjacentEntities;
+ }
+ public void setAdjacentEntities(HashSet<String> adjacentEntities) {
+ this.adjacentEntities = adjacentEntities;
+ }
+ public void setServices(ArrayList<String> services) {
+ this.services = services;
+ }
+ public ArrayList<String> getServices() {
+ return services;
+ }
+
+ public 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<String> getRefProperties() {
+ return refProperties;
+ }
+
+ public void setRefProperties(ArrayList<String> refProperties) {
+ this.refProperties = refProperties;
+ }
+
+ public ArrayList<String> getSerProperties() {
+ return serProperties;
+ }
+
+ public void setSerProperties(ArrayList<String> serProperties) {
+ this.serProperties = serProperties;
+ }
+
+ public ArrayList<String> getPropProperties() {
+ return propProperties;
+ }
+
+ public void setPropProperties(ArrayList<String> propProperties) {
+ this.propProperties = propProperties;
+ }
+
+ public int getRefHeight() {
+ return refHeight;
+ }
+
+ public int getSerHeight() {
+ return serHeight;
+ }
+
+ public int getPropLength() {
+ return propLength;
+ }
+
+}
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
new file mode 100755
index 0000000000..dad3518b90
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
@@ -0,0 +1,155 @@
+package org.apache.tuscany.sca.impl.layout;
+
+import java.util.ArrayList;
+
+import org.apache.tuscany.sca.impl.artifacts.Component;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class EntityBuilder {
+
+ private Document dom;
+ private final int initPoint = 100;
+ private final int spaceX = Component.DEFAULT_WIDTH*2;
+ private final int spaceY = Component.DEFAULT_HEIGHT*2;
+ private ArrayList<Integer> levelCount = new ArrayList<Integer>();
+
+ public EntityBuilder(Document aDom){
+ dom = aDom;
+ }
+
+ public Entity[] buildEntities(){
+ Entity[] elts = null;
+ //get the root element
+ Element docEle = dom.getDocumentElement();
+
+ //get a nodelist of elements
+ NodeList nl = docEle.getElementsByTagName("sca:component");
+ if(nl != null && nl.getLength() > 0 ) {
+ elts = new Entity[nl.getLength()];
+ for(int i = 0 ; i < nl.getLength();i++) {
+ Element nVal = (Element)nl.item(i);
+ elts[i].setComponentName(nVal.getAttribute("name"));
+ setReferences(nVal, elts[i]);
+ setServices(nVal, elts[i]);
+ setProperties(nVal, elts[i]);
+ elts[i].referenceHeight();
+ elts[i].serviceHeight();
+ elts[i].propertyLength();
+ }
+ }
+
+ //get a nodelist of elements
+ NodeList nl2 = docEle.getElementsByTagName("sca:wire");
+ if(nl2 != null && nl2.getLength() > 0 ) {
+
+ for(int i = 0 ; i < nl2.getLength();i++) {
+ Element nVal = (Element)nl2.item(i);
+ String[] source = splitValues(nVal.getAttribute("source"));
+ String[] target = splitValues(nVal.getAttribute("target"));
+
+ for(Entity ent: elts){
+ if(ent.getComponentName().equalsIgnoreCase(source[0])){
+ ent.addAnAdjacentEntity(target[0]);
+ ent.addToRefToSerMap(source[1], target[1]);
+ break;
+ }
+ }
+ }
+ }
+
+ positionEntities(elts);
+
+ return elts;
+
+ }
+
+ private void positionEntities(Entity[] ents){
+ Entity startEnt = null;
+ for(Entity ent: ents){
+ if(ent.getAdjacentEntities().size() != 0){
+ setPosition(ent, initPoint, initPoint, 0, 0);
+ levelCount.add(0, 1);
+ startEnt = ent;
+ break;
+ }
+ }
+
+ if(startEnt != null)
+ assignPositions(ents, startEnt);
+
+ }
+
+ private void assignPositions(Entity[] ents, Entity ent){
+ int i=0;
+ for(String name: ent.getAdjacentEntities()){
+ for(Entity aEnt: ents){
+ if(name.equalsIgnoreCase(aEnt.getComponentName())){
+ int lane = ent.getLane()+1;
+ if(levelCount.get(lane) != null){
+ levelCount.add(lane, 1);
+ setPosition(aEnt, ent.getX()+spaceX, ent.getY(), 0, lane);
+ }
+ else{
+ int level = levelCount.get(lane);
+ levelCount.add(lane, level+1);
+ setPosition(aEnt, ent.getX()+spaceX, ent.getY()+spaceY*level, level, lane);
+ }
+ assignPositions(ents, aEnt);
+ break;
+ }
+ }
+ i++;
+ }
+ }
+
+ private void setPosition(Entity ent, int x, int y, int level, int lane){
+ ent.setX(x);
+ ent.setY(y);
+ ent.setLevel(level);
+ ent.setLane(lane);
+ }
+
+
+ private String[] splitValues(String str){
+ return str.split("/");
+ }
+
+ private void setReferences(Element nVal, Entity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("sca:reference");
+ if(nl != null && nl.getLength() > 0 ) {
+ for(int i = 0 ; i < nl.getLength();i++) {
+ Element elt = (Element)nl.item(i);
+ ent.addAReference(elt.getAttribute("name"));
+ }
+ }
+ }
+
+ private void setServices(Element nVal, Entity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("sca:service");
+ if(nl != null && nl.getLength() > 0 ) {
+ for(int i = 0 ; i < nl.getLength();i++) {
+ Element elt = (Element)nl.item(i);
+ ent.addAService(elt.getAttribute("name"));
+ }
+ }
+ }
+
+ private void setProperties(Element nVal, Entity ent) {
+
+ NodeList nl = nVal.getElementsByTagName("sca:property");
+ if(nl != null && nl.getLength() > 0 ) {
+ for(int i = 0 ; i < nl.getLength();i++) {
+ Element elt = (Element)nl.item(i);
+ ent.addAProperty(elt.getAttribute("name"));
+ }
+ }
+ }
+
+
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/PropertyAllocator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/PropertyAllocator.java
new file mode 100755
index 0000000000..1574d1247f
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/PropertyAllocator.java
@@ -0,0 +1,26 @@
+package org.apache.tuscany.sca.impl.layout;
+
+import java.util.Iterator;
+
+import org.apache.tuscany.sca.impl.artifacts.Component;
+import org.apache.tuscany.sca.impl.artifacts.Reference;
+
+public class PropertyAllocator {
+ Entity entity;
+
+ public PropertyAllocator(Entity e) {
+ entity = e;
+ }
+
+ public void allocatePropertiesOfRefs(){
+ int height=0;
+
+
+ for(Iterator it=entity.getReferenceToServiceMap().keySet().iterator();it.hasNext();){
+ String ref = it.next();
+
+ }
+ }
+
+
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java
index 6d17547d66..bce24de749 100644
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/SVGDiagramGenerator.java
@@ -1,5 +1,5 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
+un * 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
@@ -44,7 +44,7 @@ import org.apache.tuscany.sca.impl.artifacts.Wire;
public class SVGDiagramGenerator {
private static final File outFile = new File(System.getProperty("user.dir")
- + "/output/test.svg");
+ + "/output/reference.svg");
/**
* @param args
@@ -83,15 +83,15 @@ public class SVGDiagramGenerator {
Wire edge1 = new Wire();
Wire edge2 = new Wire();
- Element rectangle1 = comp1.addElement(doc, svgNS, 50, 20, 130, 200);
- Element text1 = Text.addTextElement(doc, svgNS, 150, 90, "SCA Component");
+ Element rectangle1 = comp1.addElement(doc, svgNS, 0, 0, 130, 200);
+ Element text1 = Text.addTextElement(doc, svgNS, 100, 70, "SCA Component");
Element property1 = prop1.addElement(doc, svgNS, 120, 10, 20);
Element property2 = prop2.addElement(doc, svgNS, 160, 10, 20);
- Element polygon1 = ser1.addElement(doc, svgNS, 50, 85, 30);
+ Element polygon1 = ser1.addElement(doc, svgNS, 15, 15, 30);
- Element polygon2 = ref1.addElement(doc, svgNS, 270, 60, 30);
+ Element polygon2 = ref1.addElement(doc, svgNS, 45, 15, 30);
Element polygon3 = ref2.addElement(doc, svgNS, 270, 110, 30);
//Element wire1 = edge1.addElement(doc, svgNS, 270, 60, 390, 85);
@@ -112,37 +112,37 @@ public class SVGDiagramGenerator {
//Element wire2 = Wire.addWireElement(doc, svgNS, 270, 110, 390, 265);
// Set the width and height attributes on the root 'svg' element.
- svgRoot.setAttributeNS(null, "width", "650");
- svgRoot.setAttributeNS(null, "height", "450");
+// svgRoot.setAttributeNS(null, "width", "200");
+// svgRoot.setAttributeNS(null, "height", "130");
Element composi = composite.addElement(doc, svgNS, 0, 0, 350, 650);
Element text4 = Text.addTextElement(doc, svgNS, 75, 320, "Composite");
- svgRoot.appendChild(composi);
- svgRoot.appendChild(text4);
+// svgRoot.appendChild(composi);
+// svgRoot.appendChild(text4);
- // Attach the rectangle to the root 'svg' element.
- svgRoot.appendChild(rectangle1);
- svgRoot.appendChild(text1);
- svgRoot.appendChild(property1);
- svgRoot.appendChild(property2);
- svgRoot.appendChild(polygon1);
+// // Attach the rectangle to the root 'svg' element.
+// svgRoot.appendChild(rectangle1);
+// svgRoot.appendChild(text1);
+// svgRoot.appendChild(property1);
+// svgRoot.appendChild(property2);
+// svgRoot.appendChild(polygon1);
svgRoot.appendChild(polygon2);
- svgRoot.appendChild(polygon3);
-
- svgRoot.appendChild(rectangle2);
- svgRoot.appendChild(text2);
- svgRoot.appendChild(polygon4);
- //svgRoot.appendChild(polygon3);
-
- svgRoot.appendChild(rectangle3);
- svgRoot.appendChild(text3);
- svgRoot.appendChild(polygon5);
-
- svgRoot.appendChild(wire1);
- svgRoot.appendChild(wire2);
- //svgRoot.setAttributeNS(null, "fill", "#CAE1FF");
- //System.out.println(doc.getDocumentElement().getAttribute("width"));
+// svgRoot.appendChild(polygon3);
+//
+// svgRoot.appendChild(rectangle2);
+// svgRoot.appendChild(text2);
+// svgRoot.appendChild(polygon4);
+// //svgRoot.appendChild(polygon3);
+//
+// svgRoot.appendChild(rectangle3);
+// svgRoot.appendChild(text3);
+// svgRoot.appendChild(polygon5);
+//
+// svgRoot.appendChild(wire1);
+// svgRoot.appendChild(wire2);
+// //svgRoot.setAttributeNS(null, "fill", "#CAE1FF");
+// //System.out.println(doc.getDocumentElement().getAttribute("width"));
return doc;
}