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.directive;
016:
017: import java.io.*;
018: import java.util.*;
019: import org.griphyn.vdl.dax.*;
020: import org.griphyn.vdl.parser.DAXParser;
021: import org.griphyn.vdl.util.Logging;
022: import org.griphyn.vdl.util.DAX2DOT;
023:
024: /**
025: * The class converts a DAX specification into other formats
026: * for visualization purposes.
027: *
028: * @see org.griphyn.vdl.parser.VDLxParser
029: *
030: * @author Jens-S. Vöckler
031: * @author Yong Zhao
032: * @version $Revision: 50 $
033: */
034: public class Display extends Directive {
035: /**
036: * instance variable that is managed by this interface for web
037: * services.
038: */
039: private DAX2DOT m_dax;
040:
041: /**
042: * Constructor.
043: * @throws IOException
044: * @throws MissingResourceException
045: */
046: public Display() throws IOException, MissingResourceException {
047: super ();
048: m_dax = new DAX2DOT();
049: }
050:
051: /**
052: * Sets the graph size.
053: *
054: * @param h is the height in inches?
055: * @param w is the width in inches?
056: */
057: public void setSize(double h, double w) {
058: m_dax.setSize(h, w);
059: }
060:
061: /**
062: * Determines whether to show derivations.
063: * @param showDV if true, also show the DVs
064: */
065: public void setShowDV(boolean showDV) {
066: m_dax.setShowDV(showDV);
067: }
068:
069: /**
070: * Generates GraphViz dot format from the DAX specification.
071: * @param dax is the InputStream for the DAX
072: * @param showFiles specifies whether to show input/output files in
073: * the graph.
074: * @return a string of the GraphViz dot representation
075: * @throws IOException if there is a problem reading or writing
076: */
077: public String DAX2DOT(InputStream dax, boolean showFiles)
078: throws IOException {
079: // parse the dax file
080: Logging.instance().log("display", 0, "Initializing dax parser");
081: DAXParser daxparser = new DAXParser(m_props
082: .getDAXSchemaLocation());
083:
084: Logging.instance().log("display", 0, "parsing the dax...");
085: ADAG adag = daxparser.parse(dax);
086:
087: if (adag == null) {
088: Logging.instance().log("display", 0,
089: "failed parsing the dax.");
090: return null;
091: }
092:
093: return m_dax.toDOT(adag, showFiles);
094: }
095:
096: /**
097: * Generates GraphViz dot format from the DAX specification.
098: * @param dax is the InputStream for the DAX
099: * @param writer is the target to output GraphViz dot representation
100: * @param showFiles specifies whether to show input/output files in
101: * the graph.
102: * @throws IOException if there is a problem reading or writing
103: */
104: public void DAX2DOT(InputStream dax, Writer writer,
105: boolean showFiles) throws IOException {
106: // parse the dax file
107: Logging.instance().log("display", 0, "Initializing dax parser");
108: DAXParser daxparser = new DAXParser(m_props
109: .getDAXSchemaLocation());
110:
111: Logging.instance().log("display", 0, "parsing the dax...");
112: ADAG adag = daxparser.parse(dax);
113:
114: if (adag == null) {
115: Logging.instance().log("display", 0,
116: "failed parsing the dax.");
117: return;
118: }
119:
120: m_dax.toDOT(adag, writer, showFiles);
121: }
122:
123: /**
124: * Generates GraphViz dot format from the DAX specification.
125: * @param dax is the InputStream for the DAX
126: * @param writer is the target to output GraphViz dot representation
127: * @param showFiles specifies whether to show input/output files in
128: * the graph.
129: * @param jobURL is the base URL for jobs
130: * @param fileURL is the base URL for files
131: * @throws IOException if there is a problem reading or writing
132: */
133: public void DAX2DOT(InputStream dax, Writer writer,
134: boolean showFiles, String jobURL, String fileURL)
135: throws IOException {
136: // parse the dax file
137: Logging.instance().log("display", 0, "Initializing dax parser");
138: DAXParser daxparser = new DAXParser(m_props
139: .getDAXSchemaLocation());
140:
141: Logging.instance().log("display", 0, "parsing the dax...");
142: ADAG adag = daxparser.parse(dax);
143:
144: if (adag == null) {
145: Logging.instance().log("display", 0,
146: "failed parsing the dax.");
147: return;
148: }
149:
150: m_dax.toDOT(adag, writer, showFiles, jobURL, fileURL);
151: }
152: }
|