TraceIO.java
package edu.udel.cis.vsl.tass.trace;
import java.awt.*;
//import java.io.*;
//import com.thoughtworks.xstream.XStream;
public class TraceIO<TRANSITIONSEQUENCE> {
String filePath;
public TraceIO(){
filePath="";
}
public String getFilePath(){
return filePath;
}
/**
* Call this method before saving a trace. Opens a prompt allowing the user to specify a file location to save to.
*/
public void specifyOutputFile(){
FileDialog fd = new FileDialog(new Frame(), "Save as...", FileDialog.SAVE);
fd.setVisible(true);
filePath = new String (fd.getDirectory() + fd.getFile());
}
/**
* Call this method before reading a trace. Opens a prompt allowing the user to specify a file to read from.
*/
public void specifyInputFile(){
FileDialog fd = new FileDialog(new Frame(), "Open...", FileDialog.LOAD);
fd.setVisible(true);
if(fd.getFile()==null)
filePath=null;
else
filePath = new String(fd.getDirectory() + fd.getFile());
}
/**
* Takes a trace object and saves it as xml to the location selected with specifyOutputFile
* @param trace
*/
public void saveTrace(Trace<TRANSITIONSEQUENCE> trace){
/*try{
XStream xstream = new XStream();
FileOutputStream fout = new FileOutputStream(filePath);
PrintStream printer = new PrintStream(fout);
printer.print(xstream.toXML(trace));
}
catch(IOException e){
System.out.println("IOException when saving trace.");
}*/
}
/**
* Returns a Trace<TRANSITIONSEQUENCE> object read from the file selected with the method specifyInputFile
* @return
*/
public Trace<TRANSITIONSEQUENCE> readTrace(){
/*try{
XStream xstream = new XStream();
BufferedReader rin = new BufferedReader(new FileReader(filePath));
String xml = "";
String temp;
while((temp = rin.readLine()) != null){
xml = xml.concat(temp);
}
//convert the xml back to the trace object using xstream
return ((Trace<TRANSITIONSEQUENCE>) xstream.fromXML(xml));
}
catch(FileNotFoundException e){
System.out.println("FileNotFoundException when reading in trace.");
}
catch(IOException e){
System.out.println("IOException when reading in trace.");
}*/
return null;
}
}