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: package org.griphyn.vdl.toolkit;
016:
017: import java.io.*;
018: import org.griphyn.common.util.Version;
019: import org.griphyn.common.util.Currently;
020: import org.griphyn.vdl.classes.*;
021: import org.griphyn.vdl.parser.*;
022: import org.griphyn.vdl.classes.Definitions;
023: import org.griphyn.vdl.util.Logging;
024: import org.griphyn.vdl.directive.VDLxConvert;
025: import org.xml.sax.InputSource;
026: import gnu.getopt.*;
027:
028: /**
029: * This class uses the <code>VDLxParser</code> to parse VDL XML
030: * specification and output VDL textual specification.
031: *
032: * @author Jens-S. Vöckler
033: * @author Yong Zhao
034: * @version $Revision: 50 $
035: *
036: * @see org.griphyn.vdl.parser.VDLxParser
037: */
038: public class VDLx2VDLt extends Toolkit {
039: VDLx2VDLt(String appName) {
040: super (appName);
041: }
042:
043: public void showUsage() {
044: String linefeed = System.getProperty("line.separator", "\r\n");
045: System.out
046: .println("$Id: VDLx2VDLt.java 50 2007-05-19 00:48:32Z gmehta $"
047: + linefeed
048: + "VDS version "
049: + Version.instance().toString() + linefeed);
050:
051: System.out.println("Usage: " + this .m_application
052: + " [-v] VDLxFile VDLtFile" + linefeed + " or: "
053: + this .m_application + " [-v] VDLxFile > VDLtFile"
054: + linefeed + " or: " + this .m_application
055: + " [-v] < VDLxFile > VDLtFile" + linefeed + " or: "
056: + this .m_application + " -V");
057:
058: System.out
059: .println(linefeed
060: + "Generic options: "
061: + linefeed
062: + " -V|--version print version information and exit."
063: + linefeed
064: + " -v|--verbose verbose mode, print parser details on stdout."
065: + linefeed);
066: }
067:
068: /**
069: * Creates a set of long options.
070: */
071: protected LongOpt[] generateValidOptions() {
072: LongOpt[] lo = new LongOpt[3];
073:
074: lo[0] = new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V');
075: lo[1] = new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v');
076: lo[2] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
077:
078: return lo;
079: }
080:
081: /**
082: * the works
083: */
084: public static void main(String[] args) {
085: try {
086: VDLx2VDLt me = new VDLx2VDLt("vdlx2vdlt");
087:
088: // obtain commandline options first -- we may need the database stuff
089: Getopt opts = new Getopt(me.m_application, args, "hvV", me
090: .generateValidOptions());
091: opts.setOpterr(false);
092: int option = 0;
093: while ((option = opts.getopt()) != -1) {
094: switch (option) {
095: case 'V':
096: System.out
097: .println("$Id: VDLx2VDLt.java 50 2007-05-19 00:48:32Z gmehta $");
098: System.out.println("VDS version "
099: + Version.instance().toString());
100: return;
101:
102: case 'v':
103: option = me.increaseVerbosity();
104: if (option == 1)
105: me.m_logger.register("parser", System.out,
106: option);
107: else
108: me.m_logger.setLevel("parser", option);
109: break;
110:
111: case '?':
112: System.out.println("Invalid option '"
113: + (char) opts.getOptopt() + "'");
114: default:
115: case 'h':
116: me.showUsage();
117: return;
118: }
119: }
120:
121: // work
122: Writer wr = null;
123: Reader rd = null;
124: int where = opts.getOptind();
125: switch (args.length - where) {
126: case 2:
127: wr = new BufferedWriter(new FileWriter(args[where + 1]));
128: rd = new BufferedReader(new FileReader(args[where + 0]));
129: break;
130: case 1:
131: wr = new OutputStreamWriter(System.out);
132: rd = new BufferedReader(new FileReader(args[where]));
133: break;
134: case 0:
135: System.err.println("# reminder: reading from stdin");
136: wr = new OutputStreamWriter(System.out);
137: rd = new InputStreamReader(System.in);
138: break;
139: default:
140: me.showUsage();
141: throw new RuntimeException(
142: "Illegal number of non-option arguments");
143: }
144:
145: VDLxConvert convert = new VDLxConvert();
146: convert.VDLx2VDLt(rd, wr);
147: rd.close();
148: wr.flush();
149: wr.close();
150:
151: } catch (RuntimeException rte) {
152: System.err.println("Runtime error: " + rte.getMessage());
153: System.exit(1);
154: } catch (Exception e) {
155: System.err.println("Stumbled over " + e.getMessage());
156: e.printStackTrace(System.err);
157: System.exit(1);
158: }
159: }
160: }
|