/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure9.0 [oneit.objstore.BusinessObjectTemplate.xsl]
 *   Vendor: Apache Software Foundation (Xalan XSLTC) (Version: 1.0)
 */

    
package performa.orm;

import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.assocs.*;
import oneit.objstore.attributes.*;
import oneit.objstore.rdbms.filters.*;
import oneit.objstore.parser.*;
import oneit.objstore.validator.*;
import oneit.objstore.utils.*;
import oneit.utils.*;
import oneit.utils.filter.Filter;
import oneit.utils.transform.*;
import oneit.utils.parsers.FieldException;

import performa.orm.types.*;


public abstract class BaseSection extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Section REFERENCE_Section = new Section ();

    // Reference instance for the object
    public static final Section DUMMY_Section = new DummySection ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Description = "Description";
    public static final String FIELD_QuestionType = "QuestionType";
    public static final String MULTIPLEREFERENCE_Questions = "Questions";
    public static final String BACKREF_Questions = "";

    // Static constants corresponding to searches
    public static final String SEARCH_All = "All";
    

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Section> HELPER_Description = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<Section, QuestionType> HELPER_QuestionType =  new EnumeratedAttributeHelper<Section, QuestionType> (QuestionType.FACTORY_QuestionType);
    

    // Private attributes corresponding to business object data
    private String _Description;
    private QuestionType _QuestionType;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<Section, Question> _Questions;
    

    // Map of maps of metadata
    private static final Map ATTRIBUTES_METADATA_Section = new LinkedHashMap ();

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Description_Validators;
    private static final AttributeValidator[] FIELD_QuestionType_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<Section, String>[] FIELD_Description_Decorators;
    private static final AttributeDecorator<Section, QuestionType>[] FIELD_QuestionType_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    
    
    // Arrays of MultiAssocDecorators for each attribute
    private static final MultiAssocDecorator<Section, Question>[] MULTIPLEREFERENCE_Questions_Decorators;
    

    // Arrays of behaviour decorators
    private static final SectionBehaviourDecorator[] Section_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Questions = Question.BACKREF_Section;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Questions();
            FIELD_Description_Validators = (AttributeValidator[])setupAttribMetaData_Description(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_QuestionType_Validators = (AttributeValidator[])setupAttribMetaData_QuestionType(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Description_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_Section, FIELD_Description).toArray (new AttributeDecorator[0]);
            FIELD_QuestionType_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_Section, FIELD_QuestionType).toArray (new AttributeDecorator[0]);
            MULTIPLEREFERENCE_Questions_Decorators = (MultiAssocDecorator[])AttributeDecoratorUtils.getMultiAssocDecorators(REFERENCE_Section, MULTIPLEREFERENCE_Questions).toArray (new MultiAssocDecorator[0]);
            

            REFERENCE_Section.initialiseReference ();
            DUMMY_Section.initialiseReference ();
            Section_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Section.class).toArray(new SectionBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

    
    private static void setupAssocMetaData_Questions()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Section");
        metaInfo.put ("name", "Questions");
        metaInfo.put ("type", "Question");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Section.Questions:", metaInfo);
        ATTRIBUTES_METADATA_Section.put (MULTIPLEREFERENCE_Questions, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Description(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "quest_hdr_desc");
        metaInfo.put ("length", "30");
        metaInfo.put ("name", "Description");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_quest_hdr");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Section.Description:", metaInfo);
        ATTRIBUTES_METADATA_Section.put (FIELD_Description, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(Section.class, "Description", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for Section.Description:", validators);        

        return validators;
    }
    
    private static List setupAttribMetaData_QuestionType(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "quest_type_flag");
        metaInfo.put ("name", "QuestionType");
        metaInfo.put ("type", "QuestionType");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_quest_hdr");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Section.QuestionType:", metaInfo);
        ATTRIBUTES_METADATA_Section.put (FIELD_QuestionType, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(Section.class, "QuestionType", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for Section.QuestionType:", validators);        

        return validators;
    }
    
    // END OF STATIC METADATA DEFINITION    
    
    
    
    // This constructor should not be called
    protected BaseSection ()
    {
    }


    protected BBCBehaviourDecorator[] getBehaviours()
    {
        return Section_BehaviourDecorators;
    }

    


    protected void _initialiseNewObjAttributes (ObjectTransaction transaction) throws StorageException
    {
        super._initialiseNewObjAttributes (transaction);

        
        _Description = (String)(HELPER_Description.initialise (_Description));
        _QuestionType = (QuestionType)(HELPER_QuestionType.initialise (_QuestionType));
    }


    protected void _initialiseAssociations ()
    {
        super._initialiseAssociations ();

        _Questions = new MultipleAssociation<Section, Question> (this, MULTIPLEREFERENCE_Questions, Question.SINGLEREFERENCE_Section, Question.REFERENCE_Question);
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Questions = new MultipleAssociation<Section, Question> (this, MULTIPLEREFERENCE_Questions, Question.SINGLEREFERENCE_Section, Question.REFERENCE_Question);
        
        return this;
    }


    /**
     * Attribute Description
     */
    public String getDescription ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Description_Decorators, (Section)this, FIELD_Description, _Description);

        
        for (SectionBehaviourDecorator bhd : Section_BehaviourDecorators)
        {
            valToReturn = bhd.getDescription ((Section)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preDescriptionChange (String newDescription) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postDescriptionChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_Description ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute Description.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setDescription (String newDescription) throws FieldException
    {
        newDescription = AttributeDecoratorUtils.setValue (FIELD_Description_Decorators, (Section)this, FIELD_Description, newDescription);

        boolean oldAndNewIdentical = HELPER_Description.compare (_Description, newDescription);
        
        try
        {
            for (SectionBehaviourDecorator bhd : Section_BehaviourDecorators)
            {
                newDescription = bhd.setDescription ((Section)this, newDescription);
                oldAndNewIdentical = HELPER_Description.compare (_Description, newDescription);
            }

            

            if (FIELD_Description_Validators.length > 0)
            {
                Object newDescriptionObj = HELPER_Description.toObject (newDescription);

                if (newDescriptionObj != null)
                {
                    int     loopMax = FIELD_Description_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Section.get (FIELD_Description);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_Description_Validators[v].checkAttribute (this, FIELD_Description, metadata, newDescriptionObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Description_Decorators, (Section)this, FIELD_Description ,getWriteability_Description ()) != FieldWriteability.FALSE, "Field  Description is not writeable");
            preDescriptionChange (newDescription);
            markFieldChange (FIELD_Description);
            _Description = newDescription;            
            postFieldChange (FIELD_Description);
            postDescriptionChange ();
        }
    }

    /**
     * Attribute QuestionType
     */
    public QuestionType getQuestionType ()
    {
        assertValid();
        QuestionType valToReturn = AttributeDecoratorUtils.getValue (FIELD_QuestionType_Decorators, (Section)this, FIELD_QuestionType, _QuestionType);

        
        for (SectionBehaviourDecorator bhd : Section_BehaviourDecorators)
        {
            valToReturn = bhd.getQuestionType ((Section)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preQuestionTypeChange (QuestionType newQuestionType) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postQuestionTypeChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_QuestionType ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute QuestionType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setQuestionType (QuestionType newQuestionType) throws FieldException
    {
        newQuestionType = AttributeDecoratorUtils.setValue (FIELD_QuestionType_Decorators, (Section)this, FIELD_QuestionType, newQuestionType);

        boolean oldAndNewIdentical = HELPER_QuestionType.compare (_QuestionType, newQuestionType);
        
        try
        {
            for (SectionBehaviourDecorator bhd : Section_BehaviourDecorators)
            {
                newQuestionType = bhd.setQuestionType ((Section)this, newQuestionType);
                oldAndNewIdentical = HELPER_QuestionType.compare (_QuestionType, newQuestionType);
            }

            

            if (FIELD_QuestionType_Validators.length > 0)
            {
                Object newQuestionTypeObj = HELPER_QuestionType.toObject (newQuestionType);

                if (newQuestionTypeObj != null)
                {
                    int     loopMax = FIELD_QuestionType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Section.get (FIELD_QuestionType);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_QuestionType_Validators[v].checkAttribute (this, FIELD_QuestionType, metadata, newQuestionTypeObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_QuestionType_Decorators, (Section)this, FIELD_QuestionType ,getWriteability_QuestionType ()) != FieldWriteability.FALSE, "Field  QuestionType is not writeable");
            preQuestionTypeChange (newQuestionType);
            markFieldChange (FIELD_QuestionType);
            _QuestionType = newQuestionType;            
            postFieldChange (FIELD_QuestionType);
            postQuestionTypeChange ();
        }
    }



    /**
     * A list of multi assoc names e.g. list of strings.
     */
    public List<String> getSingleAssocs()
    {
        List result = super.getSingleAssocs ();
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            return super.getSingleAssocReferenceInstance (assocName);
        }
    }


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


    public BaseBusinessClass getSingleAssoc (String assocName, Get getType) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            return super.getSingleAssoc (assocName, getType);
        }
    }


    public Long getSingleAssocID (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            return super.getSingleAssocID (assocName);
        }
    }


    public void setSingleAssoc (String assocName, BaseBusinessClass newValue) throws StorageException, FieldException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * A list of multi assoc names e.g. list of strings.
     */
    public List<String> getMultiAssocs()
    {
        List result = super.getMultiAssocs ();
        
        result.add("Questions");

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            return Question.REFERENCE_Question ;
        }

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            return Question.SINGLEREFERENCE_Section ;
        }

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            return this.getQuestionsCount();
        }

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            return this.getQuestionsAt(index);
        }

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            addToQuestions((Question)newElement);
            return;
        }

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            removeFromQuestions((Question)oldElement);
            return;
        }

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            _Questions.__loadAssociation (elements);
            return;
        }

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        if (MULTIPLEREFERENCE_Questions.equals(attribName))
        {
            return _Questions.isLoaded ();
        }

        return super.__isMultiAssocLoaded(attribName);
    }


    public FieldWriteability getWriteability_Questions ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getQuestionsCount () throws StorageException
    {
        assertValid();
        return _Questions.getReferencedObjectsCount ();
    }


    public void addToQuestions (Question newElement) throws StorageException
    {
        if (_Questions.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (MULTIPLEREFERENCE_Questions_Decorators, (Section)this, MULTIPLEREFERENCE_Questions ,getWriteability_Questions ()) != FieldWriteability.FALSE, "MultiAssoc Questions is not writeable (add)");
            _Questions.appendElement (newElement);

            try
            {
                if (newElement.getSection () != this)
                {
                    newElement.setSection ((Section)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromQuestions (Question elementToRemove) throws StorageException
    {
        if (_Questions.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (MULTIPLEREFERENCE_Questions_Decorators, (Section)this, MULTIPLEREFERENCE_Questions ,getWriteability_Questions ()) != FieldWriteability.FALSE, "MultiAssoc Questions is not writeable (remove)");
            _Questions.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getSection () != null)
                {
                    elementToRemove.setSection (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public Question getQuestionsAt (int index) throws StorageException
    {
        return (Question)(_Questions.getElementAt (index));
    }


    public SortedSet<Question> getQuestionsSet () throws StorageException
    {
        return _Questions.getSet ();
    }



    public void onDelete ()
    {
        try 
        {
            for(Question referenced : CollectionUtils.reverse(getQuestionsSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Section from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setSection(null);
            }

        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


    public Section newInstance ()
    {
        return new Section ();
    }


    public Section referenceInstance ()
    {
        return REFERENCE_Section;
    }


    public Section getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getSectionByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Section;
    }


    public String getBaseSetName ()
    {
        return "tl_quest_hdr";
    }



    /**
     * This is where an object returns the Persistent sets that will
     * store it into the database.
     * The should be entered into allSets
     */
    public void getPersistentSets (PersistentSetCollection allSets)
    {
        ObjectStatus        myStatus = getStatus ();
        PersistentSetStatus myPSetStatus = myStatus.getPSetStatus();
        ObjectID            myID = getID();

        super.getPersistentSets (allSets);
        
        PersistentSet   tl_quest_hdrPSet = allSets.getPersistentSet (myID, "tl_quest_hdr", myPSetStatus);

        tl_quest_hdrPSet.setAttrib (FIELD_ObjectID, myID);
        tl_quest_hdrPSet.setAttrib (FIELD_Description, HELPER_Description.toObject (_Description)); //
        tl_quest_hdrPSet.setAttrib (FIELD_QuestionType, HELPER_QuestionType.toObject (_QuestionType)); //
        
    }


    /**
     * Sets the objects state based on Persistent sets.
     */
    public void setFromPersistentSets (ObjectID objectID, PersistentSetCollection allSets)
    {
        super.setFromPersistentSets (objectID, allSets);
        
        PersistentSet   tl_quest_hdrPSet = allSets.getPersistentSet (objectID, "tl_quest_hdr");

        _Description = (String)(HELPER_Description.fromObject (_Description, tl_quest_hdrPSet.getAttrib (FIELD_Description))); //
        _QuestionType = (QuestionType)(HELPER_QuestionType.fromObject (_QuestionType, tl_quest_hdrPSet.getAttrib (FIELD_QuestionType))); //
        
    }


    public void setAttributesFrom (BaseBusinessClass other, MultiException e)
    {
        super.setAttributesFrom (other, e);

        if (other instanceof Section)
        {
            Section otherSection = (Section)other;
            

            try
            {
                setDescription (otherSection.getDescription ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setQuestionType (otherSection.getQuestionType ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
        }
    }


    /**
     * Set the attributes in this to copies of the attributes in source.
     */
    public void copyAttributesFrom (BaseBusinessClass source)
    {
        super.copyAttributesFrom (source);

        if (source instanceof BaseSection)
        {
            BaseSection sourceSection = (BaseSection)(source);

            _Description = sourceSection._Description;
            _QuestionType = sourceSection._QuestionType;
            
        }
    }


    /**
     * Set the associations in this to copies of the attributes in source.
     */
    public void copySingleAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
    {
        super.copySingleAssociationsFrom (source, linkToGhosts);

        if (source instanceof BaseSection)
        {
            BaseSection sourceSection = (BaseSection)(source);

            
        }
    }


    /**
     * Set the associations in this to copies of the attributes in source.
     */
    public void copyAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
    {
        super.copyAssociationsFrom (source, linkToGhosts);

        if (source instanceof BaseSection)
        {
            BaseSection sourceSection = (BaseSection)(source);

            _Questions.copyFrom (sourceSection._Questions, linkToGhosts);
            
        }
    }


    public void validate (ValidationContext context)
    {
        super.validate (context);

        
    }


    /**
     * Subclasses must override this to read in their attributes
     */
    protected void readExternalData(Map<String, Object> vals) throws IOException, ClassNotFoundException
    {
        super.readExternalData(vals);

        _Description = (String)(HELPER_Description.readExternal (_Description, vals.get(FIELD_Description))); //
        _QuestionType = (QuestionType)(HELPER_QuestionType.readExternal (_QuestionType, vals.get(FIELD_QuestionType))); //
        _Questions.readExternalData(vals.get(MULTIPLEREFERENCE_Questions));
        
    }


    /**
     * Subclasses must override this to write out their attributes
     */
    protected void writeExternalData(Map<String, Object> vals) throws IOException
    {
        super.writeExternalData(vals);

        vals.put (FIELD_Description, HELPER_Description.writeExternal (_Description));
        vals.put (FIELD_QuestionType, HELPER_QuestionType.writeExternal (_QuestionType));
        vals.put (MULTIPLEREFERENCE_Questions, _Questions.writeExternalData());
        
    }


    public void compare (BaseBusinessClass other, AttributeChangeListener listener) throws StorageException
    {
        super.compare (other, listener);

        if (other instanceof BaseSection)
        {
            BaseSection otherSection = (BaseSection)(other);

            
            if (!HELPER_Description.compare(this._Description, otherSection._Description))
            {
                listener.notifyFieldChange(this, other, FIELD_Description, HELPER_Description.toObject(this._Description), HELPER_Description.toObject(otherSection._Description));
            }
            if (!HELPER_QuestionType.compare(this._QuestionType, otherSection._QuestionType))
            {
                listener.notifyFieldChange(this, other, FIELD_QuestionType, HELPER_QuestionType.toObject(this._QuestionType), HELPER_QuestionType.toObject(otherSection._QuestionType));
            }

            // Compare single assocs
            

            // Compare multiple assocs
            _Questions.compare (otherSection._Questions, listener);
            
        }
    }


    public void visitTransients (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        
    }


    public void visitAttributes (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        visitor.visitField(this, FIELD_Description, HELPER_Description.toObject(getDescription()));
        visitor.visitField(this, FIELD_QuestionType, HELPER_QuestionType.toObject(getQuestionType()));
        visitor.visitAssociation (_Questions);
        
    }


    public void visitAssociations (AssociationVisitor visitor, AssociatedScope scope) throws StorageException
    {
        super.visitAssociations (visitor, scope);

        if (scope.includes (_Questions))
        {
            visitor.visit (_Questions);
        }
        
    }


    public static Section createSection (ObjectTransaction transaction) throws StorageException
    {
        Section     result = new Section ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Section getSectionByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Section)(transaction.getObjectByID (REFERENCE_Section, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Description))
        {
            return filter.matches (getDescription ());
        }
        else if (attribName.equals (FIELD_QuestionType))
        {
            return filter.matches (getQuestionType ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


    public static SearchAll SearchByAll () { return new SearchAll (); }

    public static class SearchAll extends SearchObject<Section>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_quest_hdr.object_id", FIELD_ObjectID);
            return this;
        }

        public SearchAll andObjectCreated (QueryFilter<Date> filter)
        {
            filter.addFilter (context, "tl_quest_hdr.object_created_date", FIELD_ObjectCreated);
            return this;
        }

        public SearchAll andObjectLastModified (QueryFilter<Date> filter)
        {
            filter.addFilter (context, "tl_quest_hdr.object_last_updated_date", FIELD_ObjectLastModified);
            return this;
        }

            
        public SearchAll andDescription (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_quest_hdr.quest_hdr_desc", "Description");
            return this;
        }
            
        public SearchAll andQuestionType (QueryFilter<QuestionType> filter)
        {
            filter.addFilter (context, "tl_quest_hdr.quest_type_flag", "QuestionType");
            return this;
        }
            
        public Section[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Section, SEARCH_All, criteria);
            Set<Section>   typedResults = new LinkedHashSet <Section> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Section aResult = (Section)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Section[0]);
                            
        }
    }

        
    public static Section[] searchAll (ObjectTransaction transaction) throws StorageException
    {
        return SearchByAll ()
               .search (transaction);
    }



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Description))
        {
            return HELPER_Description.toObject (getDescription ());
        }
        else if (attribName.equals (FIELD_QuestionType))
        {
            return HELPER_QuestionType.toObject (getQuestionType ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Description))
        {
            return HELPER_Description;
        }
        else if (attribName.equals (FIELD_QuestionType))
        {
            return HELPER_QuestionType;
        }
        else
        {
            return super.getAttributeHelper (attribName);
        }
    }


    public void setAttribute (String attribName, Object attribValue) throws FieldException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Description))
        {
            setDescription ((String)(HELPER_Description.fromObject (_Description, attribValue)));            
        }
        else if (attribName.equals (FIELD_QuestionType))
        {
            setQuestionType ((QuestionType)(HELPER_QuestionType.fromObject (_QuestionType, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }

    

    public boolean isWriteable (String fieldName)
    {        
        return getWriteable (fieldName) == FieldWriteability.TRUE;
    }

    public boolean isReadable ()
    {
        return super.isReadable();
    }

    public boolean isReadable (String fieldName)
    {
        return super.isReadable(fieldName);
    }


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_Description))
        {
            return getWriteability_Description ();
        }
        else if (fieldName.equals (FIELD_QuestionType))
        {
            return getWriteability_QuestionType ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Questions))
        {
            return getWriteability_Questions ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Description () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Description);
        }
        
        if (getWriteability_QuestionType () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_QuestionType);
        }
        

        super.putUnwriteable (fields);
    }

    public String[] getAllTableNames()
    {
        return new String[] {"tl_quest_hdr"};
    }
    
    public boolean isPolymorphic(String tableName)
    {
        return super.isPolymorphic(tableName);
    }


    public List<AbstractAttribute> getAttributes ()
    {
        List result = super.getAttributes ();

        
        result.add(HELPER_Description.getAttribObject (getClass (), _Description, false, FIELD_Description));
        result.add(HELPER_QuestionType.getAttribObject (getClass (), _QuestionType, false, FIELD_QuestionType));

        return result;
    }


    public Map getAttributeMetadata (String attribute)
    {
        if (ATTRIBUTES_METADATA_Section.containsKey (attribute))
        {
            return (Map)ATTRIBUTES_METADATA_Section.get (attribute);
        }
        else
        {
            return super.getAttributeMetadata (attribute);
        }
    }


    public Object getAttributeMetadata (String attribute, String metadata)
    {
        if (ATTRIBUTES_METADATA_Section.containsKey (attribute))
        {
            return ((Map)ATTRIBUTES_METADATA_Section.get (attribute)).get(metadata);
        }
        else
        {
            return super.getAttributeMetadata (attribute, metadata);
        }
    }

    public void copyAllAttributeMetadata (Map copyInto)
    {
        super.copyAllAttributeMetadata(copyInto);

        copyInto.putAll(ATTRIBUTES_METADATA_Section);
    }
            

    public void preCommit (boolean willBeStored) throws Exception
    {
        super.preCommit(willBeStored);
        
        if(willBeStored)
        {
        
        }
    }

    public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
    {
        
        return super.getBinaryContentHandler(attribName);
    }

    public static class SectionBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<Section>
    {

    /**
     * Get the attribute Description
     */
    public String getDescription (Section obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Description.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setDescription (Section obj, String newDescription) throws FieldException
    {
        return newDescription;
    }

    /**
     * Get the attribute QuestionType
     */
    public QuestionType getQuestionType (Section obj, QuestionType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute QuestionType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public QuestionType setQuestionType (Section obj, QuestionType newQuestionType) throws FieldException
    {
        return newQuestionType;
    }

    }

    @Override
    public ORMPipeLine pipes()
    {
        return new SectionPipeLineFactory<Section, Section> ((Section)this);
    }

    @Override
    public ORMPipeLine pipes(Collection _items)
    {
        return pipesSection(_items);
    }
      
    /**
     * Use this instead of pipes() to get rid of type casting.
     */  
    public SectionPipeLineFactory<Section, Section> pipelineSection()
    {
        return (SectionPipeLineFactory<Section, Section>) pipes();
    }
    
    public static SectionPipeLineFactory<Section, Section> pipesSection(Collection<Section> items)
    {
        return REFERENCE_Section.new SectionPipeLineFactory<Section, Section> (items);
    }
    
    public static SectionPipeLineFactory<Section, Section> pipesSection(Section[] _items)
    {
        return pipesSection(Arrays.asList (_items));
    }
    
    public static SectionPipeLineFactory<Section, Section> pipesSection()
    {
        return pipesSection((Collection)null);
    }
    
    
    public class SectionPipeLineFactory<From extends BaseBusinessClass, Me extends Section> extends BaseBusinessClass.ORMPipeLine<From, Me>    
    {
        public <Prev> SectionPipeLineFactory (PipeLine<From, Prev> pipeLine, Pipe<Prev, Me> nextPipe)
        {
            super (pipeLine, nextPipe);
        }
        
        public SectionPipeLineFactory (From seed)
        {
            super(seed);
        }

        public SectionPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Questions"))
            {
                return toQuestions ();
            }                
            if (name.equals ("Description"))
            {
                return toDescription ();
            }                
            if (name.equals ("QuestionType"))
            {
                return toQuestionType ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toDescription () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Description));  }
        
        public QuestionType.QuestionTypePipeLineFactory<From, QuestionType> toQuestionType () 
        { 
            return new QuestionType.QuestionTypePipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_QuestionType));
        }

        public Question.QuestionPipeLineFactory<From, Question> toQuestions () { return toQuestions(Filter.ALL); }        

        public Question.QuestionPipeLineFactory<From, Question> toQuestions (Filter<Question> filter)
        {
            return Question.REFERENCE_Question.new QuestionPipeLineFactory<From, Question> (this, new ORMMultiAssocPipe<Me, Question>(MULTIPLEREFERENCE_Questions, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

class DummySection extends Section
{
    // Default constructor primarily to support Externalisable
    public DummySection()
    {
        super();
    }

    public void assertValid ()
    {
    }


    public int getQuestionsCount () throws StorageException
    {
        return 0;
    }


    public Question getQuestionsAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Questions");
    }


    public SortedSet getQuestionsSet () throws StorageException
    {
        return new TreeSet();
    }

}

    
