tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1164123 [3/4] - in /tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src: main/java/org/apache/tuscany/sca/impl/artifacts/ main/java/org/apache/tuscany/sca/impl/diagram/ main/java/org/apache/tuscany/sca/impl/html/...
Date Thu, 01 Sep 2011 15:57:26 GMT
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=1164123&r1=1164122&r2=1164123&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 Thu Sep  1 15:57:25 2011
@@ -21,727 +21,713 @@ package org.apache.tuscany.sca.impl.layo
 
 import java.util.ArrayList;
 import java.util.HashMap;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
 public class EntityBuilder {
 
-	private Document dom;
-	
-	//components connected to each other are tracked using following map
-	private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
-	private int totalWidth=0;
-	private int totalHeight=0;
-	
-	CompositeEntity composite = null;
-	
-	/**
-	 * Constructor which initiates the DOM document
-	 * @param aDom DOM document
-	 */
-	public EntityBuilder(Document aDom){
-		dom = aDom;
-	}
-
-	public CompositeEntity buildCompositeEntity(){
-		
-		//get the root element
-		Element docEle = dom.getDocumentElement();
-		
-		String compositeName;
-		compositeName = docEle.getAttribute("name");
-		//System.out.println("compositeName "+compositeName);
-		
-		ComponentEntity[] comps = buildComponentEntities(docEle);
-		
-		composite = new CompositeEntity(compositeName);
-		
-		setParent(comps);
-		
-		//System.out.println("ComponentEntity "+comps[0].getLevel());
-		int[][] conns = buildConnectionMatrix(comps);
-		
-		composite.setComponentList(comps);
-		composite.setConnections(conns);
-		
-		LayoutBuilder buildLayout = new LayoutBuilder(comps , conns);
-		buildLayout.placeEntities();
-		
-		
-		//System.out.println("conns "+conns[0][0]);
-		
-		
-		buildCompositeService(docEle);
-		buildCompositeReference(docEle);
-		buildCompositeProperty(docEle);
-		
-		addInclusions(docEle);
-		
-		composite.setAttributes();
-		
-		return composite;
-	}
-	
-	
-
-//	private void assignCoordinates() {
-//
-//		for(Entity ent: elts){
-//			ent.setX(ent.getParent().getX() + ent.getStartPosition());
-//			ent.setY(ent.getParent().getY() + ent.getStartPosition()/2);
-//		}
-//	}
-	
-	private void setParent(ComponentEntity[] comps) {
-
-		for(ComponentEntity comp: comps){
-			comp.setParent(composite);
-		}
-	}
-
-	private void buildCompositeService(Element docEle) {
-
-		NodeList nl = docEle.getElementsByTagName("service");
-		//System.err.println("^^^^^^^^^ "+nl.getLength());
-		if(nl != null && nl.getLength() > 0 ) {
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				
-				Element elt = (Element)nl.item(i);
-				
-				if(elt.getParentNode().getNodeName().equals("composite")){
-					String compositeSer = elt.getAttribute("name");
-					composite.addAService(compositeSer);
-
-					String target = elt.getAttribute("promote");
-
-					String service, serviceComp;
-					String[] arr1 = extractComp(target);
-					serviceComp = arr1[0];
-					service = arr1[1];
-
-					if(service == null){
-						composite.addToPromoteAService(compositeSer, serviceComp);
-					}
-					else{
-						composite.addToPromoteAService(compositeSer, service);
-					}
-				}
-
-			}
-		}
-	}
-	
-	private void buildCompositeReference(Element docEle) {
-
-		NodeList nl = docEle.getElementsByTagName("reference");
-		//System.out.println("^^^^^^^^^ "+nl.getLength());
-		if(nl != null && nl.getLength() > 0 ) {
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				
-				Element elt = (Element)nl.item(i);
-				
-				if(elt.getParentNode().getNodeName().equals("composite")){
-					String compositeRef = elt.getAttribute("name");
-					composite.addAReference(compositeRef);
-
-					String targetStr = elt.getAttribute("promote");
-					
-					String[] targets = targetStr.split(" ");
-					
-					for(String target: targets){
-
-						String reference, referenceComp;
-						String[] arr1 = extractComp(target);
-						referenceComp = arr1[0];
-						reference = arr1[1];
-
-						if(reference == null){
-							composite.addToPromoteAReference(compositeRef, referenceComp);
-						}
-						else{
-							composite.addToPromoteAReference(compositeRef, reference);
-						}
-					}
-
-				}
-			}
-		}
-	}
-	
-	private void buildCompositeProperty(Element docEle) {
-
-		NodeList nl = docEle.getElementsByTagName("property");
-		//System.out.println("^^^^^^^^^ "+nl.getLength());
-		if(nl != null && nl.getLength() > 0 ) {
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				
-				Element elt = (Element)nl.item(i);
-				
-				if(elt.getParentNode().getNodeName().equals("composite")){
-					String compositeProp = elt.getAttribute("name");
-					composite.addAProperty(compositeProp);
-				}
-			}
-		}
-	}
-	
-	private void addInclusions(Element docEle) {
-
-		NodeList nl = docEle.getElementsByTagName("include");
-		//System.out.println("^^^^^^^^^ "+nl.getLength());
-		if(nl != null && nl.getLength() > 0 ) {
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				
-				Element elt = (Element)nl.item(i);
-				
-				if(elt.getParentNode().getNodeName().equals("composite")){
-					String compToBeIncluded = elt.getAttribute("name");
-					composite.addToIncludedComposites(compToBeIncluded);
-				}
-			}
-		}
-	}
-
-	private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
-
-		int[][] connections = new int[comps.length][comps.length];
-		connections = initConnections(connections);
-		
-//		//sec. 5.4 in the spec
-//		NodeList nl = docEle.getElementsByTagName("wire");
-//		//System.out.println("^^^^^^^^^ "+nl.getLength());
-//		if(nl != null && nl.getLength() > 0 ) {
-//			
-//			for(int i = 0 ; i < nl.getLength();i++) {
-//				
-//				Element elt = (Element)nl.item(i);
-//				
-//				String source = elt.getAttribute("source");
-//				String target = elt.getAttribute("target");
-//				
-//				String service, serviceComp, reference, referenceComp;
-//				
-//				String[] arr1 = extractComp(target);
-//				serviceComp = arr1[0];
-//				service = arr1[1];
-//				
-//				String[] arr2 = extractComp(source);
-//				referenceComp = arr2[0];
-//				reference = arr2[1];
-				
-//				//System.out.println("^^^^^^^^^ "+source+" ::: "+target);
-//				if(target.contains("/")){
-//					String[] arr = target.split("/");
-//					serviceComp = arr[0];
-//					service = arr[1];
-//				}
-//				else{
-//					serviceComp = target;
-//					service = null;
-//				}
-//				
-//				if(source.contains("/")){
-//					String[] arr = source.split("/");
-//					referenceComp = arr[0];
-//					reference = arr[1];
-//				}
-//				else{
-//					referenceComp = source;
-//					reference = null;
-//				}
-//				//sec. 5.4 in the spec
-//		NodeList nl = docEle.getElementsByTagName("wire");
-//		//System.out.println("^^^^^^^^^ "+nl.getLength());
-//		if(nl != null && nl.getLength() > 0 ) {
-//			
-//			for(int i = 0 ; i < nl.getLength();i++) {
-//				
-//				Element elt = (Element)nl.item(i);
-//				
-//				String source = elt.getAttribute("source");
-//				String target = elt.getAttribute("target");
-//				
-//				String service, serviceComp, reference, referenceComp;
-//				
-//				String[] arr1 = extractComp(target);
-//				serviceComp = arr1[0];
-//				service = arr1[1];
-//				
-//				String[] arr2 = extractComp(source);
-//				referenceComp = arr2[0];
-//				reference = arr2[1];
-		 
-		for(Entity ent: comps){
-			for(String name: ent.getAdjacentEntities()){
-				ComponentEntity e2 = findEntity(comps, name);
-				if(ent != null && e2 != null){
-					//System.out.println("^^^^^^^^^ "+e2.getName());
-					connections[ent.getId()][e2.getId()] = 1;
-				}
-			}
-				
-		}
-//				ComponentEntity e1 = findEntity(comps, referenceComp);
-//				ComponentEntity e2 = findEntity(comps, serviceComp);
-//				
-//				System.out.println("^^^^^^^^^ "+e1.getName());
-//				if(e1 != null && e2 != null){
-//					System.out.println("^^^^^^^^^ "+e1.getId());
-//					connections[e1.getId()][e2.getId()] = 1;
-//					createConnection(e1, reference, serviceComp, service);
-//				}
-//			}
-//		}
-//		
-		return connections;
-	}
-
-	private String[] extractComp(String str) {
-		
-		String[] arr = new String[2];
-		
-		if(str.contains("/")){
-			arr = str.split("/");
-		}
-		else{
-			arr[0] = str;
-			arr[1] = null;
-		}
-		return arr;
-	}
-
-	private int[][] initConnections(int[][] connections) {
-
-		for(int i=0; i<connections.length ; i++){
-			for(int j=0; j<connections.length ; j++){
-				connections[i][j] =0;
-			}
-		}
-		return connections;
-	}
-
-	
-	public ComponentEntity[] buildComponentEntities(Element docEle){
-		
-		ComponentEntity[] 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");
-		if(nl != null && nl.getLength() > 0 ) {
-			elts = new ComponentEntity[nl.getLength()];
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				elts[i] = new ComponentEntity();
-				Element nVal = (Element)nl.item(i);
-				//System.out.println(nVal.hasAttribute("name"));
-				elts[i].setId(i);
-				elts[i].setName(nVal.getAttribute("name"));
-				
-				setServices(nVal, elts[i]);
-				setReferences(nVal, elts[i]);
-				setProperties(nVal, elts[i]);
-				
-				elts[i].referenceHeight();
-				elts[i].serviceHeight();
-				elts[i].propertyLength();
-			}
-		}
-		
-		buildWires(docEle, elts);
-//		//sec. 5.4 in the spec
-//		nl = docEle.getElementsByTagName("wire");
-//		System.out.println("^^^^^^^^^ "+nl.getLength());
-//		if(nl != null && nl.getLength() > 0 ) {
-//			for(int i = 0 ; i < nl.getLength();i++) {
-//				Element elt = (Element)nl.item(i);
-//				String source = elt.getAttribute("source");
-//				String target = elt.getAttribute("target");
-//				String service, serviceComp, reference, referenceComp;
-//				
-//				System.out.println("^^^^^^^^^ "+source+" ::: "+target);
-//				if(target.contains("/")){
-//					String[] arr = target.split("/");
-//					serviceComp = arr[0];
-//					service = arr[1];
-//				}
-//				else{
-//					serviceComp = target;
-//					service = null;
-//				}
-//				
-//				if(source.contains("/")){
-//					String[] arr = source.split("/");
-//					referenceComp = arr[0];
-//					reference = arr[1];
-//				}
-//				else{
-//					referenceComp = source;
-//					reference = null;
-//				}
-//				
-//				ComponentEntity e = findEntity(referenceComp);
-//				System.out.println("^^^^^^^^^ "+e.getName());
-//				if(e != null){
-//					createConnection(e, reference, serviceComp, service);
-//				}
-//			}
-//		}
-//
-//		positionEntities(elts);
-//
-//		calculateProperties(elts);
-	//	print(elts);
-
-		return elts;
-
-	}
-	
-	private void buildWires(Element docEle, ComponentEntity[] elts) {
-
-		//sec. 5.4 in the spec
-		NodeList nl = docEle.getElementsByTagName("wire");
-		//System.out.println("^^^^^^^^^ "+nl.getLength());
-		if(nl != null && nl.getLength() > 0 ) {
-			
-			for(int i = 0 ; i < nl.getLength();i++) {
-				
-				Element elt = (Element)nl.item(i);
-				
-				String source = elt.getAttribute("source");
-				String target = elt.getAttribute("target");
-				
-				String service, serviceComp, reference, referenceComp;
-				
-				String[] arr1 = extractComp(target);
-				serviceComp = arr1[0];
-				service = arr1[1];
-				
-				String[] arr2 = extractComp(source);
-				referenceComp = arr2[0];
-				reference = arr2[1];
-				
-//				//System.out.println("^^^^^^^^^ "+source+" ::: "+target);
-//				if(target.contains("/")){
-//					String[] arr = target.split("/");
-//					serviceComp = arr[0];
-//					service = arr[1];
-//				}
-//				else{
-//					serviceComp = target;
-//					service = null;
-//				}
-//				
-//				if(source.contains("/")){
-//					String[] arr = source.split("/");
-//					referenceComp = arr[0];
-//					reference = arr[1];
-//				}
-//				else{
-//					referenceComp = source;
-//					reference = null;
-//				}
-//				
-				ComponentEntity e1 = findEntity(elts, referenceComp);
-				//ComponentEntity e2 = findEntity(comps, serviceComp);
-				
-				//System.out.println("^^^^^^^^^ "+e1.getName());
-				if(e1 != null){
-					//System.out.println("^^^^^^^^^ "+e1.getId());
-					//connections[e1.getId()][e2.getId()] = 1;
-					createConnection(e1, reference, serviceComp, service);
-				}
-			}
-		}
-
-	}
-
-	private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
-
-		for(ComponentEntity e: elts){
-			if(e.getName().equals(componentName)){
-				return e;
-			}
-		}
-		return null;
-	}
-
-	private void setReferences(Element nVal, ComponentEntity ent) {
-
-		NodeList nl = nVal.getElementsByTagName("reference");
-		if(nl != null && nl.getLength() > 0 ) {
-			for(int i = 0 ; i < nl.getLength();i++) {
-				Element elt = (Element)nl.item(i);
-				String target = elt.getAttribute("target");
-				String ref = elt.getAttribute("name");
-				if(target.contains("/")){
-					String[] arr = target.split("/");
-					createConnection(ent, ref, arr[0], arr[1]);
-//					ent.addToRefToSerMap(ref, arr[1]);
-//					ent.addAnAdjacentEntity(arr[0]);
-//					addToConnectedEntities(ent.getComponentName(), arr[0]);
-//					addToConnectedEntities(arr[0], ent.getComponentName());
-				}
-				else if(!target.equals("")){
-					createConnection(ent, ref, target, null);
-//					ent.addToRefToSerMap(ref, target);
-//					ent.addAnAdjacentEntity(target);
-//					addToConnectedEntities(ent.getComponentName(), target);
-//					addToConnectedEntities(target, ent.getComponentName());
-				}
-
-				ent.addAReference(ref);
-
-			}
-		}
-	}
-
-	private void createConnection(ComponentEntity ent, String reference,
-			String serviceComp, String service) {
-
-		String referenceComp = ent.getName();
-
-		if(reference != null &&  service != null){
-
-			ent.addToRefToSerMap(reference, service);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else if(reference == null &&  service != null){
-			ent.addToRefToSerMap(referenceComp, service);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else if(reference != null &&  service == null){
-			ent.addToRefToSerMap(reference, serviceComp);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else{
-			ent.addToRefToSerMap(referenceComp, serviceComp);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-	}
-
-//	private void calculateProperties(ComponentEntity[] elts) {
-//		int level=0, lane=0;
-//
-//		for(ComponentEntity 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;
-//	}
-
-	
-	@SuppressWarnings("unused")
-	private void print(ComponentEntity[] elts) {
-
-		for(ComponentEntity ent: elts){
-			System.out.println(ent.getName()+" : "+ent.getLevel()+" : "
-					+ent.getLane()+" : "+ent.getX()+" : "+ent.getY());
-		}
-	}
-
-//	private void positionEntities(ComponentEntity[] ents){
-//		
-//		for(ComponentEntity ent: ents){
-//			if(ent.getAdjacentEntities().size() != 0 || ents.length==1){
-//				setPosition(ent, initPoint, initPoint, 0, 0);
-//				levelCount.add(0, 1);
-//				startEnt = ent;
-//				System.err.println(ent.getName());
-//				break;
-//			}
-//		}
-//		
-//
-//		if(startEnt != null)
-//			assignPositions(ents, startEnt);
-//
-//	}
-//
-//	private void assignPositions(ComponentEntity[] ents, ComponentEntity ent){
-//		int i=0;
-//		if(ent.getAdjacentEntities().size()>0){
-//			
-//			System.out.println(ent.getName());
-//			for(String name: ent.getAdjacentEntities()){
-//				//System.out.println("eee "+name);
-//				for(ComponentEntity aEnt: ents){
-//					i++;
-//					if(name.equalsIgnoreCase(aEnt.getName())){
-//						int lane = ent.getLane()+1;
-//						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);
-//						}
-//						if(i<ents.length)
-//							assignPositions(ents, aEnt);
-////						else
-////							System.out.println(i+ " <<<<< "+ents.length);
-//						break;
-//					}
-//
-//				}
-//			}
-//		}
-//
-//
-//		else{
-//			ArrayList<String> conns = connectedEntities.get(ent.getName());
-//			System.err.println(conns.size());
-//			if(conns.size()>0){
-//
-//				for(String conn: conns){
-//					System.err.println("conn "+conn +" : "+ent.getName());
-//					for(ComponentEntity e: ents){
-//						if(e.getLane() == -1 && e.getName().equals(conn)){
-//
-//							int lane = ent.getLane()-1;
-//							System.err.println(lane);
-//							int level = levelCount.get(lane);
-//							levelCount.add(lane, level+1);
-//							setPosition(e, ent.getX()-spaceX, ent.getY()+spaceY*level, level, lane);
-//
-//							break;
-//						}
-//					}
-//				}
-//			}
-//		}
-//	}
-//
-//	private void setPosition(ComponentEntity 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 addToConnectedEntities(String ent1, String ent2) {
-		//System.err.println(ent1+" : "+ent2);
-		ArrayList<String> list;
-		if(connectedEntities.containsKey(ent1)){
-			list = connectedEntities.get(ent1);
-			
-		}
-		else{
-			list =new ArrayList<String>();
-			
-		}
-		list.add(ent2);
-		connectedEntities.put(ent1, list);
-	}
-
-	private void setServices(Element nVal, ComponentEntity ent) {
-
-		NodeList nl = nVal.getElementsByTagName("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"));
-			}
-		}
-		else{
-		
-		NodeList nl1 = nVal.getElementsByTagName("implementation.java");
-		if(nl1 != null && nl1.getLength() > 0 ) {
-			for(int i = 0 ; i < nl1.getLength();i++) {
-				Element elt = (Element)nl1.item(i);
-				//System.out.println(elt.getAttribute("class"));
-				String serName = extractServiceName(elt.getAttribute("class"));
-				ent.addAService(serName);
-			}
-		}
-		
-		}
-		
-	}
-
-	/**
-	 * 
-	 * This will extract the service name part from the class attribute of 
-	 * implementation.java element. 
-	 * eg: if class = "NirmalServiceImpl", returning service name would be "NirmalService"
-	 */
-	private String extractServiceName(String classAttr) {
-		if(classAttr != null){
-			String[] x=classAttr.split("\\.");
-			String name = x[x.length-1];
-			if(name.endsWith("Impl")){
-				return name.substring(0, name.length()-4);
-			}
-			else{
-				return name;
-			}
-		}
-		return "";
-	}
-
-	private void setProperties(Element nVal, ComponentEntity ent) {
-
-		NodeList nl = nVal.getElementsByTagName("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"));
-			}
-		}
-	}
-
-//	public void setCompositeName(String compositeName) {
-//		this.compositeName = compositeName;
-//	}
-//
-//	public String getCompositeName() {
-//		return compositeName;
-//	}
-
-	public int getTotalWidth() {
-		return totalWidth;
-	}
-
-	public int getTotalHeight() {
-		return totalHeight;
-	}
-
+    private Document dom;
 
+    //components connected to each other are tracked using following map
+    private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
+    private int totalWidth = 0;
+    private int totalHeight = 0;
+
+    CompositeEntity composite = null;
+
+    /**
+     * Constructor which initiates the DOM document
+     * @param aDom DOM document
+     */
+    public EntityBuilder(Document aDom) {
+        dom = aDom;
+    }
+
+    public CompositeEntity buildCompositeEntity() {
+
+        //get the root element
+        Element docEle = dom.getDocumentElement();
+
+        String compositeName;
+        compositeName = docEle.getAttribute("name");
+        //System.out.println("compositeName "+compositeName);
+
+        ComponentEntity[] comps = buildComponentEntities(docEle);
+
+        composite = new CompositeEntity(compositeName);
+
+        setParent(comps);
+
+        //System.out.println("ComponentEntity "+comps[0].getLevel());
+        int[][] conns = buildConnectionMatrix(comps);
+
+        composite.setComponentList(comps);
+        composite.setConnections(conns);
+
+        LayoutBuilder buildLayout = new LayoutBuilder(comps, conns);
+        buildLayout.placeEntities();
+
+        //System.out.println("conns "+conns[0][0]);
+
+        buildCompositeService(docEle);
+        buildCompositeReference(docEle);
+        buildCompositeProperty(docEle);
+
+        addInclusions(docEle);
+
+        composite.setAttributes();
+
+        return composite;
+    }
+
+    //	private void assignCoordinates() {
+    //
+    //		for(Entity ent: elts){
+    //			ent.setX(ent.getParent().getX() + ent.getStartPosition());
+    //			ent.setY(ent.getParent().getY() + ent.getStartPosition()/2);
+    //		}
+    //	}
+
+    private void setParent(ComponentEntity[] comps) {
+
+        for (ComponentEntity comp : comps) {
+            comp.setParent(composite);
+        }
+    }
+
+    private void buildCompositeService(Element docEle) {
+
+        NodeList nl = docEle.getElementsByTagName("service");
+        //System.err.println("^^^^^^^^^ "+nl.getLength());
+        if (nl != null && nl.getLength() > 0) {
+
+            for (int i = 0; i < nl.getLength(); i++) {
+
+                Element elt = (Element)nl.item(i);
+
+                if (elt.getParentNode().getNodeName().equals("composite")) {
+                    String compositeSer = elt.getAttribute("name");
+                    composite.addAService(compositeSer);
+
+                    String target = elt.getAttribute("promote");
+
+                    String service, serviceComp;
+                    String[] arr1 = extractComp(target);
+                    serviceComp = arr1[0];
+                    service = arr1[1];
+
+                    if (service == null) {
+                        composite.addToPromoteAService(compositeSer, serviceComp);
+                    } else {
+                        composite.addToPromoteAService(compositeSer, service);
+                    }
+                }
+
+            }
+        }
+    }
+
+    private void buildCompositeReference(Element docEle) {
+
+        NodeList nl = docEle.getElementsByTagName("reference");
+        //System.out.println("^^^^^^^^^ "+nl.getLength());
+        if (nl != null && nl.getLength() > 0) {
+
+            for (int i = 0; i < nl.getLength(); i++) {
+
+                Element elt = (Element)nl.item(i);
+
+                if (elt.getParentNode().getNodeName().equals("composite")) {
+                    String compositeRef = elt.getAttribute("name");
+                    composite.addAReference(compositeRef);
+
+                    String targetStr = elt.getAttribute("promote");
+
+                    String[] targets = targetStr.split(" ");
+
+                    for (String target : targets) {
+
+                        String reference, referenceComp;
+                        String[] arr1 = extractComp(target);
+                        referenceComp = arr1[0];
+                        reference = arr1[1];
+
+                        if (reference == null) {
+                            composite.addToPromoteAReference(compositeRef, referenceComp);
+                        } else {
+                            composite.addToPromoteAReference(compositeRef, reference);
+                        }
+                    }
+
+                }
+            }
+        }
+    }
+
+    private void buildCompositeProperty(Element docEle) {
+
+        NodeList nl = docEle.getElementsByTagName("property");
+        //System.out.println("^^^^^^^^^ "+nl.getLength());
+        if (nl != null && nl.getLength() > 0) {
+
+            for (int i = 0; i < nl.getLength(); i++) {
+
+                Element elt = (Element)nl.item(i);
+
+                if (elt.getParentNode().getNodeName().equals("composite")) {
+                    String compositeProp = elt.getAttribute("name");
+                    composite.addAProperty(compositeProp);
+                }
+            }
+        }
+    }
+
+    private void addInclusions(Element docEle) {
+
+        NodeList nl = docEle.getElementsByTagName("include");
+        //System.out.println("^^^^^^^^^ "+nl.getLength());
+        if (nl != null && nl.getLength() > 0) {
+
+            for (int i = 0; i < nl.getLength(); i++) {
+
+                Element elt = (Element)nl.item(i);
+
+                if (elt.getParentNode().getNodeName().equals("composite")) {
+                    String compToBeIncluded = elt.getAttribute("name");
+                    composite.addToIncludedComposites(compToBeIncluded);
+                }
+            }
+        }
+    }
+
+    private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
+
+        int[][] connections = new int[comps.length][comps.length];
+        connections = initConnections(connections);
+
+        //		//sec. 5.4 in the spec
+        //		NodeList nl = docEle.getElementsByTagName("wire");
+        //		//System.out.println("^^^^^^^^^ "+nl.getLength());
+        //		if(nl != null && nl.getLength() > 0 ) {
+        //			
+        //			for(int i = 0 ; i < nl.getLength();i++) {
+        //				
+        //				Element elt = (Element)nl.item(i);
+        //				
+        //				String source = elt.getAttribute("source");
+        //				String target = elt.getAttribute("target");
+        //				
+        //				String service, serviceComp, reference, referenceComp;
+        //				
+        //				String[] arr1 = extractComp(target);
+        //				serviceComp = arr1[0];
+        //				service = arr1[1];
+        //				
+        //				String[] arr2 = extractComp(source);
+        //				referenceComp = arr2[0];
+        //				reference = arr2[1];
+
+        //				//System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+        //				if(target.contains("/")){
+        //					String[] arr = target.split("/");
+        //					serviceComp = arr[0];
+        //					service = arr[1];
+        //				}
+        //				else{
+        //					serviceComp = target;
+        //					service = null;
+        //				}
+        //				
+        //				if(source.contains("/")){
+        //					String[] arr = source.split("/");
+        //					referenceComp = arr[0];
+        //					reference = arr[1];
+        //				}
+        //				else{
+        //					referenceComp = source;
+        //					reference = null;
+        //				}
+        //				//sec. 5.4 in the spec
+        //		NodeList nl = docEle.getElementsByTagName("wire");
+        //		//System.out.println("^^^^^^^^^ "+nl.getLength());
+        //		if(nl != null && nl.getLength() > 0 ) {
+        //			
+        //			for(int i = 0 ; i < nl.getLength();i++) {
+        //				
+        //				Element elt = (Element)nl.item(i);
+        //				
+        //				String source = elt.getAttribute("source");
+        //				String target = elt.getAttribute("target");
+        //				
+        //				String service, serviceComp, reference, referenceComp;
+        //				
+        //				String[] arr1 = extractComp(target);
+        //				serviceComp = arr1[0];
+        //				service = arr1[1];
+        //				
+        //				String[] arr2 = extractComp(source);
+        //				referenceComp = arr2[0];
+        //				reference = arr2[1];
+
+        for (Entity ent : comps) {
+            for (String name : ent.getAdjacentEntities()) {
+                ComponentEntity e2 = findEntity(comps, name);
+                if (ent != null && e2 != null) {
+                    //System.out.println("^^^^^^^^^ "+e2.getName());
+                    connections[ent.getId()][e2.getId()] = 1;
+                }
+            }
+
+        }
+        //				ComponentEntity e1 = findEntity(comps, referenceComp);
+        //				ComponentEntity e2 = findEntity(comps, serviceComp);
+        //				
+        //				System.out.println("^^^^^^^^^ "+e1.getName());
+        //				if(e1 != null && e2 != null){
+        //					System.out.println("^^^^^^^^^ "+e1.getId());
+        //					connections[e1.getId()][e2.getId()] = 1;
+        //					createConnection(e1, reference, serviceComp, service);
+        //				}
+        //			}
+        //		}
+        //		
+        return connections;
+    }
+
+    private String[] extractComp(String str) {
+
+        String[] arr = new String[2];
+
+        if (str.contains("/")) {
+            arr = str.split("/");
+        } else {
+            arr[0] = str;
+            arr[1] = null;
+        }
+        return arr;
+    }
+
+    private int[][] initConnections(int[][] connections) {
+
+        for (int i = 0; i < connections.length; i++) {
+            for (int j = 0; j < connections.length; j++) {
+                connections[i][j] = 0;
+            }
+        }
+        return connections;
+    }
+
+    public ComponentEntity[] buildComponentEntities(Element docEle) {
+
+        ComponentEntity[] 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");
+        if (nl != null && nl.getLength() > 0) {
+            elts = new ComponentEntity[nl.getLength()];
+
+            for (int i = 0; i < nl.getLength(); i++) {
+                elts[i] = new ComponentEntity();
+                Element nVal = (Element)nl.item(i);
+                //System.out.println(nVal.hasAttribute("name"));
+                elts[i].setId(i);
+                elts[i].setName(nVal.getAttribute("name"));
+
+                setServices(nVal, elts[i]);
+                setReferences(nVal, elts[i]);
+                setProperties(nVal, elts[i]);
+
+                elts[i].referenceHeight();
+                elts[i].serviceHeight();
+                elts[i].propertyLength();
+            }
+        }
+
+        buildWires(docEle, elts);
+        //		//sec. 5.4 in the spec
+        //		nl = docEle.getElementsByTagName("wire");
+        //		System.out.println("^^^^^^^^^ "+nl.getLength());
+        //		if(nl != null && nl.getLength() > 0 ) {
+        //			for(int i = 0 ; i < nl.getLength();i++) {
+        //				Element elt = (Element)nl.item(i);
+        //				String source = elt.getAttribute("source");
+        //				String target = elt.getAttribute("target");
+        //				String service, serviceComp, reference, referenceComp;
+        //				
+        //				System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+        //				if(target.contains("/")){
+        //					String[] arr = target.split("/");
+        //					serviceComp = arr[0];
+        //					service = arr[1];
+        //				}
+        //				else{
+        //					serviceComp = target;
+        //					service = null;
+        //				}
+        //				
+        //				if(source.contains("/")){
+        //					String[] arr = source.split("/");
+        //					referenceComp = arr[0];
+        //					reference = arr[1];
+        //				}
+        //				else{
+        //					referenceComp = source;
+        //					reference = null;
+        //				}
+        //				
+        //				ComponentEntity e = findEntity(referenceComp);
+        //				System.out.println("^^^^^^^^^ "+e.getName());
+        //				if(e != null){
+        //					createConnection(e, reference, serviceComp, service);
+        //				}
+        //			}
+        //		}
+        //
+        //		positionEntities(elts);
+        //
+        //		calculateProperties(elts);
+        //	print(elts);
+
+        return elts;
+
+    }
+
+    private void buildWires(Element docEle, ComponentEntity[] elts) {
+
+        //sec. 5.4 in the spec
+        NodeList nl = docEle.getElementsByTagName("wire");
+        //System.out.println("^^^^^^^^^ "+nl.getLength());
+        if (nl != null && nl.getLength() > 0) {
+
+            for (int i = 0; i < nl.getLength(); i++) {
+
+                Element elt = (Element)nl.item(i);
+
+                String source = elt.getAttribute("source");
+                String target = elt.getAttribute("target");
+
+                String service, serviceComp, reference, referenceComp;
+
+                String[] arr1 = extractComp(target);
+                serviceComp = arr1[0];
+                service = arr1[1];
+
+                String[] arr2 = extractComp(source);
+                referenceComp = arr2[0];
+                reference = arr2[1];
+
+                //				//System.out.println("^^^^^^^^^ "+source+" ::: "+target);
+                //				if(target.contains("/")){
+                //					String[] arr = target.split("/");
+                //					serviceComp = arr[0];
+                //					service = arr[1];
+                //				}
+                //				else{
+                //					serviceComp = target;
+                //					service = null;
+                //				}
+                //				
+                //				if(source.contains("/")){
+                //					String[] arr = source.split("/");
+                //					referenceComp = arr[0];
+                //					reference = arr[1];
+                //				}
+                //				else{
+                //					referenceComp = source;
+                //					reference = null;
+                //				}
+                //				
+                ComponentEntity e1 = findEntity(elts, referenceComp);
+                //ComponentEntity e2 = findEntity(comps, serviceComp);
+
+                //System.out.println("^^^^^^^^^ "+e1.getName());
+                if (e1 != null) {
+                    //System.out.println("^^^^^^^^^ "+e1.getId());
+                    //connections[e1.getId()][e2.getId()] = 1;
+                    createConnection(e1, reference, serviceComp, service);
+                }
+            }
+        }
+
+    }
+
+    private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
+
+        for (ComponentEntity e : elts) {
+            if (e.getName().equals(componentName)) {
+                return e;
+            }
+        }
+        return null;
+    }
+
+    private void setReferences(Element nVal, ComponentEntity ent) {
+
+        NodeList nl = nVal.getElementsByTagName("reference");
+        if (nl != null && nl.getLength() > 0) {
+            for (int i = 0; i < nl.getLength(); i++) {
+                Element elt = (Element)nl.item(i);
+                String target = elt.getAttribute("target");
+                String ref = elt.getAttribute("name");
+                if (target.contains("/")) {
+                    String[] arr = target.split("/");
+                    createConnection(ent, ref, arr[0], arr[1]);
+                    //					ent.addToRefToSerMap(ref, arr[1]);
+                    //					ent.addAnAdjacentEntity(arr[0]);
+                    //					addToConnectedEntities(ent.getComponentName(), arr[0]);
+                    //					addToConnectedEntities(arr[0], ent.getComponentName());
+                } else if (!target.equals("")) {
+                    createConnection(ent, ref, target, null);
+                    //					ent.addToRefToSerMap(ref, target);
+                    //					ent.addAnAdjacentEntity(target);
+                    //					addToConnectedEntities(ent.getComponentName(), target);
+                    //					addToConnectedEntities(target, ent.getComponentName());
+                }
+
+                ent.addAReference(ref);
+
+            }
+        }
+    }
+
+    private void createConnection(ComponentEntity ent, String reference, String serviceComp, String service) {
+
+        String referenceComp = ent.getName();
+
+        if (reference != null && service != null) {
+
+            ent.addToRefToSerMap(reference, service);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else if (reference == null && service != null) {
+            ent.addToRefToSerMap(referenceComp, service);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else if (reference != null && service == null) {
+            ent.addToRefToSerMap(reference, serviceComp);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else {
+            ent.addToRefToSerMap(referenceComp, serviceComp);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        }
+    }
+
+    //	private void calculateProperties(ComponentEntity[] elts) {
+    //		int level=0, lane=0;
+    //
+    //		for(ComponentEntity 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;
+    //	}
+
+    @SuppressWarnings("unused")
+    private void print(ComponentEntity[] elts) {
+
+        for (ComponentEntity ent : elts) {
+            System.out.println(ent.getName() + " : "
+                + ent.getLevel()
+                + " : "
+                + ent.getLane()
+                + " : "
+                + ent.getX()
+                + " : "
+                + ent.getY());
+        }
+    }
+
+    //	private void positionEntities(ComponentEntity[] ents){
+    //		
+    //		for(ComponentEntity ent: ents){
+    //			if(ent.getAdjacentEntities().size() != 0 || ents.length==1){
+    //				setPosition(ent, initPoint, initPoint, 0, 0);
+    //				levelCount.add(0, 1);
+    //				startEnt = ent;
+    //				System.err.println(ent.getName());
+    //				break;
+    //			}
+    //		}
+    //		
+    //
+    //		if(startEnt != null)
+    //			assignPositions(ents, startEnt);
+    //
+    //	}
+    //
+    //	private void assignPositions(ComponentEntity[] ents, ComponentEntity ent){
+    //		int i=0;
+    //		if(ent.getAdjacentEntities().size()>0){
+    //			
+    //			System.out.println(ent.getName());
+    //			for(String name: ent.getAdjacentEntities()){
+    //				//System.out.println("eee "+name);
+    //				for(ComponentEntity aEnt: ents){
+    //					i++;
+    //					if(name.equalsIgnoreCase(aEnt.getName())){
+    //						int lane = ent.getLane()+1;
+    //						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);
+    //						}
+    //						if(i<ents.length)
+    //							assignPositions(ents, aEnt);
+    ////						else
+    ////							System.out.println(i+ " <<<<< "+ents.length);
+    //						break;
+    //					}
+    //
+    //				}
+    //			}
+    //		}
+    //
+    //
+    //		else{
+    //			ArrayList<String> conns = connectedEntities.get(ent.getName());
+    //			System.err.println(conns.size());
+    //			if(conns.size()>0){
+    //
+    //				for(String conn: conns){
+    //					System.err.println("conn "+conn +" : "+ent.getName());
+    //					for(ComponentEntity e: ents){
+    //						if(e.getLane() == -1 && e.getName().equals(conn)){
+    //
+    //							int lane = ent.getLane()-1;
+    //							System.err.println(lane);
+    //							int level = levelCount.get(lane);
+    //							levelCount.add(lane, level+1);
+    //							setPosition(e, ent.getX()-spaceX, ent.getY()+spaceY*level, level, lane);
+    //
+    //							break;
+    //						}
+    //					}
+    //				}
+    //			}
+    //		}
+    //	}
+    //
+    //	private void setPosition(ComponentEntity 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 addToConnectedEntities(String ent1, String ent2) {
+        //System.err.println(ent1+" : "+ent2);
+        ArrayList<String> list;
+        if (connectedEntities.containsKey(ent1)) {
+            list = connectedEntities.get(ent1);
+
+        } else {
+            list = new ArrayList<String>();
+
+        }
+        list.add(ent2);
+        connectedEntities.put(ent1, list);
+    }
+
+    private void setServices(Element nVal, ComponentEntity ent) {
+
+        NodeList nl = nVal.getElementsByTagName("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"));
+            }
+        } else {
+
+            NodeList nl1 = nVal.getElementsByTagName("implementation.java");
+            if (nl1 != null && nl1.getLength() > 0) {
+                for (int i = 0; i < nl1.getLength(); i++) {
+                    Element elt = (Element)nl1.item(i);
+                    //System.out.println(elt.getAttribute("class"));
+                    String serName = extractServiceName(elt.getAttribute("class"));
+                    ent.addAService(serName);
+                }
+            }
+
+        }
+
+    }
+
+    /**
+     * 
+     * This will extract the service name part from the class attribute of 
+     * implementation.java element. 
+     * eg: if class = "NirmalServiceImpl", returning service name would be "NirmalService"
+     */
+    private String extractServiceName(String classAttr) {
+        if (classAttr != null) {
+            String[] x = classAttr.split("\\.");
+            String name = x[x.length - 1];
+            if (name.endsWith("Impl")) {
+                return name.substring(0, name.length() - 4);
+            } else {
+                return name;
+            }
+        }
+        return "";
+    }
+
+    private void setProperties(Element nVal, ComponentEntity ent) {
+
+        NodeList nl = nVal.getElementsByTagName("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"));
+            }
+        }
+    }
+
+    //	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/impl/layout/LayoutBuilder.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java?rev=1164123&r1=1164122&r2=1164123&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java (original)
+++ tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java Thu Sep  1 15:57:25 2011
@@ -21,163 +21,163 @@ package org.apache.tuscany.sca.impl.layo
 
 public class LayoutBuilder {
 
-	private Entity[] elts = null;
-	private int[][] conns = null;
-	private Entity startEnt = null;
-	private int currentMaxLevel= 0;
-	
-	/**
-	 * Constructor which takes set of entities and their connection matrix
-	 */
-	public LayoutBuilder(Entity[] entities, int[][] connections){
-		elts = entities;
-		conns = connections;
-	}
-
-	/**
-	 * Layout Building Algorithm
-	 * ~~~~~~~~~~~~~~~~~~~~~~~~~
-	 *
-	 * Here we position (i.e. assigning a level and a lane) all Entities
-	 * in a unique cell of a grid.
-	 * 
-	 * 		 	lane0	  lane1	  lane2	  lane3 ....
-	 * 		 	 _______________________________
-	 * level0	|		|		|		|		|
-	 * 			|_______|_______|_______|_______|
-	 * level1	|		|		|		|		|
-	 * 			|_______|_______|_______|_______|
-	 * level2	|		|		|		|		|     
-	 * 
-	 * 1) Determining the Entity at level0, lane0 (starting entity)
-	 * 		-First Entity in the list of Entities which has one or more adjacent Entities
-	 * 		-If there is only one Entity it will eventually chosen
-	 * 
-	 * 2) Get connected Entities of starting Entity. 
-	 * 		* If there are connected entities;
-	 * 			*For each connected Entity; 
-	 * 				*We assign a corresponding level and a lane
-	 * 				*Then recurse the procedure for connections of the assigned Entity
-	 * 	
-	 * 
-	 */
-	public Entity[] placeEntities(){
-		
-		/**
-		 * Finding the starting entity
-		 */
-		for(int i = 0 ; i < elts.length; i++) {
-			//System.out.println("ELts "+elts.length);
-			Entity ent = elts[i];
-			if( isConnected(ent.getId()) ){
-				setPosition(ent, 0, 0);
-				startEnt = ent;
-				//System.out.println("startEnt "+ent.getId());
-				break;
-			}
-			
-		}
-		
-		if(startEnt!=null){
-			assignPositions(startEnt);
-		}
-		
-		assignPositionsOfOtherConncetedEntities();//such as a different cluster of components
-		assignPositionsOfIdleEntities();
-		assignCoordinates();
-		
-		return elts;
-
-	}
-	
-	private void assignPositionsOfIdleEntities() {
-
-		for(Entity ent: elts){
-			if(!ent.isPossitionSet()){
-				
-				setPosition(ent, currentMaxLevel++, 0);
-			}
-		}
-	}
-		
-	private void assignPositionsOfOtherConncetedEntities() {
-
-		for(Entity ent: elts){
-			if(!ent.isPossitionSet() && isConnected(ent.getId())){
-				assignPositions(ent);
-			}
-		}
-	}
-
-	private void assignCoordinates() {
-
-		for(Entity ent: elts){
-			ent.setX(ent.getParent().getX() + ent.getStartPosition());
-			ent.setY(ent.getParent().getY() + ent.getStartPosition()/2);
-		}
-	}
-
-	private void assignPositions(Entity ent) {
-		int id = ent.getId();
-		int[] entConns = conns[id];
-		
-		for(int i=0; i<entConns.length; i++){
-			if( entConns[i] == 1 ){
-				Entity nextEnt = findEntity(i);
-				
-//				if(nextEnt.isPossitionSet()){
-//					currentMaxLevel = nextEnt.getLevel()+1; // for diagram clearness purpose
-//				}
-				if(nextEnt != null && !nextEnt.isPossitionSet()){
-					setPosition(nextEnt, currentMaxLevel, ent.getLane()+1);
-					assignPositions(nextEnt);
-				}
-			}
-			
-		}
-		currentMaxLevel = ent.getLevel()+1;
-	}
-
-	private Entity findEntity(int i) {
-
-		for(Entity ent: elts){
-			if(ent.getId() == i){
-				return ent;
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * If there's at least 1 connection, this will return true
-	 */
-	private boolean isConnected(int id) {
-		int[] entConns = conns[id];
-		
-		//System.out.println("entConns "+entConns.length);
-		for(int i=0; i<entConns.length; i++){
-			
-			if(entConns[i] == 1){
-				return true;
-			}
-			
-		}
-		
-		return false;
-	}
-
-	private void setPosition(Entity ent, int level, int lane){
-		ent.setLevel(level);
-		ent.setLane(lane);
-		ent.setPossitionSet(true);
-	}
-
-	public Entity getStartEnt() {
-		return startEnt;
-	}
-
-	public void setStartEnt(Entity startEnt) {
-		this.startEnt = startEnt;
-	}
+    private Entity[] elts = null;
+    private int[][] conns = null;
+    private Entity startEnt = null;
+    private int currentMaxLevel = 0;
+
+    /**
+     * Constructor which takes set of entities and their connection matrix
+     */
+    public LayoutBuilder(Entity[] entities, int[][] connections) {
+        elts = entities;
+        conns = connections;
+    }
+
+    /**
+     * Layout Building Algorithm
+     * ~~~~~~~~~~~~~~~~~~~~~~~~~
+     *
+     * Here we position (i.e. assigning a level and a lane) all Entities
+     * in a unique cell of a grid.
+     * 
+     * 		 	lane0	  lane1	  lane2	  lane3 ....
+     * 		 	 _______________________________
+     * level0	|		|		|		|		|
+     * 			|_______|_______|_______|_______|
+     * level1	|		|		|		|		|
+     * 			|_______|_______|_______|_______|
+     * level2	|		|		|		|		|     
+     * 
+     * 1) Determining the Entity at level0, lane0 (starting entity)
+     * 		-First Entity in the list of Entities which has one or more adjacent Entities
+     * 		-If there is only one Entity it will eventually chosen
+     * 
+     * 2) Get connected Entities of starting Entity. 
+     * 		* If there are connected entities;
+     * 			*For each connected Entity; 
+     * 				*We assign a corresponding level and a lane
+     * 				*Then recurse the procedure for connections of the assigned Entity
+     * 	
+     * 
+     */
+    public Entity[] placeEntities() {
+
+        /**
+         * Finding the starting entity
+         */
+        for (int i = 0; i < elts.length; i++) {
+            //System.out.println("ELts "+elts.length);
+            Entity ent = elts[i];
+            if (isConnected(ent.getId())) {
+                setPosition(ent, 0, 0);
+                startEnt = ent;
+                //System.out.println("startEnt "+ent.getId());
+                break;
+            }
+
+        }
+
+        if (startEnt != null) {
+            assignPositions(startEnt);
+        }
+
+        assignPositionsOfOtherConncetedEntities();//such as a different cluster of components
+        assignPositionsOfIdleEntities();
+        assignCoordinates();
+
+        return elts;
+
+    }
+
+    private void assignPositionsOfIdleEntities() {
+
+        for (Entity ent : elts) {
+            if (!ent.isPossitionSet()) {
+
+                setPosition(ent, currentMaxLevel++, 0);
+            }
+        }
+    }
+
+    private void assignPositionsOfOtherConncetedEntities() {
+
+        for (Entity ent : elts) {
+            if (!ent.isPossitionSet() && isConnected(ent.getId())) {
+                assignPositions(ent);
+            }
+        }
+    }
+
+    private void assignCoordinates() {
+
+        for (Entity ent : elts) {
+            ent.setX(ent.getParent().getX() + ent.getStartPosition());
+            ent.setY(ent.getParent().getY() + ent.getStartPosition() / 2);
+        }
+    }
+
+    private void assignPositions(Entity ent) {
+        int id = ent.getId();
+        int[] entConns = conns[id];
+
+        for (int i = 0; i < entConns.length; i++) {
+            if (entConns[i] == 1) {
+                Entity nextEnt = findEntity(i);
+
+                //				if(nextEnt.isPossitionSet()){
+                //					currentMaxLevel = nextEnt.getLevel()+1; // for diagram clearness purpose
+                //				}
+                if (nextEnt != null && !nextEnt.isPossitionSet()) {
+                    setPosition(nextEnt, currentMaxLevel, ent.getLane() + 1);
+                    assignPositions(nextEnt);
+                }
+            }
+
+        }
+        currentMaxLevel = ent.getLevel() + 1;
+    }
+
+    private Entity findEntity(int i) {
+
+        for (Entity ent : elts) {
+            if (ent.getId() == i) {
+                return ent;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * If there's at least 1 connection, this will return true
+     */
+    private boolean isConnected(int id) {
+        int[] entConns = conns[id];
+
+        //System.out.println("entConns "+entConns.length);
+        for (int i = 0; i < entConns.length; i++) {
+
+            if (entConns[i] == 1) {
+                return true;
+            }
+
+        }
+
+        return false;
+    }
+
+    private void setPosition(Entity ent, int level, int lane) {
+        ent.setLevel(level);
+        ent.setLane(lane);
+        ent.setPossitionSet(true);
+    }
+
+    public Entity getStartEnt() {
+        return startEnt;
+    }
+
+    public void setStartEnt(Entity startEnt) {
+        this.startEnt = startEnt;
+    }
 
 }

Modified: tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java?rev=1164123&r1=1164122&r2=1164123&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java (original)
+++ tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java Thu Sep  1 15:57:25 2011
@@ -23,337 +23,337 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
-import org.apache.tuscany.sca.assembly.*;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
 
 public class TuscanyCompositeEntityBuilder {
 
-	private Composite tuscanyComp;
-	//components connected to each other are tracked using following map
-	private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
-	private int totalWidth=0;
-	private int totalHeight=0;
-	
-	CompositeEntity composite = null;
-	
-	/**
-	 * Constructor which initiates the DOM document
-	 * @param aDom DOM document
-	 */
-	public TuscanyCompositeEntityBuilder(Composite comp){
-		tuscanyComp = comp;
-	}
-
-	public CompositeEntity buildCompositeEntity(){
-				
-		String compositeName;
-		compositeName = tuscanyComp.getName().getLocalPart();
-		System.out.println("compositeName "+compositeName);
-		
-		ComponentEntity[] comps = buildComponentEntities();
-		
-		buildWires(tuscanyComp.getWires(), comps);
-		
-		composite = new CompositeEntity(compositeName);
-		
-		setParent(comps);
-		
-		System.out.println("ComponentEntity "+comps[0].getId());
-		int[][] conns = buildConnectionMatrix(comps);
-		System.out.println("ComponentEntity "+conns[0][0]);
-		
-		composite.setComponentList(comps);
-		composite.setConnections(conns);
-		
-		LayoutBuilder buildLayout = new LayoutBuilder(comps , conns);
-		buildLayout.placeEntities();
-		
-		
-		System.out.println("conns "+conns[0][0]);
-		
-		
-		buildCompositeService();
-		buildCompositeReference();
-		buildCompositeProperty();
-		
-		addInclusions();
-		
-		composite.setAttributes();
-		
-		return composite;
-	}
-	
-		
-	private void setParent(ComponentEntity[] comps) {
-
-		for(ComponentEntity comp: comps){
-			comp.setParent(composite);
-		}
-	}
-
-	private void buildCompositeService() {
-		
-		List<Service> sers = tuscanyComp.getServices();
-		
-		for(int i = 0 ; i < sers.size(); i++) {
-			Service compositeSer = sers.get(i);
-			composite.addAService(compositeSer.getName());
-			String service = ((CompositeService)compositeSer).getPromotedService().getName();
-			
-			composite.addToPromoteAService(compositeSer.getName(), service);
-		}
-
-	}
-	
-	private void buildCompositeReference() {
-		
-		List<Reference> refs = tuscanyComp.getReferences();
-		
-		for(int i = 0 ; i < refs.size(); i++) {
-			Reference compositeRef = refs.get(i);
-			composite.addAReference(compositeRef.getName());
-			
-			List<ComponentReference> promotedRefs = ((CompositeReference)compositeRef).getPromotedReferences();
-			
-			for(ComponentReference ref: promotedRefs){
-				String reference = ref.getName();
-				
-				composite.addToPromoteAReference(compositeRef.getName(), reference);
-			}
-			
-		}
-
-	}
-	
-	private void buildCompositeProperty() {
-
-		List<Property> props = tuscanyComp.getProperties();
-		
-		for(int i = 0 ; i < props.size(); i++) {
-			Property compositeProp = props.get(i);
-			composite.addAProperty(compositeProp.getName());
-		}
-
-	}
-	
-	private void addInclusions() {
-		
-		List<Composite> includes = tuscanyComp.getIncludes();
-		
-		for(int i = 0 ; i < includes.size(); i++) {
-			Composite anInclude = includes.get(i);
-			composite.addToIncludedComposites(anInclude.getName().getLocalPart());
-		}
-
-	}
-
-	private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
-
-		int[][] connections = new int[comps.length][comps.length];
-		connections = initConnections(connections);
-		 
-		for(Entity ent: comps){
-			for(String name: ent.getAdjacentEntities()){
-				ComponentEntity e2 = findEntity(comps, name);
-				if(ent != null && e2 != null){
-					//System.out.println("^^^^^^^^^ "+e2.getName());
-					connections[ent.getId()][e2.getId()] = 1;
-				}
-			}
-				
-		}
-
-		return connections;
-	}
-	
-	private String extractComp(ComponentEntity[] elts, String str, boolean isReference) {
-		
-		if(isReference){
-			for(ComponentEntity elt: elts){
-				for(String ref: elt.getReferences()){
-					if(ref.equals(str)){
-						return elt.getName();
-					}
-				}
-			}
-		}
-		else{
-			for(ComponentEntity elt: elts){
-				for(String ser: elt.getServices()){
-					if(ser.equals(str)){
-						return elt.getName();
-					}
-				}
-			}
-		}
-		return "";
-		
-	}
-
-	private int[][] initConnections(int[][] connections) {
-
-		for(int i=0; i<connections.length ; i++){
-			for(int j=0; j<connections.length ; j++){
-				connections[i][j] =0;
-			}
-		}
-		return connections;
-	}
-
-	
-	public ComponentEntity[] buildComponentEntities(){
-		
-		ComponentEntity[] elts = null;
-		
-		List<Component> components = tuscanyComp.getComponents();
-		
-		elts = new ComponentEntity[components.size()];
-		
-		for(int i = 0 ; i < components.size() ;i++) {
-			Component aComp = components.get(i);
-			
-			elts[i] = new ComponentEntity();
-			elts[i].setId(i);
-			elts[i].setName(aComp.getName());
-			
-			setServices(aComp.getServices(), elts[i]);
-			setReferences(aComp.getReferences(), elts[i]);
-			setProperties(aComp.getProperties(), elts[i]);
-			
-			elts[i].referenceHeight();
-			elts[i].serviceHeight();
-			elts[i].propertyLength();
-		}
-		
-
-		return elts;
-
-	}
-	
-	private void buildWires(List<Wire> wires, ComponentEntity[] elts) {
-
-		for(int i = 0 ; i < wires.size(); i++) {
-			String service, serviceComp, reference, referenceComp;
-			Wire aWire = wires.get(i);
-			
-			reference = aWire.getSource().getName();
-			service = aWire.getTarget().getName();
-			
-			referenceComp = extractComp(elts, reference, true);
-			serviceComp = extractComp(elts, service, false);
-			
-			ComponentEntity e1 = findEntity(elts, referenceComp);
-			
-			//System.out.println("^^^^^^^^^ "+e1.getName());
-			if(e1 != null){
-				//System.out.println("^^^^^^^^^ "+e1.getId());
-				//connections[e1.getId()][e2.getId()] = 1;
-				createConnection(e1, reference, serviceComp, service);
-			}
-		}
-
-	}
-
-	private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
-
-		for(ComponentEntity e: elts){
-			if(e.getName().equals(componentName)){
-				return e;
-			}
-		}
-		return null;
-	}
-
-	private void setReferences(List<ComponentReference> refs, ComponentEntity ent) {
-
-		for(int i = 0 ; i < refs.size() ;i++) {
-			ent.addAReference(refs.get(i).getName());
-		}
-
-	}
-
-	private void createConnection(ComponentEntity ent, String reference,
-			String serviceComp, String service) {
-
-		String referenceComp = ent.getName();
-
-		if(reference != null &&  service != null){
-
-			ent.addToRefToSerMap(reference, service);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else if(reference == null &&  service != null){
-			ent.addToRefToSerMap(referenceComp, service);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else if(reference != null &&  service == null){
-			ent.addToRefToSerMap(reference, serviceComp);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-		else{
-			ent.addToRefToSerMap(referenceComp, serviceComp);
-			ent.addAnAdjacentEntity(serviceComp);
-			addToConnectedEntities(referenceComp, serviceComp);
-			addToConnectedEntities(serviceComp, referenceComp);
-		}
-	}
-
-
-	@SuppressWarnings("unused")
-	private void print(ComponentEntity[] elts) {
-
-		for(ComponentEntity ent: elts){
-			System.out.println(ent.getName()+" : "+ent.getLevel()+" : "
-					+ent.getLane()+" : "+ent.getX()+" : "+ent.getY());
-		}
-	}
-
-
-	private void addToConnectedEntities(String ent1, String ent2) {
-		System.err.println(ent1+" : "+ent2);
-		ArrayList<String> list;
-		if(connectedEntities.containsKey(ent1)){
-			list = connectedEntities.get(ent1);
-			
-		}
-		else{
-			list =new ArrayList<String>();
-			
-		}
-		list.add(ent2);
-		connectedEntities.put(ent1, list);
-	}
-
-	private void setServices(List<ComponentService> sers, ComponentEntity ent) {
-
-		for(int i = 0 ; i < sers.size() ;i++) {
-			ent.addAService(sers.get(i).getName());
-		}
-		
-	}
-
-
-	private void setProperties(List<ComponentProperty> props, ComponentEntity ent) {
-
-		for(int i = 0 ; i < props.size(); i++) {
-			ent.addAProperty(props.get(i).getName());
-		}
-
-	}
-
-	public int getTotalWidth() {
-		return totalWidth;
-	}
-
-	public int getTotalHeight() {
-		return totalHeight;
-	}
+    private Composite tuscanyComp;
+    //components connected to each other are tracked using following map
+    private HashMap<String, ArrayList<String>> connectedEntities = new HashMap<String, ArrayList<String>>();
+    private int totalWidth = 0;
+    private int totalHeight = 0;
 
+    CompositeEntity composite = null;
 
+    /**
+     * Constructor which initiates the DOM document
+     * @param aDom DOM document
+     */
+    public TuscanyCompositeEntityBuilder(Composite comp) {
+        tuscanyComp = comp;
+    }
+
+    public CompositeEntity buildCompositeEntity() {
+
+        String compositeName;
+        compositeName = tuscanyComp.getName().getLocalPart();
+        System.out.println("compositeName " + compositeName);
+
+        ComponentEntity[] comps = buildComponentEntities();
+
+        buildWires(tuscanyComp.getWires(), comps);
+
+        composite = new CompositeEntity(compositeName);
+
+        setParent(comps);
+
+        System.out.println("ComponentEntity " + comps[0].getId());
+        int[][] conns = buildConnectionMatrix(comps);
+        System.out.println("ComponentEntity " + conns[0][0]);
+
+        composite.setComponentList(comps);
+        composite.setConnections(conns);
+
+        LayoutBuilder buildLayout = new LayoutBuilder(comps, conns);
+        buildLayout.placeEntities();
+
+        System.out.println("conns " + conns[0][0]);
+
+        buildCompositeService();
+        buildCompositeReference();
+        buildCompositeProperty();
+
+        addInclusions();
+
+        composite.setAttributes();
+
+        return composite;
+    }
+
+    private void setParent(ComponentEntity[] comps) {
+
+        for (ComponentEntity comp : comps) {
+            comp.setParent(composite);
+        }
+    }
+
+    private void buildCompositeService() {
+
+        List<Service> sers = tuscanyComp.getServices();
+
+        for (int i = 0; i < sers.size(); i++) {
+            Service compositeSer = sers.get(i);
+            composite.addAService(compositeSer.getName());
+            String service = ((CompositeService)compositeSer).getPromotedService().getName();
+
+            composite.addToPromoteAService(compositeSer.getName(), service);
+        }
+
+    }
+
+    private void buildCompositeReference() {
+
+        List<Reference> refs = tuscanyComp.getReferences();
+
+        for (int i = 0; i < refs.size(); i++) {
+            Reference compositeRef = refs.get(i);
+            composite.addAReference(compositeRef.getName());
+
+            List<ComponentReference> promotedRefs = ((CompositeReference)compositeRef).getPromotedReferences();
+
+            for (ComponentReference ref : promotedRefs) {
+                String reference = ref.getName();
+
+                composite.addToPromoteAReference(compositeRef.getName(), reference);
+            }
+
+        }
+
+    }
+
+    private void buildCompositeProperty() {
+
+        List<Property> props = tuscanyComp.getProperties();
+
+        for (int i = 0; i < props.size(); i++) {
+            Property compositeProp = props.get(i);
+            composite.addAProperty(compositeProp.getName());
+        }
+
+    }
+
+    private void addInclusions() {
+
+        List<Composite> includes = tuscanyComp.getIncludes();
+
+        for (int i = 0; i < includes.size(); i++) {
+            Composite anInclude = includes.get(i);
+            composite.addToIncludedComposites(anInclude.getName().getLocalPart());
+        }
+
+    }
+
+    private int[][] buildConnectionMatrix(ComponentEntity[] comps) {
+
+        int[][] connections = new int[comps.length][comps.length];
+        connections = initConnections(connections);
+
+        for (Entity ent : comps) {
+            for (String name : ent.getAdjacentEntities()) {
+                ComponentEntity e2 = findEntity(comps, name);
+                if (ent != null && e2 != null) {
+                    //System.out.println("^^^^^^^^^ "+e2.getName());
+                    connections[ent.getId()][e2.getId()] = 1;
+                }
+            }
+
+        }
+
+        return connections;
+    }
+
+    private String extractComp(ComponentEntity[] elts, String str, boolean isReference) {
+
+        if (isReference) {
+            for (ComponentEntity elt : elts) {
+                for (String ref : elt.getReferences()) {
+                    if (ref.equals(str)) {
+                        return elt.getName();
+                    }
+                }
+            }
+        } else {
+            for (ComponentEntity elt : elts) {
+                for (String ser : elt.getServices()) {
+                    if (ser.equals(str)) {
+                        return elt.getName();
+                    }
+                }
+            }
+        }
+        return "";
+
+    }
+
+    private int[][] initConnections(int[][] connections) {
+
+        for (int i = 0; i < connections.length; i++) {
+            for (int j = 0; j < connections.length; j++) {
+                connections[i][j] = 0;
+            }
+        }
+        return connections;
+    }
+
+    public ComponentEntity[] buildComponentEntities() {
+
+        ComponentEntity[] elts = null;
+
+        List<Component> components = tuscanyComp.getComponents();
+
+        elts = new ComponentEntity[components.size()];
+
+        for (int i = 0; i < components.size(); i++) {
+            Component aComp = components.get(i);
+
+            elts[i] = new ComponentEntity();
+            elts[i].setId(i);
+            elts[i].setName(aComp.getName());
+
+            setServices(aComp.getServices(), elts[i]);
+            setReferences(aComp.getReferences(), elts[i]);
+            setProperties(aComp.getProperties(), elts[i]);
+
+            elts[i].referenceHeight();
+            elts[i].serviceHeight();
+            elts[i].propertyLength();
+        }
+
+        return elts;
+
+    }
+
+    private void buildWires(List<Wire> wires, ComponentEntity[] elts) {
+
+        for (int i = 0; i < wires.size(); i++) {
+            String service, serviceComp, reference, referenceComp;
+            Wire aWire = wires.get(i);
+
+            reference = aWire.getSource().getName();
+            service = aWire.getTarget().getName();
+
+            referenceComp = extractComp(elts, reference, true);
+            serviceComp = extractComp(elts, service, false);
+
+            ComponentEntity e1 = findEntity(elts, referenceComp);
+
+            //System.out.println("^^^^^^^^^ "+e1.getName());
+            if (e1 != null) {
+                //System.out.println("^^^^^^^^^ "+e1.getId());
+                //connections[e1.getId()][e2.getId()] = 1;
+                createConnection(e1, reference, serviceComp, service);
+            }
+        }
+
+    }
+
+    private ComponentEntity findEntity(ComponentEntity[] elts, String componentName) {
+
+        for (ComponentEntity e : elts) {
+            if (e.getName().equals(componentName)) {
+                return e;
+            }
+        }
+        return null;
+    }
+
+    private void setReferences(List<ComponentReference> refs, ComponentEntity ent) {
+
+        for (int i = 0; i < refs.size(); i++) {
+            ent.addAReference(refs.get(i).getName());
+        }
+
+    }
+
+    private void createConnection(ComponentEntity ent, String reference, String serviceComp, String service) {
+
+        String referenceComp = ent.getName();
+
+        if (reference != null && service != null) {
+
+            ent.addToRefToSerMap(reference, service);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else if (reference == null && service != null) {
+            ent.addToRefToSerMap(referenceComp, service);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else if (reference != null && service == null) {
+            ent.addToRefToSerMap(reference, serviceComp);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        } else {
+            ent.addToRefToSerMap(referenceComp, serviceComp);
+            ent.addAnAdjacentEntity(serviceComp);
+            addToConnectedEntities(referenceComp, serviceComp);
+            addToConnectedEntities(serviceComp, referenceComp);
+        }
+    }
+
+    @SuppressWarnings("unused")
+    private void print(ComponentEntity[] elts) {
+
+        for (ComponentEntity ent : elts) {
+            System.out.println(ent.getName() + " : "
+                + ent.getLevel()
+                + " : "
+                + ent.getLane()
+                + " : "
+                + ent.getX()
+                + " : "
+                + ent.getY());
+        }
+    }
+
+    private void addToConnectedEntities(String ent1, String ent2) {
+        System.err.println(ent1 + " : " + ent2);
+        ArrayList<String> list;
+        if (connectedEntities.containsKey(ent1)) {
+            list = connectedEntities.get(ent1);
+
+        } else {
+            list = new ArrayList<String>();
+
+        }
+        list.add(ent2);
+        connectedEntities.put(ent1, list);
+    }
+
+    private void setServices(List<ComponentService> sers, ComponentEntity ent) {
+
+        for (int i = 0; i < sers.size(); i++) {
+            ent.addAService(sers.get(i).getName());
+        }
+
+    }
+
+    private void setProperties(List<ComponentProperty> props, ComponentEntity ent) {
+
+        for (int i = 0; i < props.size(); i++) {
+            ent.addAProperty(props.get(i).getName());
+        }
+
+    }
+
+    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=1164123&r1=1164122&r2=1164123&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 Thu Sep  1 15:57:25 2011
@@ -36,130 +36,123 @@ import org.apache.tuscany.sca.impl.layou
 import org.w3c.dom.Document;
 
 public class Main {
-	private static String outFileDir ; //= System.getProperty("user.dir")+"/output/";
-	private static boolean isHtml=false;
-	private static boolean isSvg=false;
-
-	/**
-	 * @param args
-	 * @throws Exception 
-	 */
-	public static void main(String[] args) throws Exception {
-	
-		if(args.length == 0){
-		
-			String help = "" +
-					"----------Apache Tuscany Composite Diagram Generator----------\n" +
-					"\n" +
-					"Error: You have not specified an input \"Composite XML\" file.\n" +
-					"\n" +
-					"-----------------------------Help-----------------------------\n" +
-					"You have 3 options:\n" +
-					"---1) Default: Specify \"Composite XML\" file paths separated \n" +
-					"---            by a space, with no arguments. This will" +
-					"---            generate SVG and HTML output.\n" +
-					"---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar \n" +
-					"---         //a//aa//a.composite //b//bb//b.composite \n" +
-					"---\n" +
-					"---2) SVG Only: Specify \"Composite XML\" file paths separated\n" +
-					"---            by a space, with '-svg' argument.\n" +
-					"---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar -svg\n" +
-					"---          //a//aa//a.composite //b//bb//b.composite \n" +
-					"---\n" +
-					"---3) HTML Only: Specify \"Composite XML\" file paths separated\n" +
-					"---            by a space, with '-html' argument.\n" +
-					"---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar -html\n" +
-					"---          //a//aa//a.composite //b//bb//b.composite \n" +
-					"---\n";
-			System.out.println(help);
-		}
-		else{
-			
-			if(args[0].equalsIgnoreCase("-svg")){
-				isSvg = true;
-				args[0] = null;
-			}
-			else if(args[0].equalsIgnoreCase("-html")){
-				isHtml = true;
-				args[0] = null;
-			}
-			else{
-				isSvg = true;
-				isHtml = true;
-			}
-
-			for(String str: args){
-				
-				if(str != null){
-					
-					File in = new File(str);
-					outFileDir = in.getParent()+"//";
-					XMLReader reader = new XMLReader();
-					Document doc =reader.parseXMLFile(str);//composite1.xml composite_with_compositeService.xml");
-					EntityBuilder eb = new EntityBuilder(doc);
-					CompositeEntity comp =eb.buildCompositeEntity();
-
-					DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
-					Document svg =dg.buildSVGDocument();
-					
-					String svgContent = extractSvg(svg);
-
-					if(isSvg){
-						writeSVG(svgContent, comp);
-					}
-
-					if(isHtml){
-						writeHTML(svgContent, comp);
-					}
-
-				}
-			}
-		}
-	}
-	
-	private static void writeHTML(String svg, CompositeEntity comp) throws Exception {
-
-		File htmlFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix()+".html");
-		HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile);
-		String content = html.buildHTML();
-		
-		System.err.println("--------------HTML Output for "+comp.getName()+"--------------\n");
-		System.out.println(content);
-		System.err.println("--------------------------------------------------------------\n");
-		
-	}
-
-	private static void writeSVG(String svg, CompositeEntity comp) throws Exception{
-		
-		String svgFileName = comp.getName()+ comp.getFileNameSuffix()+".svg";
-		File svgFile = new File(outFileDir + svgFileName);
-		XMLWriter writer = new XMLWriter();
-		writer.fileWriter(svg, svgFile);
-		
-		System.err.println("--------------SVG Output for "+comp.getName()+"--------------\n");
-		System.out.println(svg);
-		System.err.println("-------------------------------------------------------------\n");
-	}
-	
-	private static String extractSvg(Document svg) throws Exception{
-
-		// Set up the output transformer
-		TransformerFactory transfac = TransformerFactory.newInstance();
-		Transformer trans = transfac.newTransformer();
-
-		// Print the DOM node
-
-		StringWriter sw = new StringWriter();
-		StreamResult result = new StreamResult(sw);
-		DOMSource source = new DOMSource(svg);
-		trans.transform(source, result);
-		String svgString = sw.toString();
-
-		return svgString;
-	}
-	
-	
-	
-	
+    private static String outFileDir; //= System.getProperty("user.dir")+"/output/";
+    private static boolean isHtml = false;
+    private static boolean isSvg = false;
+
+    /**
+     * @param args
+     * @throws Exception 
+     */
+    public static void main(String[] args) throws Exception {
+
+        if (args.length == 0) {
+
+            String help =
+                "" + "----------Apache Tuscany Composite Diagram Generator----------\n"
+                    + "\n"
+                    + "Error: You have not specified an input \"Composite XML\" file.\n"
+                    + "\n"
+                    + "-----------------------------Help-----------------------------\n"
+                    + "You have 3 options:\n"
+                    + "---1) Default: Specify \"Composite XML\" file paths separated \n"
+                    + "---            by a space, with no arguments. This will"
+                    + "---            generate SVG and HTML output.\n"
+                    + "---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar \n"
+                    + "---         //a//aa//a.composite //b//bb//b.composite \n"
+                    + "---\n"
+                    + "---2) SVG Only: Specify \"Composite XML\" file paths separated\n"
+                    + "---            by a space, with '-svg' argument.\n"
+                    + "---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar -svg\n"
+                    + "---          //a//aa//a.composite //b//bb//b.composite \n"
+                    + "---\n"
+                    + "---3) HTML Only: Specify \"Composite XML\" file paths separated\n"
+                    + "---            by a space, with '-html' argument.\n"
+                    + "---     Eg: java -jar tuscany-composite-diagram-0.0.1.jar -html\n"
+                    + "---          //a//aa//a.composite //b//bb//b.composite \n"
+                    + "---\n";
+            System.out.println(help);
+        } else {
+
+            if (args[0].equalsIgnoreCase("-svg")) {
+                isSvg = true;
+                args[0] = null;
+            } else if (args[0].equalsIgnoreCase("-html")) {
+                isHtml = true;
+                args[0] = null;
+            } else {
+                isSvg = true;
+                isHtml = true;
+            }
+
+            for (String str : args) {
+
+                if (str != null) {
+
+                    File in = new File(str);
+                    outFileDir = in.getParent() + "//";
+                    XMLReader reader = new XMLReader();
+                    Document doc = reader.parseXMLFile(str);//composite1.xml composite_with_compositeService.xml");
+                    EntityBuilder eb = new EntityBuilder(doc);
+                    CompositeEntity comp = eb.buildCompositeEntity();
+
+                    DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
+                    Document svg = dg.buildSVGDocument();
+
+                    String svgContent = extractSvg(svg);
+
+                    if (isSvg) {
+                        writeSVG(svgContent, comp);
+                    }
+
+                    if (isHtml) {
+                        writeHTML(svgContent, comp);
+                    }
+
+                }
+            }
+        }
+    }
+
+    private static void writeHTML(String svg, CompositeEntity comp) throws Exception {
+
+        File htmlFile = new File(outFileDir + comp.getName() + comp.getFileNameSuffix() + ".html");
+        HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile);
+        String content = html.buildHTML();
+
+        System.err.println("--------------HTML Output for " + comp.getName() + "--------------\n");
+        System.out.println(content);
+        System.err.println("--------------------------------------------------------------\n");
+
+    }
+
+    private static void writeSVG(String svg, CompositeEntity comp) throws Exception {
+
+        String svgFileName = comp.getName() + comp.getFileNameSuffix() + ".svg";
+        File svgFile = new File(outFileDir + svgFileName);
+        XMLWriter writer = new XMLWriter();
+        writer.fileWriter(svg, svgFile);
+
+        System.err.println("--------------SVG Output for " + comp.getName() + "--------------\n");
+        System.out.println(svg);
+        System.err.println("-------------------------------------------------------------\n");
+    }
+
+    private static String extractSvg(Document svg) throws Exception {
+
+        // Set up the output transformer
+        TransformerFactory transfac = TransformerFactory.newInstance();
+        Transformer trans = transfac.newTransformer();
+
+        // Print the DOM node
+
+        StringWriter sw = new StringWriter();
+        StreamResult result = new StreamResult(sw);
+        DOMSource source = new DOMSource(svg);
+        trans.transform(source, result);
+        String svgString = sw.toString();
+
+        return svgString;
+    }
 
 }



Mime
View raw message