001: package net.sf.saxon.pull;
002:
003: import net.sf.saxon.trans.XPathException;
004:
005: /**
006: * PullTracer is a PullFilter that can be inserted into a pull pipeline for diagnostic purposes. It traces
007: * all the events as they are read, writing details to System.err
008: */
009:
010: public class PullTracer extends PullFilter {
011:
012: /**
013: * Create a PullTracer
014: * @param base the PullProvider to which requests are to be passed
015: */
016:
017: public PullTracer(PullProvider base) {
018: super (base);
019: }
020:
021: /**
022: * Get the next event. This implementation gets the next event from the underlying PullProvider,
023: * copies it to the branch Receiver, and then returns the event to the caller.
024: *
025: * @return an integer code indicating the type of event. The code
026: * {@link #END_OF_INPUT} is returned at the end of the sequence.
027: */
028:
029: public int next() throws XPathException {
030: currentEvent = super .next();
031: traceEvent(currentEvent);
032: return currentEvent;
033: }
034:
035: /**
036: * Copy a pull event to a Receiver
037: */
038:
039: private void traceEvent(int event) {
040: PullProvider in = getUnderlyingProvider();
041: switch (event) {
042: case START_DOCUMENT:
043: System.err.println("START_DOCUMENT");
044: break;
045:
046: case START_ELEMENT:
047: System.err.println("START_ELEMENT " + in.getNameCode());
048: break;
049:
050: case TEXT:
051: System.err.println("TEXT");
052: break;
053:
054: case COMMENT:
055: System.err.println("COMMENT");
056: break;
057:
058: case PROCESSING_INSTRUCTION:
059: System.err.println("PROCESSING_INSTRUCTION");
060: break;
061:
062: case END_ELEMENT:
063: System.err.println("END_ELEMENT " + in.getNameCode());
064: break;
065:
066: case END_DOCUMENT:
067: System.err.println("END_DOCUMENT");
068: break;
069:
070: case END_OF_INPUT:
071: System.err.println("END_OF_INPUT");
072: break;
073:
074: case ATOMIC_VALUE:
075: try {
076: System.err.println("ATOMIC VALUE: "
077: + in.getStringValue());
078: } catch (XPathException e) {
079: //
080: }
081: }
082: }
083: }
084:
085: //
086: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
087: // you may not use this file except in compliance with the License. You may obtain a copy of the
088: // License at http://www.mozilla.org/MPL/
089: //
090: // Software distributed under the License is distributed on an "AS IS" basis,
091: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
092: // See the License for the specific language governing rights and limitations under the License.
093: //
094: // The Original Code is: all this file.
095: //
096: // The Initial Developer of the Original Code is Michael H. Kay.
097: //
098: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
099: //
100: // Contributor(s): none.
101: //
|