/**********************************************************************************************
 * Copyright (c) 2001-2013 Liquid Technologies Limited. All rights reserved.
 * See www.liquid-technologies.com for product details.
 *
 * Please see products End User License Agreement for distribution permissions.
 *
 * WARNING: THIS FILE IS GENERATED
 * Changes made outside of ##HAND_CODED_BLOCK_START blocks will be overwritten
 *
 * Generation  : by Liquid XML Data Binder 11.0.7.4537
 * Using Schema: D:/Development2013/Liquid/Tools/DataBindingSamples/Samples/SimpleHierarchy/Schema/SimpleHierarchy.xsd
 **********************************************************************************************/
package SimpleHierarchyLib;

import java.util.Iterator;
import java.io.IOException;


/// <summary>
///     This class represents a collection of ComplexTypes ItemType
/// </summary>
/// <remarks>
/// </remarks>
public class ItemTypeCol extends com.liquid_technologies.ltxmllib11.XmlCollectionBase
{
    // This should not be called directly
    public ItemTypeCol(String elementName, String targetNamespace, int minOccurs, int maxOccurs)
    {
        _targetNamespace    = targetNamespace;
        setElementName(elementName);
        _minOccurs          = minOccurs;
        _maxOccurs          = maxOccurs;
// ##HAND_CODED_BLOCK_START ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS

// Add Additional initialization code here...

// ##HAND_CODED_BLOCK_END ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    }

    /// <summary>
    ///     Adds a ItemType enumeration to the collection
    /// </summary>
    /// <param name="newEnum">
    ///     The object to be copied into the collection
    /// </param>
    /// <returns>
    ///     The copied object (that was added to the collection)
    /// </returns>
    /// <remarks>
    ///     The object newProperty, is copied, and the copy is added to the
    ///     collection.
    /// </remarks>
    public SimpleHierarchyLib.ItemType  add(SimpleHierarchyLib.ItemType newCls)
      throws com.liquid_technologies.ltxmllib11.exceptions.LtException
    {
        return add(_coll.size(), newCls);
    }
    public SimpleHierarchyLib.ItemType  add(int index, SimpleHierarchyLib.ItemType newCls)
      throws com.liquid_technologies.ltxmllib11.exceptions.LtException
    {
    setElementName(newCls.getBase(), getElementName());
//      throw_IfElementNameDiffers(newCls, getElementName());
        _coll.add(index, newCls);
        fireOnCollectionChange();
        return newCls;
    }
    
    /// <summary>
    ///     Adds a ItemType object to the collection
    /// </summary>
    /// <returns>
    ///     The newly created ItemType object
    /// </returns>
    /// <remarks>
    ///     A new ItemType object is created and added to the collection
    ///     the new object is then returned.
    /// </remarks>
    public SimpleHierarchyLib.ItemType add()
      throws com.liquid_technologies.ltxmllib11.exceptions.LtException
    {
        return add(_coll.size());
    }
    public SimpleHierarchyLib.ItemType add(int index)
      throws com.liquid_technologies.ltxmllib11.exceptions.LtException
    {
        SimpleHierarchyLib.ItemType newObject = new SimpleHierarchyLib.ItemType(getElementName());
        _coll.add(index, newObject);
        fireOnCollectionChange();
        return newObject;
    }

    /// <summary>
    ///     Gets a ItemType object from the collection
    /// </summary>
    /// <param name="index">
    ///     The 0 based index of the item to retreve
    /// </param>
    /// <returns>
    ///     The object at the given location in the collection
    /// </returns>
    public SimpleHierarchyLib.ItemType getItem(int index)
    {   
        return (SimpleHierarchyLib.ItemType) _coll.get(index);
    }

    /// <summary>
    ///     Creates a copy of the collection
    /// </summary>
    /// <returns>
    ///     The copied collection object
    /// </returns>
    /// <remarks>
    ///     The function performs a 'deep copy' of the class, and all its children.
    /// </remarks>
    public Object clone() throws CloneNotSupportedException
    {
        try
        {
            ItemTypeCol newObject = (ItemTypeCol) super.clone();
            Iterator itr = _coll.iterator();
            while (itr.hasNext()) {
                newObject._coll.add(((SimpleHierarchyLib.ItemType)itr.next()).clone());
            }
// ##HAND_CODED_BLOCK_START ID="Additional clone"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS

// Add Additional clone code here...

// ##HAND_CODED_BLOCK_END ID="Additional clone"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
            return newObject;
        } catch (CloneNotSupportedException e) {
            // should never happen
            e.printStackTrace();
            throw new InternalError();
        }
    }
    
    protected void attributesToXml(
        com.liquid_technologies.ltxmllib11.XmlTextWriter xmlOut,
        com.liquid_technologies.ltxmllib11.XmlSerializationContext context)
        throws com.liquid_technologies.ltxmllib11.exceptions.LtException, IOException {
    }

    protected void toXml(
        com.liquid_technologies.ltxmllib11.XmlTextWriter xmlOut, 
        boolean bRegisterNamespaces, 
        String namespaceUri,
        com.liquid_technologies.ltxmllib11.XmlSerializationContext context,
        boolean isOptionalChoice)
    throws com.liquid_technologies.ltxmllib11.exceptions.LtException, IOException
    {
        validateCount(context);
        
        Iterator itr = _coll.iterator();
        while (itr.hasNext()) 
        {
            SimpleHierarchyLib.ItemType oObj = (SimpleHierarchyLib.ItemType)itr.next();
            toXml(oObj.getBase(), xmlOut, false, getTargetNamespace(), context, isOptionalChoice);
        }
    }


    protected com.liquid_technologies.ltxmllib11.dom.XmlElement fromXml(
        com.liquid_technologies.ltxmllib11.dom.XmlElement xmlParent,
        com.liquid_technologies.ltxmllib11.dom.XmlElement xmlChild,
        com.liquid_technologies.ltxmllib11.XmlSerializationContext context,
        boolean isOptionalChoice)
        throws com.liquid_technologies.ltxmllib11.exceptions.LtException
    {
        // go through the nodes until we run out of ones that match
        while (xmlChild != null)
        {
            // Stop reading when we hit an element we can't deal with
            if (!CompareElement(context, xmlChild, getElementName(), _targetNamespace))
                break;
            SimpleHierarchyLib.ItemType newObj = new SimpleHierarchyLib.ItemType(getElementName());
            fromXml(newObj.getBase(), xmlChild, xmlChild.getFirstChildElement(), context);

            // Add new item to the collection
            _coll.add(newObj);
            fireOnCollectionChange();

            // Move to next node
            xmlChild = xmlChild.getNextSiblingElement();
        }
        return xmlChild;
    }

    // Attribute - Namespace
    public String getTargetNamespace()
    {
        return _targetNamespace; 
    }   
    public String getNamespace()
    {
        return _targetNamespace;
    }   

// ##HAND_CODED_BLOCK_START ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS

// Add Additional Methods and members here...

// ##HAND_CODED_BLOCK_END ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS

    protected String _targetNamespace;  
}