View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.darrt.visualise.ant; 22 23 24 // Java imports 25 import java.io.File; 26 import java.io.FileReader; 27 import java.io.FileWriter; 28 import java.util.Vector; 29 30 import org.apache.axis.utils.DOM2Writer; 31 import org.apache.log4j.Logger; 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.DirectoryScanner; 34 import org.apache.tools.ant.Project; 35 import org.apache.tools.ant.Task; 36 import org.apache.tools.ant.types.FileSet; 37 import org.enableit.db.beans.Table; 38 import org.enableit.db.darrt.visualise.SchemaVisualiser; 39 import org.w3c.dom.Document; 40 41 42 /*** 43 * A task to invoke the SchemaVisualiser class for a 44 * <code>FileSet</code> of XML table representations. 45 */ 46 public class TableVisualiserTask extends Task { 47 /* 48 * Properties 49 */ 50 51 /*** 52 * The Log4J <code>Logger</code> doing the logging. 53 */ 54 protected static Logger logger = Logger.getLogger(TableVisualiserTask.class); 55 56 /*** 57 * CVS info about this class and its current version. 58 */ 59 public static final String ABOUT = "$Revision: 1.4 $"; 60 61 /*** 62 * Directory to write generated images to. 63 */ 64 private String outputDir; 65 66 /*** 67 * <code>Vector</code> of filesets. 68 */ 69 protected Vector filesets = new Vector(); 70 71 // TODO Is it confusing to extend AbstractDBTask when very few attributes are relevant? 72 // will they be more relevant in the future? 73 74 /* 75 * Constructors 76 */ 77 78 /*** 79 * Default Constructor 80 */ 81 public TableVisualiserTask() { 82 } 83 84 /* 85 * Methods 86 */ 87 88 /*** 89 * Adds a set of files (nested fileset attribute). 90 */ 91 public void addFileset(FileSet set) { 92 filesets.addElement(set); 93 } 94 95 /*** 96 * @param The directory to ouput images into. 97 */ 98 public void setOutputDir(String newOutputDir) { 99 outputDir = newOutputDir; 100 } 101 102 /*** 103 * Performs the copy operation. 104 */ 105 public void execute() 106 throws BuildException { 107 // Log the entry into the method. 108 logger.info("METHOD_ENTRY: execute"); 109 110 try { 111 logger.info("Starting schema visualiser"); 112 113 SchemaVisualiser sv = new SchemaVisualiser(); 114 115 // deal with the filesets 116 for (int i = 0; i < filesets.size(); i++) { 117 FileSet fs = (FileSet) filesets.elementAt(i); 118 DirectoryScanner ds = fs.getDirectoryScanner(project); 119 File fromDir = fs.getDir(project); 120 File toDir = null; 121 122 if (outputDir == null) { 123 toDir = fromDir; 124 } else { 125 toDir = new File(outputDir); 126 } 127 128 String[] srcFiles = ds.getIncludedFiles(); 129 130 logger.warn("No of files found=" + srcFiles.length); 131 log("No of files found=" + srcFiles.length, Project.MSG_INFO); 132 133 for (int j = 0; j < srcFiles.length; j++) { 134 long start = System.currentTimeMillis(); 135 136 try { 137 logger.warn("Processing file: " + srcFiles[j]); 138 log("Processing file: " + srcFiles[j], Project.MSG_INFO); 139 140 FileReader reader = new FileReader(new File(fromDir, 141 srcFiles[j])); 142 Table table = Table.unmarshal(reader); 143 144 Document doc = sv.toSVG(table); 145 146 DOM2Writer.serializeAsXML(doc, 147 new FileWriter(new File(toDir, 148 table.getName() + ".svg")), false, true); 149 } catch (Exception e) { 150 log("Unable to create visualisation of " + srcFiles[j] 151 + ", message is: " + e.getMessage(), 152 Project.MSG_INFO); 153 } finally { 154 logger.warn("Loading file: " + srcFiles[j]); 155 log("... " + (System.currentTimeMillis() - start) 156 + "(ms)", Project.MSG_INFO); 157 } 158 } 159 } 160 } catch (Exception e) { 161 logger.error(e); 162 throw new BuildException(e.getMessage()); 163 } 164 165 logger.info("METHOD_EXIT: execute"); 166 } 167 }

This page was automatically generated by Maven