diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/composite-diagram/src')
4 files changed, 132 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java new file mode 100644 index 0000000000..576fa118d1 --- /dev/null +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java @@ -0,0 +1,60 @@ +/* + * 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.diagram.artifacts; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class ImplementationArtifact extends Artifact { + + /** + * Create an element with specified height and width + */ + public Element addElement(Document document, String svgNs, int x, int y, int height, int width) { + + this.setHeight(height); + this.setWidth(width); + this.setxCoordinate(x); + this.setyCoordinate(y); + + Element rectangle = document.createElementNS(svgNs, "rect"); + rectangle.setAttributeNS(null, "x", x + ""); + rectangle.setAttributeNS(null, "y", y + ""); +// rectangle.setAttributeNS(null, "rx", getRoundCorner()); +// rectangle.setAttributeNS(null, "ry", getRoundCorner()); + rectangle.setAttributeNS(null, "width", width + ""); + rectangle.setAttributeNS(null, "height", height + ""); + rectangle.setAttributeNS(null, "fill", "purple"); + rectangle.setAttributeNS(null, "stroke", "black"); + rectangle.setAttributeNS(null, "stroke-width", "1"); + rectangle.setAttributeNS(null, "fill-opacity", "0.1"); + return rectangle; + } + + /** + * Create an element with default height and width + */ + public Element addElement(Document document, String svgNs, int x, int y) { + + return addElement(document, svgNs, x, y, Constant.COMPONENT_DEFAULT_HEIGHT/2, Constant.COMPONENT_DEFAULT_WIDTH/2); + + } + +} diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java index 1b7bede707..4c6b5d4640 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.diagram.artifacts.ComponentArtifact; import org.apache.tuscany.sca.diagram.artifacts.CompositeArtifact; import org.apache.tuscany.sca.diagram.artifacts.Constant; import org.apache.tuscany.sca.diagram.artifacts.DashedWire; +import org.apache.tuscany.sca.diagram.artifacts.ImplementationArtifact; import org.apache.tuscany.sca.diagram.artifacts.Layer; import org.apache.tuscany.sca.diagram.artifacts.Link; import org.apache.tuscany.sca.diagram.artifacts.NormalWire; @@ -617,6 +618,32 @@ public class DiagramGenerator { svgRoot.appendChild(text); comp.setName(ent.getName()); + + if (ent.getImplementation() == null) { + return; + } + // Add the implementation + ImplementationArtifact impl = new ImplementationArtifact(); + impl.setName(ent.getImplementation()); + impl.setContainerName(ent.getName()); + Element implElement = + impl.addElement(doc, + svgNS, + ent.getX() + ent.getWidth() / 4, + ent.getY() + ent.getHeight() / 4, + ent.getHeight() / 2, + ent.getWidth() / 2); + + Element text2 = + Text.addTextElement(doc, + svgNS, + ent.getX() + ent.getWidth() / 4, + ent.getY() + (ent.getHeight() / 4 + Constant.COMPONENT_TEXT_SPACING), + ent.getImplementation()); + text2.setAttributeNS(null, "font-size", "10"); + svgRoot.appendChild(implElement); + svgRoot.appendChild(text2); + } private void addComposite() { diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java index 582b8ed37b..678846d585 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java @@ -31,6 +31,8 @@ public abstract class Entity { private ArrayList<String> properties = new ArrayList<String>(); private HashSet<String> adjacentEntities = new HashSet<String>(); + + private String implementation; public abstract void referenceHeight(); @@ -255,5 +257,14 @@ public abstract class Entity { public Entity getParent() { return parent; } + + public String getImplementation() { + return implementation; + } + + public void setImplementation(String implementation) { + this.implementation = implementation; + } + } diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java index 33ff1209cb..70171e484c 100755 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java @@ -340,6 +340,7 @@ public class EntityBuilder { elts[i].setId(i); elts[i].setName(nVal.getAttribute("name")); + setImplementation(nVal, elts[i]); setServices(nVal, elts[i]); setReferences(nVal, elts[i]); setProperties(nVal, elts[i]); @@ -684,6 +685,39 @@ public class EntityBuilder { } + private void setImplementation(Element nVal, ComponentEntity ent) { + NodeList nodes = nVal.getChildNodes(); + + for (int i = 0; i < nodes.getLength(); i++) { + if (nodes.item(i) instanceof Element) { + Element elt = (Element)nodes.item(i); + String name = elt.getNodeName(); + if (name != null && name.contains(":")) { + name = name.substring(name.indexOf(':') + 1).trim(); + } + if (name != null && name.startsWith("implementation.")) { + String type = name.substring("implementation.".length()); + if ("implementation.java".equals(name)) { + String cls = elt.getAttribute("class"); + ent.setImplementation(type + ":" + extractClassName(cls)); + } else { + ent.setImplementation(type); + } + break; + } + } + } + } + + private String extractClassName(String classAttr){ + if(classAttr==null) { + return ""; + } else { + int index = classAttr.lastIndexOf('.'); + return classAttr.substring(index+1); + } + } + /** * * This will extract the service name part from the class attribute of |