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 QCInterface extends OCMpeerSupport {
    /**
     * User-provided code to perform the conversion.
     */
    public void cvt(Object param) throws SAXException, IOException {
	QMInterface ed=(QMInterface)dataModel;
	Conv.SubConv conv=(Conv.SubConv)context;
        conv.done.put(ed.getLabel(), ed);
        //String targetClass = Element.getTargetText(ed.targetClass);
        String targetClass = ed.getClassName();
	addStringAttribute("ID",ed.getLabel());
	addStringAttribute("targetClass",targetClass);
	addStringAttribute("tagName",ed.label);
        // textConstructor is false (default value)
        addBooleanAttribute("newClass",ed.generate);
	addBooleanAttribute("hasAClass",!Element.isJavaType(targetClass));
        addBooleanAttribute("clonable",false);
        // wild is false (default value)
        // bimodal is false (default value);
        // abst is false (default value)
	addBooleanAttribute("intf",true);
	addBooleanAttribute("generate",ed.generate);

	startElement("element");
        
        // no parentElement

        // imp
        if (ed.extendsList.size() > 0) {
	    startElement("imp");
            for (int i=0; i<ed.extendsList.size(); i++) {
                String name = ((QMExtends)ed.extendsList.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.implementations != null && ed.implementations.size() > 0) {
	    startElement("subclasses");
            for (int i=0; i<ed.implementations.size(); i++) {
                QMCoin coin = (QMCoin)ed.implementations.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 interface
        
        // no child elements in interface
        
        // no list of values for an interface

    	doCvt(ed.remList,null);

        // properties
        if (ed.propertyList != null && ed.propertyList.size() > 0) {
	    startElement("fields");
            for (int i=0; i<ed.propertyList.size(); i++) {
                QMProperty prop = (QMProperty)ed.propertyList.get(i);
                QCAbstract.addOtherProperty(this, prop);
            }
	    endElement("fields");
        }

        endElement("element");
    }
}
