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

/**
 * Models a sequence element in QDML.
 * The contentModel elements held by a sequence element define a series of content
 * sub-models within the element content of another element.
 <pre>
DTD:

&lt;!ELEMENT sequence (<a href="QDMContentModel.html#remList">rem*</a>, <a href="#contentList">(item|selection|sequence)</a>+)>

&lt;!ATTLIST sequence
&nbsp;&nbsp;&nbsp;&nbsp;<a href="QDMContentModel.html#label">label</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="QDMContentModel.html#cref">cref</a> CDATA #IMPLIED
&nbsp;&nbsp;&nbsp;&nbsp;<a href="QDMContentModel.html#optional">optional</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;<a href="QDMContentModel.html#repeating">repeating</a> CDATA "False"
&nbsp;&nbsp;&nbsp;&nbsp;ID id #IMPLIED
>
 </pre>
 */
public class QDMSequence extends QDMContentModel 
{
	/**
	 * A container for the QDMContentModel objects (QDMItem, QDMSequence, and QDMSelection)
	 * which model the contentModel elements (item, sequence, and selection) held by
	 * this elements element.
	 */
	public ArrayList contentList=new ArrayList();

	public Object clone()
	{
		QDMSequence rv=(QDMSequence)super.clone();
		rv.contentList=clone(contentList);
		return rv;
	}

	public void buildMaps(Map coinMap, Map contentMap, QDMCoin myCoin)
		throws SAXException
	{
		super.buildMaps(coinMap,contentMap,myCoin);
		int s;
		int i;

		s=contentList.size();
		for(i=0;i<s;++i)
		{
			QDMContentModel cm=(QDMContentModel)contentList.get(i);
			cm.buildMaps(coinMap,contentMap,myCoin);
		}
	}

	protected void cminit(Map coinMap, Map contentMap)
		throws SAXException
	{
		super.init(coinMap,contentMap);
	}

	public void init(Map coinMap, Map contentMap)
		throws SAXException
	{
		if (initialized)
			return;
		cminit(coinMap,contentMap);
		int s;
		int i;

		s=contentList.size();
		for(i=0;i<s;++i)
		{
			QDMContentModel cm=(QDMContentModel)contentList.get(i);
			cm.init(coinMap,contentMap);
		}

		if (content!=null && (content instanceof QDMSequence))
		{
			QDMSequence seq=(QDMSequence)content;
			ArrayList join=new ArrayList(seq.contentList);
			join.addAll(contentList);
			contentList=join;
		}
	}

	public boolean isContainedBy(String label, TreeMap coinMap)
	{
		int i,s;
		s=contentList.size();
		for (i=0;i<s;++i)
		{
			QDMContentModel cm=(QDMContentModel)contentList.get(i);
			if (cm.isContainedBy(label,coinMap))
				return true;
		}
		return false;
	}
}
