/*------------------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft Corporation. Patents pending. All rights reserved. 
------------------------------------------------------------------------------------*/ 

package com.togethersoft.modules.xmleditor.dtd.impl;

import java.util.*;
import com.togethersoft.modules.xmleditor.dtd.*;

public class DTDGroupItemDefImpl extends DTDItemDefImpl implements DTDGroupItemDef
{
  /**
   *@link aggregation
   *     @associates <{com.togethersoft.modules.xmleditor.dtd.impl.DTDItemDefImpl}>
   * @label group items*/
  private Vector m_itemDefs = new Vector();
  private int    m_groupType;

  //--------------------------------------------------------------------
  public DTDGroupItemDefImpl (int groupType, int cardinality)
  {
    super (cardinality);
    m_groupType = groupType;
  }

  //--------------------------------------------------------------------
  public Vector itemDefs()
  {
    return m_itemDefs;
  }

  //--------------------------------------------------------------------
  public void addItemDef (DTDItemDef itemDef)
  {                
    m_itemDefs.addElement (itemDef);
  }
  
  //--------------------------------------------------------------------
  public int getGroupType()
  {
    return m_groupType;
  }

  //--------------------------------------------------------------------
  public Vector getChildElementDefs()
  {
    Vector v = new Vector();

    Enumeration itemDefEnum = m_itemDefs.elements();
    while (itemDefEnum.hasMoreElements())
    {
      DTDItemDefImpl itemDef = (DTDItemDefImpl) itemDefEnum.nextElement();
      v.addAll (itemDef.getChildElementDefs());
    }

    return v;
  }

  //--------------------------------------------------------------------
  public boolean containsChildElement (DTDElementDef elementDef)
  {
    Enumeration itemDefEnum = m_itemDefs.elements();
    while (itemDefEnum.hasMoreElements())
    {
      DTDItemDefImpl itemDef = (DTDItemDefImpl) itemDefEnum.nextElement();
      if (itemDef.containsChildElement (elementDef))
        return true;
    }

    return false;
  }
}
