1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.Path; 22 import gov.nasa.jpf.XMLTraceHandler; 23 24 import org.xml.sax.*; 25 import org.xml.sax.helpers.*; 26 27 28 33 public class JVMXMLTraceHandler extends DefaultHandler implements XMLTraceHandler { 34 private boolean valid = false; 35 private Path path; 36 private TrailInfo ti; 37 private StringBuffer buffer; 38 39 public JVMXMLTraceHandler () { 40 } 41 42 public Path getPath () { 43 if (valid) { 44 return path; 45 } else { 46 return null; 47 } 48 } 49 50 public void characters (char[] text, int start, int length) { 51 if (buffer != null) { 52 buffer.append(text, start, length); 53 } 54 } 55 56 public void endElement (String namespaceURI, String localName, 57 String qualifiedName) throws SAXException { 58 if (valid) { 59 return; 60 } 61 62 if (localName.equals("Trace")) { 63 valid = true; 64 } else if (localName.equals("Step")) { 65 path.add(ti); 66 ti = null; 67 } else if (localName.equals("Comment")) { 68 ti.setAnnotation(buffer.toString()); 69 buffer = null; 70 } 71 } 72 73 public void startElement (String namespaceURI, String localName, 74 String qualifiedName, Attributes atts) 75 throws SAXException { 76 if (valid) { 77 return; 78 } 79 80 if (localName.equals("Trace")) { 81 String app = atts.getValue("Application"); 82 path = new Path(app); 83 84 } else if (localName.equals("Step")) { 86 ti = new TrailInfo(Integer.parseInt(atts.getValue("Thread")), 87 Integer.parseInt(atts.getValue("Random"))); 88 } else if (localName.equals("Instruction")) { 89 Step s = new Step(atts.getValue("File"), Integer.parseInt(atts.getValue("Line"))); 90 ti.addStep(s); 91 } else if (localName.equals("Comment")) { 92 buffer = new StringBuffer (); 93 } 94 } 95 } 96 | Popular Tags |