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

    // Reference instance for the object
    public static final DiversityAnswer DUMMY_DiversityAnswer = new DummyDiversityAnswer ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Answer = "Answer";
    public static final String SINGLEREFERENCE_Question = "Question";
    public static final String BACKREF_Question = "";

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

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

    // Private attributes corresponding to business object data
    private String _Answer;
    

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

    // Private attributes corresponding to multiple references
    

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

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

    // Arrays of behaviour decorators
    private static final DiversityAnswerBehaviourDecorator[] DiversityAnswer_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Question = DiversityQuestion.BACKREF_Answers;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Question();
            FIELD_Answer_Validators = (AttributeValidator[])setupAttribMetaData_Answer(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_DiversityAnswer.initialiseReference ();
            DUMMY_DiversityAnswer.initialiseReference ();
            DiversityAnswer_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(DiversityAnswer.class).toArray(new DiversityAnswerBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Answers");
        metaInfo.put ("dbcol", "question_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Question");
        metaInfo.put ("type", "DiversityQuestion");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for DiversityAnswer.Question:", metaInfo);
        ATTRIBUTES_METADATA_DiversityAnswer.put (SINGLEREFERENCE_Question, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Answer(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "answer");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Answer");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for DiversityAnswer.Answer:", metaInfo);
        ATTRIBUTES_METADATA_DiversityAnswer.put (FIELD_Answer, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Answer = (String)(HELPER_Answer.initialise (_Answer));
    }


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

        _Question = new SingleAssociation<DiversityAnswer, DiversityQuestion> (this, SINGLEREFERENCE_Question, DiversityQuestion.MULTIPLEREFERENCE_Answers, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_diversity_answer");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Question = new SingleAssociation<DiversityAnswer, DiversityQuestion> (this, SINGLEREFERENCE_Question, DiversityQuestion.MULTIPLEREFERENCE_Answers, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_diversity_answer");
        
        
        return this;
    }

    

    /**
     * Get the attribute Answer
     */
    public String getAnswer ()
    {
        assertValid();
        String valToReturn = _Answer;

            for (DiversityAnswerBehaviourDecorator bhd : DiversityAnswer_BehaviourDecorators)
            {
                valToReturn = bhd.getAnswer ((DiversityAnswer)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 preAnswerChange (String newAnswer) 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 postAnswerChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Answer.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setAnswer (String newAnswer) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Answer.compare (_Answer, newAnswer);
        
        try
        {
            for (DiversityAnswerBehaviourDecorator bhd : DiversityAnswer_BehaviourDecorators)
            {
                newAnswer = bhd.setAnswer ((DiversityAnswer)this, newAnswer);
                oldAndNewIdentical = HELPER_Answer.compare (_Answer, newAnswer);
            }

            BusinessObjectParser.assertFieldCondition (newAnswer != null, this, FIELD_Answer, "mandatory");
            

            if (FIELD_Answer_Validators.length > 0)
            {
                Object newAnswerObj = HELPER_Answer.toObject (newAnswer);

                if (newAnswerObj != null)
                {
                    int     loopMax = FIELD_Answer_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_DiversityAnswer.get (FIELD_Answer);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Answer () != FieldWriteability.FALSE, "Field  Answer is not writeable");
            preAnswerChange (newAnswer);
            markFieldChange (FIELD_Answer);
            _Answer = newAnswer;            
            postFieldChange (FIELD_Answer);
            postAnswerChange ();
        }
    }



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

        
        result.add("Question");
        

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


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return DiversityQuestion.MULTIPLEREFERENCE_Answers ;
        }
        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_Question))
        {
            return getQuestion ();
        }
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


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


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


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



    /**
     * 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 DiversityAnswer:", 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 (getWriteability_Question () != FieldWriteability.FALSE, "Assoc Question is not writeable");
            preQuestionChange (newQuestion);
            DiversityQuestion oldQuestion = getQuestion ();

                    if (oldQuestion != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Question.set (null);
                        oldQuestion.removeFromAnswers ((DiversityAnswer)(this));
                    }

                    _Question.set (newQuestion);

                    if (newQuestion != null)
                    {
                        newQuestion.addToAnswers ((DiversityAnswer)(this));
                    }
                
            postQuestionChange ();
        }
    }

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

        

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


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

        return super.getMultiAssocAt(attribName, index);
    }


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

        super.addToMultiAssoc(attribName, newElement);
    }

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

        super.removeFromMultiAssoc(attribName, oldElement);
    }


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

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        

        return super.__isMultiAssocLoaded(attribName);
    }

    



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

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

        super.onDelete ();
    }


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


    public DiversityAnswer referenceInstance ()
    {
        return REFERENCE_DiversityAnswer;
    }


    public DiversityAnswer getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getDiversityAnswerByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_DiversityAnswer;
    }


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

        tl_diversity_answerPSet.setAttrib (FIELD_ObjectID, myID);
        tl_diversity_answerPSet.setAttrib (FIELD_Answer, HELPER_Answer.toObject (_Answer)); //
        _Question.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_diversity_answerPSet = allSets.getPersistentSet (objectID, "tl_diversity_answer");

        _Answer = (String)(HELPER_Answer.fromObject (_Answer, tl_diversity_answerPSet.getAttrib (FIELD_Answer))); //
        _Question.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof DiversityAnswer)
        {
            DiversityAnswer otherDiversityAnswer = (DiversityAnswer)other;
            
            try
            {
                setAnswer (otherDiversityAnswer.getAnswer ());
            }
            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 BaseDiversityAnswer)
        {
            BaseDiversityAnswer sourceDiversityAnswer = (BaseDiversityAnswer)(source);

            _Answer = sourceDiversityAnswer._Answer;
            
        }
    }


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

            _Question.copyFrom (sourceDiversityAnswer._Question, linkToGhosts);
            
        }
    }


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

        if (source instanceof BaseDiversityAnswer)
        {
            BaseDiversityAnswer sourceDiversityAnswer = (BaseDiversityAnswer)(source);

            
        }
    }


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

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


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

        _Answer = (String)(HELPER_Answer.readExternal (_Answer, vals.get(FIELD_Answer))); //
        _Question.readExternalData(vals.get(SINGLEREFERENCE_Question));
        
    }


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

        vals.put (FIELD_Answer, HELPER_Answer.writeExternal (_Answer));
        vals.put (SINGLEREFERENCE_Question, _Question.writeExternalData());
        
    }


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

        if (other instanceof BaseDiversityAnswer)
        {
            BaseDiversityAnswer otherDiversityAnswer = (BaseDiversityAnswer)(other);

            
            if (!HELPER_Answer.compare(this._Answer, otherDiversityAnswer._Answer))
            {
                listener.notifyFieldChange(this, other, FIELD_Answer, HELPER_Answer.toObject(this._Answer), HELPER_Answer.toObject(otherDiversityAnswer._Answer));
            }

            // Compare single assocs
            _Question.compare (otherDiversityAnswer._Question, listener);
            

            // Compare multiple assocs
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_Answer, HELPER_Answer.toObject(getAnswer()));
        visitor.visitAssociation (_Question);
        
    }


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

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


    public static DiversityAnswer createDiversityAnswer (ObjectTransaction transaction) throws StorageException
    {
        DiversityAnswer     result = new DiversityAnswer ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static DiversityAnswer getDiversityAnswerByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (DiversityAnswer)(transaction.getObjectByID (REFERENCE_DiversityAnswer, objectID));
    }

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


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

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

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

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

            
            public SearchAll andAnswer (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_diversity_answer.answer", "Answer");
                return this;
            }
            
            public SearchAll andQuestion (QueryFilter<DiversityQuestion> filter)
            {
                filter.addFilter (context, "tl_diversity_answer.question_id", "Question");
                return this;
            }
            
                public DiversityAnswer[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_DiversityAnswer, SEARCH_All, criteria);
            Set<DiversityAnswer>   typedResults = new LinkedHashSet <DiversityAnswer> ();
            for (BaseBusinessClass bbcResult : results)
            {
                DiversityAnswer aResult = (DiversityAnswer)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new DiversityAnswer[0]);
                            
        }
    }

        
                public static DiversityAnswer[]
             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_Answer))
        {
            return HELPER_Answer.toObject (getAnswer ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Answer))
        {
            return HELPER_Answer;
        }
        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_Answer))
        {
            setAnswer ((String)(HELPER_Answer.fromObject (_Answer, 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_Answer))
        {
            return getWriteability_Answer ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Question))
        {
            return getWriteability_Question ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


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

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Answer.getAttribObject (getClass (), _Answer, true, FIELD_Answer));

        return result;
    }


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


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

    /**
     * Get the attribute Answer
     */
    public String getAnswer (DiversityAnswer obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Answer.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setAnswer (DiversityAnswer obj, String newAnswer) throws FieldException
    {
        return newAnswer;
    }

    }

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

        public DiversityAnswerPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Answer"))
            {
                return toAnswer ();
            }                
            if (name.equals ("Question"))
            {
                return toQuestion ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toAnswer () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Answer));  }
        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 boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


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

}

    
