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

    // Reference instance for the object
    public static final Narrative DUMMY_Narrative = new DummyNarrative ();

    // Static constants corresponding to field names
    
    public static final String FIELD_NarrativeCode = "NarrativeCode";
    public static final String FIELD_Description = "Description";
    public static final String FIELD_GraphicNotes = "GraphicNotes";
    public static final String FIELD_SummaryNotes = "SummaryNotes";
    public static final String FIELD_ModConnect = "ModConnect";
    public static final String FIELD_NarrativeNotes = "NarrativeNotes";
    public static final String FIELD_DevelNarrative = "DevelNarrative";
    public static final String FIELD_Question = "Question";
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String BACKREF_Level = "";
    public static final String MULTIPLEREFERENCE_Results = "Results";
    public static final String BACKREF_Results = "";
    public static final String MULTIPLEREFERENCE_FactorScores = "FactorScores";
    public static final String BACKREF_FactorScores = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Narrative> HELPER_NarrativeCode = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_Description = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_GraphicNotes = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_SummaryNotes = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_ModConnect = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_NarrativeNotes = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_DevelNarrative = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Narrative> HELPER_Question = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _NarrativeCode;
    private String _Description;
    private String _GraphicNotes;
    private String _SummaryNotes;
    private String _ModConnect;
    private String _NarrativeNotes;
    private String _DevelNarrative;
    private String _Question;
    

    // Private attributes corresponding to single references
    private SingleAssociation<Narrative, Level> _Level;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<Narrative, FactorScoreResult> _Results;
    private MultipleAssociation<Narrative, FactorScore> _FactorScores;
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_NarrativeCode_Validators;
    private static final AttributeValidator[] FIELD_Description_Validators;
    private static final AttributeValidator[] FIELD_GraphicNotes_Validators;
    private static final AttributeValidator[] FIELD_SummaryNotes_Validators;
    private static final AttributeValidator[] FIELD_ModConnect_Validators;
    private static final AttributeValidator[] FIELD_NarrativeNotes_Validators;
    private static final AttributeValidator[] FIELD_DevelNarrative_Validators;
    private static final AttributeValidator[] FIELD_Question_Validators;
    

    // Arrays of behaviour decorators
    private static final NarrativeBehaviourDecorator[] Narrative_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Results = FactorScoreResult.BACKREF_Narrative;
            String tmp_FactorScores = FactorScore.BACKREF_Narrative;
            String tmp_Level = Level.BACKREF_Narratives;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Results();
            setupAssocMetaData_FactorScores();
            setupAssocMetaData_Level();
            FIELD_NarrativeCode_Validators = (AttributeValidator[])setupAttribMetaData_NarrativeCode(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Description_Validators = (AttributeValidator[])setupAttribMetaData_Description(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_GraphicNotes_Validators = (AttributeValidator[])setupAttribMetaData_GraphicNotes(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_SummaryNotes_Validators = (AttributeValidator[])setupAttribMetaData_SummaryNotes(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ModConnect_Validators = (AttributeValidator[])setupAttribMetaData_ModConnect(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_NarrativeNotes_Validators = (AttributeValidator[])setupAttribMetaData_NarrativeNotes(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_DevelNarrative_Validators = (AttributeValidator[])setupAttribMetaData_DevelNarrative(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Question_Validators = (AttributeValidator[])setupAttribMetaData_Question(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_Narrative.initialiseReference ();
            DUMMY_Narrative.initialiseReference ();
            Narrative_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Narrative.class).toArray(new NarrativeBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Narrative");
        metaInfo.put ("name", "Results");
        metaInfo.put ("type", "FactorScoreResult");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.Results:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (MULTIPLEREFERENCE_Results, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_FactorScores()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Narrative");
        metaInfo.put ("name", "FactorScores");
        metaInfo.put ("type", "FactorScore");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.FactorScores:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (MULTIPLEREFERENCE_FactorScores, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Level()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Narratives");
        metaInfo.put ("dbcol", "level_number");
        metaInfo.put ("name", "Level");
        metaInfo.put ("type", "Level");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.Level:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (SINGLEREFERENCE_Level, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_NarrativeCode(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "narrative_code");
        metaInfo.put ("length", "15");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "NarrativeCode");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.NarrativeCode:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_NarrativeCode, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "narrative_desc");
        metaInfo.put ("length", "30");
        metaInfo.put ("name", "Description");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.Description:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_Description, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "graphic_notes");
        metaInfo.put ("name", "GraphicNotes");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.GraphicNotes:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_GraphicNotes, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "exec_sum_notes");
        metaInfo.put ("name", "SummaryNotes");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.SummaryNotes:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_SummaryNotes, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "mod_connect_flag");
        metaInfo.put ("length", "15");
        metaInfo.put ("name", "ModConnect");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.ModConnect:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_ModConnect, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "narrative_notes");
        metaInfo.put ("name", "NarrativeNotes");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.NarrativeNotes:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_NarrativeNotes, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "devel_narrative");
        metaInfo.put ("length", "128");
        metaInfo.put ("name", "DevelNarrative");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.DevelNarrative:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_DevelNarrative, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "question");
        metaInfo.put ("name", "Question");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Narrative.Question:", metaInfo);
        ATTRIBUTES_METADATA_Narrative.put (FIELD_Question, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _NarrativeCode = (String)(HELPER_NarrativeCode.initialise (_NarrativeCode));
        _Description = (String)(HELPER_Description.initialise (_Description));
        _GraphicNotes = (String)(HELPER_GraphicNotes.initialise (_GraphicNotes));
        _SummaryNotes = (String)(HELPER_SummaryNotes.initialise (_SummaryNotes));
        _ModConnect = (String)(HELPER_ModConnect.initialise (_ModConnect));
        _NarrativeNotes = (String)(HELPER_NarrativeNotes.initialise (_NarrativeNotes));
        _DevelNarrative = (String)(HELPER_DevelNarrative.initialise (_DevelNarrative));
        _Question = (String)(HELPER_Question.initialise (_Question));
    }


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

        _Level = new SingleAssociation<Narrative, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_Narratives, Level.REFERENCE_Level, "rs_narrative");
        _Results = new MultipleAssociation<Narrative, FactorScoreResult> (this, MULTIPLEREFERENCE_Results, FactorScoreResult.SINGLEREFERENCE_Narrative, FactorScoreResult.REFERENCE_FactorScoreResult);
        _FactorScores = new MultipleAssociation<Narrative, FactorScore> (this, MULTIPLEREFERENCE_FactorScores, FactorScore.SINGLEREFERENCE_Narrative, FactorScore.REFERENCE_FactorScore);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Level = new SingleAssociation<Narrative, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_Narratives, Level.REFERENCE_Level, "rs_narrative");
        _Results = new MultipleAssociation<Narrative, FactorScoreResult> (this, MULTIPLEREFERENCE_Results, FactorScoreResult.SINGLEREFERENCE_Narrative, FactorScoreResult.REFERENCE_FactorScoreResult);
        _FactorScores = new MultipleAssociation<Narrative, FactorScore> (this, MULTIPLEREFERENCE_FactorScores, FactorScore.SINGLEREFERENCE_Narrative, FactorScore.REFERENCE_FactorScore);
        
        
        return this;
    }

    

    /**
     * Get the attribute NarrativeCode
     */
    public String getNarrativeCode ()
    {
        assertValid();
        String valToReturn = _NarrativeCode;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getNarrativeCode ((Narrative)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 preNarrativeCodeChange (String newNarrativeCode) 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 postNarrativeCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute NarrativeCode.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setNarrativeCode (String newNarrativeCode) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_NarrativeCode.compare (_NarrativeCode, newNarrativeCode);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newNarrativeCode = bhd.setNarrativeCode ((Narrative)this, newNarrativeCode);
                oldAndNewIdentical = HELPER_NarrativeCode.compare (_NarrativeCode, newNarrativeCode);
            }

            BusinessObjectParser.assertFieldCondition (newNarrativeCode != null, this, FIELD_NarrativeCode, "mandatory");
            

            if (FIELD_NarrativeCode_Validators.length > 0)
            {
                Object newNarrativeCodeObj = HELPER_NarrativeCode.toObject (newNarrativeCode);

                if (newNarrativeCodeObj != null)
                {
                    int     loopMax = FIELD_NarrativeCode_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_NarrativeCode);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_NarrativeCode () != FieldWriteability.FALSE, "Field  NarrativeCode is not writeable");
            preNarrativeCodeChange (newNarrativeCode);
            markFieldChange (FIELD_NarrativeCode);
            _NarrativeCode = newNarrativeCode;            
            postFieldChange (FIELD_NarrativeCode);
            postNarrativeCodeChange ();
        }
    }

    /**
     * Get the attribute Description
     */
    public String getDescription ()
    {
        assertValid();
        String valToReturn = _Description;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getDescription ((Narrative)this, valToReturn);
            }
            
            return valToReturn;
        
    }


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


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

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

    /**
     * Set the attribute Description.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setDescription (String newDescription) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Description.compare (_Description, newDescription);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newDescription = bhd.setDescription ((Narrative)this, newDescription);
                oldAndNewIdentical = HELPER_Description.compare (_Description, newDescription);
            }

            

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

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

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

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

    /**
     * Get the attribute GraphicNotes
     */
    public String getGraphicNotes ()
    {
        assertValid();
        String valToReturn = _GraphicNotes;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getGraphicNotes ((Narrative)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 preGraphicNotesChange (String newGraphicNotes) 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 postGraphicNotesChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute GraphicNotes.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setGraphicNotes (String newGraphicNotes) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_GraphicNotes.compare (_GraphicNotes, newGraphicNotes);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newGraphicNotes = bhd.setGraphicNotes ((Narrative)this, newGraphicNotes);
                oldAndNewIdentical = HELPER_GraphicNotes.compare (_GraphicNotes, newGraphicNotes);
            }

            

            if (FIELD_GraphicNotes_Validators.length > 0)
            {
                Object newGraphicNotesObj = HELPER_GraphicNotes.toObject (newGraphicNotes);

                if (newGraphicNotesObj != null)
                {
                    int     loopMax = FIELD_GraphicNotes_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_GraphicNotes);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_GraphicNotes () != FieldWriteability.FALSE, "Field  GraphicNotes is not writeable");
            preGraphicNotesChange (newGraphicNotes);
            markFieldChange (FIELD_GraphicNotes);
            _GraphicNotes = newGraphicNotes;            
            postFieldChange (FIELD_GraphicNotes);
            postGraphicNotesChange ();
        }
    }

    /**
     * Get the attribute SummaryNotes
     */
    public String getSummaryNotes ()
    {
        assertValid();
        String valToReturn = _SummaryNotes;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getSummaryNotes ((Narrative)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 preSummaryNotesChange (String newSummaryNotes) 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 postSummaryNotesChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute SummaryNotes.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setSummaryNotes (String newSummaryNotes) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_SummaryNotes.compare (_SummaryNotes, newSummaryNotes);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newSummaryNotes = bhd.setSummaryNotes ((Narrative)this, newSummaryNotes);
                oldAndNewIdentical = HELPER_SummaryNotes.compare (_SummaryNotes, newSummaryNotes);
            }

            

            if (FIELD_SummaryNotes_Validators.length > 0)
            {
                Object newSummaryNotesObj = HELPER_SummaryNotes.toObject (newSummaryNotes);

                if (newSummaryNotesObj != null)
                {
                    int     loopMax = FIELD_SummaryNotes_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_SummaryNotes);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_SummaryNotes () != FieldWriteability.FALSE, "Field  SummaryNotes is not writeable");
            preSummaryNotesChange (newSummaryNotes);
            markFieldChange (FIELD_SummaryNotes);
            _SummaryNotes = newSummaryNotes;            
            postFieldChange (FIELD_SummaryNotes);
            postSummaryNotesChange ();
        }
    }

    /**
     * Get the attribute ModConnect
     */
    public String getModConnect ()
    {
        assertValid();
        String valToReturn = _ModConnect;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getModConnect ((Narrative)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 preModConnectChange (String newModConnect) 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 postModConnectChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ModConnect.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setModConnect (String newModConnect) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ModConnect.compare (_ModConnect, newModConnect);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newModConnect = bhd.setModConnect ((Narrative)this, newModConnect);
                oldAndNewIdentical = HELPER_ModConnect.compare (_ModConnect, newModConnect);
            }

            

            if (FIELD_ModConnect_Validators.length > 0)
            {
                Object newModConnectObj = HELPER_ModConnect.toObject (newModConnect);

                if (newModConnectObj != null)
                {
                    int     loopMax = FIELD_ModConnect_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_ModConnect);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ModConnect () != FieldWriteability.FALSE, "Field  ModConnect is not writeable");
            preModConnectChange (newModConnect);
            markFieldChange (FIELD_ModConnect);
            _ModConnect = newModConnect;            
            postFieldChange (FIELD_ModConnect);
            postModConnectChange ();
        }
    }

    /**
     * Get the attribute NarrativeNotes
     */
    public String getNarrativeNotes ()
    {
        assertValid();
        String valToReturn = _NarrativeNotes;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getNarrativeNotes ((Narrative)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 preNarrativeNotesChange (String newNarrativeNotes) 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 postNarrativeNotesChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute NarrativeNotes.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setNarrativeNotes (String newNarrativeNotes) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_NarrativeNotes.compare (_NarrativeNotes, newNarrativeNotes);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newNarrativeNotes = bhd.setNarrativeNotes ((Narrative)this, newNarrativeNotes);
                oldAndNewIdentical = HELPER_NarrativeNotes.compare (_NarrativeNotes, newNarrativeNotes);
            }

            

            if (FIELD_NarrativeNotes_Validators.length > 0)
            {
                Object newNarrativeNotesObj = HELPER_NarrativeNotes.toObject (newNarrativeNotes);

                if (newNarrativeNotesObj != null)
                {
                    int     loopMax = FIELD_NarrativeNotes_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_NarrativeNotes);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_NarrativeNotes () != FieldWriteability.FALSE, "Field  NarrativeNotes is not writeable");
            preNarrativeNotesChange (newNarrativeNotes);
            markFieldChange (FIELD_NarrativeNotes);
            _NarrativeNotes = newNarrativeNotes;            
            postFieldChange (FIELD_NarrativeNotes);
            postNarrativeNotesChange ();
        }
    }

    /**
     * Get the attribute DevelNarrative
     */
    public String getDevelNarrative ()
    {
        assertValid();
        String valToReturn = _DevelNarrative;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getDevelNarrative ((Narrative)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 preDevelNarrativeChange (String newDevelNarrative) 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 postDevelNarrativeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute DevelNarrative.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setDevelNarrative (String newDevelNarrative) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_DevelNarrative.compare (_DevelNarrative, newDevelNarrative);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newDevelNarrative = bhd.setDevelNarrative ((Narrative)this, newDevelNarrative);
                oldAndNewIdentical = HELPER_DevelNarrative.compare (_DevelNarrative, newDevelNarrative);
            }

            

            if (FIELD_DevelNarrative_Validators.length > 0)
            {
                Object newDevelNarrativeObj = HELPER_DevelNarrative.toObject (newDevelNarrative);

                if (newDevelNarrativeObj != null)
                {
                    int     loopMax = FIELD_DevelNarrative_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_DevelNarrative);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_DevelNarrative () != FieldWriteability.FALSE, "Field  DevelNarrative is not writeable");
            preDevelNarrativeChange (newDevelNarrative);
            markFieldChange (FIELD_DevelNarrative);
            _DevelNarrative = newDevelNarrative;            
            postFieldChange (FIELD_DevelNarrative);
            postDevelNarrativeChange ();
        }
    }

    /**
     * Get the attribute Question
     */
    public String getQuestion ()
    {
        assertValid();
        String valToReturn = _Question;

            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                valToReturn = bhd.getQuestion ((Narrative)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 preQuestionChange (String newQuestion) 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 postQuestionChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Question.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setQuestion (String newQuestion) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Question.compare (_Question, newQuestion);
        
        try
        {
            for (NarrativeBehaviourDecorator bhd : Narrative_BehaviourDecorators)
            {
                newQuestion = bhd.setQuestion ((Narrative)this, newQuestion);
                oldAndNewIdentical = HELPER_Question.compare (_Question, newQuestion);
            }

            

            if (FIELD_Question_Validators.length > 0)
            {
                Object newQuestionObj = HELPER_Question.toObject (newQuestion);

                if (newQuestionObj != null)
                {
                    int     loopMax = FIELD_Question_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Narrative.get (FIELD_Question);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Question () != FieldWriteability.FALSE, "Field  Question is not writeable");
            preQuestionChange (newQuestion);
            markFieldChange (FIELD_Question);
            _Question = newQuestion;            
            postFieldChange (FIELD_Question);
            postQuestionChange ();
        }
    }



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

        
        result.add("Level");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return _Level.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_Level))
        {
            return Level.MULTIPLEREFERENCE_Narratives ;
        }
        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_Level))
        {
            return getLevel ();
        }
        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_Level))
        {
            return getLevel (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_Level))
        {
            return getLevelID ();
        }
        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_Level))
        {
            setLevel ((Level)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getLevelID ()
    {
        assertValid();
        
        if (_Level == null)
        {
            return null;
        }
        else
        {
            return _Level.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 preLevelChange (Level newLevel) 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 postLevelChange () throws FieldException
    {
    }



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

        if (_Level.wouldReferencedChange (newLevel))
        {
            assertValid();
            Debug.assertion (getWriteability_Level () != FieldWriteability.FALSE, "Assoc Level is not writeable");
            preLevelChange (newLevel);
            Level oldLevel = getLevel ();

                    if (oldLevel != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Level.set (null);
                        oldLevel.removeFromNarratives ((Narrative)(this));
                    }

                    _Level.set (newLevel);

                    if (newLevel != null)
                    {
                        newLevel.addToNarratives ((Narrative)(this));
                    }
                
            postLevelChange ();
        }
    }

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

        
        result.add("Results");
        
        result.add("FactorScores");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return FactorScoreResult.REFERENCE_FactorScoreResult ;
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return FactorScore.REFERENCE_FactorScore ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return FactorScoreResult.SINGLEREFERENCE_Narrative ;
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return FactorScore.SINGLEREFERENCE_Narrative ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return this.getResultsAt(index);
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return this.getFactorScoresAt(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_Results.equals(attribName))
        {
            addToResults((FactorScoreResult)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            addToFactorScores((FactorScore)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_Results.equals(attribName))
        {
            removeFromResults((FactorScoreResult)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            removeFromFactorScores((FactorScore)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            _Results.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            _FactorScores.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return _Results.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return _FactorScores.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_Results ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getResultsCount () throws StorageException
    {
        assertValid();
        return _Results.getReferencedObjectsCount ();
    }


    public void addToResults (FactorScoreResult newElement) throws StorageException
    {
        if (_Results.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Results () != FieldWriteability.FALSE, "MultiAssoc Results is not writeable (add)");
            _Results.appendElement (newElement);

            try
            {
                if (newElement.getNarrative () != this)
                {
                    newElement.setNarrative ((Narrative)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromResults (FactorScoreResult elementToRemove) throws StorageException
    {
        if (_Results.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Results () != FieldWriteability.FALSE, "MultiAssoc Results is not writeable (remove)");
            _Results.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getNarrative () != null)
                {
                    elementToRemove.setNarrative (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public FactorScoreResult getResultsAt (int index) throws StorageException
    {
        return (FactorScoreResult)(_Results.getElementAt (index));
    }


    public SortedSet<FactorScoreResult> getResultsSet () throws StorageException
    {
        return _Results.getSet ();
    }

    public FieldWriteability getWriteability_FactorScores ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getFactorScoresCount () throws StorageException
    {
        assertValid();
        return _FactorScores.getReferencedObjectsCount ();
    }


    public void addToFactorScores (FactorScore newElement) throws StorageException
    {
        if (_FactorScores.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_FactorScores () != FieldWriteability.FALSE, "MultiAssoc FactorScores is not writeable (add)");
            _FactorScores.appendElement (newElement);

            try
            {
                if (newElement.getNarrative () != this)
                {
                    newElement.setNarrative ((Narrative)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromFactorScores (FactorScore elementToRemove) throws StorageException
    {
        if (_FactorScores.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_FactorScores () != FieldWriteability.FALSE, "MultiAssoc FactorScores is not writeable (remove)");
            _FactorScores.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getNarrative () != null)
                {
                    elementToRemove.setNarrative (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public FactorScore getFactorScoresAt (int index) throws StorageException
    {
        return (FactorScore)(_FactorScores.getElementAt (index));
    }


    public SortedSet<FactorScore> getFactorScoresSet () throws StorageException
    {
        return _FactorScores.getSet ();
    }



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

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Narratives from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Level.set (null);
                    referenced.removeFromNarratives ((Narrative)this);
                }
            }
        
            for(FactorScoreResult referenced : CollectionUtils.reverse(getResultsSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Narrative from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setNarrative(null);
            }

            for(FactorScore referenced : CollectionUtils.reverse(getFactorScoresSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Narrative from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setNarrative(null);
            }

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

        super.onDelete ();
    }


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


    public Narrative referenceInstance ()
    {
        return REFERENCE_Narrative;
    }


    public Narrative getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getNarrativeByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Narrative;
    }


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





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

        rs_narrativePSet.setAttrib (FIELD_ObjectID, myID);
        rs_narrativePSet.setAttrib (FIELD_NarrativeCode, HELPER_NarrativeCode.toObject (_NarrativeCode)); //
        rs_narrativePSet.setAttrib (FIELD_Description, HELPER_Description.toObject (_Description)); //
        rs_narrativePSet.setAttrib (FIELD_GraphicNotes, HELPER_GraphicNotes.toObject (_GraphicNotes)); //
        rs_narrativePSet.setAttrib (FIELD_SummaryNotes, HELPER_SummaryNotes.toObject (_SummaryNotes)); //
        rs_narrativePSet.setAttrib (FIELD_ModConnect, HELPER_ModConnect.toObject (_ModConnect)); //
        rs_narrativePSet.setAttrib (FIELD_NarrativeNotes, HELPER_NarrativeNotes.toObject (_NarrativeNotes)); //
        rs_narrativePSet.setAttrib (FIELD_DevelNarrative, HELPER_DevelNarrative.toObject (_DevelNarrative)); //
        rs_narrativePSet.setAttrib (FIELD_Question, HELPER_Question.toObject (_Question)); //
        _Level.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   rs_narrativePSet = allSets.getPersistentSet (objectID, "rs_narrative");

        _NarrativeCode = (String)(HELPER_NarrativeCode.fromObject (_NarrativeCode, rs_narrativePSet.getAttrib (FIELD_NarrativeCode))); //
        _Description = (String)(HELPER_Description.fromObject (_Description, rs_narrativePSet.getAttrib (FIELD_Description))); //
        _GraphicNotes = (String)(HELPER_GraphicNotes.fromObject (_GraphicNotes, rs_narrativePSet.getAttrib (FIELD_GraphicNotes))); //
        _SummaryNotes = (String)(HELPER_SummaryNotes.fromObject (_SummaryNotes, rs_narrativePSet.getAttrib (FIELD_SummaryNotes))); //
        _ModConnect = (String)(HELPER_ModConnect.fromObject (_ModConnect, rs_narrativePSet.getAttrib (FIELD_ModConnect))); //
        _NarrativeNotes = (String)(HELPER_NarrativeNotes.fromObject (_NarrativeNotes, rs_narrativePSet.getAttrib (FIELD_NarrativeNotes))); //
        _DevelNarrative = (String)(HELPER_DevelNarrative.fromObject (_DevelNarrative, rs_narrativePSet.getAttrib (FIELD_DevelNarrative))); //
        _Question = (String)(HELPER_Question.fromObject (_Question, rs_narrativePSet.getAttrib (FIELD_Question))); //
        _Level.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof Narrative)
        {
            Narrative otherNarrative = (Narrative)other;
            
            try
            {
                setNarrativeCode (otherNarrative.getNarrativeCode ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setDescription (otherNarrative.getDescription ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setGraphicNotes (otherNarrative.getGraphicNotes ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setSummaryNotes (otherNarrative.getSummaryNotes ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setModConnect (otherNarrative.getModConnect ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setNarrativeNotes (otherNarrative.getNarrativeNotes ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setDevelNarrative (otherNarrative.getDevelNarrative ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setQuestion (otherNarrative.getQuestion ());
            }
            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 BaseNarrative)
        {
            BaseNarrative sourceNarrative = (BaseNarrative)(source);

            _NarrativeCode = sourceNarrative._NarrativeCode;
            _Description = sourceNarrative._Description;
            _GraphicNotes = sourceNarrative._GraphicNotes;
            _SummaryNotes = sourceNarrative._SummaryNotes;
            _ModConnect = sourceNarrative._ModConnect;
            _NarrativeNotes = sourceNarrative._NarrativeNotes;
            _DevelNarrative = sourceNarrative._DevelNarrative;
            _Question = sourceNarrative._Question;
            
        }
    }


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

            _Level.copyFrom (sourceNarrative._Level, 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 BaseNarrative)
        {
            BaseNarrative sourceNarrative = (BaseNarrative)(source);

            _Results.copyFrom (sourceNarrative._Results, linkToGhosts);
            _FactorScores.copyFrom (sourceNarrative._FactorScores, 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);

        _NarrativeCode = (String)(HELPER_NarrativeCode.readExternal (_NarrativeCode, vals.get(FIELD_NarrativeCode))); //
        _Description = (String)(HELPER_Description.readExternal (_Description, vals.get(FIELD_Description))); //
        _GraphicNotes = (String)(HELPER_GraphicNotes.readExternal (_GraphicNotes, vals.get(FIELD_GraphicNotes))); //
        _SummaryNotes = (String)(HELPER_SummaryNotes.readExternal (_SummaryNotes, vals.get(FIELD_SummaryNotes))); //
        _ModConnect = (String)(HELPER_ModConnect.readExternal (_ModConnect, vals.get(FIELD_ModConnect))); //
        _NarrativeNotes = (String)(HELPER_NarrativeNotes.readExternal (_NarrativeNotes, vals.get(FIELD_NarrativeNotes))); //
        _DevelNarrative = (String)(HELPER_DevelNarrative.readExternal (_DevelNarrative, vals.get(FIELD_DevelNarrative))); //
        _Question = (String)(HELPER_Question.readExternal (_Question, vals.get(FIELD_Question))); //
        _Level.readExternalData(vals.get(SINGLEREFERENCE_Level));
        _Results.readExternalData(vals.get(MULTIPLEREFERENCE_Results));
        _FactorScores.readExternalData(vals.get(MULTIPLEREFERENCE_FactorScores));
        
    }


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

        vals.put (FIELD_NarrativeCode, HELPER_NarrativeCode.writeExternal (_NarrativeCode));
        vals.put (FIELD_Description, HELPER_Description.writeExternal (_Description));
        vals.put (FIELD_GraphicNotes, HELPER_GraphicNotes.writeExternal (_GraphicNotes));
        vals.put (FIELD_SummaryNotes, HELPER_SummaryNotes.writeExternal (_SummaryNotes));
        vals.put (FIELD_ModConnect, HELPER_ModConnect.writeExternal (_ModConnect));
        vals.put (FIELD_NarrativeNotes, HELPER_NarrativeNotes.writeExternal (_NarrativeNotes));
        vals.put (FIELD_DevelNarrative, HELPER_DevelNarrative.writeExternal (_DevelNarrative));
        vals.put (FIELD_Question, HELPER_Question.writeExternal (_Question));
        vals.put (SINGLEREFERENCE_Level, _Level.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Results, _Results.writeExternalData());
        vals.put (MULTIPLEREFERENCE_FactorScores, _FactorScores.writeExternalData());
        
    }


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

        if (other instanceof BaseNarrative)
        {
            BaseNarrative otherNarrative = (BaseNarrative)(other);

            
            if (!HELPER_NarrativeCode.compare(this._NarrativeCode, otherNarrative._NarrativeCode))
            {
                listener.notifyFieldChange(this, other, FIELD_NarrativeCode, HELPER_NarrativeCode.toObject(this._NarrativeCode), HELPER_NarrativeCode.toObject(otherNarrative._NarrativeCode));
            }
            if (!HELPER_Description.compare(this._Description, otherNarrative._Description))
            {
                listener.notifyFieldChange(this, other, FIELD_Description, HELPER_Description.toObject(this._Description), HELPER_Description.toObject(otherNarrative._Description));
            }
            if (!HELPER_GraphicNotes.compare(this._GraphicNotes, otherNarrative._GraphicNotes))
            {
                listener.notifyFieldChange(this, other, FIELD_GraphicNotes, HELPER_GraphicNotes.toObject(this._GraphicNotes), HELPER_GraphicNotes.toObject(otherNarrative._GraphicNotes));
            }
            if (!HELPER_SummaryNotes.compare(this._SummaryNotes, otherNarrative._SummaryNotes))
            {
                listener.notifyFieldChange(this, other, FIELD_SummaryNotes, HELPER_SummaryNotes.toObject(this._SummaryNotes), HELPER_SummaryNotes.toObject(otherNarrative._SummaryNotes));
            }
            if (!HELPER_ModConnect.compare(this._ModConnect, otherNarrative._ModConnect))
            {
                listener.notifyFieldChange(this, other, FIELD_ModConnect, HELPER_ModConnect.toObject(this._ModConnect), HELPER_ModConnect.toObject(otherNarrative._ModConnect));
            }
            if (!HELPER_NarrativeNotes.compare(this._NarrativeNotes, otherNarrative._NarrativeNotes))
            {
                listener.notifyFieldChange(this, other, FIELD_NarrativeNotes, HELPER_NarrativeNotes.toObject(this._NarrativeNotes), HELPER_NarrativeNotes.toObject(otherNarrative._NarrativeNotes));
            }
            if (!HELPER_DevelNarrative.compare(this._DevelNarrative, otherNarrative._DevelNarrative))
            {
                listener.notifyFieldChange(this, other, FIELD_DevelNarrative, HELPER_DevelNarrative.toObject(this._DevelNarrative), HELPER_DevelNarrative.toObject(otherNarrative._DevelNarrative));
            }
            if (!HELPER_Question.compare(this._Question, otherNarrative._Question))
            {
                listener.notifyFieldChange(this, other, FIELD_Question, HELPER_Question.toObject(this._Question), HELPER_Question.toObject(otherNarrative._Question));
            }

            // Compare single assocs
            _Level.compare (otherNarrative._Level, listener);
            

            // Compare multiple assocs
            _Results.compare (otherNarrative._Results, listener);
            _FactorScores.compare (otherNarrative._FactorScores, 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_NarrativeCode, HELPER_NarrativeCode.toObject(getNarrativeCode()));
        visitor.visitField(this, FIELD_Description, HELPER_Description.toObject(getDescription()));
        visitor.visitField(this, FIELD_GraphicNotes, HELPER_GraphicNotes.toObject(getGraphicNotes()));
        visitor.visitField(this, FIELD_SummaryNotes, HELPER_SummaryNotes.toObject(getSummaryNotes()));
        visitor.visitField(this, FIELD_ModConnect, HELPER_ModConnect.toObject(getModConnect()));
        visitor.visitField(this, FIELD_NarrativeNotes, HELPER_NarrativeNotes.toObject(getNarrativeNotes()));
        visitor.visitField(this, FIELD_DevelNarrative, HELPER_DevelNarrative.toObject(getDevelNarrative()));
        visitor.visitField(this, FIELD_Question, HELPER_Question.toObject(getQuestion()));
        visitor.visitAssociation (_Level);
        visitor.visitAssociation (_Results);
        visitor.visitAssociation (_FactorScores);
        
    }


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

        if (scope.includes (_Level))
        {
            visitor.visit (_Level);
        }
        if (scope.includes (_Results))
        {
            visitor.visit (_Results);
        }
        if (scope.includes (_FactorScores))
        {
            visitor.visit (_FactorScores);
        }
        
    }


    public static Narrative createNarrative (ObjectTransaction transaction) throws StorageException
    {
        Narrative     result = new Narrative ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Narrative getNarrativeByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Narrative)(transaction.getObjectByID (REFERENCE_Narrative, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_NarrativeCode))
        {
            return filter.matches (getNarrativeCode ());
        }
        else if (attribName.equals (FIELD_Description))
        {
            return filter.matches (getDescription ());
        }
        else if (attribName.equals (FIELD_GraphicNotes))
        {
            return filter.matches (getGraphicNotes ());
        }
        else if (attribName.equals (FIELD_SummaryNotes))
        {
            return filter.matches (getSummaryNotes ());
        }
        else if (attribName.equals (FIELD_ModConnect))
        {
            return filter.matches (getModConnect ());
        }
        else if (attribName.equals (FIELD_NarrativeNotes))
        {
            return filter.matches (getNarrativeNotes ());
        }
        else if (attribName.equals (FIELD_DevelNarrative))
        {
            return filter.matches (getDevelNarrative ());
        }
        else if (attribName.equals (FIELD_Question))
        {
            return filter.matches (getQuestion ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Level))
        {
            return filter.matches (getLevel ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andNarrativeCode (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.narrative_code", "NarrativeCode");
                return this;
            }
            
            public SearchAll andDescription (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.narrative_desc", "Description");
                return this;
            }
            
            public SearchAll andGraphicNotes (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.graphic_notes", "GraphicNotes");
                return this;
            }
            
            public SearchAll andSummaryNotes (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.exec_sum_notes", "SummaryNotes");
                return this;
            }
            
            public SearchAll andModConnect (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.mod_connect_flag", "ModConnect");
                return this;
            }
            
            public SearchAll andNarrativeNotes (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.narrative_notes", "NarrativeNotes");
                return this;
            }
            
            public SearchAll andDevelNarrative (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.devel_narrative", "DevelNarrative");
                return this;
            }
            
            public SearchAll andQuestion (QueryFilter<String> filter)
            {
                filter.addFilter (context, "rs_narrative.question", "Question");
                return this;
            }
            
            public SearchAll andLevel (QueryFilter<Level> filter)
            {
                filter.addFilter (context, "rs_narrative.level_number", "Level");
                return this;
            }
            
                public Narrative[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Narrative, SEARCH_All, criteria);
            Set<Narrative>   typedResults = new LinkedHashSet <Narrative> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Narrative aResult = (Narrative)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Narrative[0]);
                            
        }
    }

        
                public static Narrative[]
             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_NarrativeCode))
        {
            return HELPER_NarrativeCode.toObject (getNarrativeCode ());
        }
        else if (attribName.equals (FIELD_Description))
        {
            return HELPER_Description.toObject (getDescription ());
        }
        else if (attribName.equals (FIELD_GraphicNotes))
        {
            return HELPER_GraphicNotes.toObject (getGraphicNotes ());
        }
        else if (attribName.equals (FIELD_SummaryNotes))
        {
            return HELPER_SummaryNotes.toObject (getSummaryNotes ());
        }
        else if (attribName.equals (FIELD_ModConnect))
        {
            return HELPER_ModConnect.toObject (getModConnect ());
        }
        else if (attribName.equals (FIELD_NarrativeNotes))
        {
            return HELPER_NarrativeNotes.toObject (getNarrativeNotes ());
        }
        else if (attribName.equals (FIELD_DevelNarrative))
        {
            return HELPER_DevelNarrative.toObject (getDevelNarrative ());
        }
        else if (attribName.equals (FIELD_Question))
        {
            return HELPER_Question.toObject (getQuestion ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_NarrativeCode))
        {
            return HELPER_NarrativeCode;
        }
        else if (attribName.equals (FIELD_Description))
        {
            return HELPER_Description;
        }
        else if (attribName.equals (FIELD_GraphicNotes))
        {
            return HELPER_GraphicNotes;
        }
        else if (attribName.equals (FIELD_SummaryNotes))
        {
            return HELPER_SummaryNotes;
        }
        else if (attribName.equals (FIELD_ModConnect))
        {
            return HELPER_ModConnect;
        }
        else if (attribName.equals (FIELD_NarrativeNotes))
        {
            return HELPER_NarrativeNotes;
        }
        else if (attribName.equals (FIELD_DevelNarrative))
        {
            return HELPER_DevelNarrative;
        }
        else if (attribName.equals (FIELD_Question))
        {
            return HELPER_Question;
        }
        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_NarrativeCode))
        {
            setNarrativeCode ((String)(HELPER_NarrativeCode.fromObject (_NarrativeCode, attribValue)));            
        }
        else if (attribName.equals (FIELD_Description))
        {
            setDescription ((String)(HELPER_Description.fromObject (_Description, attribValue)));            
        }
        else if (attribName.equals (FIELD_GraphicNotes))
        {
            setGraphicNotes ((String)(HELPER_GraphicNotes.fromObject (_GraphicNotes, attribValue)));            
        }
        else if (attribName.equals (FIELD_SummaryNotes))
        {
            setSummaryNotes ((String)(HELPER_SummaryNotes.fromObject (_SummaryNotes, attribValue)));            
        }
        else if (attribName.equals (FIELD_ModConnect))
        {
            setModConnect ((String)(HELPER_ModConnect.fromObject (_ModConnect, attribValue)));            
        }
        else if (attribName.equals (FIELD_NarrativeNotes))
        {
            setNarrativeNotes ((String)(HELPER_NarrativeNotes.fromObject (_NarrativeNotes, attribValue)));            
        }
        else if (attribName.equals (FIELD_DevelNarrative))
        {
            setDevelNarrative ((String)(HELPER_DevelNarrative.fromObject (_DevelNarrative, attribValue)));            
        }
        else if (attribName.equals (FIELD_Question))
        {
            setQuestion ((String)(HELPER_Question.fromObject (_Question, 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_NarrativeCode))
        {
            return getWriteability_NarrativeCode ();
        }
        else if (fieldName.equals (FIELD_Description))
        {
            return getWriteability_Description ();
        }
        else if (fieldName.equals (FIELD_GraphicNotes))
        {
            return getWriteability_GraphicNotes ();
        }
        else if (fieldName.equals (FIELD_SummaryNotes))
        {
            return getWriteability_SummaryNotes ();
        }
        else if (fieldName.equals (FIELD_ModConnect))
        {
            return getWriteability_ModConnect ();
        }
        else if (fieldName.equals (FIELD_NarrativeNotes))
        {
            return getWriteability_NarrativeNotes ();
        }
        else if (fieldName.equals (FIELD_DevelNarrative))
        {
            return getWriteability_DevelNarrative ();
        }
        else if (fieldName.equals (FIELD_Question))
        {
            return getWriteability_Question ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Results))
        {
            return getWriteability_Results ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_FactorScores))
        {
            return getWriteability_FactorScores ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Level))
        {
            return getWriteability_Level ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_NarrativeCode () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_NarrativeCode);
            }
        
            if (getWriteability_Description () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Description);
            }
        
            if (getWriteability_GraphicNotes () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_GraphicNotes);
            }
        
            if (getWriteability_SummaryNotes () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_SummaryNotes);
            }
        
            if (getWriteability_ModConnect () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ModConnect);
            }
        
            if (getWriteability_NarrativeNotes () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_NarrativeNotes);
            }
        
            if (getWriteability_DevelNarrative () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_DevelNarrative);
            }
        
            if (getWriteability_Question () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Question);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_NarrativeCode.getAttribObject (getClass (), _NarrativeCode, true, FIELD_NarrativeCode));
        result.add(HELPER_Description.getAttribObject (getClass (), _Description, false, FIELD_Description));
        result.add(HELPER_GraphicNotes.getAttribObject (getClass (), _GraphicNotes, false, FIELD_GraphicNotes));
        result.add(HELPER_SummaryNotes.getAttribObject (getClass (), _SummaryNotes, false, FIELD_SummaryNotes));
        result.add(HELPER_ModConnect.getAttribObject (getClass (), _ModConnect, false, FIELD_ModConnect));
        result.add(HELPER_NarrativeNotes.getAttribObject (getClass (), _NarrativeNotes, false, FIELD_NarrativeNotes));
        result.add(HELPER_DevelNarrative.getAttribObject (getClass (), _DevelNarrative, false, FIELD_DevelNarrative));
        result.add(HELPER_Question.getAttribObject (getClass (), _Question, false, FIELD_Question));

        return result;
    }


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


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

    /**
     * Get the attribute NarrativeCode
     */
    public String getNarrativeCode (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute NarrativeCode.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setNarrativeCode (Narrative obj, String newNarrativeCode) throws FieldException
    {
        return newNarrativeCode;
    }

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

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

    /**
     * Get the attribute GraphicNotes
     */
    public String getGraphicNotes (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute GraphicNotes.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setGraphicNotes (Narrative obj, String newGraphicNotes) throws FieldException
    {
        return newGraphicNotes;
    }

    /**
     * Get the attribute SummaryNotes
     */
    public String getSummaryNotes (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute SummaryNotes.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setSummaryNotes (Narrative obj, String newSummaryNotes) throws FieldException
    {
        return newSummaryNotes;
    }

    /**
     * Get the attribute ModConnect
     */
    public String getModConnect (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ModConnect.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setModConnect (Narrative obj, String newModConnect) throws FieldException
    {
        return newModConnect;
    }

    /**
     * Get the attribute NarrativeNotes
     */
    public String getNarrativeNotes (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute NarrativeNotes.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setNarrativeNotes (Narrative obj, String newNarrativeNotes) throws FieldException
    {
        return newNarrativeNotes;
    }

    /**
     * Get the attribute DevelNarrative
     */
    public String getDevelNarrative (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute DevelNarrative.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setDevelNarrative (Narrative obj, String newDevelNarrative) throws FieldException
    {
        return newDevelNarrative;
    }

    /**
     * Get the attribute Question
     */
    public String getQuestion (Narrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Question.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setQuestion (Narrative obj, String newQuestion) throws FieldException
    {
        return newQuestion;
    }

    }

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

        public NarrativePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Results"))
            {
                return toResults ();
            }                
            if (name.equals ("FactorScores"))
            {
                return toFactorScores ();
            }                
            if (name.equals ("NarrativeCode"))
            {
                return toNarrativeCode ();
            }                
            if (name.equals ("Description"))
            {
                return toDescription ();
            }                
            if (name.equals ("GraphicNotes"))
            {
                return toGraphicNotes ();
            }                
            if (name.equals ("SummaryNotes"))
            {
                return toSummaryNotes ();
            }                
            if (name.equals ("ModConnect"))
            {
                return toModConnect ();
            }                
            if (name.equals ("NarrativeNotes"))
            {
                return toNarrativeNotes ();
            }                
            if (name.equals ("DevelNarrative"))
            {
                return toDevelNarrative ();
            }                
            if (name.equals ("Question"))
            {
                return toQuestion ();
            }                
            if (name.equals ("Level"))
            {
                return toLevel ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toNarrativeCode () { return pipe(new ORMAttributePipe<Me, String>(FIELD_NarrativeCode));  }
        
        public PipeLine<From, String> toDescription () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Description));  }
        
        public PipeLine<From, String> toGraphicNotes () { return pipe(new ORMAttributePipe<Me, String>(FIELD_GraphicNotes));  }
        
        public PipeLine<From, String> toSummaryNotes () { return pipe(new ORMAttributePipe<Me, String>(FIELD_SummaryNotes));  }
        
        public PipeLine<From, String> toModConnect () { return pipe(new ORMAttributePipe<Me, String>(FIELD_ModConnect));  }
        
        public PipeLine<From, String> toNarrativeNotes () { return pipe(new ORMAttributePipe<Me, String>(FIELD_NarrativeNotes));  }
        
        public PipeLine<From, String> toDevelNarrative () { return pipe(new ORMAttributePipe<Me, String>(FIELD_DevelNarrative));  }
        
        public PipeLine<From, String> toQuestion () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Question));  }
        public Level.LevelPipeLineFactory<From, Level> toLevel () { return toLevel (Filter.ALL); }

        public Level.LevelPipeLineFactory<From, Level> toLevel (Filter<Level> filter) 
        { 
            return Level.REFERENCE_Level.new LevelPipeLineFactory<From, Level> (this, new ORMSingleAssocPipe<Me, Level>(SINGLEREFERENCE_Level, filter)); 
        }
        public FactorScoreResult.FactorScoreResultPipeLineFactory<From, FactorScoreResult> toResults () { return toResults(Filter.ALL); }        

        public FactorScoreResult.FactorScoreResultPipeLineFactory<From, FactorScoreResult> toResults (Filter<FactorScoreResult> filter)
        {
            return FactorScoreResult.REFERENCE_FactorScoreResult.new FactorScoreResultPipeLineFactory<From, FactorScoreResult> (this, new ORMMultiAssocPipe<Me, FactorScoreResult>(MULTIPLEREFERENCE_Results, filter)); 
        }
        public FactorScore.FactorScorePipeLineFactory<From, FactorScore> toFactorScores () { return toFactorScores(Filter.ALL); }        

        public FactorScore.FactorScorePipeLineFactory<From, FactorScore> toFactorScores (Filter<FactorScore> filter)
        {
            return FactorScore.REFERENCE_FactorScore.new FactorScorePipeLineFactory<From, FactorScore> (this, new ORMMultiAssocPipe<Me, FactorScore>(MULTIPLEREFERENCE_FactorScores, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Level getLevel () throws StorageException
    {
        return (Level)(Level.DUMMY_Level);
    }


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

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


    public FactorScoreResult getResultsAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Results");
    }


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

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


    public FactorScore getFactorScoresAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association FactorScores");
    }


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

}

    
