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

package com.togethersoft.modules.xmleditor.xmltree;

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

public class ORGroupInst extends GroupInst 
{
  //--------------------------------------------------------------------
  public ORGroupInst (DTDGroupItemDef groupDef)
  {
    super (groupDef);
  }

  //--------------------------------------------------------------------
  public boolean isComplete()
  {
    boolean complete = false;

    for (int i = 0; i < m_itemInstHolders.length; i ++)
    {
      InstHolder instHolder = m_itemInstHolders[i];
      if (! instHolder.isEmpty())
      {
        complete = instHolder.isComplete();
        break;
      }

      if (instHolder.isComplete())
        complete = true;
    }

    return complete;
  }

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

    for (i = 0; i < m_itemInstHolders.length; i ++)
    {
      int allowance = m_itemInstHolders[i].checkElementInstAllowance (elementDef);
      if (allowance != ElementInst.NEA_PROHIBITED)
        return allowance;
    }

    return ElementInst.NEA_PROHIBITED;
  }

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

    for (i = 0; i < m_itemInstHolders.length; i ++)
    {
      if (m_itemInstHolders[i].putElementInst (elementInst))
        return true;
    }

    return false;
  }

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

    return new Vector();
  }

  //--------------------------------------------------------------------
}
