package com.jxml.quick.ocm; // Open Conversion Model
import com.jxml.quick.*;
import com.jxml.quick.recycle.*;
import com.jxml.quick.engine.*;
import org.xml.sax.*;
import java.io.*;
import java.util.*;

/**
 * <p>
 * Support class for ocm applications which do not perform conversion.
 * </p>
 */
public abstract class OCMrootPeerSupportLite extends OCMpeerSupportLite implements OCMrootPeer
{
	/**
	 * Returns the root of the output data model.
	 * (Defaults to this.)
	 */
	public Object getOutputRoot()
		throws SAXException, IOException
	{
		return this;
	}

	// Implement method on OCMrootPeer
	public QDoc convert()
		throws SAXException, IOException
	{
		QDoc schema=context.getSchemaDoc();
		return Quick.createDoc(getOutputRoot(),schema);
	}

	// Implement method on OCMrootPeer
	public QDoc convert(String url)
		throws SAXException, IOException
	{
		QDoc schema=context.getSchemaDoc();
		QDoc rv=Quick.createDoc(getOutputRoot(),schema);
		rv.setKey(QCMLBindings.forceUrl(url));
		QSoftDocHash sdh=schema.getDocHash();
		QDoc rv1=sdh.add(rv);
		if (rv==rv1)
		{
			QRefHash.add(rv);
			if (schema==Quick.QIMLSchema()) // schema?
				((QDocImpl)rv).pool=new QContextPool(rv);
		}
		return rv1;
	}

	// Implement method on OCMrootPeer
	public String express(boolean expressDefaults)
		throws SAXException, IOException
	{
		QDoc outputSchemaDoc=context.getSchemaDoc();
		QDoc xdoc=Quick.createDoc(getOutputRoot(),outputSchemaDoc);

		return Quick.express(xdoc,expressDefaults);
	}

	// Implement method on OCMrootPeer
	public void express(PrintWriter pw, boolean expressDefaults)
		throws SAXException, IOException
	{
		QDoc outputSchemaDoc=context.getSchemaDoc();
		QDoc xdoc=Quick.createDoc(getOutputRoot(),outputSchemaDoc);

		Quick.express(xdoc,pw,expressDefaults);
	}
}
