summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-08 00:45:19 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-08 00:45:19 +0000
commit197b8082810e456fbc79fbc9057868a8996a3192 (patch)
tree4bd06b6302b59ca0720ccc0db19d8e75ec7a64aa /collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik
parent1470267cde75a7a1af4b979bdeef27ce0da2edc1 (diff)
Further clean-up of the code
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1166477 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik')
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml12
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java34
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLReader.java42
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLWriter.java42
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java157
-rw-r--r--collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java33
6 files changed, 149 insertions, 171 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml
index 9882f288ed..e38c9badb6 100644
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml
@@ -21,11 +21,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-composite-diagram</artifactId>
- <version>0.0.1</version>
+ <version>2.0-SNAPSHOT</version>
<name>Apache Tuscany SCA Composite Diagram Generator Application</name>
<dependencies>
<dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-anim</artifactId>
<version>1.7</version>
@@ -110,11 +115,12 @@
<build>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
- <finalName>${artifactId}-${version}</finalName>
+ <finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
@@ -122,7 +128,9 @@
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
+ <version>2.1</version>
<executions>
<execution>
<id>${project.artifactId}-fetch-deps</id>
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
index 511bced0e8..5d4a40fcfb 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
@@ -139,10 +139,11 @@ public class DiagramGenerator {
private void addReferencePromotion() {
- for (Iterator it = comp.getPromoteAReference().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry)it.next();
- String compositeRef = (String)entry.getKey();
- ArrayList<String> componentRef = (ArrayList<String>)entry.getValue();
+ for (Iterator<Entry<String, ArrayList<String>>> it = comp.getPromoteAReference().entrySet().iterator(); it
+ .hasNext();) {
+ Entry<String, ArrayList<String>> entry = it.next();
+ String compositeRef = entry.getKey();
+ ArrayList<String> componentRef = entry.getValue();
ReferenceArtifact r1 = getRef(compositeRef);
@@ -160,10 +161,10 @@ public class DiagramGenerator {
private void addServicePromotion() {
- for (Iterator it = comp.getPromoteAService().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry)it.next();
- String compositeSer = (String)entry.getKey();
- String componentSer = (String)entry.getValue();
+ for (Iterator<Entry<String, String>> it = comp.getPromoteAService().entrySet().iterator(); it.hasNext();) {
+ Entry<String, String> entry = it.next();
+ String compositeSer = entry.getKey();
+ String componentSer = entry.getValue();
ServiceArtifact s1 = getSer(compositeSer);
ServiceArtifact s2 = getSer(componentSer);
@@ -222,10 +223,11 @@ public class DiagramGenerator {
for (Entity ent : comp.getComponentList()) {
//if(ent instanceof ComponentEntity){
- for (Iterator it = ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry)it.next();
- String ref = (String)entry.getKey();
- String ser = (String)entry.getValue();
+ for (Iterator<Entry<String, String>> it =
+ ((ComponentEntity)ent).getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
+ Entry<String, String> entry = it.next();
+ String ref = entry.getKey();
+ String ser = entry.getValue();
ReferenceArtifact r = getRef(ref);
ServiceArtifact s = getSer(ser);
@@ -415,11 +417,11 @@ public class DiagramGenerator {
sers.add(i, "");
}
- for (Iterator it = e.getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
+ for (Iterator<Entry<String, String>> it = e.getReferenceToServiceMap().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry)it.next();
- String ref = (String)entry.getKey();
- String ser = (String)entry.getValue();
+ Entry<String, String> entry = it.next();
+ String ref = entry.getKey();
+ String ser = entry.getValue();
//System.out.println("---------"+ref);
int idx = refs.indexOf(ref);
//System.out.println("---------"+sers.get(idx));
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLReader.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLReader.java
deleted file mode 100755
index 087c6370f8..0000000000
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLReader.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.io;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.w3c.dom.Document;
-
-public class XMLReader {
-
- //get the factory
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- private Document dom;
-
- public Document parseXMLFile(String file) throws Exception {
- //Using factory get an instance of document builder
- DocumentBuilder db = dbf.newDocumentBuilder();
-
- //parse using builder to get DOM representation of the XML file
- dom = db.parse(file);
-
- return dom;
- }
-}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLWriter.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLWriter.java
deleted file mode 100755
index b1d87e1381..0000000000
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/io/XMLWriter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.io;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-
-public class XMLWriter {
-
- public void fileWriter(String content, File outFile) throws Exception {
-
- FileWriter fileWriter = new FileWriter(outFile);
- BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
- bufferedWriter.write(content);
- bufferedWriter.close();
-
- // TransformerFactory transformerFactory = TransformerFactory.newInstance();
- // Transformer transformer = transformerFactory.newTransformer();
- // DOMSource source = new DOMSource(doc);
- // StreamResult result = new StreamResult(bufferedWriter);
- // transformer.transform(source, result);
-
- }
-}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
index c933ece35c..8aa7366899 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
@@ -20,103 +20,124 @@
package org.apache.tuscany.sca.diagram.main;
import java.io.File;
+import java.io.FileWriter;
import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
import org.apache.tuscany.sca.diagram.generator.DiagramGenerator;
import org.apache.tuscany.sca.diagram.html.HTMLWrapper;
-import org.apache.tuscany.sca.diagram.io.XMLReader;
-import org.apache.tuscany.sca.diagram.io.XMLWriter;
import org.apache.tuscany.sca.diagram.layout.CompositeEntity;
import org.apache.tuscany.sca.diagram.layout.EntityBuilder;
import org.w3c.dom.Document;
public class Main {
- private static String outFileDir; //= System.getProperty("user.dir")+"/output/";
- private static boolean isHtml = false;
- private static boolean isSvg = false;
+
+ static Options getCommandLineOptions() {
+ Options options = new Options();
+ Option opt1 = new Option("s", "svg", false, "Generate SVG diagrams");
+ options.addOption(opt1);
+ Option opt2 = new Option("h", "html", false, "Generate HTML documents");
+ options.addOption(opt2);
+
+ Option opt3 = new Option("o", "output", true, "Output directory");
+ options.addOption(opt3);
+
+ return options;
+ }
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
+ CommandLineParser parser = new PosixParser();
+ Options options = getCommandLineOptions();
+ CommandLine cli = null;
+ boolean help = false;
+ try {
+ cli = parser.parse(options, args);
+ if (cli.getArgList().size() == 0) {
+ help = true;
+ }
+ } catch (ParseException e) {
+ System.out.println(e);
+ help = true;
+ }
- if (args.length == 0) {
-
- String help =
- "" + "----------Apache Tuscany Composite Diagram Generator----------\n"
- + "\n"
- + "Error: You have not specified an input \"Composite XML\" file.\n"
- + "\n"
- + "-----------------------------Help-----------------------------\n"
- + "You have 3 options:\n"
- + "---1) Default: Specify \"Composite XML\" file paths separated \n"
- + "--- by a space, with no arguments. This will"
- + "--- generate SVG and HTML output.\n"
- + "--- Eg: java -jar tuscany-composite-diagram-0.0.1.jar \n"
- + "--- //a//aa//a.composite //b//bb//b.composite \n"
- + "---\n"
- + "---2) SVG Only: Specify \"Composite XML\" file paths separated\n"
- + "--- by a space, with '-svg' argument.\n"
- + "--- Eg: java -jar tuscany-composite-diagram-0.0.1.jar -svg\n"
- + "--- //a//aa//a.composite //b//bb//b.composite \n"
- + "---\n"
- + "---3) HTML Only: Specify \"Composite XML\" file paths separated\n"
- + "--- by a space, with '-html' argument.\n"
- + "--- Eg: java -jar tuscany-composite-diagram-0.0.1.jar -html\n"
- + "--- //a//aa//a.composite //b//bb//b.composite \n"
- + "---\n";
- System.out.println(help);
- } else {
+ // Print out the options and quit
+ if (help) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("<-h> <-s> <-o outputDirectory> file1 file2 ...: ", options);
+ return;
+ }
- if (args[0].equalsIgnoreCase("-svg")) {
- isSvg = true;
- args[0] = null;
- } else if (args[0].equalsIgnoreCase("-html")) {
- isHtml = true;
- args[0] = null;
- } else {
- isSvg = true;
- isHtml = true;
- }
+ boolean isHtml = false;
+ boolean isSvg = false;
+ isSvg = cli.hasOption('s');
+ isHtml = cli.hasOption('h');
- for (String str : args) {
+ if (!isSvg && !isHtml) {
+ isSvg = true;
+ isHtml = true;
+ }
- if (str != null) {
+ String outFileDir;
- File in = new File(str);
- outFileDir = in.getParent() + "//";
- XMLReader reader = new XMLReader();
- Document doc = reader.parseXMLFile(str);//composite1.xml composite_with_compositeService.xml");
- EntityBuilder eb = new EntityBuilder(doc);
- CompositeEntity comp = eb.buildCompositeEntity();
+ if (cli.hasOption('o')) {
+ outFileDir = cli.getOptionValue('o');
+ } else {
+ outFileDir = ".";
+ }
+ File dir = new File(outFileDir);
+ String[] compositeFiles = cli.getArgs();
+ generate(dir, isSvg, isHtml, compositeFiles);
+ }
+
+ public static void generate(File dir, boolean isSvg, boolean isHtml, String... compositeFiles) throws Exception {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ for (String str : compositeFiles) {
+
+ if (str != null) {
- DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
- Document svg = dg.buildSVGDocument();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(str);
- String svgContent = extractSvg(svg);
+ EntityBuilder eb = new EntityBuilder(doc);
+ CompositeEntity comp = eb.buildCompositeEntity();
- if (isSvg) {
- writeSVG(svgContent, comp);
- }
+ DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
+ Document svg = dg.buildSVGDocument();
- if (isHtml) {
- writeHTML(svgContent, comp);
- }
+ String svgContent = extractSvg(svg);
+ if (isSvg) {
+ writeSVG(dir, svgContent, comp);
}
+
+ if (isHtml) {
+ writeHTML(dir, svgContent, comp);
+ }
+
}
}
}
- private static void writeHTML(String svg, CompositeEntity comp) throws Exception {
+ private static void writeHTML(File dir, String svg, CompositeEntity comp) throws Exception {
- File htmlFile = new File(outFileDir + comp.getName() + comp.getFileNameSuffix() + ".html");
+ File htmlFile = new File(dir, comp.getName() + comp.getFileNameSuffix() + ".html");
HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile);
String content = html.buildHTML();
@@ -126,16 +147,14 @@ public class Main {
}
- private static void writeSVG(String svg, CompositeEntity comp) throws Exception {
+ private static File writeSVG(File dir, String svg, CompositeEntity comp) throws Exception {
String svgFileName = comp.getName() + comp.getFileNameSuffix() + ".svg";
- File svgFile = new File(outFileDir + svgFileName);
- XMLWriter writer = new XMLWriter();
- writer.fileWriter(svg, svgFile);
-
- System.err.println("--------------SVG Output for " + comp.getName() + "--------------\n");
- System.out.println(svg);
- System.err.println("-------------------------------------------------------------\n");
+ File svgFile = new File(dir, svgFileName);
+ FileWriter fw = new FileWriter(svgFile);
+ fw.write(svg);
+ fw.close();
+ return svgFile;
}
private static String extractSvg(Document svg) throws Exception {
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
new file mode 100644
index 0000000000..aee42dbfc0
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
@@ -0,0 +1,33 @@
+/**********************************************************************
+ * NAME:
+ * DiagramGeneratorTestCase
+ *
+ * AUTHOR:
+ * rfeng
+ *
+ * DESCRIPTION:
+ *
+ *
+ * Copyright (c) Shutterfly, Inc. 2010. All Rights reserved.
+ **********************************************************************/
+
+package org.apache.tuscany.sca.diagram.layout;
+
+import java.io.File;
+
+import org.apache.tuscany.sca.diagram.main.Main;
+import org.junit.Test;
+
+public class DiagramGeneratorTestCase {
+
+ @Test
+ public final void test() throws Exception {
+ for (File xml : new File("input").listFiles()) {
+ if (xml.getName().endsWith(".xml")) {
+ System.out.println(xml);
+ Main.generate(new File("target"), true, false, xml.toString());
+ }
+ }
+ }
+
+}