SourceSectionsType.java

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-2 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2015.05.31 at 05:43:54 PM CEST 
//


package org.jomc.tools.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Generated;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * List of source sections.
 * 
 * <p>Java class for SourceSectionsType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="SourceSectionsType">
 *   &lt;complexContent>
 *     &lt;extension base="{http://jomc.org/tools/model}ToolsType">
 *       &lt;sequence>
 *         &lt;element ref="{http://jomc.org/tools/model}source-section" maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/extension>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SourceSectionsType", namespace = "http://jomc.org/tools/model", propOrder = {
    "sourceSection"
})
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
public class SourceSectionsType
    extends ToolsType
    implements Cloneable
{

    @XmlElement(name = "source-section", namespace = "http://jomc.org/tools/model")
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
    protected List<SourceSectionType> sourceSection;

    /**
     * Creates a new {@code SourceSectionsType} instance.
     * 
     */
    public SourceSectionsType() {
        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
        super();
    }

    /**
     * Creates a new {@code SourceSectionsType} instance by deeply copying a given {@code SourceSectionsType} instance.
     * 
     * 
     * @param o
     *     The instance to copy.
     * @throws NullPointerException
     *     if {@code o} is {@code null}.
     */
    public SourceSectionsType(final SourceSectionsType o) {
        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
        super(o);
        if (o == null) {
            throw new NullPointerException("Cannot create a copy of 'SourceSectionsType' from 'null'.");
        }
        // 'SourceSection' collection.
        if (o.sourceSection!= null) {
            copySourceSection(o.getSourceSection(), this.getSourceSection());
        }
    }

    /**
     * Gets the value of the sourceSection property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the sourceSection property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getSourceSection().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link SourceSectionType }
     * 
     * 
     */
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
    public List<SourceSectionType> getSourceSection() {
        if (sourceSection == null) {
            sourceSection = new ArrayList<SourceSectionType>();
        }
        return this.sourceSection;
    }

    /**
     * Copies all values of property {@code SourceSection} deeply.
     * 
     * @param source
     *     The source to copy from.
     * @param target
     *     The target to copy {@code source} to.
     * @throws NullPointerException
     *     if {@code target} is {@code null}.
     */
    @SuppressWarnings("unchecked")
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
    private static void copySourceSection(final List<SourceSectionType> source, final List<SourceSectionType> target) {
        // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
        if ((source!= null)&&(!source.isEmpty())) {
            for (final Iterator<?> it = source.iterator(); it.hasNext(); ) {
                final Object next = it.next();
                if (next instanceof SourceSectionType) {
                    // CClassInfo: org.jomc.tools.model.SourceSectionType
                    target.add(((SourceSectionType) next).clone());
                    continue;
                }
                // Please report this at https://apps.sourceforge.net/mantisbt/ccxjc/
                throw new AssertionError((("Unexpected instance '"+ next)+"' for property 'SourceSection' of class 'org.jomc.tools.model.SourceSectionsType'."));
            }
        }
    }

    /**
     * Creates and returns a deep copy of this object.
     * 
     * 
     * @return
     *     A deep copy of this object.
     */
    @Override
    @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-05-31T05:43:54+02:00", comments = "JAXB RI vhudson-jaxb-ri-2.1-2")
    public SourceSectionsType clone() {
        {
            // CC-XJC Version 2.0.1 Build 2012-03-02T12:09:12+0000
            final SourceSectionsType clone = ((SourceSectionsType) super.clone());
            // 'SourceSection' collection.
            if (this.sourceSection!= null) {
                clone.sourceSection = null;
                copySourceSection(this.getSourceSection(), clone.getSourceSection());
            }
            return clone;
        }
    }
    
    /**
     * Gets a section for a given name recursively from the list of sections.
     *
     * @param name The name of the section to return.
     *
     * @return The first matching section or {@code null}, if no such section is found.
     *
     * @throws NullPointerException if {@code name} is {@code null}.
     *
     * @see #getSourceSection()
     * @see SourceSectionType#getName()
     * @see SourceSectionType#getSourceSections()
     */
    public SourceSectionType getSourceSection( final String name )
    {
        if ( name == null )
        {
            throw new NullPointerException( "name" );
        }

        return this.getSourceSection( this, name );
    }

    private SourceSectionType getSourceSection( final SourceSectionsType sourceSectionsType, final String name )
    {
        if ( sourceSectionsType != null )
        {
            for ( int i = 0, s0 = sourceSectionsType.getSourceSection().size(); i < s0; i++ )
            {
                final SourceSectionType s = sourceSectionsType.getSourceSection().get( i );

                if ( name.equals( s.getName() ) )
                {
                    return s;
                }

                final SourceSectionType sourceSectionType = this.getSourceSection( s.getSourceSections(), name );
                if ( sourceSectionType != null )
                {
                    return sourceSectionType;
                }
            }
        }

        return null;
    }
      
}