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

package com.jxml.quick;
import org.xml.sax.*;

public class QFilterFactory extends QBase
{
    public QContext newContext=null;
    private QFilter mf=null;

    public QContext createContext()
	throws SAXException
    {
	QDoc doc=com.jxml.quick.engine.QCMLBindings.createDoc(this);
	return com.jxml.quick.engine.QCMLBindings.createContext(doc);
    }

    public final synchronized QFilter createFilter(QContext context)
	throws QE
    {
	if (context!=null && newContext==context)
	    {
		return mf;
	    }
	initFF(context);
	newContext=context;
	mf=newFilter();
	mf.init();
	return mf;
    }

    protected void initFF(QContext context)
	throws QE
    {
    }

    protected QFilter newFilter()
	throws QE
    {
	return new QFilter();
    }

    public void addToFactory(QFilterFactory factory)
	throws QE
    {
	factory.addFactory(this);
    }

    public void addFactory(QFilterFactory factory)
	throws QE
    {
	throw new QE("not a container");
    }

    public class QFilter extends QBaseFilter
    {
	public QContext context;
	
	public QFilter()
	    throws QE
	{
	    this.context=newContext;
	}

	public void init()
	    throws QE
	{
	}
    }
}
