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

public class QCQIML extends OCMtemplate
{
	String inputQiml;
	String packageName=null;
	String className;
	String var;
	String PUBLIC=null;
	String SYSTEM=null;
	String key;

	public void cvt(Object param)
		throws SAXException, IOException
	{
		QIML2JAVA.SubQIML2JAVA qiml=(QIML2JAVA.SubQIML2JAVA)context;
		className=qiml.properties.get("class").toString();
		boolean bootstrap=Boolean.valueOf(qiml.properties.get("bootstrap").toString())
					.booleanValue();
		key=qiml.properties.get("key").toString();
		int i,s;
		i=className.lastIndexOf('.');
		Qiml dm=(Qiml)dataModel;
		StringBuffer sb=qiml.sb;
		inputQiml=qiml.properties.get("in").toString();
		if (i!=-1)
		{
			packageName=className.substring(0,i);
			if(!"".equals(packageName))
				packageName+=";";
			className=className.substring(i+1);
		}
		if (dm.getQiml_PUBLIC_1()!=null && !"".equals(dm.getQiml_PUBLIC_1()))
			PUBLIC=dm.getQiml_PUBLIC_1();
		if (dm.getQiml_SYSTEM_2()!=null && !"".equals(dm.getQiml_SYSTEM_2()))
			SYSTEM=dm.getQiml_SYSTEM_2();
		var=qiml.makeName();
		if (bootstrap)
			expand("bootTemplate");
		else
			expand("template");
	}

	public String express(boolean expressDefaults)
		throws SAXException, IOException
	{
		QIML2JAVA.SubQIML2JAVA qiml=(QIML2JAVA.SubQIML2JAVA)context;
		qiml.sb=new StringBuffer();
		qiml.varIndex=0;
		cvt(null);
		return qiml.sb.toString();
	}

	public void express(PrintWriter pw, boolean expressDefaults)
		throws SAXException, IOException
	{
		pw.print(express(expressDefaults));
	}

	public String process(String templateName, String arg)
		throws SAXException, IOException
	{
		if ("inputQiml".equals(arg))
			return inputQiml;
		if ("PACKAGE_TEMPLATE".equals(arg))
		{
			if (packageName!=null)
				expand("PACKAGE_TEMPLATE");
			return "";
		}
		if ("packageName".equals(arg))
			return packageName;
		if ("className".equals(arg))
			return className;
		if ("PUBLIC_TEMPLATE".equals(arg))
		{
			if (PUBLIC!=null)
				expand("PUBLIC_TEMPLATE");
			return "";
		}
		if ("PUBLIC".equals(arg))
			return PUBLIC;
		if ("SYSTEM_TEMPLATE".equals(arg))
		{
			if (SYSTEM!=null)
				expand("SYSTEM_TEMPLATE");
			return "";
		}
		if ("SYSTEM".equals(arg))
			return SYSTEM;
		if ("ElementDefinition".equals(arg))
		{
			Qiml dm=(Qiml)dataModel;
			doCvt(dm.getElementDefinition_3(),var);
		}
		if ("var".equals(arg))
			return var;
		if ("key".equals(arg))
			return key;
		return "";
	}
}
