/*
 * 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 BaseDiversityQuestion extends BaseBusinessClass
{
    // Reference instance for the object
    public static final DiversityQuestion REFERENCE_DiversityQuestion = new DiversityQuestion ();

    // Reference instance for the object
    public static final DiversityQuestion DUMMY_DiversityQuestion = new DummyDiversityQuestion ();

    // Static constants corresponding to field names
    
    public static final String FIELD_QuestionText = "QuestionText";
    public static final String FIELD_AustraliaOnly = "AustraliaOnly";
    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 static final DefaultAttributeHelper<DiversityQuestion> HELPER_QuestionText = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<DiversityQuestion> HELPER_AustraliaOnly = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _QuestionText;
    private Boolean _AustraliaOnly;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<DiversityQuestion, DiversityAnswer> _Answers;
    

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

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

    // Arrays of behaviour decorators
    private static final DiversityQuestionBehaviourDecorator[] DiversityQuestion_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Answers = DiversityAnswer.BACKREF_Question;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Answers();
            FIELD_QuestionText_Validators = (AttributeValidator[])setupAttribMetaData_QuestionText(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_AustraliaOnly_Validators = (AttributeValidator[])setupAttribMetaData_AustraliaOnly(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_DiversityQuestion.initialiseReference ();
            DUMMY_DiversityQuestion.initialiseReference ();
            DiversityQuestion_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(DiversityQuestion.class).toArray(new DiversityQuestionBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Question");
        metaInfo.put ("name", "Answers");
        metaInfo.put ("type", "DiversityAnswer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for DiversityQuestion.Answers:", metaInfo);
        ATTRIBUTES_METADATA_DiversityQuestion.put (MULTIPLEREFERENCE_Answers, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_QuestionText(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "question_text");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "QuestionText");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for DiversityQuestion.QuestionText:", metaInfo);
        ATTRIBUTES_METADATA_DiversityQuestion.put (FIELD_QuestionText, Collections.unmodifiableMap (metaInfo));

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

        return validators;
    }
    
    // Meta Info setup
    private static List setupAttribMetaData_AustraliaOnly(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "australia_only");
        metaInfo.put ("defaultValue", "Boolean.FALSE");
        metaInfo.put ("name", "AustraliaOnly");
        metaInfo.put ("type", "Boolean");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for DiversityQuestion.AustraliaOnly:", metaInfo);
        ATTRIBUTES_METADATA_DiversityQuestion.put (FIELD_AustraliaOnly, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _QuestionText = (String)(HELPER_QuestionText.initialise (_QuestionText));
        _AustraliaOnly = (Boolean)(Boolean.FALSE);
    }


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

        _Answers = new MultipleAssociation<DiversityQuestion, DiversityAnswer> (this, MULTIPLEREFERENCE_Answers, DiversityAnswer.SINGLEREFERENCE_Question, DiversityAnswer.REFERENCE_DiversityAnswer);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Answers = new MultipleAssociation<DiversityQuestion, DiversityAnswer> (this, MULTIPLEREFERENCE_Answers, DiversityAnswer.SINGLEREFERENCE_Question, DiversityAnswer.REFERENCE_DiversityAnswer);
        
        
        return this;
    }

    

    /**
     * Get the attribute QuestionText
     */
    public String getQuestionText ()
    {
        assertValid();
        String valToReturn = _QuestionText;

            for (DiversityQuestionBehaviourDecorator bhd : DiversityQuestion_BehaviourDecorators)
            {
                valToReturn = bhd.getQuestionText ((DiversityQuestion)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 preQuestionTextChange (String newQuestionText) 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 postQuestionTextChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute QuestionText.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setQuestionText (String newQuestionText) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_QuestionText.compare (_QuestionText, newQuestionText);
        
        try
        {
            for (DiversityQuestionBehaviourDecorator bhd : DiversityQuestion_BehaviourDecorators)
            {
                newQuestionText = bhd.setQuestionText ((DiversityQuestion)this, newQuestionText);
                oldAndNewIdentical = HELPER_QuestionText.compare (_QuestionText, newQuestionText);
            }

            BusinessObjectParser.assertFieldCondition (newQuestionText != null, this, FIELD_QuestionText, "mandatory");
            

            if (FIELD_QuestionText_Validators.length > 0)
            {
                Object newQuestionTextObj = HELPER_QuestionText.toObject (newQuestionText);

                if (newQuestionTextObj != null)
                {
                    int     loopMax = FIELD_QuestionText_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_DiversityQuestion.get (FIELD_QuestionText);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_QuestionText () != FieldWriteability.FALSE, "Field  QuestionText is not writeable");
            preQuestionTextChange (newQuestionText);
            markFieldChange (FIELD_QuestionText);
            _QuestionText = newQuestionText;            
            postFieldChange (FIELD_QuestionText);
            postQuestionTextChange ();
        }
    }

    /**
     * Get the attribute AustraliaOnly
     */
    public Boolean getAustraliaOnly ()
    {
        assertValid();
        Boolean valToReturn = _AustraliaOnly;

            for (DiversityQuestionBehaviourDecorator bhd : DiversityQuestion_BehaviourDecorators)
            {
                valToReturn = bhd.getAustraliaOnly ((DiversityQuestion)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 preAustraliaOnlyChange (Boolean newAustraliaOnly) 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 postAustraliaOnlyChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute AustraliaOnly.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setAustraliaOnly (Boolean newAustraliaOnly) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_AustraliaOnly.compare (_AustraliaOnly, newAustraliaOnly);
        
        try
        {
            for (DiversityQuestionBehaviourDecorator bhd : DiversityQuestion_BehaviourDecorators)
            {
                newAustraliaOnly = bhd.setAustraliaOnly ((DiversityQuestion)this, newAustraliaOnly);
                oldAndNewIdentical = HELPER_AustraliaOnly.compare (_AustraliaOnly, newAustraliaOnly);
            }

            

            if (FIELD_AustraliaOnly_Validators.length > 0)
            {
                Object newAustraliaOnlyObj = HELPER_AustraliaOnly.toObject (newAustraliaOnly);

                if (newAustraliaOnlyObj != null)
                {
                    int     loopMax = FIELD_AustraliaOnly_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_DiversityQuestion.get (FIELD_AustraliaOnly);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_AustraliaOnly () != FieldWriteability.FALSE, "Field  AustraliaOnly is not writeable");
            preAustraliaOnlyChange (newAustraliaOnly);
            markFieldChange (FIELD_AustraliaOnly);
            _AustraliaOnly = newAustraliaOnly;            
            postFieldChange (FIELD_AustraliaOnly);
            postAustraliaOnlyChange ();
        }
    }



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

        

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


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


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


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


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



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

        
        result.add("Answers");
        

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return DiversityAnswer.SINGLEREFERENCE_Question ;
        }
        

        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((DiversityAnswer)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((DiversityAnswer)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 (DiversityAnswer newElement) throws StorageException
    {
        if (_Answers.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Answers () != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (add)");
            _Answers.appendElement (newElement);

            try
            {
                if (newElement.getQuestion () != this)
                {
                    newElement.setQuestion ((DiversityQuestion)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromAnswers (DiversityAnswer elementToRemove) throws StorageException
    {
        if (_Answers.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Answers () != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (remove)");
            _Answers.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getQuestion () != null)
                {
                    elementToRemove.setQuestion (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


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


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



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

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

        super.onDelete ();
    }


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


    public DiversityQuestion referenceInstance ()
    {
        return REFERENCE_DiversityQuestion;
    }


    public DiversityQuestion getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getDiversityQuestionByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_DiversityQuestion;
    }


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





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

        tl_diversity_questionPSet.setAttrib (FIELD_ObjectID, myID);
        tl_diversity_questionPSet.setAttrib (FIELD_QuestionText, HELPER_QuestionText.toObject (_QuestionText)); //
        tl_diversity_questionPSet.setAttrib (FIELD_AustraliaOnly, HELPER_AustraliaOnly.toObject (_AustraliaOnly)); //
        
    }


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

        
        PersistentSet   tl_diversity_questionPSet = allSets.getPersistentSet (objectID, "tl_diversity_question");

        _QuestionText = (String)(HELPER_QuestionText.fromObject (_QuestionText, tl_diversity_questionPSet.getAttrib (FIELD_QuestionText))); //
        _AustraliaOnly = (Boolean)(HELPER_AustraliaOnly.fromObject (_AustraliaOnly, tl_diversity_questionPSet.getAttrib (FIELD_AustraliaOnly))); //
        
    }





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

        if (other instanceof DiversityQuestion)
        {
            DiversityQuestion otherDiversityQuestion = (DiversityQuestion)other;
            
            try
            {
                setQuestionText (otherDiversityQuestion.getQuestionText ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setAustraliaOnly (otherDiversityQuestion.getAustraliaOnly ());
            }
            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 BaseDiversityQuestion)
        {
            BaseDiversityQuestion sourceDiversityQuestion = (BaseDiversityQuestion)(source);

            _QuestionText = sourceDiversityQuestion._QuestionText;
            _AustraliaOnly = sourceDiversityQuestion._AustraliaOnly;
            
        }
    }


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

            
        }
    }


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

        if (source instanceof BaseDiversityQuestion)
        {
            BaseDiversityQuestion sourceDiversityQuestion = (BaseDiversityQuestion)(source);

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


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

        
    }


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

        _QuestionText = (String)(HELPER_QuestionText.readExternal (_QuestionText, vals.get(FIELD_QuestionText))); //
        _AustraliaOnly = (Boolean)(HELPER_AustraliaOnly.readExternal (_AustraliaOnly, vals.get(FIELD_AustraliaOnly))); //
        _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 (FIELD_QuestionText, HELPER_QuestionText.writeExternal (_QuestionText));
        vals.put (FIELD_AustraliaOnly, HELPER_AustraliaOnly.writeExternal (_AustraliaOnly));
        vals.put (MULTIPLEREFERENCE_Answers, _Answers.writeExternalData());
        
    }


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

        if (other instanceof BaseDiversityQuestion)
        {
            BaseDiversityQuestion otherDiversityQuestion = (BaseDiversityQuestion)(other);

            
            if (!HELPER_QuestionText.compare(this._QuestionText, otherDiversityQuestion._QuestionText))
            {
                listener.notifyFieldChange(this, other, FIELD_QuestionText, HELPER_QuestionText.toObject(this._QuestionText), HELPER_QuestionText.toObject(otherDiversityQuestion._QuestionText));
            }
            if (!HELPER_AustraliaOnly.compare(this._AustraliaOnly, otherDiversityQuestion._AustraliaOnly))
            {
                listener.notifyFieldChange(this, other, FIELD_AustraliaOnly, HELPER_AustraliaOnly.toObject(this._AustraliaOnly), HELPER_AustraliaOnly.toObject(otherDiversityQuestion._AustraliaOnly));
            }

            // Compare single assocs
            

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


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

        
    }


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

        visitor.visitField(this, FIELD_QuestionText, HELPER_QuestionText.toObject(getQuestionText()));
        visitor.visitField(this, FIELD_AustraliaOnly, HELPER_AustraliaOnly.toObject(getAustraliaOnly()));
        visitor.visitAssociation (_Answers);
        
    }


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

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


    public static DiversityQuestion createDiversityQuestion (ObjectTransaction transaction) throws StorageException
    {
        DiversityQuestion     result = new DiversityQuestion ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static DiversityQuestion getDiversityQuestionByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (DiversityQuestion)(transaction.getObjectByID (REFERENCE_DiversityQuestion, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_QuestionText))
        {
            return filter.matches (getQuestionText ());
        }
        else if (attribName.equals (FIELD_AustraliaOnly))
        {
            return filter.matches (getAustraliaOnly ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andQuestionText (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_diversity_question.question_text", "QuestionText");
                return this;
            }
            
            public SearchAll andAustraliaOnly (QueryFilter<Boolean> filter)
            {
                filter.addFilter (context, "tl_diversity_question.australia_only", "AustraliaOnly");
                return this;
            }
            
                public DiversityQuestion[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_DiversityQuestion, SEARCH_All, criteria);
            Set<DiversityQuestion>   typedResults = new LinkedHashSet <DiversityQuestion> ();
            for (BaseBusinessClass bbcResult : results)
            {
                DiversityQuestion aResult = (DiversityQuestion)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new DiversityQuestion[0]);
                            
        }
    }

        
                public static DiversityQuestion[]
             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_QuestionText))
        {
            return HELPER_QuestionText.toObject (getQuestionText ());
        }
        else if (attribName.equals (FIELD_AustraliaOnly))
        {
            return HELPER_AustraliaOnly.toObject (getAustraliaOnly ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_QuestionText))
        {
            return HELPER_QuestionText;
        }
        else if (attribName.equals (FIELD_AustraliaOnly))
        {
            return HELPER_AustraliaOnly;
        }
        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_QuestionText))
        {
            setQuestionText ((String)(HELPER_QuestionText.fromObject (_QuestionText, attribValue)));            
        }
        else if (attribName.equals (FIELD_AustraliaOnly))
        {
            setAustraliaOnly ((Boolean)(HELPER_AustraliaOnly.fromObject (_AustraliaOnly, 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_QuestionText))
        {
            return getWriteability_QuestionText ();
        }
        else if (fieldName.equals (FIELD_AustraliaOnly))
        {
            return getWriteability_AustraliaOnly ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Answers))
        {
            return getWriteability_Answers ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_QuestionText () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_QuestionText);
            }
        
            if (getWriteability_AustraliaOnly () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_AustraliaOnly);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_QuestionText.getAttribObject (getClass (), _QuestionText, true, FIELD_QuestionText));
        result.add(HELPER_AustraliaOnly.getAttribObject (getClass (), _AustraliaOnly, false, FIELD_AustraliaOnly));

        return result;
    }


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


    public Object getAttributeMetadata (String attribute, String metadata)
    {
        if (ATTRIBUTES_METADATA_DiversityQuestion.containsKey (attribute))
        {
            return ((Map)ATTRIBUTES_METADATA_DiversityQuestion.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 DiversityQuestionBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<DiversityQuestion>
    {

    /**
     * Get the attribute QuestionText
     */
    public String getQuestionText (DiversityQuestion obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute QuestionText.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setQuestionText (DiversityQuestion obj, String newQuestionText) throws FieldException
    {
        return newQuestionText;
    }

    /**
     * Get the attribute AustraliaOnly
     */
    public Boolean getAustraliaOnly (DiversityQuestion obj, Boolean original)
    {
        return original;
    }

    /**
     * Change the value set for attribute AustraliaOnly.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Boolean setAustraliaOnly (DiversityQuestion obj, Boolean newAustraliaOnly) throws FieldException
    {
        return newAustraliaOnly;
    }

    }

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

        public DiversityQuestionPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Answers"))
            {
                return toAnswers ();
            }                
            if (name.equals ("QuestionText"))
            {
                return toQuestionText ();
            }                
            if (name.equals ("AustraliaOnly"))
            {
                return toAustraliaOnly ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toQuestionText () { return pipe(new ORMAttributePipe<Me, String>(FIELD_QuestionText));  }
        
        public PipeLine<From, Boolean> toAustraliaOnly () { return pipe(new ORMAttributePipe<Me, Boolean>(FIELD_AustraliaOnly));  }
        public DiversityAnswer.DiversityAnswerPipeLineFactory<From, DiversityAnswer> toAnswers () { return toAnswers(Filter.ALL); }        

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

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


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


    public DiversityAnswer 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();
    }

}

    
