001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015:
016: package org.griphyn.vdl.toolkit;
017:
018: import java.io.*;
019: import java.util.*;
020: import org.griphyn.common.util.Version;
021: import org.griphyn.vdl.dax.*;
022: import org.griphyn.vdl.parser.DAXParser;
023: import org.griphyn.vdl.util.Logging;
024: import org.griphyn.vdl.directive.Display;
025: import gnu.getopt.*;
026:
027: /**
028: * This class generates GraphViz dot format from a DAX
029: *
030: * @author Jens-S. Vöckler
031: * @author Yong Zhao
032: * @version $Revision: 50 $
033: *
034: */
035: public class VizDAX extends Toolkit {
036: /**
037: * ctor: Constructs a new instance object with the given application name.
038: */
039: public VizDAX(String appName) {
040: super (appName);
041: }
042:
043: /**
044: * Implements printing the usage string onto stdout.
045: */
046: public void showUsage() {
047: String linefeed = System.getProperty("line.separator", "\r\n");
048:
049: System.out
050: .println("$Id: VizDAX.java 50 2007-05-19 00:48:32Z gmehta $"
051: + linefeed
052: + "VDS version "
053: + Version.instance().toString() + linefeed);
054:
055: System.out.println("Usage: " + this .m_application
056: + " [general] [-f] [-o dot] [dax]");
057:
058: System.out
059: .println(linefeed
060: + " -V|--version print version information and exit."
061: + linefeed
062: + " -v|--verbose increases the verbosity level."
063: + linefeed
064: + " -f|--files if present, show input and output files in graph."
065: + linefeed
066: + " -d|--dv if present, also show the DV names in graph."
067: + linefeed
068: + " -o|--output dot put the output into the file dot, defaults to stdout."
069: + linefeed
070: + " dax reads the specified dax file; if absent, uses stdin."
071: + linefeed);
072: }
073:
074: /**
075: * Creates a set of options.
076: */
077: protected LongOpt[] generateValidOptions() {
078: LongOpt[] lo = new LongOpt[6];
079:
080: lo[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
081: lo[1] = new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V');
082: lo[2] = new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v');
083:
084: lo[3] = new LongOpt("files", LongOpt.NO_ARGUMENT, null, 'f');
085: lo[4] = new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null,
086: 'o');
087: lo[5] = new LongOpt("dv", LongOpt.NO_ARGUMENT, null, 'd');
088:
089: return lo;
090: }
091:
092: /**
093: * Get the DAX and generate GraphViz dot representation.
094: */
095: public static void main(String[] args) {
096: int result = 0;
097:
098: try {
099: VizDAX me = new VizDAX("dax2dot");
100:
101: // get the commandline options
102: Getopt opts = new Getopt(me.m_application, args, "hdfo:V",
103: me.generateValidOptions());
104: opts.setOpterr(false);
105: boolean files = false;
106: boolean showDV = false;
107: String arg = null;
108: String dot = null;
109:
110: int option = 0;
111: while ((option = opts.getopt()) != -1) {
112: switch (option) {
113: case 'V':
114: System.out
115: .println("$Id: VizDAX.java 50 2007-05-19 00:48:32Z gmehta $");
116: System.out.println("VDS version "
117: + Version.instance().toString());
118: return;
119:
120: case 'd':
121: showDV = true;
122: break;
123:
124: case 'f':
125: files = true;
126: break;
127:
128: case 'o':
129: arg = opts.getOptarg();
130: if (arg != null && arg.length() > 0)
131: dot = arg;
132: break;
133:
134: case 'v':
135: me.increaseVerbosity();
136: break;
137:
138: case 'h':
139: default:
140: me.showUsage();
141: return;
142: }
143: }
144:
145: Display display = new Display();
146: String daxfn = (opts.getOptind() < args.length ? args[opts
147: .getOptind()] : null);
148:
149: BufferedInputStream input = null;
150: if (daxfn == null || daxfn.equals("-")) {
151: input = new BufferedInputStream(System.in);
152: System.err.println("# reminder: reading from stdin");
153: } else {
154: input = new BufferedInputStream(new FileInputStream(
155: daxfn));
156: }
157:
158: BufferedWriter output = new BufferedWriter(
159: (dot == null || dot.equals("-")) ? new OutputStreamWriter(
160: System.out)
161: : // convert stream to writer
162: new FileWriter(dot));
163:
164: display.setShowDV(showDV);
165: display.DAX2DOT(input, output, files);
166: output.flush();
167: if (dot != null)
168: output.close();
169: } catch (RuntimeException rte) {
170: System.err.println("ERROR: " + rte.getMessage());
171: result = 1;
172: } catch (IOException ioe) {
173: System.err.println("ERROR: " + ioe.getMessage());
174: result = 1;
175: } catch (Exception e) {
176: e.printStackTrace();
177: System.err.println("FATAL: " + e.getMessage());
178: result = 2;
179: }
180:
181: if (result != 0)
182: System.exit(result);
183: }
184: }
|