01: /*
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */
15:
16: package org.griphyn.vdl.util;
17:
18: import java.util.Iterator;
19: import java.io.*;
20: import org.griphyn.vdl.dax.*;
21:
22: /**
23: * Convert a dag structure into the new CoG's XML format for
24: * visualization.
25: *
26: * @author Jens-S. Vöckler
27: * @author Yong Zhao
28: * @version $Revision: 50 $
29: */
30: public class DAX2CoG {
31: /**
32: * Converts a given DAX into CoG visualizier XML.
33: *
34: * @param w is a writer onto which to dump the generated XML.
35: * @param dax is the input ADAG.
36: * @throws IOException if the stream write runs into trouble.
37: */
38: public static void toString(Writer w, ADAG dax) throws IOException {
39: String newline = System.getProperty("line.separator", "\r\n");
40:
41: // start graph
42: w.write("<graph>");
43: w.write(newline);
44:
45: // start nodes
46: for (Iterator i = dax.iterateJob(); i.hasNext();) {
47: Job job = (Job) i.next();
48: w.write(" <node nodeid=\"");
49: w.write(job.getID());
50: w.write("\" name=\"");
51: w.write(job.getName());
52: w.write("\"/>");
53: w.write(newline);
54: }
55:
56: // start edges
57: for (Iterator c = dax.iterateChild(); c.hasNext();) {
58: Child child = (Child) c.next();
59: String name = child.getChild();
60: for (Iterator p = child.iterateParent(); p.hasNext();) {
61: w.write(" <edge to=\"");
62: w.write(name);
63: w.write("\" from=\"");
64: w.write((String) p.next());
65: w.write("\"/>");
66: w.write(newline);
67: }
68: }
69:
70: // done
71: w.write("</graph>");
72: w.write(newline);
73: w.flush();
74: }
75:
76: /**
77: * Converts a DAGMan <code>.dag</code> file into a Peudo-DAX.
78: *
79: * @param dag is a File pointing to the DAG file
80: * @return a Pseudo DAX, or null in case of error.
81: * @throws IOException if reading the DAGMan file fails.
82: */
83: public static ADAG DAGMan2DAX(File dag) {
84: // sanity check
85: if (dag == null)
86: return null;
87:
88: ADAG result = new ADAG();
89: return result;
90: }
91: }
|