tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1171840 - in /tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram: artifacts/ImplementationArtifact.java generator/DiagramGenerator.java layout/Entity.java layout/EntityBuilder.java
Date Fri, 16 Sep 2011 22:45:07 GMT
Author: rfeng
Date: Fri Sep 16 22:45:07 2011
New Revision: 1171840

URL: http://svn.apache.org/viewvc?rev=1171840&view=rev
Log:
Add implementation info

Added:
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
  (with props)
Modified:
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java

Added: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java?rev=1171840&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
(added)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
Fri Sep 16 22:45:07 2011
@@ -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);
+
+    }
+
+}

Propchange: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/ImplementationArtifact.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java?rev=1171840&r1=1171839&r2=1171840&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
Fri Sep 16 22:45:07 2011
@@ -28,6 +28,7 @@ import org.apache.tuscany.sca.diagram.ar
 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() {

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java?rev=1171840&r1=1171839&r2=1171840&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/Entity.java
Fri Sep 16 22:45:07 2011
@@ -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;
+    }
+
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java?rev=1171840&r1=1171839&r2=1171840&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/layout/EntityBuilder.java
Fri Sep 16 22:45:07 2011
@@ -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 



Mime
View raw message