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 QCItem extends OCMpeerSupport
{
	/**
	 * User-provided code to perform the conversion.
	 */
	public void cvt(Object param)
		throws SAXException, IOException
	{
		QDMItem dm=(QDMItem)dataModel;
		TreeMap coinMap=(TreeMap)param;
		String coinName=dm.coinName;
		QDMElement element=(QDMElement)coinMap.get(coinName);
		String tag=element.getTag();
		if (dm.optional && dm.repeating )
			addStringAttribute("cardinal","ZEROMANY");
		else if (dm.optional)
			addStringAttribute("cardinal","OPTIONAL");
		else if (dm.repeating)
			addStringAttribute("cardinal","ONEMANY");
		else 
			addStringAttribute("cardinal","NONE");
		ArrayList concrete=((QDMCoin)element).getConcreteDecendants();
		if (concrete.size()==1)
		{
			QDMElement e=(QDMElement)concrete.get(0);
			tag=e.getTag();
			addStringAttribute("element",tag);
			startElement("name");
			endElement("name");
			return;
		}
		startElement("choice");
		int i,s;
		s=concrete.size();
		for(i=0;i<s;++i)
		{
			QDMElement e=(QDMElement)concrete.get(i);
			tag=e.getTag();
			addStringAttribute("element",tag);
			startElement("name");
			endElement("name");
		}
		endElement("choice");
	}
}
