001package edu.pdx.cs410J.net;
002
003import java.io.*;
004
005/**
006 * This program constructs a graph of <code>Node</code>s and
007 * serializes them to a file.
008 */
009public class WriteGraphNodes {
010
011  /**
012   * Creates a graph of <code>GraphNode</code>s and serializes them to a
013   * file whose name is given on the command line.
014   */
015  public static void main(String[] args) {
016    String fileName = args[0];
017
018    // Make a graph of nodes
019    GraphNode a = new GraphNode();
020    GraphNode b = new GraphNode();
021    GraphNode c = new GraphNode();
022    GraphNode d = new GraphNode();
023    GraphNode e = new GraphNode();
024
025    a.addChild(b);
026    a.addChild(c);
027    a.addChild(d);
028    b.addChild(e);
029    c.addChild(e);
030    d.addChild(e);
031
032    System.out.println("Graph has " + a.traverse() + " nodes");
033
034    try {
035      FileOutputStream fos = new FileOutputStream(fileName);
036      ObjectOutputStream out = new ObjectOutputStream(fos);
037      out.writeObject(a);
038      out.flush();
039      out.close();
040
041    } catch (IOException ex) {
042      System.err.println("** IOException: " + ex);
043      System.exit(1);
044    }
045  }
046}