package com.jxml.quick.util.qjml2java;
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.*;

/**
 * Extracts QJML data.
 */
public class QCText extends OCMpeerSupport {
    /**
     * User-provided code to perform the conversion.
     */
    public void cvt(Object param) throws SAXException, IOException {
	QMText ed=(QMText)dataModel;
	Conv.SubConv conv=(Conv.SubConv)context;
        conv.done.put(ed.getLabel(), ed);
        QMTarget target = ed.target;
        //String targetClass = Element.getTargetText(target);
        String targetClass = ed.getClassName();
	addStringAttribute("ID",ed.getLabel());
	addStringAttribute("targetClass",targetClass);
        String tagName = ed.tag;
        if (tagName == null || tagName.equals("")) // useful when wild
            tagName = ed.getLabel();
	addStringAttribute("tagName", tagName);
	addBooleanAttribute("textConstructor",true);
        if (target instanceof QMTargetClass)
            addBooleanAttribute("newClass",ed.generate);
        else
            addBooleanAttribute("newClass",false);
	addBooleanAttribute("hasAClass",!Element.isJavaType(targetClass));
        // clonable is true (default value)
	addBooleanAttribute("wild",ed.wild);
	addBooleanAttribute("bimodal", "BIMODAL".equals(ed.type));
        // abst is false (default value)
        // intf is false (default value)
	addBooleanAttribute("generate",ed.generate);

	startElement("element");
        
        // making parentElement
        QMExtends ext = ed.extendor;
        if (ext != null) {
            String name = ext.getQText();
            if (conv.done.get(name) == null) {
                QMCoin coin = (QMCoin)conv.coinMap.get(name);
                doCvt(coin,null);
            } else {
	        addStringAttribute("href","#"+name);
	        emptyElement("link");
            }
        }

        // imp
        if (ed.implementsList.size() > 0) {
	    startElement("imp");
            for (int i=0; i<ed.implementsList.size(); i++) {
                String name = ((QMImplements)ed.implementsList.get(i)).text;
                if (conv.done.get(name) == null)
                    doCvt(conv.coinMap.get(name),null);
                else {
	            addStringAttribute("href","#"+name);
	            emptyElement("link");
                }
            }
	    endElement("imp");
        }

        // subclasses
        if (ed.extensions != null && ed.extensions.size() > 0) {
	    startElement("subclasses");
            for (int i=0; i<ed.extensions.size(); i++) {
                QMCoin coin = (QMCoin)ed.extensions.get(i);
                String name = coin.getLabel();
                if (conv.done.get(name) == null)
                    doCvt(coin,null);
                else {
	            addStringAttribute("href","#"+name);
	            emptyElement("link");
                }
            }
	    endElement("subclasses");
        }
        
    	// no attributes for text
        
        // no child elements in text
        
        doCvt(ed.validList,null);

    	doCvt(ed.remList,null);

	endElement("element");
    }
}
