Author: nirmal070125
Date: Mon Jun 13 07:37:39 2011
New Revision: 1135039

URL: http://svn.apache.org/viewvc?rev=1135039&view=rev
Log:
Another version of layout algorithm and diagram creation

Added:
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg
   (with props)
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
   (with props)
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
   (with props)
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java
   (with props)
Modified:
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
    
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java

Added: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg?rev=1135039&view=auto
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg
 (added)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg
 Mon Jun 13 07:37:39 2011
@@ -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" alignment-baseline="central" fill="#E5E5E5" 
width="900" rx="20" ry="20" height="1140" stroke="#919191"/><text x="450" 
font-size="20" dominant-baseline="mathematical" y="20" 
text-anchor="middle">Calculator</text><rect x="100" y="100" fill-opacity="0.75" 
fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text 
x="150" font-size="20" dominant-baseline="mathematical" y="250" 
text-anchor="middle">CalculatorServiceComponent</text><polygon fill="#BF3EFF" 
points="286,110 318,110 334,121 318,132 286,132 302,121 " 
stroke="#68228B"/><text x="286" font-size="20" dominant-baseline="mathematical" 
y="121" text-anchor="middle">addService</text><polygon fill="#BF3EFF" 
points="286,142 318,142 334,153 
 318,164 286,164 302,153 " stroke="#68228B"/><text x="286" font-size="20" 
dominant-baseline="mathematical" y="153" 
text-anchor="middle">subtractService</text><polygon fill="#BF3EFF" 
points="286,174 318,174 334,185 318,196 286,196 302,185 " 
stroke="#68228B"/><text x="286" font-size="20" dominant-baseline="mathematical" 
y="185" text-anchor="middle">multiplyService</text><polygon fill="#BF3EFF" 
points="286,206 318,206 334,217 318,228 286,228 302,217 " 
stroke="#68228B"/><text x="286" font-size="20" dominant-baseline="mathematical" 
y="217" text-anchor="middle">divideService</text><rect x="500" y="880" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="550" font-size="20" dominant-baseline="mathematical" 
y="1030" text-anchor="middle">AddServiceComponent</text><rect x="500" y="100" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="550" font-size="20" dominant-baseline="mathematic
 al" y="250" text-anchor="middle">SubtractServiceComponent</text><rect x="500" 
y="620" fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" 
height="130" stroke="#104E8B"/><text x="550" font-size="20" 
dominant-baseline="mathematical" y="770" 
text-anchor="middle">MultiplyServiceComponent</text><rect x="500" y="360" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="550" font-size="20" dominant-baseline="mathematical" 
y="510" text-anchor="middle">DivideServiceComponent</text></svg>
\ No newline at end of file

Propchange: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg
------------------------------------------------------------------------------
    svn:executable = *

Added: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg?rev=1135039&view=auto
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
 (added)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
 Mon Jun 13 07:37:39 2011
@@ -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" alignment-baseline="central" fill="#E5E5E5" 
width="1300" rx="20" ry="20" height="620" stroke="#919191"/><text x="650" 
font-size="20" dominant-baseline="mathematical" y="20" 
text-anchor="middle">store</text><rect x="100" y="100" fill-opacity="0.75" 
fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text 
x="150" font-size="20" dominant-baseline="mathematical" y="250" 
text-anchor="middle">Store</text><polygon fill="#00CD66" points="80,110 110,110 
125,125 110,140 80,140 95,125 " stroke="#008B45"/><text x="80" font-size="20" 
dominant-baseline="mathematical" y="125" 
text-anchor="middle">Widget</text><polygon fill="#BF3EFF" points="280,110 
310,110 325,125 310,140 280,140 295,125 " stroke="
 #68228B"/><text x="280" font-size="20" dominant-baseline="mathematical" 
y="125" text-anchor="middle">catalog</text><polygon fill="#BF3EFF" 
points="280,150 310,150 325,165 310,180 280,180 295,165 " 
stroke="#68228B"/><text x="280" font-size="20" dominant-baseline="mathematical" 
y="165" text-anchor="middle">shoppingCart</text><polygon fill="#BF3EFF" 
points="280,190 310,190 325,205 310,220 280,220 295,205 " 
stroke="#68228B"/><text x="280" font-size="20" dominant-baseline="mathematical" 
y="205" text-anchor="middle">shoppingTotal</text><rect x="500" y="100" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="550" font-size="20" dominant-baseline="mathematical" 
y="250" text-anchor="middle">Catalog</text><polygon fill="#00CD66" 
points="480,110 510,110 525,125 510,140 480,140 495,125 " 
stroke="#008B45"/><text x="480" font-size="20" dominant-baseline="mathematical" 
y="125" text-anchor="middle">Catalog</text><polygon fill="#BF3EFF" poi
 nts="680,110 710,110 725,125 710,140 680,140 695,125 " stroke="#68228B"/><text 
x="680" font-size="20" dominant-baseline="mathematical" y="125" 
text-anchor="middle">currencyConverter</text><rect fill="#EEEE00" x="520" 
width="20" height="20" y="90" stroke="#EEC900"/><text x="520" font-size="20" 
dominant-baseline="mathematical" y="90" 
text-anchor="middle">currencyCode</text><rect x="500" y="360" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="550" font-size="20" dominant-baseline="mathematical" 
y="510" text-anchor="middle">ShoppingCart</text><polygon fill="#00CD66" 
points="480,370 510,370 525,385 510,400 480,400 495,385 " 
stroke="#008B45"/><text x="480" font-size="20" dominant-baseline="mathematical" 
y="385" text-anchor="middle">Cart</text><polygon fill="#00CD66" points="480,410 
510,410 525,425 510,440 480,440 495,425 " stroke="#008B45"/><text x="480" 
font-size="20" dominant-baseline="mathematical" y="425" text-anchor="midd
 le">Total</text><rect x="900" y="100" fill-opacity="0.75" fill="#3D59AB" 
width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="950" 
font-size="20" dominant-baseline="mathematical" y="250" 
text-anchor="middle">CurrencyConverter</text><polyline stroke-width="2" 
points="325,205 495,425" stroke="black"/><polyline stroke-width="2" 
points="325,165 495,385" stroke="black"/><polyline stroke-width="2" 
points="325,125 495,125" stroke="black"/></svg>
\ No newline at end of file

Propchange: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg
------------------------------------------------------------------------------
    svn:executable = *

Added: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg?rev=1135039&view=auto
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
 (added)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
 Mon Jun 13 07:37:39 2011
@@ -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" alignment-baseline="central" fill="#E5E5E5" 
width="1700" rx="20" ry="20" height="360" stroke="#919191"/><text x="850" 
font-size="20" dominant-baseline="mathematical" y="20" 
text-anchor="middle">supplychain</text><rect x="100" y="100" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="150" font-size="20" dominant-baseline="mathematical" 
y="250" text-anchor="middle">CustomerComponent</text><polygon fill="#BF3EFF" 
points="280,110 310,110 325,125 310,140 280,140 295,125 " 
stroke="#68228B"/><text x="280" font-size="20" dominant-baseline="mathematical" 
y="125" text-anchor="middle">retailer</text><rect x="500" y="100" 
fill-opacity="0.75" fill="#3D59AB" width="20
 0" rx="20" ry="20" height="130" stroke="#104E8B"/><text x="550" font-size="20" 
dominant-baseline="mathematical" y="250" 
text-anchor="middle">RetailerComponent</text><polygon fill="#BF3EFF" 
points="680,110 710,110 725,125 710,140 680,140 695,125 " 
stroke="#68228B"/><text x="680" font-size="20" dominant-baseline="mathematical" 
y="125" text-anchor="middle">warehouse</text><rect x="900" y="100" 
fill-opacity="0.75" fill="#3D59AB" width="200" rx="20" ry="20" height="130" 
stroke="#104E8B"/><text x="950" font-size="20" dominant-baseline="mathematical" 
y="250" text-anchor="middle">WarehouseComponent</text><polygon fill="#BF3EFF" 
points="1080,110 1110,110 1125,125 1110,140 1080,140 1095,125 " 
stroke="#68228B"/><text x="1080" font-size="20" 
dominant-baseline="mathematical" y="125" 
text-anchor="middle">shipper</text><rect x="1300" y="100" fill-opacity="0.75" 
fill="#3D59AB" width="200" rx="20" ry="20" height="130" stroke="#104E8B"/><text 
x="1350" font-size="20" dominant-baseline="mathema
 tical" y="250" text-anchor="middle">ShipperComponent</text><polygon 
fill="#BF3EFF" points="1480,110 1510,110 1525,125 1510,140 1480,140 1495,125 " 
stroke="#68228B"/><text x="1480" font-size="20" 
dominant-baseline="mathematical" y="125" 
text-anchor="middle">customer</text></svg>
\ No newline at end of file

Propchange: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Artifact.java
 Mon Jun 13 07:37:39 2011
@@ -24,6 +24,8 @@ import org.w3c.dom.Element;
 
 public abstract class Artifact {
 
+       private String name;
+       private String containerName;
        private int height;
        private int width;
        private int xCoordinate;
@@ -88,5 +90,21 @@ public abstract class Artifact {
        public static String getRoundCorner() {
                return ROUND_CORNER;
        }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setContainerName(String containerName) {
+               this.containerName = containerName;
+       }
+
+       public String getContainerName() {
+               return containerName;
+       }
        
 }

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Component.java
 Mon Jun 13 07:37:39 2011
@@ -26,39 +26,8 @@ public class Component extends Artifact{
        
        public static final int DEFAULT_WIDTH = 200 ;
        public static final int DEFAULT_HEIGHT = 130 ;
+       public static final int TEXT_SPACING = 20 ;
        
-       
-//     public  Element addElement(Document document, 
-//                     String svgNs, int x, int y) {
-//             
-//             
-//             //Element g = document.createElementNS(svgNs, "g");
-//             //g.setAttributeNS(null, "transform", "translate(100 100)");
-//             // Create the rectangle.
-//             Element rectangle = document.createElementNS(svgNs, "rect");
-//             rectangle.setAttributeNS(null, "x", x+"");
-//             rectangle.setAttributeNS(null, "y", y+"");
-//             rectangle.setAttributeNS(null, "rx", ROUND_CORNER);
-//             rectangle.setAttributeNS(null, "ry", ROUND_CORNER);
-//             rectangle.setAttributeNS(null, "width", WIDTH);
-//             rectangle.setAttributeNS(null, "height", HEIGHT);
-//             rectangle.setAttributeNS(null, "fill", "#3D59AB");
-//             rectangle.setAttributeNS(null, "stroke", "#104E8B");
-//             rectangle.setAttributeNS(null, "fill-opacity", "0.75");
-//                             
-//             
-////           Element text = document.createElementNS(svgNs, "text");
-////           text.setAttributeNS(null, "text-anchor", "middle");
-////           text.setAttributeNS(null, "dominant-baseline", "mathematical");
-////           text.setAttributeNS(null, "font-size", "30");
-////           text.setTextContent("A Component");
-//             
-//             //document.appendChild(rectangle);
-//             //g.appendChild(text);
-//
-//             
-//             return rectangle;
-//     }
 
        /**
         * Create an element with specified height and width

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Composite.java
 Mon Jun 13 07:37:39 2011
@@ -24,37 +24,10 @@ import org.w3c.dom.Element;
 
 /**
  * Structure of a "Composite" element in SCA, as a SVG element
- * @author nirmal
  *
  */
 public class Composite extends Artifact{
-//     
-//     private Document document;
-//     private String svgNs;
-//     
-//     public Composite(Document doc, String uri){
-//             document = doc;
-//             svgNs = uri;
-//     }
-//
-       
-       
-//     public static Element addCompositeElement(Document document, String 
svgNs, 
-//                     int x, int y, int width, int height) {
-//             // Create the rectangle.
-//             Element rectangle = document.createElementNS(svgNs, "rect");
-//             rectangle.setAttributeNS(null, "x", x+"");
-//             rectangle.setAttributeNS(null, "y", y+"");
-//             rectangle.setAttributeNS(null, "rx", ROUND_CORNER);
-//             rectangle.setAttributeNS(null, "ry", ROUND_CORNER);
-//             rectangle.setAttributeNS(null, "width", width+"");
-//             rectangle.setAttributeNS(null, "height", height+"");
-//             rectangle.setAttributeNS(null, "fill", "#E5E5E5");
-//             rectangle.setAttributeNS(null, "stroke", "#919191");
-//             rectangle.setAttributeNS(null, "alignment-baseline", "central");
-//             
-//             return rectangle;
-//     }
+
 
        public Element addElement(Document document, String svgNs, int x, int y,
                        int height, int width) {

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Property.java
 Mon Jun 13 07:37:39 2011
@@ -27,19 +27,6 @@ public class Property extends Artifact{
        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) {
-//             Element rectangle = document.createElementNS(svgNs, "rect");
-//             rectangle.setAttributeNS(null, "x", x+"");
-//             rectangle.setAttributeNS(null, "y", y+"");
-//             rectangle.setAttributeNS(null, "width", WIDTH);
-//             rectangle.setAttributeNS(null, "height", WIDTH);
-//             rectangle.setAttributeNS(null, "fill", "#EEEE00");
-//             rectangle.setAttributeNS(null, "stroke", "#EEC900");
-//             //rectangle.setAttributeNS(null, "fill-opacity", "0.75");
-//             
-//             return rectangle;
-//     }
 
        /**
         * Property is a square.

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Reference.java
 Mon Jun 13 07:37:39 2011
@@ -27,27 +27,6 @@ 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) {
-//             
-//             // Create the rectangle.
-//             Element polygon = document.createElementNS(svgNs, "polygon");
-//             polygon.setAttributeNS(null, "points", 
-//                             ""+ (midX-COMMON_LENGTH) +","+midY+" " +
-//                             ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " +
-//                             ""+ (midX+COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH)+" " +
-//                             ""+ (midX+(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH*2)+" " +
-//                             ""+ (midX-COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH*2)+" " +
-//                             ""+ (midX-(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH)+" "
-//                     );
-//             polygon.setAttributeNS(null, "fill", "#BF3EFF");
-//             polygon.setAttributeNS(null, "stroke", "#68228B");
-//             //rectangle.setAttributeNS(null, "alignment-baseline", 
"central");
-//             
-//             return polygon;
-//     }
-//     
 
        /**
         * In a Reference the (x,y) coordinates refers to the top corner edge 
of the polygon
@@ -72,10 +51,10 @@ public class Reference extends Artifact 
                polygon.setAttributeNS(null, "points", 
                                ""+ x +","+y+" " +
                                ""+ (x+2*halfOfHeight) +","+(y)+" " +
-                               ""+ (x+3*halfOfHeight) +","+(y-halfOfHeight)+" 
" +
-                               ""+ (x+2*halfOfHeight) 
+","+(y-2*halfOfHeight)+" " +
-                               ""+ (x) +","+(y-2*halfOfHeight)+" " +
-                               ""+ (x+halfOfHeight) +","+(y-halfOfHeight)+" "
+                               ""+ (x+3*halfOfHeight) +","+(y+halfOfHeight)+" 
" +
+                               ""+ (x+2*halfOfHeight) 
+","+(y+2*halfOfHeight)+" " +
+                               ""+ (x) +","+(y+2*halfOfHeight)+" " +
+                               ""+ (x+halfOfHeight) +","+(y+halfOfHeight)+" "
                        );
                
                polygon.setAttributeNS(null, "fill", "#BF3EFF");

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Service.java
 Mon Jun 13 07:37:39 2011
@@ -27,22 +27,6 @@ public class Service extends Artifact{
        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.
-//             Element polygon = document.createElementNS(svgNs, "polygon");
-//             polygon.setAttributeNS(null, "points", 
-//                             ""+ (midX-COMMON_LENGTH) +","+midY+" " +
-//                             ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " +
-//                             ""+ (midX+COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH)+" " +
-//                             ""+ (midX+(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH*2)+" " +
-//                             ""+ (midX-COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH*2)+" " +
-//                             ""+ (midX-(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH)+" "
-//                     );
-//             polygon.setAttributeNS(null, "fill", "#00CD66");
-//             polygon.setAttributeNS(null, "stroke", "#008B45");
-//             
-//             return polygon;
-//     }
 
        /**
         * In a Service the (x,y) coordinates refers to the top corner edge of 
the polygon
@@ -66,10 +50,10 @@ public class Service extends Artifact{
                polygon.setAttributeNS(null, "points", 
                                ""+ x +","+y+" " +
                                ""+ (x+2*halfOfHeight) +","+(y)+" " +
-                               ""+ (x+3*halfOfHeight) +","+(y-halfOfHeight)+" 
" +
-                               ""+ (x+2*halfOfHeight) 
+","+(y-2*halfOfHeight)+" " +
-                               ""+ (x) +","+(y-2*halfOfHeight)+" " +
-                               ""+ (x+halfOfHeight) +","+(y-halfOfHeight)+" "
+                               ""+ (x+3*halfOfHeight) +","+(y+halfOfHeight)+" 
" +
+                               ""+ (x+2*halfOfHeight) 
+","+(y+2*halfOfHeight)+" " +
+                               ""+ (x) +","+(y+2*halfOfHeight)+" " +
+                               ""+ (x+halfOfHeight) +","+(y+halfOfHeight)+" "
                        );
                
                polygon.setAttributeNS(null, "fill", "#00CD66");

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/artifacts/Wire.java
 Mon Jun 13 07:37:39 2011
@@ -24,39 +24,20 @@ import org.w3c.dom.Element;
 
 public class Wire {
        
-//     <path d="M 100 100 L 300 100 L 200 300 z"
-//        fill="red" stroke="blue" stroke-width="3" />
-       
-//     public static Element addWireElement(Document document, String svgNs, 
int x1, int y1,
-//                     int x2, int y2) {
-//             // Create the rectangle.
-//             Element polyline = document.createElementNS(svgNs, "polyline");
-//             //polyline.setAttributeNS(null,"class", "Connect");
-//             polyline.setAttributeNS(null, "points", x1+","+y1+" 
"+x2+","+y2);
-//             polyline.setAttributeNS(null, "stroke", "black");
-//             polyline.setAttributeNS(null, "stroke-width", "2");
-////           polygon.setAttributeNS(null, "points", 
-////                           ""+ (midX-COMMON_LENGTH) +","+midY+" " +
-////                           ""+ (midX+(COMMON_LENGTH/2)) +","+midY+" " +
-////                           ""+ (midX+COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH)+" " +
-////                           ""+ (midX+(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH*2)+" " +
-////                           ""+ (midX-COMMON_LENGTH) 
+","+(midY-COMMON_LENGTH*2)+" " +
-////                           ""+ (midX-(COMMON_LENGTH/2)) 
+","+(midY-COMMON_LENGTH)+" "
-////                   );
-//             //polyline.setAttributeNS(null, "fill", "purple");
-//             //rectangle.setAttributeNS(null, "alignment-baseline", 
"central");
-//             
-//             return polyline;
-//     }
        
        public Element addElement(Document document, String svgNs, 
                        Reference aReference, Service aService){
                
                Element polyline = document.createElementNS(svgNs, "polyline");
+               int x1=aReference.getxCoordinate()+aReference.getHeight()*3/2;
+               int y1=aReference.getyCoordinate()+aReference.getHeight()/2;
+               
+               int x2=aService.getxCoordinate()+aService.getHeight()/2;
+               int y2=aService.getyCoordinate()+aService.getHeight()/2;
                //polyline.setAttributeNS(null,"class", "Connect");
-               polyline.setAttributeNS(null, "points", 
aReference.getxCoordinate()+","+
-                               aReference.getyCoordinate()+" 
"+aService.getxCoordinate()+","+
-                               aService.getyCoordinate());
+               polyline.setAttributeNS(null, "points", x1+","+
+                               y1+" "+x2+","+y2
+                               );
                polyline.setAttributeNS(null, "stroke", "black");
                polyline.setAttributeNS(null, "stroke-width", "2");
                

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
 Mon Jun 13 07:37:39 2011
@@ -1,16 +1,188 @@
 package org.apache.tuscany.sca.impl.diagram;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.tuscany.sca.impl.artifacts.Component;
+import org.apache.tuscany.sca.impl.artifacts.Composite;
+import org.apache.tuscany.sca.impl.artifacts.Property;
+import org.apache.tuscany.sca.impl.artifacts.Reference;
+import org.apache.tuscany.sca.impl.artifacts.Service;
+import org.apache.tuscany.sca.impl.artifacts.Text;
+import org.apache.tuscany.sca.impl.artifacts.Wire;
 import org.apache.tuscany.sca.impl.layout.Entity;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 public class DiagramGenerator {
        
        Entity[] entities;
+       int height, width;
+       Document doc;
+       String compositeName;
+       String svgNS ;
+       Element svgRoot;
+       ArrayList<Reference> refs= new ArrayList<Reference>();
+       ArrayList<Service> sers= new ArrayList<Service>();
 
-       public DiagramGenerator(Entity[] entities) {
+       public DiagramGenerator(Entity[] entities, int height, int width, 
String compositeName) {
                this.entities = entities;
+               this.height = height;
+               this.width = width;
+               this.compositeName = compositeName;
        }
        
+       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();
+               
+               addComposite();
+               for(Entity ent: entities){
+                       addComponent(ent);
+                       addService(ent);
+                       addReference(ent);
+                       addProperties(ent);
+               }
+               
+               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();
+                               
+                               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();
+               Element wire = edge.addElement(doc, svgNS, r, s);
+               svgRoot.appendChild(wire);
+       }
+
+       private Service getSer(String ser) {
+
+               for(Service s: sers){
+                       if(s.getContainerName().equals(ser) || 
s.getName().equals(ser)){
+                               return s;
+                       }
+               }
+               return null;
+       }
+
+       private Reference getRef(String ref) {
+
+               for(Reference r: refs){
+                       if(r.getContainerName().equals(ref) || 
r.getName().equals(ref)){
+                               return r;
+                       }
+               }
+               return null;
+       }
+
+       private void addProperties(Entity ent) {
+               int propLen = ent.getPropLength();
+               int x=ent.getX()+Property.SPACING;
+               int y= ent.getY()-propLen/2;
+
+               for(String prop: ent.getProperties()){
+                       Property pro = new Property();
+                       Element property = pro.addElement(doc, svgNS, x, y, 
propLen);
+                       Element text = Text.addTextElement(doc, svgNS, x, y, 
prop);
+                       
+                       svgRoot.appendChild(property);
+                       svgRoot.appendChild(text);
+                       
+                       x += (propLen + Property.SPACING);
+                       
+                       pro.setName(prop);
+                       pro.setContainerName(ent.getComponentName());
+               }
+       }
+
+       private void addReference(Entity ent) {
+               int refHeight = ent.getRefHeight();
+               int x=(ent.getX()+ent.getWidth())-(refHeight*2/3);
+               int y=ent.getY()+Reference.SPACING;
+
+               for(String ref: ent.getReferences()){
+                       Reference refer= new Reference();
+                       Element polygon = refer.addElement(doc, svgNS, x, y, 
refHeight);
+                       Element text = Text.addTextElement(doc, svgNS, x, 
y+refHeight/2, ref);
+                       svgRoot.appendChild(polygon);
+                       svgRoot.appendChild(text);
+                       
+                       y += (refHeight + Reference.SPACING);
+                       
+                       refer.setName(ref);
+                       refer.setContainerName(ent.getComponentName());
+                       refs.add(refer);
+                       
+               }
+       }
+
+       private void addService(Entity ent) {
+               int serHeight = ent.getSerHeight();
+               int x=ent.getX()-(serHeight*2/3);
+               int y=ent.getY()+Service.SPACING;
+
+               for(String ser: ent.getServices()){
+                       Service serve= new Service();
+                       Element polygon = serve.addElement(doc, svgNS, x, y, 
serHeight);
+                       Element text = Text.addTextElement(doc, svgNS, x, 
y+serHeight/2, ser);
+                       svgRoot.appendChild(polygon);
+                       svgRoot.appendChild(text);
+                       
+                       y += (serHeight + Service.SPACING);
+                       
+                       serve.setName(ser);
+                       serve.setContainerName(ent.getComponentName());
+                       sers.add(serve);
+               }
+       }
+
+       private void addComponent(Entity ent) {
+
+               Component comp = new Component();
+               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());
+               
+               svgRoot.appendChild(com);
+               svgRoot.appendChild(text);
+               
+               comp.setName(ent.getComponentName());
+       }
+
+       private void addComposite() {
+
+               Composite composite = new Composite();
+               Element composi = composite.addElement(doc, svgNS, 0, 0, 
height, width);
+               Element text = Text.addTextElement(doc, svgNS, width/2, 20, 
compositeName);
+               
+               svgRoot.appendChild(composi);
+               svgRoot.appendChild(text);
+               
+               composite.setName(compositeName);
+               
+               
+       }
        
        
 

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLReader.java
 Mon Jun 13 07:37:39 2011
@@ -1,13 +1,8 @@
 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 {
 

Added: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java?rev=1135039&view=auto
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java
 (added)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java
 Mon Jun 13 07:37:39 2011
@@ -0,0 +1,27 @@
+package org.apache.tuscany.sca.impl.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+
+public class XMLWriter {
+
+       public void fileWriter(Document doc, File outFile) throws Exception{
+
+               FileWriter fileWriter = new FileWriter(outFile);
+               BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
+               TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
+               Transformer transformer = transformerFactory.newTransformer();
+               DOMSource source = new DOMSource(doc);
+               StreamResult result =  new StreamResult(bufferedWriter);
+               transformer.transform(source, result);
+
+       }
+}

Propchange: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/Entity.java
 Mon Jun 13 07:37:39 2011
@@ -12,14 +12,13 @@ import org.apache.tuscany.sca.impl.artif
 /**
  * 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=-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); 
@@ -178,6 +177,7 @@ public class Entity {
        public void setServices(ArrayList<String> services) {
                this.services = services;
        }
+       
        public ArrayList<String> getServices() {
                return services;
        }
@@ -217,6 +217,10 @@ public class Entity {
        public ArrayList<String> getRefProperties() {
                return refProperties;
        }
+       
+       public ArrayList<String> getReferences() {
+               return references;
+       }
 
        public void setRefProperties(ArrayList<String> refProperties) {
                this.refProperties = refProperties;
@@ -258,4 +262,12 @@ public class Entity {
                return connectedEntities;
        }
 
+       public int getHeight() {
+               return height;
+       }
+
+       public int getWidth() {
+               return width;
+       }
+
 }

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java
 Mon Jun 13 07:37:39 2011
@@ -2,23 +2,23 @@ package org.apache.tuscany.sca.impl.layo
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
-
 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 initPoint = 100;//initial point
        private final int spaceX = Component.DEFAULT_WIDTH*2;
        private final int spaceY = Component.DEFAULT_HEIGHT*2;
        private ArrayList<Integer> levelCount = new 
ArrayList<Integer>();//keeps track of levels used in lanes
        private HashMap<String, ArrayList<String>> connectedEntities = new 
HashMap<String, ArrayList<String>>();
-       public final int totalLength=0, totalHeight=0;
+       private int totalWidth=0;
+       private int totalHeight=0;
+       private Entity startEnt = null;
+       private String compositeName;
        
        public EntityBuilder(Document aDom){
                dom = aDom;
@@ -28,6 +28,8 @@ public class EntityBuilder {
                Entity[] elts = null;
                //get the root element
                Element docEle = dom.getDocumentElement();
+               compositeName = docEle.getAttribute("name");
+               System.out.println("compositeName "+compositeName);
 
                //get a nodelist of elements
                NodeList nl = docEle.getElementsByTagName("component");
@@ -47,51 +49,36 @@ public class EntityBuilder {
                        }
                }
 
-               //              //get a nodelist of elements
-               //              NodeList nl2 = 
docEle.getElementsByTagName("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;
-               //                                      }
-               //                              }
-               //                      }
-               //              }
-
-               //correctMap(elts);
-
                positionEntities(elts);
 
+               calculateProperties(elts);
                print(elts);
 
                return elts;
 
        }
 
-       //      private void correctMap(Entity[] elts) {
-       //
-       //              for(Entity ent: elts){
-       //                      for(Iterator 
it=ent.getReferenceToServiceMap().values().iterator();it.hasNext();){
-       //                              String target = (String)it.next();
-       //                              if(target.startsWith("#")){
-       //                                      for(Entity e: elts){
-       //                                              
if(e.getComponentName().equals(target.substring(1))){
-       //                                                      
-       //                                              }
-       //                                      }
-       //                              }
-       //                      }
-       //              }
-       //      }
+       private void calculateProperties(Entity[] elts) {
+               int level=0, lane=0;
+
+               for(Entity ent: elts){
+                       level = max(level, ent.getLevel());
+                       lane = max(lane, ent.getLane());
 
+               }
+               totalHeight += spaceY*(level+1) + initPoint;
+               totalWidth += spaceX*(lane+1) + initPoint;
+               
+               System.err.println(totalHeight + " :: "+totalWidth);
+       }
+       
+       private int max(int a, int b){
+               if(a>=b)
+                       return a;
+               return b;
+       }
+
+       
        private void print(Entity[] elts) {
 
                for(Entity ent: elts){
@@ -101,7 +88,7 @@ public class EntityBuilder {
        }
 
        private void positionEntities(Entity[] ents){
-               Entity startEnt = null;
+               
                for(Entity ent: ents){
                        if(ent.getAdjacentEntities().size() != 0 || 
ents.length==1){
                                setPosition(ent, initPoint, initPoint, 0, 0);
@@ -112,31 +99,19 @@ public class EntityBuilder {
                        }
                }
                
-//             for(Entity ent: ents){
-//                     if(ent != startEnt){
-//                             assignPosition(ent, ents);
-//                     }
-//             }
 
                if(startEnt != null)
                        assignPositions(ents, startEnt);
 
        }
 
-       private void assignPosition(Entity ent, Entity[] ents) {
-
-               
-       }
-
        private void assignPositions(Entity[] ents, Entity ent){
                int i=0;
-               
-               //for(Entity ent: ents){
+               if(ent.getAdjacentEntities().size()>0){
                        
-                       if(ent.getAdjacentEntities().size()>0){
-                               System.out.println(ent.getComponentName());
+                       System.out.println(ent.getComponentName());
                        for(String name: ent.getAdjacentEntities()){
-                               System.out.println("eee "+name);
+                               //System.out.println("eee "+name);
                                for(Entity aEnt: ents){
                                        i++;
                                        
if(name.equalsIgnoreCase(aEnt.getComponentName())){
@@ -150,7 +125,7 @@ public class EntityBuilder {
                                                        levelCount.add(lane, 
level+1);
                                                        setPosition(aEnt, 
ent.getX()+spaceX, ent.getY()+spaceY*level, level, lane);
                                                }
-                                       if(i<ents.length)
+                                               if(i<ents.length)
                                                        assignPositions(ents, 
aEnt);
                                                break;
                                        }
@@ -158,42 +133,30 @@ public class EntityBuilder {
                                }
                        }
                }
-                       
-               //}
-       
-                       else{
-                               ArrayList<String> conns = 
connectedEntities.get(ent.getComponentName());
-                               System.err.println(conns.size());
-                               if(conns.size()>0){
-                                       
-                                       for(String conn: conns){
-                                               System.err.println("conn "+conn 
+" : "+ent.getComponentName());
+
+
+               else{
+                       ArrayList<String> conns = 
connectedEntities.get(ent.getComponentName());
+                       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)){
-                                                       
+
                                                        int lane = 
ent.getLane()-1;
                                                        
System.err.println(lane);
                                                        int level = 
levelCount.get(lane);
                                                        levelCount.add(lane, 
level+1);
                                                        setPosition(e, 
ent.getX()-spaceX, ent.getY()+spaceY*level, level, lane);
-                                                       
-//                                                     if(levelCount.size()<= 
lane){
-//                                                             
levelCount.add(lane, 1);
-//                                                             
setPosition(aEnt, ent.getX()+spaceX, ent.getY(), 0, lane);
-//                                                     }
-//                                                     else{
-//                                                             int level = 
levelCount.get(lane);
-//                                                             
levelCount.add(lane, level+1);
-//                                                             
setPosition(aEnt, ent.getX()+spaceX, ent.getY()+spaceY*level, level, lane);
-//                                                     }
-//                                                     
System.err.println(e.getComponentName());
-//                                                     assignPositions(ents, 
e);
+
                                                        break;
                                                }
                                        }
-                                       }
                                }
                        }
+               }
        }
 
        private void setPosition(Entity ent, int x, int y, int level, int lane){
@@ -223,9 +186,8 @@ public class EntityBuilder {
                                        
addToConnectedEntities(target.split("/")[0], ent.getComponentName());
                                }
                                else if(!target.equals("")){
-                                       //adding a #, since this is not the 
name of the service 
-                                       //but the component which has only one 
service
-                                       ent.addToRefToSerMap(ref,  "#"+target);
+                                       
+                                       ent.addToRefToSerMap(ref, target);
                                        ent.addAnAdjacentEntity(target);
                                        
addToConnectedEntities(ent.getComponentName(), target);
                                        addToConnectedEntities(target, 
ent.getComponentName());
@@ -274,6 +236,22 @@ public class EntityBuilder {
                }
        }
 
+       public void setCompositeName(String compositeName) {
+               this.compositeName = compositeName;
+       }
+
+       public String getCompositeName() {
+               return compositeName;
+       }
+
+       public int getTotalWidth() {
+               return totalWidth;
+       }
+
+       public int getTotalHeight() {
+               return totalHeight;
+       }
+
 
 
 }

Modified: 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
URL: 
http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java?rev=1135039&r1=1135038&r2=1135039&view=diff
==============================================================================
--- 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
 (original)
+++ 
tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
 Mon Jun 13 07:37:39 2011
@@ -1,10 +1,16 @@
 package org.apache.tuscany.sca.main;
 
+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.EntityBuilder;
 import org.w3c.dom.Document;
 
 public class Main {
+       private static final String outFileDir = 
System.getProperty("user.dir")+"/output/";
 
        /**
         * @param args
@@ -15,8 +21,12 @@ public class Main {
                XMLReader reader = new XMLReader();
                Document doc 
=reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite2.xml");
                EntityBuilder eb = new EntityBuilder(doc);
-               eb.buildEntities();
-               
+               Entity[] 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");
+               XMLWriter writer = new XMLWriter();
+               writer.fileWriter(svg, outFile);
        }
 
 }


Reply via email to