/*
 * This class was automatically generated with 
 * <a href="http://www.castor.org">Castor 0.9.5.3</a>, using an XML
 * Schema.
 * $Id$
 */

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Vector;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.ContentHandler;

/**
 * Class DetectorPart.
 * 
 * @version $Revision$ $Date$
 */
public class DetectorPart implements java.io.Serializable {


      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    /**
     * Field _layerList
     */
    private java.util.Vector _layerList;


      //----------------/
     //- Constructors -/
    //----------------/

    public DetectorPart() {
        super();
        _layerList = new Vector();
    } //-- DetectorPart()


      //-----------/
     //- Methods -/
    //-----------/

    /**
     * Method addLayer
     * 
     * @param vLayer
     */
    public void addLayer(Layer vLayer)
        throws java.lang.IndexOutOfBoundsException
    {
        _layerList.addElement(vLayer);
    } //-- void addLayer(Layer) 

    /**
     * Method addLayer
     * 
     * @param index
     * @param vLayer
     */
    public void addLayer(int index, Layer vLayer)
        throws java.lang.IndexOutOfBoundsException
    {
        _layerList.insertElementAt(vLayer, index);
    } //-- void addLayer(int, Layer) 

    /**
     * Method enumerateLayer
     */
    public java.util.Enumeration enumerateLayer()
    {
        return _layerList.elements();
    } //-- java.util.Enumeration enumerateLayer() 

    /**
     * Method getLayer
     * 
     * @param index
     */
    public Layer getLayer(int index)
        throws java.lang.IndexOutOfBoundsException
    {
        //-- check bounds for index
        if ((index < 0) || (index > _layerList.size())) {
            throw new IndexOutOfBoundsException();
        }
        
        return (Layer) _layerList.elementAt(index);
    } //-- Layer getLayer(int) 

    /**
     * Method getLayer
     */
    public Layer[] getLayer()
    {
        int size = _layerList.size();
        Layer[] mArray = new Layer[size];
        for (int index = 0; index < size; index++) {
            mArray[index] = (Layer) _layerList.elementAt(index);
        }
        return mArray;
    } //-- Layer[] getLayer() 

    /**
     * Method getLayerCount
     */
    public int getLayerCount()
    {
        return _layerList.size();
    } //-- int getLayerCount() 

    /**
     * Method isValid
     */
    public boolean isValid()
    {
        try {
            validate();
        }
        catch (org.exolab.castor.xml.ValidationException vex) {
            return false;
        }
        return true;
    } //-- boolean isValid() 

    /**
     * Method marshal
     * 
     * @param out
     */
    public void marshal(java.io.Writer out)
        throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
    {
        
        Marshaller.marshal(this, out);
    } //-- void marshal(java.io.Writer) 

    /**
     * Method marshal
     * 
     * @param handler
     */
    public void marshal(org.xml.sax.ContentHandler handler)
        throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
    {
        
        Marshaller.marshal(this, handler);
    } //-- void marshal(org.xml.sax.ContentHandler) 

    /**
     * Method removeAllLayer
     */
    public void removeAllLayer()
    {
        _layerList.removeAllElements();
    } //-- void removeAllLayer() 

    /**
     * Method removeLayer
     * 
     * @param index
     */
    public Layer removeLayer(int index)
    {
        java.lang.Object obj = _layerList.elementAt(index);
        _layerList.removeElementAt(index);
        return (Layer) obj;
    } //-- Layer removeLayer(int) 

    /**
     * Method setLayer
     * 
     * @param index
     * @param vLayer
     */
    public void setLayer(int index, Layer vLayer)
        throws java.lang.IndexOutOfBoundsException
    {
        //-- check bounds for index
        if ((index < 0) || (index > _layerList.size())) {
            throw new IndexOutOfBoundsException();
        }
        _layerList.setElementAt(vLayer, index);
    } //-- void setLayer(int, Layer) 

    /**
     * Method setLayer
     * 
     * @param layerArray
     */
    public void setLayer(Layer[] layerArray)
    {
        //-- copy array
        _layerList.removeAllElements();
        for (int i = 0; i < layerArray.length; i++) {
            _layerList.addElement(layerArray[i]);
        }
    } //-- void setLayer(Layer) 

    /**
     * Method unmarshal
     * 
     * @param reader
     */
    public static java.lang.Object unmarshal(java.io.Reader reader)
        throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException
    {
        return (DetectorPart) Unmarshaller.unmarshal(DetectorPart.class, reader);
    } //-- java.lang.Object unmarshal(java.io.Reader) 

    /**
     * Method validate
     */
    public void validate()
        throws org.exolab.castor.xml.ValidationException
    {
        org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
        validator.validate(this);
    } //-- void validate() 

}
