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

package com.queplix.core.jxb.entity;

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

import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;

import java.util.ArrayList;

/**
 * The sequence of tables
 *
 * @version $Revision$ $Date$
 */
public class DataschemaType extends com.queplix.core.utils.jxb.JXBObject
        implements java.io.Serializable {

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

    /**
     * The unique name of dataschema
     */
    private java.lang.String _name;

    /**
     * The reference type (1:1, 1:n,..)
     */
    private com.queplix.core.jxb.entity.types.RefSType _reftype = com.queplix
            .core.jxb.entity.types.RefSType.valueOf("1:1");

    /**
     * The table for linking
     */
    private java.util.ArrayList _tableList;

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

    public DataschemaType() {
        super();
        setReftype(com.queplix.core.jxb.entity.types.RefSType.valueOf("1:1"));
        _tableList = new ArrayList();
    } //-- com.queplix.core.jxb.entity.DataschemaType()

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

    /**
     * Method addTable
     *
     * @param vTable
     */
    public void addTable(com.queplix.core.jxb.entity.Table vTable)
            throws java.lang.IndexOutOfBoundsException {
        if(!(_tableList.size() < 2)) {
            throw new IndexOutOfBoundsException();
        }
        _tableList.add(vTable);
    } //-- void addTable(com.queplix.core.jxb.entity.Table) 

    /**
     * Method addTable
     *
     * @param index
     * @param vTable
     */
    public void addTable(int index, com.queplix.core.jxb.entity.Table vTable)
            throws java.lang.IndexOutOfBoundsException {
        if(!(_tableList.size() < 2)) {
            throw new IndexOutOfBoundsException();
        }
        _tableList.add(index, vTable);
    } //-- void addTable(int, com.queplix.core.jxb.entity.Table) 

    /**
     * Method clearTable
     */
    public void clearTable() {
        _tableList.clear();
    } //-- void clearTable() 

    /**
     * Method enumerateTable
     *
     * @return Enumeration
     */
    public java.util.Enumeration enumerateTable() {
        return new org.exolab.castor.util.IteratorEnumeration(
                _tableList.iterator());
    } //-- java.util.Enumeration enumerateTable() 

    /**
     * Returns the value of field 'name'. The field 'name' has the
     * following description: The unique name of dataschema
     *
     * @return the value of field 'name'.
     */
    public java.lang.String getName() {
        return this._name;
    } //-- java.lang.String getName() 

    /**
     * Returns the value of field 'reftype'. The field 'reftype'
     * has the following description: The reference type (1:1,
     * 1:n,..)
     *
     * @return the value of field 'reftype'.
     */
    public com.queplix.core.jxb.entity.types.RefSType getReftype() {
        return this._reftype;
    } //-- com.queplix.core.jxb.entity.types.RefSType getReftype() 

    /**
     * Method getTable
     *
     * @param index
     * @return Table
     */
    public com.queplix.core.jxb.entity.Table getTable(int index)
            throws java.lang.IndexOutOfBoundsException {
        //-- check bounds for index
        if((index < 0) || (index > _tableList.size())) {
            throw new IndexOutOfBoundsException();
        }

        return (com.queplix.core.jxb.entity.Table) _tableList.get(index);
    } //-- com.queplix.core.jxb.entity.Table getTable(int) 

    /**
     * Method getTable
     *
     * @return Table
     */
    public com.queplix.core.jxb.entity.Table[] getTable() {
        int size = _tableList.size();
        com.queplix.core.jxb.entity.Table[] mArray
                = new com.queplix.core.jxb.entity.Table[size];
        for(int index = 0; index < size; index++) {
            mArray[index] = (com.queplix.core.jxb.entity.Table) _tableList.get(
                    index);
        }
        return mArray;
    } //-- com.queplix.core.jxb.entity.Table[] getTable() 

    /**
     * Method getTableCount
     *
     * @return int
     */
    public int getTableCount() {
        return _tableList.size();
    } //-- int getTableCount() 

    /**
     * Method isValid
     *
     * @return boolean
     */
    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 removeTable
     *
     * @param vTable
     * @return boolean
     */
    public boolean removeTable(com.queplix.core.jxb.entity.Table vTable) {
        boolean removed = _tableList.remove(vTable);
        return removed;
    } //-- boolean removeTable(com.queplix.core.jxb.entity.Table) 

    /**
     * Sets the value of field 'name'. The field 'name' has the
     * following description: The unique name of dataschema
     *
     * @param name the value of field 'name'.
     */
    public void setName(java.lang.String name) {
        this._name = name;
    } //-- void setName(java.lang.String) 

    /**
     * Sets the value of field 'reftype'. The field 'reftype' has
     * the following description: The reference type (1:1, 1:n,..)
     *
     * @param reftype the value of field 'reftype'.
     */
    public void setReftype(com.queplix.core.jxb.entity.types.RefSType reftype) {
        this._reftype = reftype;
    } //-- void setReftype(com.queplix.core.jxb.entity.types.RefSType) 

    /**
     * Method setTable
     *
     * @param index
     * @param vTable
     */
    public void setTable(int index, com.queplix.core.jxb.entity.Table vTable)
            throws java.lang.IndexOutOfBoundsException {
        //-- check bounds for index
        if((index < 0) || (index > _tableList.size())) {
            throw new IndexOutOfBoundsException();
        }
        if(!(index < 2)) {
            throw new IndexOutOfBoundsException();
        }
        _tableList.set(index, vTable);
    } //-- void setTable(int, com.queplix.core.jxb.entity.Table) 

    /**
     * Method setTable
     *
     * @param tableArray
     */
    public void setTable(com.queplix.core.jxb.entity.Table[] tableArray) {
        //-- copy array
        _tableList.clear();
        for(int i = 0; i < tableArray.length; i++) {
            _tableList.add(tableArray[i]);
        }
    } //-- void setTable(com.queplix.core.jxb.entity.Table) 

    /**
     * Method unmarshal
     *
     * @param reader
     * @return Object
     */
    public static java.lang.Object unmarshal(java.io.Reader reader)
            throws org.exolab.castor.xml.MarshalException,
            org.exolab.castor.xml.ValidationException {
        return (com.queplix.core.jxb.entity.DataschemaType) Unmarshaller
                .unmarshal(com.queplix.core.jxb.entity.DataschemaType.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() 

}
