KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > pull > PullTracer


1 package net.sf.saxon.pull;
2
3 import net.sf.saxon.trans.XPathException;
4
5 /**
6  * PullTracer is a PullFilter that can be inserted into a pull pipeline for diagnostic purposes. It traces
7  * all the events as they are read, writing details to System.err
8 */

9
10 public class PullTracer extends PullFilter {
11
12     /**
13      * Create a PullTracer
14      * @param base the PullProvider to which requests are to be passed
15      */

16
17     public PullTracer(PullProvider base) {
18         super(base);
19     }
20
21     /**
22      * Get the next event. This implementation gets the next event from the underlying PullProvider,
23      * copies it to the branch Receiver, and then returns the event to the caller.
24      *
25      * @return an integer code indicating the type of event. The code
26      * {@link #END_OF_INPUT} is returned at the end of the sequence.
27      */

28
29     public int next() throws XPathException {
30         currentEvent = super.next();
31         traceEvent(currentEvent);
32         return currentEvent;
33     }
34
35
36     /**
37      * Copy a pull event to a Receiver
38      */

39
40     private void traceEvent(int event) {
41         PullProvider in = getUnderlyingProvider();
42         switch (event) {
43             case START_DOCUMENT:
44                 System.err.println("START_DOCUMENT");
45                 break;
46
47             case START_ELEMENT:
48                 System.err.println("START_ELEMENT " + in.getNameCode());
49                 break;
50
51             case TEXT:
52                 System.err.println("TEXT");
53                 break;
54
55             case COMMENT:
56                 System.err.println("COMMENT");
57                 break;
58
59             case PROCESSING_INSTRUCTION:
60                 System.err.println("PROCESSING_INSTRUCTION");
61                 break;
62
63             case END_ELEMENT:
64                 System.err.println("END_ELEMENT " + in.getNameCode());
65                 break;
66
67             case END_DOCUMENT:
68                 System.err.println("END_DOCUMENT");
69                 break;
70
71             case END_OF_INPUT:
72                 System.err.println("END_OF_INPUT");
73                 break;
74
75             case ATOMIC_VALUE:
76                 try {
77                     System.err.println("ATOMIC VALUE: " + in.getStringValue());
78                 } catch (XPathException e) {
79                     //
80
}
81         }
82     }
83 }
84
85 //
86
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
87
// you may not use this file except in compliance with the License. You may obtain a copy of the
88
// License at http://www.mozilla.org/MPL/
89
//
90
// Software distributed under the License is distributed on an "AS IS" basis,
91
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
92
// See the License for the specific language governing rights and limitations under the License.
93
//
94
// The Original Code is: all this file.
95
//
96
// The Initial Developer of the Original Code is Michael H. Kay.
97
//
98
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
99
//
100
// Contributor(s): none.
101
//
102
Popular Tags