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

/**
 * Provides the functionality for the conversion.
 */
public abstract class OCMrootPeerSupport extends OCMpeerSupport implements OCMrootPeer
{
	/**
	 * A unique token for root conversion.
	 */
	public class Root{}

	// Override QConverterSupport method
	public void evalRoot()
		throws SAXException, IOException
	{
		context.setDestination(destination);
		cvt(new Root());
	}

	// Implement method on OCMrootPeer
	public QDoc convert()
		throws SAXException, IOException
	{
		QDoc outputSchema=context.getSchemaDoc();
		QDoc inputSchema=context.getInputSchemaDoc();
		QDoc xdoc=Quick.createDoc(this,inputSchema);
		return Quick.convert(xdoc,outputSchema);
	}

	// Implement method on OCMrootPeer
	public QDoc convert(String url)
		throws SAXException, IOException
	{
		QDoc outputSchema=context.getSchemaDoc();
		QDoc inputSchema=context.getInputSchemaDoc();
		QDoc xdoc=Quick.createDoc(this,inputSchema);
		return Quick.convert(xdoc,outputSchema,url);
	}

	// Implement method on OCMrootPeer
	public String express(boolean expressDefaults)
		throws SAXException, IOException
	{
		QDoc xdoc=Quick.createDoc(this,null);
		return Quick.express(xdoc,expressDefaults);
	}

	// Implement method on OCMrootPeer
	public void express(PrintWriter pw, boolean expressDefaults)
		throws SAXException, IOException
	{
		QDoc xdoc=Quick.createDoc(this,null);
		Quick.express(xdoc,pw,expressDefaults);
	}

	public String getPUBLIC()
		throws SAXException, IOException
	{
		if (!"".equals(context.getPUBLIC()))
			return context.getPUBLIC();
		QDoc outputSchema=context.getSchemaDoc();
		if (outputSchema==null)
			return "";
		QIML schemaRoot=(QIML)outputSchema.getRoot();
		if (schemaRoot==null)
			return "";
		return schemaRoot.PUBLIC;
	}

	public String getSYSTEM()
		throws SAXException, IOException
	{
		if (!"".equals(context.getSYSTEM()))
			return context.getSYSTEM();
		QDoc outputSchema=context.getSchemaDoc();
		if (outputSchema==null)
			return "";
		QIML schemaRoot=(QIML)outputSchema.getRoot();
		if (schemaRoot==null)
			return "";
		return schemaRoot.SYSTEM;
	}

	public String getRootTag()
		throws SAXException, IOException
	{
		if (!"".equals(context.getRootTag()))
			return context.getRootTag();
		QDoc outputSchema=context.getSchemaDoc();
		if (outputSchema==null)
			return "";
		QIML schemaRoot=(QIML)outputSchema.getRoot();
		if (schemaRoot==null)
			return "";
		List factories=schemaRoot.factories;
		if (factories.size()!=1)
			return "";
		Object efo=factories.get(0);
		if (!(efo instanceof QElementFactory))
			return "";
		QElementFactory ef=(QElementFactory)efo;
		return ef.tagName;
	}
}
