// copyright => http://www.jxml.com/mdsax/License.txt

package com.jxml.quick.engine;

import com.jxml.quick.*;
import java.util.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

public final class QContextImpl extends QContext
{
    int ndx;
    ArrayList elements=new ArrayList();

    public QContextImpl()
    {
	locator=new LocatorImpl();
    }

    QEI getCurrentEntry()
    {
	return (QEI)elements.get(ndx);
    }

    QEI getParentEntry()
    {
	if (ndx==0)
	    return null;
	return (QEI)elements.get(ndx-1);
    }

    public void startDocument()
	throws QPE
    {
	if (doc==null)
		doc=new com.jxml.quick.engine.QDocImpl(this);
	ndx=-1;
	filter.startDocument();
    }

    public void endDocument()
	throws QPE
    {
	((QDocImpl)doc).end();
	filter.endDocument();
    }

    public void startElement(String name)
	throws QPE
    {
	//System.out.println("start "+name);
	++ndx;
	filter.startElement(name);
    }

    public void endElement(String name, String text, boolean cdata)
	throws QPE
    {
	//System.out.println("  end "+name+": "+text);
	filter.endElement(name,text,cdata);
	--ndx;
    }

    public void walk(QDoc doc, QContext outputContext)
	throws QPE
    {
	this.doc=doc;
	((QDocImpl)doc).beginWalk();
	outputContext.startDocument();
	filter.walk(doc.getRoot(),outputContext);
	outputContext.endDocument();
    }
}
