01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19: 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: * concrete JPF SAX parser implementation to read in XML error traces. Note that the
29: * handler class name is stored in the trace itself, gets instantiated and then delegated by
30: * by the gov.nasa.jpf.BootstrapXMLHandler
31: */
32: public class JVMXMLTraceHandler extends DefaultHandler implements
33: 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) throws SAXException {
75: if (valid) {
76: return;
77: }
78:
79: if (localName.equals("Trace")) {
80: String app = atts.getValue("Application");
81: path = new Path(app);
82:
83: // System.out.println("Message is " + atts.getValue("Message"));
84: } else if (localName.equals("Step")) {
85: ti = new TrailInfo(Integer
86: .parseInt(atts.getValue("Thread")), Integer
87: .parseInt(atts.getValue("Random")));
88: } else if (localName.equals("Instruction")) {
89: Step s = new Step(atts.getValue("File"), Integer
90: .parseInt(atts.getValue("Line")));
91: ti.addStep(s);
92: } else if (localName.equals("Comment")) {
93: buffer = new StringBuffer();
94: }
95: }
96: }
|