/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure8.2 rev3 [oneit.objstore.BusinessObjectTemplate.xsl]
 *
 *   Version: 1.0
 *   Vendor: Apache Software Foundation (Xalan XSLTC)
 *   Vendor URL: http://xml.apache.org/xalan-j
 */


    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;



public abstract class BaseAnswer extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Answer REFERENCE_Answer = new Answer ();

    // Reference instance for the object
    public static final Answer DUMMY_Answer = new DummyAnswer ();

    // Static constants corresponding to field names
    
    public static final String FIELD_AnswerNo = "AnswerNo";
    public static final String SINGLEREFERENCE_Section = "Section";
    public static final String SINGLEREFERENCE_JobApplication = "JobApplication";
    public static final String BACKREF_JobApplication = "";
    public static final String SINGLEREFERENCE_Question = "Question";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Answer> HELPER_AnswerNo = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private Integer _AnswerNo;
    

    // Private attributes corresponding to single references
    private SingleAssociation<Answer, Section> _Section;
    private SingleAssociation<Answer, JobApplication> _JobApplication;
    private SingleAssociation<Answer, Question> _Question;
    

    // Private attributes corresponding to multiple references
    

    // Map of maps of metadata
    private static final Map ATTRIBUTES_METADATA_Answer = new HashMap ();

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

    // Arrays of behaviour decorators
    private static final AnswerBehaviourDecorator[] Answer_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_JobApplication = JobApplication.BACKREF_ProfileAssessmentAnswers;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Section();
            setupAssocMetaData_JobApplication();
            setupAssocMetaData_Question();
            FIELD_AnswerNo_Validators = (AttributeValidator[])setupAttribMetaData_AnswerNo(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_Answer.initialiseReference ();
            DUMMY_Answer.initialiseReference ();
            Answer_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Answer.class).toArray(new AnswerBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

    
    // Meta Info setup
    private static void setupAssocMetaData_Section()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "section_number");
        metaInfo.put ("name", "Section");
        metaInfo.put ("type", "Section");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Answer.Section:", metaInfo);
        ATTRIBUTES_METADATA_Answer.put (SINGLEREFERENCE_Section, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_JobApplication()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "ProfileAssessmentAnswers");
        metaInfo.put ("dbcol", "job_application_id");
        metaInfo.put ("name", "JobApplication");
        metaInfo.put ("type", "JobApplication");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Answer.JobApplication:", metaInfo);
        ATTRIBUTES_METADATA_Answer.put (SINGLEREFERENCE_JobApplication, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Question()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "quest_number");
        metaInfo.put ("name", "Question");
        metaInfo.put ("type", "Question");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Answer.Question:", metaInfo);
        ATTRIBUTES_METADATA_Answer.put (SINGLEREFERENCE_Question, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_AnswerNo(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "answer_number");
        metaInfo.put ("name", "AnswerNo");
        metaInfo.put ("type", "Integer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Answer.AnswerNo:", metaInfo);
        ATTRIBUTES_METADATA_Answer.put (FIELD_AnswerNo, Collections.unmodifiableMap (metaInfo));

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

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


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


    


    // Initialise the attributes
    protected void _initialiseNewObjAttributes (ObjectTransaction transaction) throws StorageException
    {
        super._initialiseNewObjAttributes (transaction);

        
        _AnswerNo = (Integer)(HELPER_AnswerNo.initialise (_AnswerNo));
    }


    // Initialise the associations
    protected void _initialiseAssociations ()
    {
        super._initialiseAssociations ();

        _Section = new SingleAssociation<Answer, Section> (this, SINGLEREFERENCE_Section, null, Section.REFERENCE_Section, "tl_answer");
        _JobApplication = new SingleAssociation<Answer, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_ProfileAssessmentAnswers, JobApplication.REFERENCE_JobApplication, "tl_answer");
        _Question = new SingleAssociation<Answer, Question> (this, SINGLEREFERENCE_Question, null, Question.REFERENCE_Question, "tl_answer");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Section = new SingleAssociation<Answer, Section> (this, SINGLEREFERENCE_Section, null, Section.REFERENCE_Section, "tl_answer");
        _JobApplication = new SingleAssociation<Answer, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_ProfileAssessmentAnswers, JobApplication.REFERENCE_JobApplication, "tl_answer");
        _Question = new SingleAssociation<Answer, Question> (this, SINGLEREFERENCE_Question, null, Question.REFERENCE_Question, "tl_answer");
        
        
        return this;
    }

    

    /**
     * Get the attribute AnswerNo
     */
    public Integer getAnswerNo ()
    {
        assertValid();
        Integer valToReturn = _AnswerNo;

            for (AnswerBehaviourDecorator bhd : Answer_BehaviourDecorators)
            {
                valToReturn = bhd.getAnswerNo ((Answer)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 preAnswerNoChange (Integer newAnswerNo) 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 postAnswerNoChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute AnswerNo.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setAnswerNo (Integer newAnswerNo) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_AnswerNo.compare (_AnswerNo, newAnswerNo);
        
        try
        {
            for (AnswerBehaviourDecorator bhd : Answer_BehaviourDecorators)
            {
                newAnswerNo = bhd.setAnswerNo ((Answer)this, newAnswerNo);
                oldAndNewIdentical = HELPER_AnswerNo.compare (_AnswerNo, newAnswerNo);
            }

            

            if (FIELD_AnswerNo_Validators.length > 0)
            {
                Object newAnswerNoObj = HELPER_AnswerNo.toObject (newAnswerNo);

                if (newAnswerNoObj != null)
                {
                    int     loopMax = FIELD_AnswerNo_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Answer.get (FIELD_AnswerNo);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_AnswerNo () != FieldWriteability.FALSE, "Field  AnswerNo is not writeable");
            preAnswerNoChange (newAnswerNo);
            markFieldChange (FIELD_AnswerNo);
            _AnswerNo = newAnswerNo;            
            postFieldChange (FIELD_AnswerNo);
            postAnswerNoChange ();
        }
    }



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

        
        result.add("Section");
        
        result.add("JobApplication");
        
        result.add("Question");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Section))
        {
            return _Section.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return _JobApplication.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return _Question.getReferencedType ();
        }
        else
        {
            return super.getSingleAssocReferenceInstance (assocName);
        }
    }


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Section))
        {
            return null ;
        }else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return JobApplication.MULTIPLEREFERENCE_ProfileAssessmentAnswers ;
        }else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return null ;
        }
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Section))
        {
            return getSection ();
        }else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getJobApplication ();
        }else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return getQuestion ();
        }
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


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


    public Long getSingleAssocID (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Section))
        {
            return getSectionID ();
        }else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getJobApplicationID ();
        }else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return getQuestionID ();
        }
        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 if (assocName.equals (SINGLEREFERENCE_Section))
        {
            setSection ((Section)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            setJobApplication ((JobApplication)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            setQuestion ((Question)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference Section
     */
    public Section getSection () throws StorageException
    {
        assertValid();
        
        try
        {
            return (Section)(_Section.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Answer:", this.getObjectID (), ", was trying to get Section:",  getSectionID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _Section.get ().getClass ());
            throw e;
        }
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Section getSection (Get getType) throws StorageException
    {
        assertValid();
        return _Section.get(getType);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getSectionID ()
    {
        assertValid();
        
        if (_Section == null)
        {
            return null;
        }
        else
        {
            return _Section.getID ();
        }
    }

    /**
     * Called prior to the assoc 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 preSectionChange (Section newSection) throws FieldException
    {
    }


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



    
    public FieldWriteability getWriteability_Section ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference Section.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setSection (Section newSection) throws StorageException, FieldException
    {
        

        if (_Section.wouldReferencedChange (newSection))
        {
            assertValid();
            Debug.assertion (getWriteability_Section () != FieldWriteability.FALSE, "Assoc Section is not writeable");
            preSectionChange (newSection);
            
                    _Section.set (newSection);
                
            postSectionChange ();
        }
    }

    /**
     * Get the reference JobApplication
     */
    public JobApplication getJobApplication () throws StorageException
    {
        assertValid();
        
        try
        {
            return (JobApplication)(_JobApplication.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Answer:", this.getObjectID (), ", was trying to get JobApplication:",  getJobApplicationID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _JobApplication.get ().getClass ());
            throw e;
        }
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public JobApplication getJobApplication (Get getType) throws StorageException
    {
        assertValid();
        return _JobApplication.get(getType);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobApplicationID ()
    {
        assertValid();
        
        if (_JobApplication == null)
        {
            return null;
        }
        else
        {
            return _JobApplication.getID ();
        }
    }

    /**
     * Called prior to the assoc 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 preJobApplicationChange (JobApplication newJobApplication) throws FieldException
    {
    }


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



    
    public FieldWriteability getWriteability_JobApplication ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference JobApplication.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setJobApplication (JobApplication newJobApplication) throws StorageException, FieldException
    {
        

        if (_JobApplication.wouldReferencedChange (newJobApplication))
        {
            assertValid();
            Debug.assertion (getWriteability_JobApplication () != FieldWriteability.FALSE, "Assoc JobApplication is not writeable");
            preJobApplicationChange (newJobApplication);
            JobApplication oldJobApplication = getJobApplication ();

                    if (oldJobApplication != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _JobApplication.set (null);
                        oldJobApplication.removeFromProfileAssessmentAnswers ((Answer)(this));
                    }

                    _JobApplication.set (newJobApplication);

                    if (newJobApplication != null)
                    {
                        newJobApplication.addToProfileAssessmentAnswers ((Answer)(this));
                    }
                
            postJobApplicationChange ();
        }
    }

    /**
     * Get the reference Question
     */
    public Question getQuestion () throws StorageException
    {
        assertValid();
        
        try
        {
            return (Question)(_Question.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Answer:", this.getObjectID (), ", was trying to get Question:",  getQuestionID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _Question.get ().getClass ());
            throw e;
        }
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Question getQuestion (Get getType) throws StorageException
    {
        assertValid();
        return _Question.get(getType);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getQuestionID ()
    {
        assertValid();
        
        if (_Question == null)
        {
            return null;
        }
        else
        {
            return _Question.getID ();
        }
    }

    /**
     * Called prior to the assoc 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 preQuestionChange (Question newQuestion) throws FieldException
    {
    }


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



    
    public FieldWriteability getWriteability_Question ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference Question.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setQuestion (Question newQuestion) throws StorageException, FieldException
    {
        

        if (_Question.wouldReferencedChange (newQuestion))
        {
            assertValid();
            Debug.assertion (getWriteability_Question () != FieldWriteability.FALSE, "Assoc Question is not writeable");
            preQuestionChange (newQuestion);
            
                    _Question.set (newQuestion);
                
            postQuestionChange ();
        }
    }

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

        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {
        

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {
        

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        

        return super.__isMultiAssocLoaded(attribName);
    }

    



    public void onDelete ()
    {
        try 
        {
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_JobApplication.isLoaded () || getTransaction ().isObjectLoaded (_JobApplication.getReferencedType (), getJobApplicationID ()))
            {
                JobApplication  referenced = getJobApplication ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null ProfileAssessmentAnswers from ", getObjectID (), " to ", referenced.getObjectID ());
                    _JobApplication.set (null);
                    referenced.removeFromProfileAssessmentAnswers ((Answer)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public Answer referenceInstance ()
    {
        return REFERENCE_Answer;
    }


    public Answer getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getAnswerByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Answer;
    }


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





    /**
     * 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_answerPSet = allSets.getPersistentSet (myID, "tl_answer", myPSetStatus);

        tl_answerPSet.setAttrib (FIELD_ObjectID, myID);
        tl_answerPSet.setAttrib (FIELD_AnswerNo, HELPER_AnswerNo.toObject (_AnswerNo)); //
        _Section.getPersistentSets (allSets);
        _JobApplication.getPersistentSets (allSets);
        _Question.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_answerPSet = allSets.getPersistentSet (objectID, "tl_answer");

        _AnswerNo = (Integer)(HELPER_AnswerNo.fromObject (_AnswerNo, tl_answerPSet.getAttrib (FIELD_AnswerNo))); //
        _Section.setFromPersistentSets (objectID, allSets);
        _JobApplication.setFromPersistentSets (objectID, allSets);
        _Question.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof Answer)
        {
            Answer otherAnswer = (Answer)other;
            
            try
            {
                setAnswerNo (otherAnswer.getAnswerNo ());
            }
            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 BaseAnswer)
        {
            BaseAnswer sourceAnswer = (BaseAnswer)(source);

            _AnswerNo = sourceAnswer._AnswerNo;
            
        }
    }


    /**
     * 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 BaseAnswer)
        {
            BaseAnswer sourceAnswer = (BaseAnswer)(source);

            _Section.copyFrom (sourceAnswer._Section, linkToGhosts);
            _JobApplication.copyFrom (sourceAnswer._JobApplication, linkToGhosts);
            _Question.copyFrom (sourceAnswer._Question, linkToGhosts);
            
        }
    }


    /**
     * 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 BaseAnswer)
        {
            BaseAnswer sourceAnswer = (BaseAnswer)(source);

            
        }
    }


    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);

        _AnswerNo = (Integer)(HELPER_AnswerNo.readExternal (_AnswerNo, vals.get(FIELD_AnswerNo))); //
        _Section.readExternalData(vals.get(SINGLEREFERENCE_Section));
        _JobApplication.readExternalData(vals.get(SINGLEREFERENCE_JobApplication));
        _Question.readExternalData(vals.get(SINGLEREFERENCE_Question));
        
    }


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

        vals.put (FIELD_AnswerNo, HELPER_AnswerNo.writeExternal (_AnswerNo));
        vals.put (SINGLEREFERENCE_Section, _Section.writeExternalData());
        vals.put (SINGLEREFERENCE_JobApplication, _JobApplication.writeExternalData());
        vals.put (SINGLEREFERENCE_Question, _Question.writeExternalData());
        
    }


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

        if (other instanceof BaseAnswer)
        {
            BaseAnswer otherAnswer = (BaseAnswer)(other);

            
            if (!HELPER_AnswerNo.compare(this._AnswerNo, otherAnswer._AnswerNo))
            {
                listener.notifyFieldChange(this, other, FIELD_AnswerNo, HELPER_AnswerNo.toObject(this._AnswerNo), HELPER_AnswerNo.toObject(otherAnswer._AnswerNo));
            }

            // Compare single assocs
            _Section.compare (otherAnswer._Section, listener);
            _JobApplication.compare (otherAnswer._JobApplication, listener);
            _Question.compare (otherAnswer._Question, listener);
            

            // Compare multiple assocs
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_AnswerNo, HELPER_AnswerNo.toObject(getAnswerNo()));
        visitor.visitAssociation (_Section);
        visitor.visitAssociation (_JobApplication);
        visitor.visitAssociation (_Question);
        
    }


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

        if (scope.includes (_Section))
        {
            visitor.visit (_Section);
        }
        if (scope.includes (_JobApplication))
        {
            visitor.visit (_JobApplication);
        }
        if (scope.includes (_Question))
        {
            visitor.visit (_Question);
        }
        
    }


    public static Answer createAnswer (ObjectTransaction transaction) throws StorageException
    {
        Answer     result = new Answer ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Answer getAnswerByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Answer)(transaction.getObjectByID (REFERENCE_Answer, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_AnswerNo))
        {
            return filter.matches (getAnswerNo ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Section))
        {
            return filter.matches (getSection ());
        }
        else if (attribName.equals (SINGLEREFERENCE_JobApplication))
        {
            return filter.matches (getJobApplication ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Question))
        {
            return filter.matches (getQuestion ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andAnswerNo (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "tl_answer.answer_number", "AnswerNo");
                return this;
            }
            
            public SearchAll andSection (QueryFilter<Section> filter)
            {
                filter.addFilter (context, "tl_answer.section_number", "Section");
                return this;
            }
            
            public SearchAll andJobApplication (QueryFilter<JobApplication> filter)
            {
                filter.addFilter (context, "tl_answer.job_application_id", "JobApplication");
                return this;
            }
            
            public SearchAll andQuestion (QueryFilter<Question> filter)
            {
                filter.addFilter (context, "tl_answer.quest_number", "Question");
                return this;
            }
            
                public Answer[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Answer, SEARCH_All, criteria);
            Set<Answer>   typedResults = new LinkedHashSet <Answer> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Answer aResult = (Answer)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Answer[0]);
                            
        }
    }

        
                public static Answer[]
             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_AnswerNo))
        {
            return HELPER_AnswerNo.toObject (getAnswerNo ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_AnswerNo))
        {
            return HELPER_AnswerNo;
        }
        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_AnswerNo))
        {
            setAnswerNo ((Integer)(HELPER_AnswerNo.fromObject (_AnswerNo, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }



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


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_AnswerNo))
        {
            return getWriteability_AnswerNo ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Section))
        {
            return getWriteability_Section ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getWriteability_JobApplication ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Question))
        {
            return getWriteability_Question ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_AnswerNo () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_AnswerNo);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_AnswerNo.getAttribObject (getClass (), _AnswerNo, false, FIELD_AnswerNo));

        return result;
    }


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


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

    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 AnswerBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<Answer>
    {

    /**
     * Get the attribute AnswerNo
     */
    public Integer getAnswerNo (Answer obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute AnswerNo.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setAnswerNo (Answer obj, Integer newAnswerNo) throws FieldException
    {
        return newAnswerNo;
    }

    }

    
    public ORMPipeLine pipes()
    {
        return new AnswerPipeLineFactory<Answer, Answer> ((Answer)this);
    }
      
    /**
     * Use this instead of pipes() to get rid of type casting.
     */  
    public AnswerPipeLineFactory<Answer, Answer> pipelineAnswer()
    {
        return (AnswerPipeLineFactory<Answer, Answer>) pipes();
    }
    
    public static AnswerPipeLineFactory<Answer, Answer> pipesAnswer(Collection<Answer> items)
    {
        return REFERENCE_Answer.new AnswerPipeLineFactory<Answer, Answer> (items);
    }
    
    public static AnswerPipeLineFactory<Answer, Answer> pipesAnswer(Answer[] _items)
    {
        return pipesAnswer(Arrays.asList (_items));
    }
    
    public static AnswerPipeLineFactory<Answer, Answer> pipesAnswer()
    {
        return pipesAnswer((Collection)null);
    }
    
    
    public class AnswerPipeLineFactory<From extends BaseBusinessClass, Me extends Answer> extends BaseBusinessClass.ORMPipeLine<From, Me>    
    {
        public <Prev> AnswerPipeLineFactory (PipeLine<From, Prev> pipeLine, Pipe<Prev, Me> nextPipe)
        {
            super (pipeLine, nextPipe);
        }
        
        public AnswerPipeLineFactory (From seed)
        {
            super(seed);
        }

        public AnswerPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("AnswerNo"))
            {
                return toAnswerNo ();
            }                
            if (name.equals ("Section"))
            {
                return toSection ();
            }                
            if (name.equals ("JobApplication"))
            {
                return toJobApplication ();
            }                
            if (name.equals ("Question"))
            {
                return toQuestion ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Integer> toAnswerNo () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_AnswerNo));  }
        public Section.SectionPipeLineFactory<From, Section> toSection () { return toSection (Filter.ALL); }

        public Section.SectionPipeLineFactory<From, Section> toSection (Filter<Section> filter) 
        { 
            return Section.REFERENCE_Section.new SectionPipeLineFactory<From, Section> (this, new ORMSingleAssocPipe<Me, Section>(SINGLEREFERENCE_Section, filter)); 
        }
        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication () { return toJobApplication (Filter.ALL); }

        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication (Filter<JobApplication> filter) 
        { 
            return JobApplication.REFERENCE_JobApplication.new JobApplicationPipeLineFactory<From, JobApplication> (this, new ORMSingleAssocPipe<Me, JobApplication>(SINGLEREFERENCE_JobApplication, filter)); 
        }
        public Question.QuestionPipeLineFactory<From, Question> toQuestion () { return toQuestion (Filter.ALL); }

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

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Section getSection () throws StorageException
    {
        return (Section)(Section.DUMMY_Section);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getSectionID ()
    {
        return Section.DUMMY_Section.getObjectID();
    }

    public JobApplication getJobApplication () throws StorageException
    {
        return (JobApplication)(JobApplication.DUMMY_JobApplication);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobApplicationID ()
    {
        return JobApplication.DUMMY_JobApplication.getObjectID();
    }

    public Question getQuestion () throws StorageException
    {
        return (Question)(Question.DUMMY_Question);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getQuestionID ()
    {
        return Question.DUMMY_Question.getObjectID();
    }

}

    
