diff options
author | nirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-15 21:08:48 +0000 |
---|---|---|
committer | nirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-15 21:08:48 +0000 |
commit | 47efc8c83cd6764e75c68fe06f864d60de24468c (patch) | |
tree | 0633b57936f02aa04f8dcb1976d55fa70128ff3e /collaboration | |
parent | a99e7c2d1708ba8bb1598c54571dcf540308b03b (diff) |
Providing a command line interface
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1158011 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration')
8 files changed, 192 insertions, 92 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml index 64ce98b8e2..0d4b58de28 100644 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml @@ -104,11 +104,6 @@ <version>2.0-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.apache.ws.commons.schema</groupId> - <artifactId>XmlSchema</artifactId> - <version>1.4.3</version> - </dependency> </dependencies> @@ -125,6 +120,36 @@ <target>1.5</target> </configuration> </plugin> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>${project.artifactId}-fetch-deps</id> + <phase>generate-sources</phase> + <goals><goal>unpack-dependencies</goal></goals> + <configuration> + <outputDirectory>${project.build.outputDirectory}</outputDirectory> + <stripVersion>true</stripVersion> + <excludeTransitive>true</excludeTransitive> + <excludeArtifactIds>junit</excludeArtifactIds> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.1</version> + <configuration> + <archive> + <manifest> + <mainClass>org.apache.tuscany.sca.main.Main</mainClass> + </manifest> + </archive> + </configuration> + </plugin> </plugins> </build> diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java index df366581de..f2c0ca08eb 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.impl.diagram; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.Map.Entry; @@ -54,6 +53,8 @@ public class DiagramGenerator { private ArrayList<ServiceArtifact> sers= new ArrayList<ServiceArtifact>(); private int diagramHeight, diagramWidth; + private boolean isHtml; + private int lastUsedChangingFactor = 0; enum changingFactor{a(20), b(25), c(30), d(35), e(40), f(15); @@ -76,10 +77,11 @@ public class DiagramGenerator { * Constructor to generate a SVG diagram for a given CompositeEntity * Object. */ - public DiagramGenerator(CompositeEntity comp) { + public DiagramGenerator(CompositeEntity comp, boolean isHtml) { this.comp = comp; - + this.isHtml = isHtml; + } /** @@ -189,11 +191,20 @@ public class DiagramGenerator { svgRoot.appendChild(text); text = Text.addTextElement(doc, svgNS, x0+constant, y0+constant*7, ""); + + String ext; + + if(isHtml){ + ext = ".html"; + } + else{ + ext = ".svg"; + } for(String includedComposite : comp.getIncludedComposites()){ Link link = new Link(); - Element aLink = link.addElement(doc, svgNS, includedComposite+comp.getFileNameSuffix()+".svg", includedComposite); + Element aLink = link.addElement(doc, svgNS, includedComposite+comp.getFileNameSuffix()+ext, includedComposite); text.appendChild(aLink); } @@ -358,7 +369,7 @@ public class DiagramGenerator { //System.err.println("XXXXX "+ sers.get(1)+ " ::::::: "+refs.get(1)); // System.err.println("XXXXX "+ sers.get(2)+ " ::::::: "+refs.get(2)); // System.err.println("XXXXX "+ sers.get(3)+ " ::::::: "+refs.get(3)); - System.err.println("XXXXX "+ refs.get(sers.indexOf(s))+" ::: "+ent.getLevel()+" ::: "+ent.getName()); + //System.err.println("XXXXX "+ refs.get(sers.indexOf(s))+" ::: "+ent.getLevel()+" ::: "+ent.getName()); orderedRefs[ent.getLevel()] = refs.get(sers.indexOf(s)); break; } @@ -369,10 +380,10 @@ public class DiagramGenerator { orderedRefs[i] = refs.get(sers.indexOf(s)); break; } - else{ - if(i==orderedRefs.length) - System.out.println("GRRR"); - } +// else{ +// if(i==orderedRefs.length) +// System.out.println("GRRR"); +// } } } } @@ -429,7 +440,7 @@ public class DiagramGenerator { int x= ent.getX()-(serHeight*2/3); int y= ent.getY() + Constant.SPACING_FOR_COMPONENT_OF_SERVICE; - System.out.println("''''''"+ent.getName() +" '''''' "+ ent.getServices().size()); + //System.out.println("''''''"+ent.getName() +" '''''' "+ ent.getServices().size()); for(String ser: ent.getServices()){ ServiceArtifact serve= new ServiceArtifact(); @@ -541,7 +552,7 @@ public class DiagramGenerator { private void addComponent(Entity ent) { ComponentArtifact comp = new ComponentArtifact(); - System.err.println(ent.getX()); + //System.err.println(ent.getX()); Element com = comp.addElement(doc, svgNS, ent.getX(), ent.getY(), ent.getHeight(), ent.getWidth()); Element text = Text.addTextElement(doc, svgNS, ent.getX(), diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java index 076e28fd70..e53c9ff90f 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java @@ -37,33 +37,23 @@ public class HTMLWrapper { private File htmlFilePath; private String compositeName; - private String svgFileName; - private int compositeHeight, compositeWidth; - private Document svg; - private static final String CANVG_LIB_DIR = System.getProperty("user.dir")+"/resources/"; - private static final String CANVG_FILE = "canvg-1.0.js"; - private static final String RGB_FILE = "rgbcolor.js"; + private String svg; + /** * + * @param svg * @param compositeName - * @param svgFileName - * @param compositeHeight - * @param compositeWidth * @param htmlFilePath */ - public HTMLWrapper(Document svg, String compositeName, String svgFileName, - int compositeHeight, int compositeWidth, File htmlFilePath) { + public HTMLWrapper(String svg, String compositeName, File htmlFilePath) { this.svg = svg; this.compositeName = compositeName; - this.svgFileName = svgFileName; - this.compositeHeight = compositeHeight; - this.compositeWidth = compositeWidth; this.htmlFilePath = htmlFilePath; } - public void buildHTML() throws Exception{ + public String buildHTML() throws Exception{ String content = "" + "<html>\n" + "<head>\n" + @@ -83,7 +73,7 @@ public class HTMLWrapper { // "</script>\n" + "</head>\n" + "<body>\n" + - extractSvg()+"\n"+ + svg+"\n"+ // "<canvas id=\"canvas\" width=\""+compositeWidth+"px\" height=\""+compositeHeight+"px\">\n" + // "</canvas>\n" + "</body>\n" + @@ -91,25 +81,8 @@ public class HTMLWrapper { fileWriter(content); - } - - public String extractSvg() throws Exception{ - - // Set up the output transformer - TransformerFactory transfac = TransformerFactory.newInstance(); - Transformer trans = transfac.newTransformer(); - - // Print the DOM node - - StringWriter sw = new StringWriter(); - StreamResult result = new StreamResult(sw); - DOMSource source = new DOMSource(svg); - trans.transform(source, result); - String svgString = sw.toString(); - - System.out.println(svgString); - - return svgString; + return content; + } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java index 59db0878a7..15e9785d3c 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/io/XMLWriter.java @@ -32,15 +32,18 @@ import org.w3c.dom.Document; public class XMLWriter { - public void fileWriter(Document doc, File outFile) throws Exception{ + public void fileWriter(String content, File outFile) throws Exception{ FileWriter fileWriter = new FileWriter(outFile); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - DOMSource source = new DOMSource(doc); - StreamResult result = new StreamResult(bufferedWriter); - transformer.transform(source, result); + 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/impl/layout/CompositeEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java index aa98c3db65..e916b176a5 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java @@ -73,7 +73,7 @@ public class CompositeEntity extends Entity{ } public void referenceHeight(){ - System.err.println(getDefaultNoOfRefs() + " kkkkkkk "+getNoOfRefs()); + //System.err.println(getDefaultNoOfRefs() + " kkkkkkk "+getNoOfRefs()); if(getDefaultNoOfRefs() < getNoOfRefs()){ @@ -146,7 +146,7 @@ public class CompositeEntity extends Entity{ } public void calcWidth(int initPoint) { - System.err.println("maxInternalLane "+maxInternalLane); + //System.err.println("maxInternalLane "+maxInternalLane); setWidth((Constant.COMPONENT_DEFAULT_WIDTH * getSpaceFactor()) * (maxInternalLane + 1) + initPoint); } @@ -164,7 +164,7 @@ public class CompositeEntity extends Entity{ maxInternalLane = max(maxInternalLane, ent.getLane()); } - System.out.println("++++++ "+maxInternalLevel+" +++++ "+maxInternalLane); + //System.out.println("++++++ "+maxInternalLevel+" +++++ "+maxInternalLane); } public int getMaxInternalLevel() { diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java index 5f6c6a3d6b..b859e2de55 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/EntityBuilder.java @@ -656,7 +656,7 @@ public class EntityBuilder { private void addToConnectedEntities(String ent1, String ent2) { - System.err.println(ent1+" : "+ent2); + //System.err.println(ent1+" : "+ent2); ArrayList<String> list; if(connectedEntities.containsKey(ent1)){ list = connectedEntities.get(ent1); @@ -685,7 +685,7 @@ public class EntityBuilder { if(nl1 != null && nl1.getLength() > 0 ) { for(int i = 0 ; i < nl1.getLength();i++) { Element elt = (Element)nl1.item(i); - System.out.println(elt.getAttribute("class")); + //System.out.println(elt.getAttribute("class")); String serName = extractServiceName(elt.getAttribute("class")); ent.addAService(serName); } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java index 191d98b6b7..ab2da110e4 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java @@ -20,6 +20,12 @@ package org.apache.tuscany.sca.main; import java.io.File; +import java.io.StringWriter; + +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.tuscany.sca.impl.diagram.DiagramGenerator; import org.apache.tuscany.sca.impl.html.HTMLWrapper; @@ -30,7 +36,9 @@ import org.apache.tuscany.sca.impl.layout.EntityBuilder; import org.w3c.dom.Document; public class Main { - private static final String outFileDir = System.getProperty("user.dir")+"/output/"; + private static String outFileDir ; //= System.getProperty("user.dir")+"/output/"; + private static boolean isHtml=false; + private static boolean isSvg=false; /** * @param args @@ -38,40 +46,120 @@ public class Main { */ public static void main(String[] args) throws Exception { -// 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.\n" + -// "--- Eg: java CompositeDiagramGenerator \\a\\aa\\a.composite \\b\\b\\b.composite \n" + -// "---" + -// "---2) SVG Only"; -// System.out.println(); -// } - - XMLReader reader = new XMLReader(); - Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite_with_compositeService.xml");//composite1.xml composite_with_compositeService.xml"); - EntityBuilder eb = new EntityBuilder(doc); - CompositeEntity comp =eb.buildCompositeEntity(); + if(args.length == 0){ - DiagramGenerator dg = new DiagramGenerator(comp); - Document svg =dg.buildSVGDocument(); + 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{ + + 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; + } + + for(String str: args){ + + if(str != null){ + + 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(); + + DiagramGenerator dg = new DiagramGenerator(comp, isHtml); + Document svg =dg.buildSVGDocument(); + + String svgContent = extractSvg(svg); + + if(isSvg){ + writeSVG(svgContent, comp); + } + + if(isHtml){ + writeHTML(svgContent, comp); + } + + } + } + } + } + + private static void writeHTML(String svg, CompositeEntity comp) throws Exception { + + File htmlFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix()+".html"); + HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile); + String content = html.buildHTML(); + + System.err.println("--------------HTML Output for "+comp.getName()+"--------------\n"); + System.out.println(content); + System.err.println("--------------------------------------------------------------\n"); + + } + + private static void writeSVG(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); - File htmlFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix()+".html"); - HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), svgFileName, dg.getDiagramHeight(), - dg.getDiagramWidth(), htmlFile); - html.buildHTML(); + System.err.println("--------------SVG Output for "+comp.getName()+"--------------\n"); + System.out.println(svg); + System.err.println("-------------------------------------------------------------\n"); + } + + private static String extractSvg(Document svg) throws Exception{ + + // Set up the output transformer + TransformerFactory transfac = TransformerFactory.newInstance(); + Transformer trans = transfac.newTransformer(); + + // Print the DOM node + + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + DOMSource source = new DOMSource(svg); + trans.transform(source, result); + String svgString = sw.toString(); + + return svgString; } + + + + } diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java index 3c3e96c0f2..6d45eed39b 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/test/layout/LayoutBuilderTest.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/layout/LayoutBuilderTest.java @@ -1,4 +1,4 @@ -package org.apache.tuscany.sca.test.layout; +package org.apache.tuscany.sca.layout; import static org.junit.Assert.*; import junit.framework.Assert; @@ -128,7 +128,7 @@ public class LayoutBuilderTest { Assert.assertEquals(5, ents.length); Assert.assertEquals(1, lb.getStartEnt().getId()); - Assert.assertEquals(2, ents[0].getLevel()); + Assert.assertEquals(1, ents[0].getLevel()); Assert.assertEquals(0, ents[1].getLevel()); Assert.assertEquals(0, ents[2].getLevel()); Assert.assertEquals(0, ents[3].getLevel()); |