/* Generated by Together */

package com.togethersoft.modules.xmleditor.xmltree;

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

abstract public class GroupInst implements Inst
{
  protected InstHolder[] m_itemInstHolders;

  //--------------------------------------------------------------------
  public GroupInst (DTDGroupItemDef groupDef)
  {
    m_itemInstHolders = new InstHolder [groupDef.itemDefs().size()];

    int i = 0;
    Enumeration itemDefEnum = groupDef.itemDefs().elements();
    while (itemDefEnum.hasMoreElements())
    {
      DTDItemDef itemDef = (DTDItemDef) itemDefEnum.nextElement();
      m_itemInstHolders [i ++] = InstHolder.newInstHolder (itemDef);
    }
  }

  //--------------------------------------------------------------------
  public abstract boolean isComplete();
  public abstract int     checkElementInstAllowance (DTDElementDef elementDef);
  public abstract boolean putElementInst (ElementInst elementInst);
  public abstract Vector  getContainedElements();

  //--------------------------------------------------------------------
  public static GroupInst newGroupInst (DTDGroupItemDef groupDef)
  {
    return (groupDef.getGroupType() == DTDGroupItemDef.AND_GROUP)
      ? (GroupInst) new ANDGroupInst (groupDef)
      : (GroupInst) new ORGroupInst (groupDef);
  }

  //--------------------------------------------------------------------
  public boolean deleteElementInst (ElementInst elementInst)
  {
    for (int i = 0; i < m_itemInstHolders.length; i ++)
    {
      InstHolder instHolder = m_itemInstHolders[i];
      if (instHolder.deleteElementInst (elementInst))
        return true;
    }

    return false;
  }

  //--------------------------------------------------------------------
  public boolean isEmpty()
  {
    for (int i = 0; i < m_itemInstHolders.length; i ++)
    {
      InstHolder instHolder = m_itemInstHolders[i];
      if (! instHolder.isEmpty())
        return false;
    }

    return true;
  }

}
