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

/**
 * Extracts DTD data.
 */
public class QCElements extends OCMpeerSupport
{
	/**
	 * User-provided code to perform the conversion.
	 */
	public void cvt(Object param)
		throws SAXException, IOException
	{
		QDMElements dm=(QDMElements)dataModel;
		QCBean bean=(QCBean)param;
		TreeMap coinMap=bean.coinMap;
		QDMBean beanDM=bean.dm;
		String type=beanDM.type;
		if ("".equals(type))
		{
			if (dm.contentList.size()==0)
			{
				startElement("empty");
				endElement("empty");
			}
			else if (dm.contentList.size()>1)
			{
				startElement("sequence");
				doCvt(dm.contentList,coinMap);
				endElement("sequence");
			}
			else 
				{
				Object c=dm.contentList.get(0);
				if (c instanceof QDMItem )
				{
					startElement("choice");
					doCvt(c,coinMap);
					endElement("choice");
				}
				else 
					doCvt(c,coinMap);
			}
		}
		else
		{
			if (dm.contentList.size()==0)
			{
				addStringAttribute("cardinal","NONE");
				startElement("mixed");
				startElement("pcData");
				endElement("pcData");
				endElement("mixed");
			}
			else if ((dm.contentList.size()==1)
			&& (dm.contentList.get(0) instanceof QDMSelection))
			{
				addStringAttribute("cardinal","ZEROMANY");
				startElement("mixed");
				startElement("pcData");
				endElement("pcData");
				QDMSelection selection=(QDMSelection)dm.contentList.get(0);
				doCvt(selection.contentList,coinMap);
				endElement("mixed");
			}
			else
			{
				addStringAttribute("cardinal","ZEROMANY");
				startElement("mixed");
				startElement("pcData");
				endElement("pcData");
				doCvt(dm.contentList,coinMap);
				endElement("mixed");
			}
		}
	}
}
