/*
 * 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;



public abstract class BaseCandidateDiversityAnswer extends BaseBusinessClass
{
    // Reference instance for the object
    public static final CandidateDiversityAnswer REFERENCE_CandidateDiversityAnswer = new CandidateDiversityAnswer ();

    // Reference instance for the object
    public static final CandidateDiversityAnswer DUMMY_CandidateDiversityAnswer = new DummyCandidateDiversityAnswer ();

    // Static constants corresponding to field names
    
    public static final String SINGLEREFERENCE_AnswerOption = "AnswerOption";
    public static final String SINGLEREFERENCE_Question = "Question";
    public static final String SINGLEREFERENCE_Candidate = "Candidate";
    public static final String BACKREF_Candidate = "";
    public static final String MULTIPLEREFERENCE_Answers = "Answers";
    public static final String BACKREF_Answers = "";

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

    // Static constants corresponding to attribute helpers
    

    // Private attributes corresponding to business object data
    

    // Private attributes corresponding to single references
    private SingleAssociation<CandidateDiversityAnswer, DiversityAnswer> _AnswerOption;
    private SingleAssociation<CandidateDiversityAnswer, DiversityQuestion> _Question;
    private SingleAssociation<CandidateDiversityAnswer, Candidate> _Candidate;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<CandidateDiversityAnswer, AnswerOption> _Answers;
    

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

    // Arrays of validators for each attribute
    

    // Arrays of AttributeDecorators for each attribute
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<CandidateDiversityAnswer, DiversityAnswer>[] SINGLEREFERENCE_AnswerOption_Decorators;
    private static final SingleAssocDecorator<CandidateDiversityAnswer, DiversityQuestion>[] SINGLEREFERENCE_Question_Decorators;
    private static final SingleAssocDecorator<CandidateDiversityAnswer, Candidate>[] SINGLEREFERENCE_Candidate_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    private static final MultiAssocDecorator<CandidateDiversityAnswer, AnswerOption>[] MULTIPLEREFERENCE_Answers_Decorators;
    

    // Arrays of behaviour decorators
    private static final CandidateDiversityAnswerBehaviourDecorator[] CandidateDiversityAnswer_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Answers = AnswerOption.BACKREF_CandidateAnswer;
            String tmp_Candidate = Candidate.BACKREF_DiversityAnswers;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_AnswerOption();
            setupAssocMetaData_Answers();
            setupAssocMetaData_Question();
            setupAssocMetaData_Candidate();
            SINGLEREFERENCE_AnswerOption_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CandidateDiversityAnswer, SINGLEREFERENCE_AnswerOption).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Question_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CandidateDiversityAnswer, SINGLEREFERENCE_Question).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Candidate_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CandidateDiversityAnswer, SINGLEREFERENCE_Candidate).toArray (new SingleAssocDecorator[0]);
            MULTIPLEREFERENCE_Answers_Decorators = (MultiAssocDecorator[])AttributeDecoratorUtils.getMultiAssocDecorators(REFERENCE_CandidateDiversityAnswer, MULTIPLEREFERENCE_Answers).toArray (new MultiAssocDecorator[0]);
            

            REFERENCE_CandidateDiversityAnswer.initialiseReference ();
            DUMMY_CandidateDiversityAnswer.initialiseReference ();
            CandidateDiversityAnswer_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CandidateDiversityAnswer.class).toArray(new CandidateDiversityAnswerBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("name", "AnswerOption");
        metaInfo.put ("type", "DiversityAnswer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CandidateDiversityAnswer.AnswerOption:", metaInfo);
        ATTRIBUTES_METADATA_CandidateDiversityAnswer.put (SINGLEREFERENCE_AnswerOption, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Answers()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "CandidateAnswer");
        metaInfo.put ("name", "Answers");
        metaInfo.put ("type", "AnswerOption");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CandidateDiversityAnswer.Answers:", metaInfo);
        ATTRIBUTES_METADATA_CandidateDiversityAnswer.put (MULTIPLEREFERENCE_Answers, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Question()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "question_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Question");
        metaInfo.put ("type", "DiversityQuestion");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_candidate_diversity_answer");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CandidateDiversityAnswer.Question:", metaInfo);
        ATTRIBUTES_METADATA_CandidateDiversityAnswer.put (SINGLEREFERENCE_Question, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Candidate()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "DiversityAnswers");
        metaInfo.put ("dbcol", "candidate_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Candidate");
        metaInfo.put ("type", "Candidate");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_candidate_diversity_answer");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CandidateDiversityAnswer.Candidate:", metaInfo);
        ATTRIBUTES_METADATA_CandidateDiversityAnswer.put (SINGLEREFERENCE_Candidate, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // END OF STATIC METADATA DEFINITION    
    
    
    
    // This constructor should not be called
    protected BaseCandidateDiversityAnswer ()
    {
    }


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

    


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

        
    }


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

        _AnswerOption = new SingleAssociation<CandidateDiversityAnswer, DiversityAnswer> (this, SINGLEREFERENCE_AnswerOption, null, DiversityAnswer.REFERENCE_DiversityAnswer, "");
        _Question = new SingleAssociation<CandidateDiversityAnswer, DiversityQuestion> (this, SINGLEREFERENCE_Question, null, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_candidate_diversity_answer");
        _Candidate = new SingleAssociation<CandidateDiversityAnswer, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_DiversityAnswers, Candidate.REFERENCE_Candidate, "tl_candidate_diversity_answer");
        _Answers = new MultipleAssociation<CandidateDiversityAnswer, AnswerOption> (this, MULTIPLEREFERENCE_Answers, AnswerOption.SINGLEREFERENCE_CandidateAnswer, AnswerOption.REFERENCE_AnswerOption);
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _AnswerOption = new SingleAssociation<CandidateDiversityAnswer, DiversityAnswer> (this, SINGLEREFERENCE_AnswerOption, null, DiversityAnswer.REFERENCE_DiversityAnswer, "");
        _Question = new SingleAssociation<CandidateDiversityAnswer, DiversityQuestion> (this, SINGLEREFERENCE_Question, null, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_candidate_diversity_answer");
        _Candidate = new SingleAssociation<CandidateDiversityAnswer, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_DiversityAnswers, Candidate.REFERENCE_Candidate, "tl_candidate_diversity_answer");
        _Answers = new MultipleAssociation<CandidateDiversityAnswer, AnswerOption> (this, MULTIPLEREFERENCE_Answers, AnswerOption.SINGLEREFERENCE_CandidateAnswer, AnswerOption.REFERENCE_AnswerOption);
        
        return this;
    }




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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_AnswerOption))
        {
            return _AnswerOption.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return _Question.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return _Candidate.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_Question))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return Candidate.MULTIPLEREFERENCE_DiversityAnswers ;
        }
        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_AnswerOption))
        {
            return getAnswerOption ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return getQuestion ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidate ();
        }
        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_AnswerOption))
        {
            return getAnswerOption (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return getQuestion (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidate (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_AnswerOption))
        {
            return getAnswerOptionID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return getQuestionID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidateID ();
        }
        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_AnswerOption))
        {
            setAnswerOption ((DiversityAnswer)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            setQuestion ((DiversityQuestion)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            setCandidate ((Candidate)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference AnswerOption
     */
    public DiversityAnswer getAnswerOption () throws StorageException
    {
        assertValid();
        
        try
        {
            return (DiversityAnswer)(_AnswerOption.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in CandidateDiversityAnswer:", this.getObjectID (), ", was trying to get DiversityAnswer:",  getAnswerOptionID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _AnswerOption.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getAnswerOptionID ()
    {
        assertValid();
        
        if (_AnswerOption == null)
        {
            return null;
        }
        else
        {
            return _AnswerOption.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 preAnswerOptionChange (DiversityAnswer newAnswerOption) 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 postAnswerOptionChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference AnswerOption.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setAnswerOption (DiversityAnswer newAnswerOption) throws StorageException, FieldException
    {
        if (_AnswerOption.wouldReferencedChange (newAnswerOption))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_AnswerOption_Decorators, (CandidateDiversityAnswer)this, SINGLEREFERENCE_AnswerOption ,getWriteability_AnswerOption ()) != FieldWriteability.FALSE, "Assoc AnswerOption is not writeable");
            preAnswerOptionChange (newAnswerOption);
            
            _AnswerOption.set (newAnswerOption);
                
            postAnswerOptionChange ();
        }
    }

    /**
     * Get the reference Question
     */
    public DiversityQuestion getQuestion () throws StorageException
    {
        assertValid();
        
        try
        {
            return (DiversityQuestion)(_Question.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in CandidateDiversityAnswer:", this.getObjectID (), ", was trying to get DiversityQuestion:",  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 DiversityQuestion 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 (DiversityQuestion 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 (DiversityQuestion newQuestion) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newQuestion != null, this, SINGLEREFERENCE_Question, "mandatory");

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

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCandidateID ()
    {
        assertValid();
        
        if (_Candidate == null)
        {
            return null;
        }
        else
        {
            return _Candidate.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 preCandidateChange (Candidate newCandidate) 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 postCandidateChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference Candidate.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setCandidate (Candidate newCandidate) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newCandidate != null, this, SINGLEREFERENCE_Candidate, "mandatory");

        if (_Candidate.wouldReferencedChange (newCandidate))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Candidate_Decorators, (CandidateDiversityAnswer)this, SINGLEREFERENCE_Candidate ,getWriteability_Candidate ()) != FieldWriteability.FALSE, "Assoc Candidate is not writeable");
            preCandidateChange (newCandidate);
            Candidate oldCandidate = getCandidate ();

            if (oldCandidate != null)
            {
                // This is to stop validation from triggering when we are removed
                _Candidate.set (null);
                oldCandidate.removeFromDiversityAnswers ((CandidateDiversityAnswer)(this));
            }

            _Candidate.set (newCandidate);

            if (newCandidate != null)
            {
                newCandidate.addToDiversityAnswers ((CandidateDiversityAnswer)(this));
            }
                
            postCandidateChange ();
        }
    }

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

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return AnswerOption.SINGLEREFERENCE_CandidateAnswer ;
        }

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return this.getAnswersAt(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_Answers.equals(attribName))
        {
            addToAnswers((AnswerOption)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_Answers.equals(attribName))
        {
            removeFromAnswers((AnswerOption)oldElement);
            return;
        }

        super.removeFromMultiAssoc(attribName, oldElement);
    }


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

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return _Answers.isLoaded ();
        }

        return super.__isMultiAssocLoaded(attribName);
    }


    public FieldWriteability getWriteability_Answers ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getAnswersCount () throws StorageException
    {
        assertValid();
        return _Answers.getReferencedObjectsCount ();
    }


    public void addToAnswers (AnswerOption newElement) throws StorageException
    {
        if (_Answers.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (MULTIPLEREFERENCE_Answers_Decorators, (CandidateDiversityAnswer)this, MULTIPLEREFERENCE_Answers ,getWriteability_Answers ()) != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (add)");
            _Answers.appendElement (newElement);

            try
            {
                if (newElement.getCandidateAnswer () != this)
                {
                    newElement.setCandidateAnswer ((CandidateDiversityAnswer)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromAnswers (AnswerOption elementToRemove) throws StorageException
    {
        if (_Answers.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (MULTIPLEREFERENCE_Answers_Decorators, (CandidateDiversityAnswer)this, MULTIPLEREFERENCE_Answers ,getWriteability_Answers ()) != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (remove)");
            _Answers.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getCandidateAnswer () != null)
                {
                    elementToRemove.setCandidateAnswer (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public AnswerOption getAnswersAt (int index) throws StorageException
    {
        return (AnswerOption)(_Answers.getElementAt (index));
    }


    public SortedSet<AnswerOption> getAnswersSet () throws StorageException
    {
        return _Answers.getSet ();
    }



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

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null DiversityAnswers from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Candidate.set (null);
                    referenced.removeFromDiversityAnswers ((CandidateDiversityAnswer)this);
                }
            }
        
            for(AnswerOption referenced : CollectionUtils.reverse(getAnswersSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null CandidateAnswer from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setCandidateAnswer(null);
            }

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

        super.onDelete ();
    }


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


    public CandidateDiversityAnswer referenceInstance ()
    {
        return REFERENCE_CandidateDiversityAnswer;
    }


    public CandidateDiversityAnswer getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCandidateDiversityAnswerByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CandidateDiversityAnswer;
    }


    public String getBaseSetName ()
    {
        return "tl_candidate_diversity_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_candidate_diversity_answerPSet = allSets.getPersistentSet (myID, "tl_candidate_diversity_answer", myPSetStatus);

        tl_candidate_diversity_answerPSet.setAttrib (FIELD_ObjectID, myID);
        _Question.getPersistentSets (allSets);
        _Candidate.getPersistentSets (allSets);
        
    }


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

        _Question.setFromPersistentSets (objectID, allSets);
        _Candidate.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof CandidateDiversityAnswer)
        {
            CandidateDiversityAnswer otherCandidateDiversityAnswer = (CandidateDiversityAnswer)other;
            
        }
    }


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

        if (source instanceof BaseCandidateDiversityAnswer)
        {
            BaseCandidateDiversityAnswer sourceCandidateDiversityAnswer = (BaseCandidateDiversityAnswer)(source);

            
        }
    }


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

            _AnswerOption.copyFrom (sourceCandidateDiversityAnswer._AnswerOption, linkToGhosts);
            _Question.copyFrom (sourceCandidateDiversityAnswer._Question, linkToGhosts);
            _Candidate.copyFrom (sourceCandidateDiversityAnswer._Candidate, 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 BaseCandidateDiversityAnswer)
        {
            BaseCandidateDiversityAnswer sourceCandidateDiversityAnswer = (BaseCandidateDiversityAnswer)(source);

            _Answers.copyFrom (sourceCandidateDiversityAnswer._Answers, linkToGhosts);
            
        }
    }


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

        
        context.check (getQuestionID() != null, this, SINGLEREFERENCE_Question, "mandatory");
        
        context.check (getCandidateID() != null, this, SINGLEREFERENCE_Candidate, "mandatory");
        
    }


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

        _AnswerOption.readExternalData(vals.get(SINGLEREFERENCE_AnswerOption));
        _Question.readExternalData(vals.get(SINGLEREFERENCE_Question));
        _Candidate.readExternalData(vals.get(SINGLEREFERENCE_Candidate));
        _Answers.readExternalData(vals.get(MULTIPLEREFERENCE_Answers));
        
    }


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

        vals.put (SINGLEREFERENCE_AnswerOption, _AnswerOption.writeExternalData());
        vals.put (SINGLEREFERENCE_Question, _Question.writeExternalData());
        vals.put (SINGLEREFERENCE_Candidate, _Candidate.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Answers, _Answers.writeExternalData());
        
    }


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

        if (other instanceof BaseCandidateDiversityAnswer)
        {
            BaseCandidateDiversityAnswer otherCandidateDiversityAnswer = (BaseCandidateDiversityAnswer)(other);

            

            // Compare single assocs
            _AnswerOption.compare (otherCandidateDiversityAnswer._AnswerOption, listener);
            _Question.compare (otherCandidateDiversityAnswer._Question, listener);
            _Candidate.compare (otherCandidateDiversityAnswer._Candidate, listener);
            

            // Compare multiple assocs
            _Answers.compare (otherCandidateDiversityAnswer._Answers, listener);
            
        }
    }


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

        
    }


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

        visitor.visitAssociation (_AnswerOption);
        visitor.visitAssociation (_Question);
        visitor.visitAssociation (_Candidate);
        visitor.visitAssociation (_Answers);
        
    }


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

        if (scope.includes (_AnswerOption))
        {
            visitor.visit (_AnswerOption);
        }
        if (scope.includes (_Question))
        {
            visitor.visit (_Question);
        }
        if (scope.includes (_Candidate))
        {
            visitor.visit (_Candidate);
        }
        if (scope.includes (_Answers))
        {
            visitor.visit (_Answers);
        }
        
    }


    public static CandidateDiversityAnswer createCandidateDiversityAnswer (ObjectTransaction transaction) throws StorageException
    {
        CandidateDiversityAnswer     result = new CandidateDiversityAnswer ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CandidateDiversityAnswer getCandidateDiversityAnswerByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CandidateDiversityAnswer)(transaction.getObjectByID (REFERENCE_CandidateDiversityAnswer, objectID));
    }

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


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

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

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

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

            
        public SearchAll andQuestion (QueryFilter<DiversityQuestion> filter)
        {
            filter.addFilter (context, "tl_candidate_diversity_answer.question_id", "Question");
            return this;
        }
            
        public SearchAll andCandidate (QueryFilter<Candidate> filter)
        {
            filter.addFilter (context, "tl_candidate_diversity_answer.candidate_id", "Candidate");
            return this;
        }
            
        public CandidateDiversityAnswer[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_CandidateDiversityAnswer, SEARCH_All, criteria);
            Set<CandidateDiversityAnswer>   typedResults = new LinkedHashSet <CandidateDiversityAnswer> ();
            for (BaseBusinessClass bbcResult : results)
            {
                CandidateDiversityAnswer aResult = (CandidateDiversityAnswer)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new CandidateDiversityAnswer[0]);
                            
        }
    }

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



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


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


    public void setAttribute (String attribName, Object attribValue) throws FieldException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        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 (MULTIPLEREFERENCE_Answers))
        {
            return getWriteability_Answers ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Question))
        {
            return getWriteability_Question ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Candidate))
        {
            return getWriteability_Candidate ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_AnswerOption))
        {
            return getWriteability_AnswerOption ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {

        super.putUnwriteable (fields);
    }

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


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

        

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_CandidateDiversityAnswer);
    }
            

    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 CandidateDiversityAnswerBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<CandidateDiversityAnswer>
    {

    }

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

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

        public CandidateDiversityAnswerPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("AnswerOption"))
            {
                return toAnswerOption ();
            }                
            if (name.equals ("Answers"))
            {
                return toAnswers ();
            }                
            if (name.equals ("Question"))
            {
                return toQuestion ();
            }                
            if (name.equals ("Candidate"))
            {
                return toCandidate ();
            }                
            
            
            return super.to(name);
        }
        

        public DiversityAnswer.DiversityAnswerPipeLineFactory<From, DiversityAnswer> toAnswerOption () { return toAnswerOption (Filter.ALL); }

        public DiversityAnswer.DiversityAnswerPipeLineFactory<From, DiversityAnswer> toAnswerOption (Filter<DiversityAnswer> filter) 
        { 
            return DiversityAnswer.REFERENCE_DiversityAnswer.new DiversityAnswerPipeLineFactory<From, DiversityAnswer> (this, new ORMSingleAssocPipe<Me, DiversityAnswer>(SINGLEREFERENCE_AnswerOption, filter)); 
        }

        public DiversityQuestion.DiversityQuestionPipeLineFactory<From, DiversityQuestion> toQuestion () { return toQuestion (Filter.ALL); }

        public DiversityQuestion.DiversityQuestionPipeLineFactory<From, DiversityQuestion> toQuestion (Filter<DiversityQuestion> filter) 
        { 
            return DiversityQuestion.REFERENCE_DiversityQuestion.new DiversityQuestionPipeLineFactory<From, DiversityQuestion> (this, new ORMSingleAssocPipe<Me, DiversityQuestion>(SINGLEREFERENCE_Question, filter)); 
        }

        public Candidate.CandidatePipeLineFactory<From, Candidate> toCandidate () { return toCandidate (Filter.ALL); }

        public Candidate.CandidatePipeLineFactory<From, Candidate> toCandidate (Filter<Candidate> filter) 
        { 
            return Candidate.REFERENCE_Candidate.new CandidatePipeLineFactory<From, Candidate> (this, new ORMSingleAssocPipe<Me, Candidate>(SINGLEREFERENCE_Candidate, filter)); 
        }

        public AnswerOption.AnswerOptionPipeLineFactory<From, AnswerOption> toAnswers () { return toAnswers(Filter.ALL); }        

        public AnswerOption.AnswerOptionPipeLineFactory<From, AnswerOption> toAnswers (Filter<AnswerOption> filter)
        {
            return AnswerOption.REFERENCE_AnswerOption.new AnswerOptionPipeLineFactory<From, AnswerOption> (this, new ORMMultiAssocPipe<Me, AnswerOption>(MULTIPLEREFERENCE_Answers, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        
        if(CollectionUtils.equals(assocName, "AnswerOption"))
        {
            return true;
        }
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public DiversityAnswer getAnswerOption () throws StorageException
    {
        return (DiversityAnswer)(DiversityAnswer.DUMMY_DiversityAnswer);
    }


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

    public DiversityQuestion getQuestion () throws StorageException
    {
        return (DiversityQuestion)(DiversityQuestion.DUMMY_DiversityQuestion);
    }


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

    public Candidate getCandidate () throws StorageException
    {
        return (Candidate)(Candidate.DUMMY_Candidate);
    }


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

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


    public AnswerOption getAnswersAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Answers");
    }


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

}

    
