All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.pull.PullTracer Maven / Gradle / Ivy

package net.sf.saxon.pull;

import net.sf.saxon.trans.XPathException;
import net.sf.saxon.om.NamePool;
import net.sf.saxon.om.FastStringBuffer;

/**
 * PullTracer is a PullFilter that can be inserted into a pull pipeline for diagnostic purposes. It traces
 * all the events as they are read, writing details to System.err
*/

public class PullTracer extends PullFilter {

    private NamePool pool;

    /**
     * Create a PullTracer
     * @param base the PullProvider to which requests are to be passed
     */

    public PullTracer(PullProvider base) {
        super(base);
    }

    /**
     * Get the next event. This implementation gets the next event from the underlying PullProvider,
     * copies it to the branch Receiver, and then returns the event to the caller.
     *
     * @return an integer code indicating the type of event. The code
     *         {@link #END_OF_INPUT} is returned at the end of the sequence.
     */

    public int next() throws XPathException {
        currentEvent = super.next();
        traceEvent(currentEvent);
        return currentEvent;
    }


    /**
     * Copy a pull event to a Receiver
     */

    private void traceEvent(int event) {
        if (pool == null) {
            pool = getPipelineConfiguration().getConfiguration().getNamePool();
        }
        PullProvider in = getUnderlyingProvider();
        switch (event) {
            case START_DOCUMENT:
                System.err.println("START_DOCUMENT");
                break;

            case START_ELEMENT:
                System.err.println("START_ELEMENT " + pool.getDisplayName(in.getNameCode()));
                break;

            case TEXT:
                System.err.println("TEXT");
                try {
                    CharSequence cs = this.getStringValue();
                    FastStringBuffer sb = new FastStringBuffer(cs.length() * 5);
                    sb.append('(');
                    for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy