package com.jxml.quick.util.qjml2java2;
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.*;
/**
 * Class for extracting QJML data.
 * @see <a href="http://quickutil.sourceforge.net/view/Main/QjmlBean">QjmlBean</a><br>
 */
public class QCBean extends QCCoin
{
	StringBuffer sb;
	public QMBean ed;
/**
 * Method declaration<br> 
 * @param param The parameter name
 * @exception SAXException It is legal SAXException  
 * @exception IOException It is legal IOException
 */
	public void cvt(Object param) 
		throws SAXException, IOException 
	{
		OCMcontextSupport.SubContextSupport 							scs=(OCMcontextSupport.SubContextSupport)context;
		sb=scs.sb;
		ed=(QMBean)dataModel;
		if((ed.type).equals("BIMODAL"))
			altTemplate="biModal";
		super.cvt(param);
	}
/**
 * Method declaration<br>
 * This method contains template processing logic to <code>process</code> the       templates.
 * @param templateName The name of the Template<br>
 * @param arg The parameter name<br>
 * @return The string values to be plugged inside the templates
 * @exception SAXException It is legal SAXException
 * @exception IOException It is legal IOException
 */
	public String process(String templateName, String arg)
		throws SAXException, IOException
	{
		int i,s;

		if("import".equals(arg))
		{
			ArrayList imports=new ArrayList();
			imports.add(packageName);
			imports.add("com.jxml.quick");
			doCvt(ed.extendor,imports);
			doCvt(ed.implementsList,imports);
			doCvt(ed.elements,imports);
			doCvt(ed.attributes,imports);
			doCvt(ed.fieldList,imports);
			doCvt(ed.propertyList,imports);
			s=imports.size();
			for (i=1;i<s;++i)
			{
				String imp=(String)imports.get(i);
				if (!imp.equals("java.lang"))
					sb.append("import "+imp+".*;\n");
			}
			return "";
		}
		
		if("extendor".equals(arg))
		{
			if(!(ed.extendor==null))
			{
				sb.append("extends ");
				doCvt(ed.extendor,null);
			}

			return "";
		}

		if ("implementor".equals(arg))
		{
			if(!(ed.implementsList.size() < 1) || 							(ed.type).equals("BIMODAL"))
			{
				sb.append("implements ");
				if((ed.type).equals("BIMODAL"))
					sb.append(" QBiModal, ");
				List l=ed.implementsList;
				s=l.size();
				for (i=0;i<s;++i)
				{
					if (i>0)
					sb.append(", ");
					Object o=l.get(i);
					doCvt(o,null);
				}
			}
			return "";
		}

		if ("variables".equals(arg))
		{
			doCvt(ed.attributes,null);
			doCvt(ed.elements,null);
			doCvt(ed.fieldList,null);
			doCvt(ed.propertyList,null);
			return "";
		}

		if ("methods".equals(arg))
		{
			doCvt(ed.attributes,"");
			doCvt(ed.elements,"");
			doCvt(ed.fieldList,"");
			doCvt(ed.propertyList,"");
			return "";
		}

		return	super.process(templateName,arg);
	}
}

