1 26 package org.objectweb.fractal.explorer.graph; 27 28 import java.awt.Dimension ; 29 import java.util.List ; 30 31 import org.jgraph.graph.DefaultGraphModel; 32 import org.jgraph.graph.GraphModel; 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.Interface; 35 import org.objectweb.fractal.api.type.InterfaceType; 36 import org.objectweb.fractal.explorer.FcExplorer; 37 import org.objectweb.util.explorer.swing.graph.CompositeVertex; 38 import org.objectweb.util.explorer.swing.graph.Graph; 39 import org.objectweb.util.explorer.swing.graph.MyPort; 40 import org.objectweb.util.explorer.swing.graph.PortType; 41 import org.objectweb.util.explorer.swing.graph.PrimitiveVertex; 42 43 48 public class FractalGraph 49 { 50 51 54 public FractalGraph(){ 55 } 56 57 62 protected void addPortsComposite (Component component, CompositeVertex composite){ 63 Interface[] listExtItf = GraphInformations.getSortExtItf(component); 64 for (int i=0 ; i<listExtItf.length ; i++){ 65 String nameItf = GraphInformations.getInterfaceName(listExtItf[i]); 66 String typePort = GraphInformations.getPortType(listExtItf[i]); 67 if (!typePort.equals(PortType.COLLECTION_PORT)) composite.addCompositePort(listExtItf[i], nameItf, typePort); 69 } 70 71 List listItfCollection = GraphInformations.getItfCollection(component); 73 if (listItfCollection.size()!=0){ 74 InterfaceType itType; 75 for (int j=0 ; j<listItfCollection.size() ; j++){ 76 itType = (InterfaceType)listItfCollection.get(j); 77 composite.addCompositePort(listItfCollection.get(j), itType.getFcItfName() , PortType.COLLECTION_PORT); 78 } 79 } 80 } 81 82 88 protected void addPortsPrimitive (Component component, PrimitiveVertex primitive){ 89 Interface[] listExtItf = GraphInformations.getSortExtItf(component); 90 for (int i=0 ; i<listExtItf.length ; i++){ 91 String nameItf = GraphInformations.getInterfaceName(listExtItf[i]); 92 String typePort = GraphInformations.getPortType(listExtItf[i]); 93 if (!typePort.equals(PortType.COLLECTION_PORT)) primitive.addPort(listExtItf[i], nameItf, typePort); 95 } 96 97 List listItfCollection = GraphInformations.getItfCollection(component); 99 if (listItfCollection.size()!=0){ 100 InterfaceType itType; 101 for (int j=0 ; j<listItfCollection.size() ; j++){ 102 itType = (InterfaceType)listItfCollection.get(j); 103 primitive.addPort(listItfCollection.get(j), itType.getFcItfName() , PortType.COLLECTION_PORT); 104 } 105 } 106 } 107 108 116 protected void addNeighbors (Component component, PrimitiveVertex primitiveVertex, Graph graph, boolean controllersDisplay){ 117 PrimitiveVertex neighborVertex; 118 List serverNeighbors = GraphInformations.getServerNeighbors(component); 119 List clientNeighbors = GraphInformations.getClientNeighbors(component); 120 Component neighborComponent; 121 Interface[] listExtItf; 122 Interface targetItf; 123 Component targetComponent; 124 String namePort; 125 boolean isOpen = false; boolean isCompositeEdge = false; 128 for (int i=0 ; i<serverNeighbors.size() ; i++){ 130 neighborComponent = (Component)serverNeighbors.get(i); 131 if (GraphInformations.isPrimitiveComponent(neighborComponent)){ 132 neighborVertex = new PrimitiveVertex(neighborComponent, FcExplorer.getName(neighborComponent), 133 graph, new Dimension (), controllersDisplay, 134 GraphInformations.isStarted(neighborComponent), 135 GraphInformations.isSharedComponent(neighborComponent));} 136 else { neighborVertex = new CompositeVertex(neighborComponent, FcExplorer.getName(neighborComponent), 137 graph, new Dimension (), isOpen, controllersDisplay, 138 GraphInformations.isStarted(neighborComponent), 139 GraphInformations.isSharedComponent(neighborComponent));} 140 graph.addPrimitiveComponent(neighborVertex); 141 addPortsPrimitive(neighborComponent, neighborVertex); 142 listExtItf = GraphInformations.getSortExtItf(neighborComponent); 143 for(int j=0 ; j<listExtItf.length ; j++){ 144 if(GraphInformations.isClientInterface(listExtItf[j])){ 145 targetComponent = GraphInformations.getTargetComponent(neighborComponent, listExtItf[j]); 146 if(targetComponent.equals(component)){ 147 targetItf = GraphInformations.getTargetInterface(neighborComponent, listExtItf[j]); 148 if(GraphInformations.isCollectionInterface(listExtItf[j])){ 149 InterfaceType itType = (InterfaceType)listExtItf[j].getFcItfType(); 150 namePort = itType.getFcItfName(); 151 } 152 else namePort = GraphInformations.getInterfaceName(listExtItf[j]); 153 graph.primitiveConnect(neighborVertex.getPort(namePort), 154 primitiveVertex.getPort(GraphInformations.getInterfaceName(targetItf)), isCompositeEdge); 155 } 156 } 157 } 158 } 159 160 for (int i=0 ; i<clientNeighbors.size() ; i++){ 162 neighborComponent = (Component)clientNeighbors.get(i); 163 if (GraphInformations.isPrimitiveComponent(neighborComponent)){ 164 neighborVertex = new PrimitiveVertex(neighborComponent, FcExplorer.getName(neighborComponent), 165 graph, new Dimension (), controllersDisplay, 166 GraphInformations.isStarted(neighborComponent), 167 GraphInformations.isSharedComponent(neighborComponent));} 168 else { neighborVertex = new CompositeVertex(neighborComponent, FcExplorer.getName(neighborComponent), 169 graph, new Dimension (), isOpen, controllersDisplay, 170 GraphInformations.isStarted(neighborComponent), 171 GraphInformations.isSharedComponent(neighborComponent));} 172 graph.addPrimitiveComponent(neighborVertex); 173 addPortsPrimitive(neighborComponent, neighborVertex); 174 175 listExtItf = GraphInformations.getSortExtItf(component); 176 for(int j=0 ; j<listExtItf.length ; j++){ 177 if(GraphInformations.isClientInterface(listExtItf[j])){ 178 targetComponent = GraphInformations.getTargetComponent(component, listExtItf[j]); 179 if (targetComponent.equals(neighborComponent)){ 180 targetItf = GraphInformations.getTargetInterface(component, listExtItf[j]); 181 if(GraphInformations.isCollectionInterface(listExtItf[j])){ 182 InterfaceType itType = (InterfaceType)listExtItf[j].getFcItfType(); 183 namePort = itType.getFcItfName(); 184 } 185 else namePort = GraphInformations.getInterfaceName(listExtItf[j]); 186 graph.primitiveConnect(primitiveVertex.getPort(namePort), 187 neighborVertex.getPort(GraphInformations.getInterfaceName(targetItf)), 188 isCompositeEdge); 189 } 190 } 191 } 192 } 193 } 194 195 200 protected void addSubComponentPorts (CompositeVertex composite, Component subComponent){ 201 Interface[] listExtItf = GraphInformations.getSortExtItf(subComponent); 202 String portName, typePort; 203 for (int i=0 ; i<listExtItf.length ; i++){ 204 portName = GraphInformations.getInterfaceName(listExtItf[i]); 205 typePort = GraphInformations.getPortType(listExtItf[i]); 206 if (!typePort.equals(PortType.COLLECTION_PORT)) 207 composite.addSubComponentPort(FcExplorer.getName(subComponent), subComponent, portName, typePort); 208 } 209 210 List listItfCollection = GraphInformations.getItfCollection(subComponent); 212 if (listItfCollection.size()!=0){ 213 InterfaceType itType; 214 for (int j=0 ; j<listItfCollection.size() ; j++){ 215 itType = (InterfaceType)listItfCollection.get(j); 216 composite.addSubComponentPort(FcExplorer.getName(subComponent), subComponent, itType.getFcItfName(), PortType.COLLECTION_PORT); 217 } 218 } 219 } 220 221 227 protected void addSubComponents (Graph graph, Component superComponent, CompositeVertex composite){ 228 Component[] listSubComponents = GraphInformations.getSubComponents(superComponent); 229 Component subComponent; 230 String nameSubComponent = ""; 231 for (int i=0 ; i<listSubComponents.length ; i++){ 232 subComponent = listSubComponents[i]; 233 composite.addVertex(subComponent, FcExplorer.getName(subComponent), graph, 234 GraphInformations.getComponentType(subComponent), false, true, 235 GraphInformations.isStarted(subComponent), GraphInformations.isSharedComponent(subComponent)); 236 addSubComponentPorts(composite, subComponent); 237 } 238 } 239 240 250 protected void drawBind(Graph graph, String nameComponent, String namePort, String nameTargetComponent, 251 String nameTargetPort, CompositeVertex composite, boolean isInternalEdge) { 252 Object sourcePort; 253 if(!isInternalEdge) 254 sourcePort = composite.getVertex(nameComponent).getPort(namePort); 255 else 256 sourcePort = composite.getGeneratedPort(namePort); 257 Object v = composite.getVertex(nameTargetComponent); 258 Object targetPort; 259 targetPort = composite.getVertex(nameTargetComponent).getPort(nameTargetPort); 260 graph.compositeConnect((MyPort)sourcePort, (MyPort)targetPort, isInternalEdge, composite); 261 } 262 263 270 protected void addBinds (Graph graph, Component superComponent, CompositeVertex composite){ 271 272 Interface[] listExtItf; 273 Interface itf; 274 Component subComponent; 275 Component[] listSubComponents = GraphInformations.getSubComponents(superComponent); 276 String nameComponent, namePort, nameTargetComponent, nameTargetPort; 277 278 for (int i=0 ; i<listSubComponents.length ; i++){ 279 subComponent = listSubComponents[i]; 280 listExtItf = GraphInformations.getSortExtItf(subComponent); 281 282 for (int j=0 ; j<listExtItf.length ; j++){ 283 itf = listExtItf[j]; 284 if ((GraphInformations.isClientInterface(itf)) 285 && (GraphInformations.getTargetComponent(subComponent, itf)!=null) 286 && (GraphInformations.getTargetInterface(subComponent, itf)!=null)){ 287 288 if (GraphInformations.isCollectionInterface(itf)){ 289 InterfaceType itType = (InterfaceType)itf.getFcItfType(); 290 namePort = itType.getFcItfName(); 291 } 292 293 else namePort = GraphInformations.getInterfaceName(itf); 294 nameComponent = FcExplorer.getName(subComponent); 295 nameTargetComponent = FcExplorer.getName(GraphInformations.getTargetComponent(subComponent, itf)); 296 nameTargetPort = GraphInformations.getInterfaceName(GraphInformations.getTargetInterface(subComponent, itf)); 297 298 if ((GraphInformations.getTargetInterface(subComponent, itf).isFcInternalItf()) 301 && FcExplorer.getName(superComponent).equals(nameTargetComponent)) { 302 drawBind(graph, FcExplorer.getName(superComponent), nameTargetPort, 303 nameComponent, namePort, composite, true); 304 } 305 else if (!GraphInformations.getTargetInterface(subComponent, itf).isFcInternalItf()){ 306 drawBind(graph, nameComponent, namePort, 307 nameTargetComponent, nameTargetPort, composite, false); 308 } 309 } 310 } 311 } 312 } 313 314 321 protected void addInternalBinds (Graph graph, Component superComponent, CompositeVertex composite){ 322 323 Interface internalItf; 324 Interface[] listIntItf = GraphInformations.getIntItf(superComponent); 325 String nameSuperComponent = FcExplorer.getName(superComponent); 326 String nameInternalItf, nameTargetPort, nameTargetComponent; 327 328 for (int i=0 ; i<listIntItf.length ; i++){ 329 internalItf = listIntItf[i]; 330 331 if (((GraphInformations.getPortType(internalItf))!=PortType.SERVER_PORT) 333 && (GraphInformations.getTargetComponent(superComponent, internalItf)!=null) 334 && (GraphInformations.getTargetInterface(superComponent, internalItf)!=null)){ 335 336 nameInternalItf = GraphInformations.getInterfaceName(internalItf); 337 nameTargetPort = GraphInformations.getInterfaceName(GraphInformations.getTargetInterface(superComponent, internalItf)); 338 nameTargetComponent = FcExplorer.getName(GraphInformations.getTargetComponent(superComponent, internalItf)); 339 340 drawBind(graph, nameSuperComponent, nameInternalItf, 341 nameTargetComponent, nameTargetPort, composite, true); 342 343 } 344 } 345 } 346 347 353 public Graph getFractalGraph (Component component){ 354 355 String nameComponent = FcExplorer.getName(component); 356 357 PortGraphics pg = new PortGraphics(); 358 VertexGraphics vg = new VertexGraphics(); 359 360 Dimension frameSize = new Dimension (100, 100); 363 GraphModel model = new DefaultGraphModel(); 364 Graph graph = new Graph(model, pg, vg); 365 graph.setPortsVisible(true); 366 367 boolean controllersDisplay = true; boolean isPrimitive = GraphInformations.isPrimitiveComponent(component); 369 370 371 if(!isPrimitive){ 372 374 boolean isOpen = true; 376 CompositeVertex compositeVertex = new CompositeVertex(component, 377 nameComponent, graph, frameSize, isOpen, controllersDisplay, GraphInformations.isStarted(component), 378 GraphInformations.isSharedComponent(component)); 379 graph.addSuperComponent(compositeVertex); 380 381 addPortsComposite(component, compositeVertex); 383 addSubComponents(graph, component, compositeVertex); 385 addBinds(graph, component, compositeVertex); 387 addInternalBinds (graph, component, compositeVertex); 388 389 graph.insertIntoModel(isPrimitive); 391 graph.applyLayout(compositeVertex); 392 393 return graph; 394 } 395 396 else { 397 399 PrimitiveVertex primitiveVertex = new PrimitiveVertex(component, nameComponent, graph, new Dimension (), controllersDisplay, 400 GraphInformations.isStarted(component), GraphInformations.isSharedComponent(component)); 401 graph.addPrimitiveComponent(primitiveVertex); 402 403 addPortsPrimitive(component, primitiveVertex); 405 addNeighbors (component, primitiveVertex, graph, controllersDisplay); 407 408 graph.insertIntoModel(isPrimitive); 410 graph.applyLayout(frameSize); 411 412 return graph; 413 } 414 } 415 416 } | Popular Tags |