package com.jxml.quick.util.qjml4;

import java.io.PrintWriter;
import java.util.ArrayList;
import org.xml.sax.*;

public class QMSequence extends QGBase implements QGBaseIntf {

    public QGBase access;

    public String label="";

    /** default = "False" */
    public boolean optional;

    /** default = "False" */
    public boolean repeating;

    public ArrayList items = new ArrayList();


    public QMSequence() {
    }

    public QMSequence(QGBase access, String label, boolean optional, boolean repeating, ArrayList items) {
        this.access = access;
        this.label = label;
        this.optional = optional;
        this.repeating = repeating;
        this.items = items;
    }

    public void setDestination(DocumentHandler destination)
    {
	super.setDestination(destination);
	if (access!=null)
	    access.setDestination(destination);
	int i,s;
	s=items.size();
	for (i=0;i<s;++i)
	{
	    QGBase b=(QGBase)items.get(i);
	    b.setDestination(destination);
	}
    }

    public void cvt()
	throws SAXException
    {
	if (!"".equals(label))
	    addStringAttribute("label",label);
	if (optional)
	    addBooleanAttribute("optional",true);
	if (repeating)
	    addBooleanAttribute("repeating",true);

	startElement("sequence");

	if (access!=null)
	    access.cvt();

	int i,s;
	s=items.size();
	for (i=0;i<s;++i)
	{
	    QGBase b=(QGBase)items.get(i);
	    b.cvt();
	}

	endElement("sequence");
    }

    public void print(PrintWriter pw, String indent) {
        pw.println(indent + "element sequence");
        if (access != null) {
            if (access instanceof QGBaseIntf)
                ((QGBaseIntf)access).print(pw, indent + "    ");
            else
                pw.println(indent + "access = " + access);
        } else
            pw.println(indent + "access = null");
        pw.println(indent + "label = " + label);
        pw.println(indent + "optional = " + optional);
        pw.println(indent + "repeating = " + repeating);
        for (int i=0; i<items.size(); i++) {
            if (items.get(i) instanceof QGBaseIntf)
                ((QGBaseIntf)items.get(i)).print(pw, indent + "    ");
            else
                pw.println(indent + "items["+i+"] = " + items.get(i));
        }
    }

}
