001package com.hfg.xml.xsd;
002
003
004import java.util.HashSet;
005import java.util.Set;
006
007import com.hfg.xml.XMLNamespace;
008import com.hfg.xml.XMLNode;
009
010//------------------------------------------------------------------------------
011/**
012 Representation of a choice element in an XML Schema Definition (XSD) specification.
013 <div>
014  @author J. Alex Taylor, hairyfatguy.com
015 </div>
016 */
017//------------------------------------------------------------------------------
018// com.hfg XML/HTML Coding Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class XsdChoice extends XsdContent
039{
040   private Set<XsdContent>  mOptions;
041
042   //---------------------------------------------------------------------------
043   public XsdChoice()
044   {
045   }
046
047   //---------------------------------------------------------------------------
048   public XsdChoice(XMLNode inTag, XMLNamespace inNamespace)
049   {
050      super(inTag);
051
052      inTag.verifyTagName(XsdXML.CHOICE.getLocalName());
053
054      for (XMLNode subtag : inTag.getXMLNodeSubtags())
055      {
056         if (subtag.getTagName().equals(XsdXML.ELEMENT.getLocalName()))
057         {
058            addOption(new XsdElement(subtag).setNamespace(inNamespace));
059         }
060         else if (subtag.getTagName().equals(XsdXML.GROUP.getLocalName()))
061         {
062            addOption(new XsdGroup(subtag, inNamespace));
063         }
064      }
065   }
066
067   //---------------------------------------------------------------------------
068   @Override
069   public XsdChoice setMaxOccurs(int inValue)
070   {
071      super.setMaxOccurs(inValue);
072      return this;
073   }
074
075   //---------------------------------------------------------------------------
076   @Override
077   public XsdChoice setMinOccurs(int inValue)
078   {
079      super.setMinOccurs(inValue);
080      return this;
081   }
082
083   //---------------------------------------------------------------------------
084   public Set<XsdContent> getOptions()
085   {
086      return mOptions;
087   }
088
089   //---------------------------------------------------------------------------
090   public XsdChoice addOption(XsdContent inValue)
091   {
092      if (null == mOptions)
093      {
094         mOptions = new HashSet<>(20);
095      }
096
097      mOptions.add(inValue);
098      return this;
099   }
100}