summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-16 00:19:27 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-16 00:19:27 +0000
commitbb2ce1c766d81435a35cafdd02c7963b11dc5dc7 (patch)
tree97cc95bd1dd515886eb5b923dbe27ec1bbea012a /sca-java-2.x/trunk
parent5d97dad51802597583e07731e76577116d2836e2 (diff)
Add the ablity to generate links for the component/service/reference/property
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java6
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java58
-rwxr-xr-xsca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java12
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java2
4 files changed, 68 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java b/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
index aa55be9618..c0cc6adeb0 100644
--- a/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
+++ b/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
@@ -70,6 +70,11 @@ public class TuscanyDiagramMojo extends AbstractMojo {
private File outputDirectory;
/**
+ * @parameter The base URL for the clickable blocks
+ */
+ private String baseURL;
+
+ /**
* @parameter
*/
private boolean generateSVG = true;
@@ -97,6 +102,7 @@ public class TuscanyDiagramMojo extends AbstractMojo {
try {
getLog().info("Generating diagram for " + f);
org.apache.tuscany.sca.diagram.main.Main.generate(outputDirectory,
+ baseURL,
generateSVG,
generateHTML,
generateJPG,
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 5d4a40fcfb..1b7bede707 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
@@ -45,6 +45,7 @@ import org.w3c.dom.Element;
public class DiagramGenerator {
+ private static final String XLINK_NS = "http://www.w3.org/1999/xlink";
private CompositeEntity comp;
private Document doc;
private String svgNS;
@@ -54,6 +55,7 @@ public class DiagramGenerator {
private int diagramHeight, diagramWidth;
private boolean isHtml;
+ private final String baseURL;
private int lastUsedChangingFactor = 0;
@@ -82,10 +84,11 @@ public class DiagramGenerator {
* Constructor to generate a SVG diagram for a given CompositeEntity
* Object.
*/
- public DiagramGenerator(CompositeEntity comp, boolean isHtml) {
+ public DiagramGenerator(CompositeEntity comp, boolean isHtml, String baseURL) {
this.comp = comp;
this.isHtml = isHtml;
+ this.baseURL = baseURL;
}
@@ -101,6 +104,8 @@ public class DiagramGenerator {
// Get the root element (the 'svg' element).
svgRoot = doc.getDocumentElement();
+ svgRoot.setAttribute("xmlns:xlink", XLINK_NS);
+
setDiagramHeight(comp.getHeight() + 200);
setDiagramWidth(comp.getWidth() + 400);
@@ -311,7 +316,18 @@ public class DiagramGenerator {
Element property = pro.addElement(doc, svgNS, x, y, propLen);
Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, prop);
- svgRoot.appendChild(property);
+ Element child = property;
+ if (baseURL != null) {
+ Element link = doc.createElementNS(svgNS, "a");
+ link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+ + ent.getName()
+ + "/properties/"
+ + prop);
+ link.appendChild(property);
+ child = link;
+ }
+
+ svgRoot.appendChild(child);
svgRoot.appendChild(text);
x += (propLen + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY);
@@ -330,8 +346,20 @@ public class DiagramGenerator {
for (String ref : setRefOrder(ent)) {
ReferenceArtifact refer = new ReferenceArtifact();
Element polygon = refer.addElement(doc, svgNS, x, y, refHeight);
+
+ Element child = polygon;
+ if (baseURL != null) {
+ Element link = doc.createElementNS(svgNS, "a");
+ link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+ + ent.getName()
+ + "/services/"
+ + ref);
+ link.appendChild(polygon);
+ child = link;
+ }
+
Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, ref);
- svgRoot.appendChild(polygon);
+ svgRoot.appendChild(child);
svgRoot.appendChild(text);
y += (refHeight + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE);
@@ -450,7 +478,18 @@ public class DiagramGenerator {
else
text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT, "");
- svgRoot.appendChild(polygon);
+ Element child = polygon;
+ if (baseURL != null) {
+ Element link = doc.createElementNS(svgNS, "a");
+ link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+ + ent.getName()
+ + "/services/"
+ + ser);
+ link.appendChild(polygon);
+ child = link;
+ }
+
+ svgRoot.appendChild(child);
svgRoot.appendChild(text);
y += (serHeight + Constant.SPACING_FOR_COMPONENT_OF_SERVICE);
@@ -558,6 +597,15 @@ public class DiagramGenerator {
ComponentArtifact comp = new ComponentArtifact();
//System.err.println(ent.getX());
Element com = comp.addElement(doc, svgNS, ent.getX(), ent.getY(), ent.getHeight(), ent.getWidth());
+
+ Element component = com;
+ if (baseURL != null) {
+ Element link = doc.createElementNS(svgNS, "a");
+ link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" + ent.getName());
+ link.appendChild(com);
+ component = link;
+ }
+
Element text =
Text.addTextElement(doc,
svgNS,
@@ -565,7 +613,7 @@ public class DiagramGenerator {
ent.getY() + (ent.getHeight() + Constant.COMPONENT_TEXT_SPACING),
ent.getName());
- svgRoot.appendChild(com);
+ svgRoot.appendChild(component);
svgRoot.appendChild(text);
comp.setName(ent.getName());
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
index 2ce360a9c3..10f0b26713 100755
--- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
@@ -118,11 +118,15 @@ public class Main {
}
File dir = new File(outFileDir);
String[] compositeFiles = cli.getArgs();
- generate(dir, isSvg, isHtml, false, compositeFiles);
+ generate(dir, null, isSvg, isHtml, false, compositeFiles);
}
- public static void generate(File dir, boolean isSvg, boolean isHtml, boolean isJpeg, String... compositeFiles)
- throws Exception {
+ public static void generate(File dir,
+ String baseURL,
+ boolean isSvg,
+ boolean isHtml,
+ boolean isJpeg,
+ String... compositeFiles) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
for (String str : compositeFiles) {
@@ -134,7 +138,7 @@ public class Main {
EntityBuilder eb = new EntityBuilder(doc);
CompositeEntity comp = eb.buildCompositeEntity();
- DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
+ DiagramGenerator dg = new DiagramGenerator(comp, isHtml, baseURL);
Document svg = dg.buildSVGDocument();
if (isJpeg) {
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
index ee0feb86bb..6fbe4c976b 100644
--- a/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
+++ b/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
@@ -25,7 +25,7 @@ public class DiagramGeneratorTestCase {
for (File xml : new File("input").listFiles()) {
if (xml.getName().endsWith(".xml")) {
System.out.println(xml);
- Main.generate(new File("target"), true, false, false, xml.toString());
+ Main.generate(new File("target"), null, true, false, false, xml.toString());
}
}
}