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.*;

/**
 * Transcribes data to a new set of classes, 
 * but using the same data model.
<pre>
DTD:

&lt;!ELEMENT transcribe((<a href="OCMsinkSupport.html#source">(contextSupport | transcribe | input) | sourceLink</a>),(<a href="OCMsinkSupport.html#validator">validatorSupport | validateLink</a>)?)>

&lt;!ATTLIST transcribe
&nbsp;&nbsp;&nbsp;&nbsp;<a href="OCMsinkSupport.html#prefix">docNamePrefix</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="OCMsinkSupport.html#expressDefaults">expressDefaults</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;ID CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;<a href=#schemaName>outputSchema</a> CDATA #IMPLIED
>
</pre>
 */
public class OCMtranscribe extends OCMsinkSupport implements OCMsource
{
	/**
	 * The schema name for the output of the transcribe.
	 */
	public String schemaName="";

	// implements an OCMbase method
	public OCMbase.SubBase spawn(HashMap prior)
	{
		OCMbase.SubBase rv=(OCMbase.SubBase)prior.get(this);
		if (rv!=null)
			return rv;
		OCMbase.SubBase base=new SubTranscribe(prior);
		prior.put(this,base);
		return base;
	}

	public class SubTranscribe extends SubSinkSupport implements OCMsource.SubSource
	{
		/**
		 * The output document.
		 */
		public QDoc outputDoc=null;

		/**
		 * The config properties
		 */
		public Map properties=new HashMap();

		public SubTranscribe(HashMap prior)
		{
			super(prior);
		}

		// implements OCMsource method
		public QDoc getSchemaDoc()
			throws SAXException, IOException
		{
			return Quick.parseSchema(schemaName);
		}

		// implements SubSource method
		public QDoc getDoc()
			throws SAXException, IOException
		{
			if (outputDoc!=null)
				return outputDoc;
			QDoc inputDoc=getInputDoc();
			QDoc schema=getSchemaDoc();
			if ("".equals(docName))
				outputDoc=Quick.transcribe(inputDoc,schema,expressDefaults);
			else
				outputDoc=Quick.transcribe(inputDoc,schema,docName,expressDefaults);
			return outputDoc;
		}	

		// Implement SubSink method.
		public String express()
			throws SAXException, IOException
		{
			return Quick.express(getDoc(),expressDefaults);
		}

		// Implement SubSink method.
		public void express(PrintWriter pw)
			throws SAXException, IOException
		{
			Quick.express(getDoc(),pw,expressDefaults);
		}
	}
}
