package com.jxml.quick.util.qjml2qiml;
import com.jxml.quick.model.qjml.*;
import com.jxml.quick.*;
import org.xml.sax.*;
import java.util.*;
import com.jxml.quick.ocm.*;
import java.io.*;

/**
 * Extracts QJML data.
 */
public class QCItem extends OCMpeerSupport
{
	public boolean beenHere=false;

	/**
	 * Convert item.
	 */
	public void cvt(Object param)
		throws SAXException, IOException
	// param=null: cvt element
	// param="": cvt attribute
	{
		QMItem dm=(QMItem)dataModel;

		if (beenHere)
		{
			addStringAttribute("href","#"+dm.label);
			//addStringAttribute("schema","http://www.jxml.com/qiml.qiml");
			emptyElement("clink");
			return;
		}
		if (!"".equals(dm.label))
			beenHere=true;

		addStringAttribute("ID",dm.label);
		if (dm.fixed)
		{
			addStringAttribute("fixed","True");
			addStringAttribute("optional","True");
		}
		else if (dm.optional)
			addStringAttribute("optional","True");
		if (dm.repeating)
			addStringAttribute("repeating","True");
		if (!"".equals(dm.value))
			addStringAttribute("default",dm.value);

		startElement("childElement");

		if (dm.access!=null)
			doCvt(dm.access,null);
		else if (param!=null)
		{
			System.err.println("coinName="+dm.coinName);
			System.err.println("cref="+dm.cref);
			System.err.println("aref="+dm.aref);
			throw new SAXException("access missing from attribute");
		}

		if (dm.coin!=null)
			doCvt(dm.coin,param); // cvt element or attribute
		else // element only
		{
			addStringAttribute("href",dm.schema+"#"+dm.coinName);
			emptyElement("link");
		}

		endElement("childElement");
	}
}
