KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > JVMXMLTraceHandler


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// 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 /**
29  * concrete JPF SAX parser implementation to read in XML error traces. Note that the
30  * handler class name is stored in the trace itself, gets instantiated and then delegated by
31  * by the gov.nasa.jpf.BootstrapXMLHandler
32  */

33 public class JVMXMLTraceHandler extends DefaultHandler implements XMLTraceHandler {
34   private boolean valid = false;
35   private Path path;
36   private TrailInfo ti;
37   private StringBuffer JavaDoc 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 JavaDoc namespaceURI, String JavaDoc localName,
57                           String JavaDoc 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 JavaDoc namespaceURI, String JavaDoc localName,
74                             String JavaDoc qualifiedName, Attributes atts)
75                      throws SAXException {
76     if (valid) {
77       return;
78     }
79
80     if (localName.equals("Trace")) {
81       String JavaDoc app = atts.getValue("Application");
82       path = new Path(app);
83
84       // System.out.println("Message is " + atts.getValue("Message"));
85
} 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 JavaDoc();
93     }
94   }
95 }
96
Popular Tags