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.*;
/**
 * Controller Class for Fields<br> 
 * @see <a href="http://quickutil.sourceforge.net/view/Main/QjmlField">QjmlField</a><br>
 */
public class QCField extends OCMrootPeerSupportLite
{		
/**
 * Method declaration<br>
 * This method contains template processing logic 
 * @param param Name of the parameter
 * @return string name of the package
 * @return string it is veriables type
 * @exception SAXException 
 * @exception IOException 
 */
	public void cvt(Object param) throws SAXException, IOException 
	{
		OCMcontextSupport.SubContextSupport 		scs=(OCMcontextSupport.SubContextSupport)context;
		StringBuffer sb=scs.sb;
		QMQJML qjml=(QMQJML)scs.dataModelRoot;
		
		QMField ed = (QMField)dataModel;

		String initializer=ed.initializer;
	       	String variableType=ed.getClassName();
	
		int i=variableType.lastIndexOf('.');
		String vt="";
		if (i==-1)
			vt=variableType;
		else
			vt=variableType.substring(i+1);

		if (param instanceof ArrayList)
		{
			if (i==-1)
				return;
			ArrayList imports=(ArrayList)param;
			int j,s;
			s=imports.size();
			String pkg=variableType.substring(0,i);
			for (j=0;j<s;++j)
			{
				if (pkg.equals(imports.get(j)))

					return;
			}

			imports.add(pkg);

			return;
		}

		if (param==null)
		{
			if (ed.ia!=null)
				return;
			sb.append("\tpublic ");
			sb.append(vt);
			sb.append("  ");
			sb.append(ed.name);

			if (!"".equals(initializer))
			{
				sb.append("=");
				sb.append(initializer);
			}
			else if ("list".equals(ed.kind)
			      || "map".equals(ed.kind))
			{
				sb.append("=new ");
				sb.append(vt);
				sb.append("()");
			}
			sb.append(";");
			sb.append("\n");
			return ;
		}
		
	}
}

