001package com.hfg.xml.xsd;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.hfg.util.StringUtil;
007import com.hfg.xml.XMLNamespace;
008import com.hfg.xml.XMLNode;
009
010//------------------------------------------------------------------------------
011/**
012 Representation of a group 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 XsdGroup extends XsdContent
039{
040   private String  mName;
041   private List<XsdContent> mContent;
042
043   //---------------------------------------------------------------------------
044   public XsdGroup()
045   {
046   }
047
048   //---------------------------------------------------------------------------
049   public XsdGroup(XMLNode inTag, XMLNamespace inNamespace)
050   {
051      super(inTag);
052
053      inTag.verifyTagName(XsdXML.GROUP.getLocalName());
054
055      String name = inTag.getAttributeValue(XsdXML.NAME_ATT.getLocalName());
056      if (StringUtil.isSet(name))
057      {
058         mName = name;
059      }
060
061      String ref = inTag.getAttributeValue(XsdXML.REF_ATT.getLocalName());
062      if (StringUtil.isSet(ref))
063      {
064         mName = ref;
065      }
066
067      for (XMLNode subtag : inTag.getXMLNodeSubtags())
068      {
069         if (subtag.getTagName().equals(XsdXML.ELEMENT.getLocalName()))
070         {
071            addContent(new XsdElement(subtag).setNamespace(inNamespace));
072         }
073         else if (subtag.getTagName().equals(XsdXML.GROUP.getLocalName()))
074         {
075            addContent(new XsdGroup(subtag, inNamespace));
076         }
077         else if (subtag.getTagName().equals(XsdXML.CHOICE.getLocalName()))
078         {
079            addContent(new XsdChoice(subtag, inNamespace));
080         }
081         else if (subtag.getTagName().equals(XsdXML.SEQUENCE.getLocalName()))
082         {
083            addContent(new XsdSequence(subtag, inNamespace));
084         }
085      }
086   }
087
088
089   //---------------------------------------------------------------------------
090   @Override
091   public XsdGroup setMaxOccurs(int inValue)
092   {
093      super.setMaxOccurs(inValue);
094      return this;
095   }
096
097   //---------------------------------------------------------------------------
098   @Override
099   public XsdGroup setMinOccurs(int inValue)
100   {
101      super.setMinOccurs(inValue);
102      return this;
103   }
104
105   //---------------------------------------------------------------------------
106   public String getName()
107   {
108      return mName;
109   }
110
111   //---------------------------------------------------------------------------
112   public List<XsdContent> getContent()
113   {
114      return mContent;
115   }
116
117   //---------------------------------------------------------------------------
118   public XsdGroup addContent(XsdContent inValue)
119   {
120      if (null == mContent)
121      {
122         mContent = new ArrayList<>(20);
123      }
124
125      mContent.add(inValue);
126      return this;
127   }
128}