/*
 * An XML document type.
 * Localname: To
 * Namespace: http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd
 * Java type: org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument
 *
 * Automatically generated - do not modify.
 */
package org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.impl;
/**
 * A document containing one To(@http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd) element.
 *
 * This is a complex type.
 */
public class ToDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument
{
    
    public ToDocumentImpl(org.apache.xmlbeans.SchemaType sType)
    {
        super(sType);
    }
    
    private static final javax.xml.namespace.QName TO$0 = 
        new javax.xml.namespace.QName("http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd", "To");
    
    
    /**
     * Gets the "To" element
     */
    public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To getTo()
    {
        synchronized (monitor())
        {
            check_orphaned();
            org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To target = null;
            target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To)get_store().find_element_user(TO$0, 0);
            if (target == null)
            {
                return null;
            }
            return target;
        }
    }
    
    /**
     * Sets the "To" element
     */
    public void setTo(org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To to)
    {
        synchronized (monitor())
        {
            check_orphaned();
            org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To target = null;
            target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To)get_store().find_element_user(TO$0, 0);
            if (target == null)
            {
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To)get_store().add_element_user(TO$0);
            }
            target.set(to);
        }
    }
    
    /**
     * Appends and returns a new empty "To" element
     */
    public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To addNewTo()
    {
        synchronized (monitor())
        {
            check_orphaned();
            org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To target = null;
            target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To)get_store().add_element_user(TO$0);
            return target;
        }
    }
    /**
     * An XML To(@http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd).
     *
     * This is a complex type.
     */
    public static class ToImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.ToDocument.To
    {
        
        public ToImpl(org.apache.xmlbeans.SchemaType sType)
        {
            super(sType);
        }
        
        private static final javax.xml.namespace.QName PARTYID$0 = 
            new javax.xml.namespace.QName("http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd", "PartyId");
        private static final javax.xml.namespace.QName ROLE$2 = 
            new javax.xml.namespace.QName("http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd", "Role");
        
        
        /**
         * Gets a List of "PartyId" elements
         */
        public java.util.List<org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId> getPartyIdList()
        {
            final class PartyIdList extends java.util.AbstractList<org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId>
            {
                public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId get(int i)
                    { return ToImpl.this.getPartyIdArray(i); }
                
                public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId set(int i, org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId o)
                {
                    org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId old = ToImpl.this.getPartyIdArray(i);
                    ToImpl.this.setPartyIdArray(i, o);
                    return old;
                }
                
                public void add(int i, org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId o)
                    { ToImpl.this.insertNewPartyId(i).set(o); }
                
                public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId remove(int i)
                {
                    org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId old = ToImpl.this.getPartyIdArray(i);
                    ToImpl.this.removePartyId(i);
                    return old;
                }
                
                public int size()
                    { return ToImpl.this.sizeOfPartyIdArray(); }
                
            }
            
            synchronized (monitor())
            {
                check_orphaned();
                return new PartyIdList();
            }
        }
        
        /**
         * Gets array of all "PartyId" elements
         */
        public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId[] getPartyIdArray()
        {
            synchronized (monitor())
            {
                check_orphaned();
                java.util.List targetList = new java.util.ArrayList();
                get_store().find_all_element_users(PARTYID$0, targetList);
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId[] result = new org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId[targetList.size()];
                targetList.toArray(result);
                return result;
            }
        }
        
        /**
         * Gets ith "PartyId" element
         */
        public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId getPartyIdArray(int i)
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId)get_store().find_element_user(PARTYID$0, i);
                if (target == null)
                {
                    throw new IndexOutOfBoundsException();
                }
                return target;
            }
        }
        
        /**
         * Returns number of "PartyId" element
         */
        public int sizeOfPartyIdArray()
        {
            synchronized (monitor())
            {
                check_orphaned();
                return get_store().count_elements(PARTYID$0);
            }
        }
        
        /**
         * Sets array of all "PartyId" element
         */
        public void setPartyIdArray(org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId[] partyIdArray)
        {
            synchronized (monitor())
            {
                check_orphaned();
                arraySetterHelper(partyIdArray, PARTYID$0);
            }
        }
        
        /**
         * Sets ith "PartyId" element
         */
        public void setPartyIdArray(int i, org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId partyId)
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId)get_store().find_element_user(PARTYID$0, i);
                if (target == null)
                {
                    throw new IndexOutOfBoundsException();
                }
                target.set(partyId);
            }
        }
        
        /**
         * Inserts and returns a new empty value (as xml) as the ith "PartyId" element
         */
        public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId insertNewPartyId(int i)
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId)get_store().insert_element_user(PARTYID$0, i);
                return target;
            }
        }
        
        /**
         * Appends and returns a new empty value (as xml) as the last "PartyId" element
         */
        public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId addNewPartyId()
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.PartyIdDocument.PartyId)get_store().add_element_user(PARTYID$0);
                return target;
            }
        }
        
        /**
         * Removes the ith "PartyId" element
         */
        public void removePartyId(int i)
        {
            synchronized (monitor())
            {
                check_orphaned();
                get_store().remove_element(PARTYID$0, i);
            }
        }
        
        /**
         * Gets the "Role" element
         */
        public java.lang.String getRole()
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.apache.xmlbeans.SimpleValue target = null;
                target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(ROLE$2, 0);
                if (target == null)
                {
                    return null;
                }
                return target.getStringValue();
            }
        }
        
        /**
         * Gets (as xml) the "Role" element
         */
        public org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString xgetRole()
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString)get_store().find_element_user(ROLE$2, 0);
                return target;
            }
        }
        
        /**
         * True if has "Role" element
         */
        public boolean isSetRole()
        {
            synchronized (monitor())
            {
                check_orphaned();
                return get_store().count_elements(ROLE$2) != 0;
            }
        }
        
        /**
         * Sets the "Role" element
         */
        public void setRole(java.lang.String role)
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.apache.xmlbeans.SimpleValue target = null;
                target = (org.apache.xmlbeans.SimpleValue)get_store().find_element_user(ROLE$2, 0);
                if (target == null)
                {
                    target = (org.apache.xmlbeans.SimpleValue)get_store().add_element_user(ROLE$2);
                }
                target.setStringValue(role);
            }
        }
        
        /**
         * Sets (as xml) the "Role" element
         */
        public void xsetRole(org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString role)
        {
            synchronized (monitor())
            {
                check_orphaned();
                org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString target = null;
                target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString)get_store().find_element_user(ROLE$2, 0);
                if (target == null)
                {
                    target = (org.oasisOpen.committees.ebxmlMsg.schema.msgHeader20.NonEmptyString)get_store().add_element_user(ROLE$2);
                }
                target.set(role);
            }
        }
        
        /**
         * Unsets the "Role" element
         */
        public void unsetRole()
        {
            synchronized (monitor())
            {
                check_orphaned();
                get_store().remove_element(ROLE$2, 0);
            }
        }
    }
}
