// To compile and run this program, put
// /proj/demsys/demjava/rt.jar into your class path.

// If you use the CCS .software file, use:
// CLASSPATH=.:/proj/demsys/demjava/rt.jar

import java.util.*;
import edu.neu.ccs.demeter.dj.*;
// import edu.neu.ccs.demeter.*;

// Location.java
class Location {
  String name;
  Location(String n){ name = n ;}
}

 class Main {
  public Main() {
    super();
    }
  
  static public void main(String args[]) throws Exception {

    // Build Trip-object
    Vector v1 = new Vector();
    Location l1 = new Location("Zurich");
    v1.add(l1);
    Location l2 = new Location("Chur");
    v1.add(l2);
    Location l3 = new Location("St. Moritz");
    v1.add(l3);
    Location l4 = new Location("Pontresina");
    v1.add(l4);
    Trip a = new Trip(v1,9,17);
    System.out.println("DJ start ");
    ClassGraph cg = Main.buildClassGraph();
    System.out.println();
    TraversalGraph allLocations = new TraversalGraph(
      "from Trip to Location" ,cg);
    System.out.println("---- TG begin ");
    System.out.println(allLocations);
    System.out.println("---- TG done ");
    System.out.println();
    System.out.println("Output");

    a.printItinerary(allLocations);

    System.out.println(" DONE");
  }

  
public static ClassGraph buildClassGraph() {
   ClassGraph cg=new  ClassGraph(true,false);
   // true: include all fields 
   // false: do NOT include all non-void no-argument methods
  
  System.out.println("The DJ version is: " + cg.getVersion());
  System.out.println("The class graph is" + "=============================");
  System.out.println(cg);
  System.out.println("end class graph " + "=============================");
  return cg;
}

}

class Trip {
  Trip(Vector it, int d, int a) {
    itinerary = it;
    departure = d;
    arrival = a;
  }
  Vector itinerary;
  int arrival;
  int departure;
  void printItinerary(TraversalGraph allLocations) {
    allLocations.traverse(this, new Visitor() {
      void before (Trip host) {System.out.println("departure " + 
	host.departure);}
      void before (Location host) { System.out.println(host.name);}
      void after (Trip host) {System.out.println("arrival " +
	host.arrival);}
   });
  }
}


