package dk.brics.xact.analysis.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Set;
import dk.brics.automaton.Automaton;
import dk.brics.xmlgraph.XMLGraph;
import dk.brics.xmlgraph.converter.XMLGraph2Dot;
public class Util {
/**
* Returns a human readable description of an automaton.
*/
public static String getAutomatonDescription(Automaton auto) {
if (auto == null)
return "<null automaton>";
if (auto.isTotal())
return "<all strings>";
if (auto.isEmpty())
return "<no string>";
if (auto.isEmptyString())
return "<empty string>";
Set<String> fin = auto.getFiniteStrings(1);
if (fin != null)
return fin.iterator().next();
return "<" + auto.getNumberOfStates() + " states>";
}
/**
* Prints the specified XML graph to a file as a graphviz dot graph.
* @param xg the XML graph
* @param filename filename to print to
*/
public static void dumpXMLGraph(XMLGraph xg, String filename) {
try {
FileOutputStream out = new FileOutputStream(filename);
PrintStream pout = new PrintStream(out);
new XMLGraph2Dot(pout).print(xg, true);
pout.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
}