diff options
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout')
5 files changed, 443 insertions, 95 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java index 7507b4ab57..9059187c6d 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/ComponentEntity.java @@ -23,10 +23,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import org.apache.tuscany.sca.impl.artifacts.Component; -import org.apache.tuscany.sca.impl.artifacts.Property; -import org.apache.tuscany.sca.impl.artifacts.Reference; -import org.apache.tuscany.sca.impl.artifacts.Service; +import org.apache.tuscany.sca.impl.artifacts.ComponentArtifact; +import org.apache.tuscany.sca.impl.artifacts.Constant; +import org.apache.tuscany.sca.impl.artifacts.PropertyArtifact; +import org.apache.tuscany.sca.impl.artifacts.ReferenceArtifact; +import org.apache.tuscany.sca.impl.artifacts.ServiceArtifact; /** * Represents an unit (a component including its references, services, properties @@ -49,45 +50,48 @@ public class ComponentEntity extends Entity{ public ComponentEntity(){ setStartPosition(200); - setHeight(Component.DEFAULT_HEIGHT); - setWidth(Component.DEFAULT_WIDTH); + setHeight(Constant.COMPONENT_DEFAULT_HEIGHT); + setWidth(Constant.COMPONENT_DEFAULT_HEIGHT); setDefaultNoOfSers( - Component.DEFAULT_HEIGHT / - (Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Service.SPACING_FOR_COMPONENT)); + Constant.COMPONENT_DEFAULT_HEIGHT / + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE + + Constant.SPACING_FOR_COMPONENT_OF_SERVICE)); setDefaultNoOfRefs( - Component.DEFAULT_HEIGHT / - (Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Reference.SPACING_FOR_COMPONENT)); + Constant.COMPONENT_DEFAULT_HEIGHT / + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE + + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE)); setDefaultNoOfProps( - Component.DEFAULT_WIDTH / - (Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT+Property.SPACING_FOR_COMPONENT)); + Constant.COMPONENT_DEFAULT_WIDTH / + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY + + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY)); } public void referenceHeight(){ if(getDefaultNoOfRefs() < getNoOfRefs()){ - setRefHeight((Component.DEFAULT_HEIGHT / getNoOfRefs()) - Reference.SPACING_FOR_COMPONENT); + setRefHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfRefs()) - Constant.SPACING_FOR_COMPONENT_OF_REFERENCE); } else - setRefHeight(Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_REFERENCE); } public void serviceHeight(){ if(getDefaultNoOfSers() < getNoOfSers()){ - setSerHeight((Component.DEFAULT_HEIGHT / getNoOfSers()) - Service.SPACING_FOR_COMPONENT); + setSerHeight((Constant.COMPONENT_DEFAULT_HEIGHT / getNoOfSers()) - Constant.SPACING_FOR_COMPONENT_OF_SERVICE); } else - setSerHeight(Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_SERVICE); } public void propertyLength(){ if(getDefaultNoOfProps() < getNoOfProps()){ - setPropLength((Component.DEFAULT_WIDTH / getNoOfProps()) - Property.SPACING_FOR_COMPONENT); + setPropLength((Constant.COMPONENT_DEFAULT_WIDTH / getNoOfProps()) - Constant.SPACING_FOR_COMPONENT_OF_PROPERTY); } else - setPropLength(Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT); + setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPONENT_OF_PROPERTY); } /** diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java index 810c0a8f09..c7f1142964 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java @@ -23,11 +23,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import org.apache.tuscany.sca.impl.artifacts.Component; -import org.apache.tuscany.sca.impl.artifacts.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.ComponentArtifact; +import org.apache.tuscany.sca.impl.artifacts.CompositeArtifact; +import org.apache.tuscany.sca.impl.artifacts.Constant; +import org.apache.tuscany.sca.impl.artifacts.PropertyArtifact; +import org.apache.tuscany.sca.impl.artifacts.ReferenceArtifact; +import org.apache.tuscany.sca.impl.artifacts.ServiceArtifact; /** * Represents an unit (a component including its references, services, properties @@ -49,7 +50,7 @@ public class CompositeEntity extends Entity{ private ComponentEntity[] componentList; private int[][] connections; private HashMap<String, String> promoteAService = new HashMap<String, String>(); - private HashMap<String, String> promoteAReference = new HashMap<String, String>(); + private HashMap<String, ArrayList<String>> promoteAReference = new HashMap<String, ArrayList<String>>(); private ArrayList<String> includedComposites = new ArrayList<String>(); //private HashSet<String> connectedEntities = new HashSet<String>(); @@ -76,27 +77,27 @@ public class CompositeEntity extends Entity{ if(getDefaultNoOfRefs() < getNoOfRefs()){ - setRefHeight((getHeight() / getNoOfRefs()) - Reference.SPACING_FOR_COMPOSITE); + setRefHeight((getHeight() / getNoOfRefs()) - Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE); } else - setRefHeight(Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE); + setRefHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE); } public void serviceHeight(){ if(getDefaultNoOfSers() < getNoOfSers()){ - setSerHeight((getHeight() / getNoOfSers()) - Service.SPACING_FOR_COMPOSITE); + setSerHeight((getHeight() / getNoOfSers()) - Constant.SPACING_FOR_COMPOSITE_OF_SERVICE); } else - setSerHeight(Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE); + setSerHeight(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE); } public void propertyLength(){ if(getDefaultNoOfProps() < getNoOfProps()){ - setPropLength((getWidth() / getNoOfProps()) - Property.SPACING_FOR_COMPOSITE); + setPropLength((getWidth() / getNoOfProps()) - Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY); } else - setPropLength(Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE); + setPropLength(Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY); } // /** @@ -141,12 +142,12 @@ public class CompositeEntity extends Entity{ // } public void calcHeight(int initPoint) { - setHeight((Component.DEFAULT_HEIGHT * getSpaceFactor()) * (maxInternalLevel + 1) + initPoint); + setHeight((Constant.COMPONENT_DEFAULT_HEIGHT * getSpaceFactor()) * (maxInternalLevel + 1) + initPoint); } public void calcWidth(int initPoint) { System.err.println("maxInternalLane "+maxInternalLane); - setWidth((Component.DEFAULT_WIDTH * getSpaceFactor()) * (maxInternalLane + 1) + initPoint); + setWidth((Constant.COMPONENT_DEFAULT_WIDTH * getSpaceFactor()) * (maxInternalLane + 1) + initPoint); } private int max(int a, int b){ @@ -194,13 +195,17 @@ public class CompositeEntity extends Entity{ } public boolean addToPromoteAReference(String compositeRef, String componentRef){ - //ref = ref.toLowerCase(); - //ser = ser.toLowerCase(); + ArrayList<String> list; - if (promoteAReference.containsKey(compositeRef)) - return false; + if (promoteAReference.containsKey(compositeRef)){ + list = promoteAReference.get(compositeRef); + } + else{ + list = new ArrayList<String>(); + } - promoteAReference.put(compositeRef, componentRef); + list.add(componentRef); + promoteAReference.put(compositeRef, list); return true; } @@ -211,11 +216,11 @@ public class CompositeEntity extends Entity{ return true; } - public void setPromoteAReference(HashMap<String, String> promoteAReference) { + public void setPromoteAReference(HashMap<String, ArrayList<String>> promoteAReference) { this.promoteAReference = promoteAReference; } - public HashMap<String, String> getPromoteAReference() { + public HashMap<String, ArrayList<String>> getPromoteAReference() { return promoteAReference; } @@ -247,13 +252,16 @@ public class CompositeEntity extends Entity{ setDefaultNoOfSers( getHeight()/ - (Service.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Service.SPACING_FOR_COMPOSITE)); + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_SERVICE + + Constant.SPACING_FOR_COMPOSITE_OF_SERVICE)); setDefaultNoOfRefs( getHeight()/ - (Reference.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Reference.SPACING_FOR_COMPOSITE)); + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_REFERENCE + + Constant.SPACING_FOR_COMPOSITE_OF_REFERENCE)); setDefaultNoOfProps( getWidth()/ - (Property.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE+Property.SPACING_FOR_COMPOSITE)); + (Constant.DEFAULT_MAXIMUM_HEIGHT_FOR_COMPOSITE_OF_PROPERTY + + Constant.SPACING_FOR_COMPOSITE_OF_PROPERTY)); referenceHeight(); serviceHeight(); diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java index 07ee0d7c75..5f6c6a3d6b 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java @@ -21,7 +21,6 @@ package org.apache.tuscany.sca.impl.layout; import java.util.ArrayList; import java.util.HashMap; -import org.apache.tuscany.sca.impl.artifacts.Component; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -29,16 +28,11 @@ import org.w3c.dom.NodeList; public class EntityBuilder { private Document dom; - private final int initPoint = 200;//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 + //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; - private ComponentEntity startEnt = null; - //private String compositeName; CompositeEntity composite = null; @@ -75,7 +69,7 @@ public class EntityBuilder { buildLayout.placeEntities(); - System.out.println("conns "+conns[0][0]); + //System.out.println("conns "+conns[0][0]); buildCompositeService(docEle); @@ -109,7 +103,7 @@ public class EntityBuilder { private void buildCompositeService(Element docEle) { NodeList nl = docEle.getElementsByTagName("service"); - System.err.println("^^^^^^^^^ "+nl.getLength()); + //System.err.println("^^^^^^^^^ "+nl.getLength()); if(nl != null && nl.getLength() > 0 ) { for(int i = 0 ; i < nl.getLength();i++) { @@ -153,18 +147,23 @@ public class EntityBuilder { String compositeRef = elt.getAttribute("name"); composite.addAReference(compositeRef); - String target = elt.getAttribute("promote"); - - 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); + 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); + } } } @@ -281,7 +280,7 @@ public class EntityBuilder { for(String name: ent.getAdjacentEntities()){ ComponentEntity e2 = findEntity(comps, name); if(ent != null && e2 != null){ - System.out.println("^^^^^^^^^ "+e2.getName()); + //System.out.println("^^^^^^^^^ "+e2.getName()); connections[ent.getId()][e2.getId()] = 1; } } @@ -326,33 +325,7 @@ public class EntityBuilder { return connections; } - /** - * Layout Building Algorithm - * ~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * An Entity object represents a component element of a composite XML. - * Here we position (i.e. assigning a level and a lane) all such components - * 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 adjacent Entities of starting Entity. - * * If there are adjacent entities; - * *For each adjacent Entity; - * - * - * @return - */ + public ComponentEntity[] buildComponentEntities(Element docEle){ ComponentEntity[] elts = null; @@ -481,9 +454,9 @@ public class EntityBuilder { ComponentEntity e1 = findEntity(elts, referenceComp); //ComponentEntity e2 = findEntity(comps, serviceComp); - System.out.println("^^^^^^^^^ "+e1.getName()); + //System.out.println("^^^^^^^^^ "+e1.getName()); if(e1 != null){ - System.out.println("^^^^^^^^^ "+e1.getId()); + //System.out.println("^^^^^^^^^ "+e1.getId()); //connections[e1.getId()][e2.getId()] = 1; createConnection(e1, reference, serviceComp, service); } @@ -585,6 +558,7 @@ public class EntityBuilder { // } + @SuppressWarnings("unused") private void print(ComponentEntity[] elts) { for(ComponentEntity ent: elts){ diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java index c2acdf8f89..b7c594f406 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/LayoutBuilder.java @@ -67,7 +67,7 @@ public class LayoutBuilder { * 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); @@ -78,7 +78,10 @@ public class LayoutBuilder { } - assignPositions(startEnt); + if(startEnt!=null){ + assignPositions(startEnt); + } + assignPositionsOfIdleEntities(); assignCoordinates(); diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java new file mode 100755 index 0000000000..2e521387e7 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/TuscanyCompositeEntityBuilder.java @@ -0,0 +1,359 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.impl.layout; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.assembly.*; + +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; + } + + + +} |