/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure9.0 [oneit.objstore.BusinessObjectTemplate.xsl]
 *   Vendor: Apache Software Foundation (Xalan XSLTC) (Version: 1.0)
 */

    
package performa.orm;

import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.assocs.*;
import oneit.objstore.attributes.*;
import oneit.objstore.rdbms.filters.*;
import oneit.objstore.parser.*;
import oneit.objstore.validator.*;
import oneit.objstore.utils.*;
import oneit.utils.*;
import oneit.utils.filter.Filter;
import oneit.utils.transform.*;
import oneit.utils.parsers.FieldException;

import performa.orm.types.*;


public abstract class BaseFactorScore extends BaseBusinessClass
{
    // Reference instance for the object
    public static final FactorScore REFERENCE_FactorScore = new FactorScore ();

    // Reference instance for the object
    public static final FactorScore DUMMY_FactorScore = new DummyFactorScore ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Score = "Score";
    public static final String FIELD_ColorCode = "ColorCode";
    public static final String FIELD_WghtdScore = "WghtdScore";
    public static final String SINGLEREFERENCE_TestAnalysis = "TestAnalysis";
    public static final String BACKREF_TestAnalysis = "";
    public static final String SINGLEREFERENCE_Factor = "Factor";
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String SINGLEREFERENCE_Narrative = "Narrative";
    public static final String BACKREF_Narrative = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<FactorScore> HELPER_Score = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<FactorScore, ColorCode> HELPER_ColorCode =  new EnumeratedAttributeHelper<FactorScore, ColorCode> (ColorCode.FACTORY_ColorCode);
    private static final DefaultAttributeHelper<FactorScore> HELPER_WghtdScore = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private Integer _Score;
    private ColorCode _ColorCode;
    private Integer _WghtdScore;
    

    // Private attributes corresponding to single references
    private SingleAssociation<FactorScore, TestAnalysis> _TestAnalysis;
    private SingleAssociation<FactorScore, Factor> _Factor;
    private SingleAssociation<FactorScore, Level> _Level;
    private SingleAssociation<FactorScore, Narrative> _Narrative;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Score_Validators;
    private static final AttributeValidator[] FIELD_ColorCode_Validators;
    private static final AttributeValidator[] FIELD_WghtdScore_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<FactorScore, Integer>[] FIELD_Score_Decorators;
    private static final AttributeDecorator<FactorScore, ColorCode>[] FIELD_ColorCode_Decorators;
    private static final AttributeDecorator<FactorScore, Integer>[] FIELD_WghtdScore_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<FactorScore, TestAnalysis>[] SINGLEREFERENCE_TestAnalysis_Decorators;
    private static final SingleAssocDecorator<FactorScore, Factor>[] SINGLEREFERENCE_Factor_Decorators;
    private static final SingleAssocDecorator<FactorScore, Level>[] SINGLEREFERENCE_Level_Decorators;
    private static final SingleAssocDecorator<FactorScore, Narrative>[] SINGLEREFERENCE_Narrative_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final FactorScoreBehaviourDecorator[] FactorScore_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_TestAnalysis = TestAnalysis.BACKREF_FactorScores;
            String tmp_Narrative = Narrative.BACKREF_FactorScores;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_TestAnalysis();
            setupAssocMetaData_Factor();
            setupAssocMetaData_Level();
            setupAssocMetaData_Narrative();
            FIELD_Score_Validators = (AttributeValidator[])setupAttribMetaData_Score(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ColorCode_Validators = (AttributeValidator[])setupAttribMetaData_ColorCode(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_WghtdScore_Validators = (AttributeValidator[])setupAttribMetaData_WghtdScore(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Score_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScore, FIELD_Score).toArray (new AttributeDecorator[0]);
            FIELD_ColorCode_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScore, FIELD_ColorCode).toArray (new AttributeDecorator[0]);
            FIELD_WghtdScore_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScore, FIELD_WghtdScore).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_TestAnalysis_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScore, SINGLEREFERENCE_TestAnalysis).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Factor_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScore, SINGLEREFERENCE_Factor).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Level_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScore, SINGLEREFERENCE_Level).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Narrative_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScore, SINGLEREFERENCE_Narrative).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_FactorScore.initialiseReference ();
            DUMMY_FactorScore.initialiseReference ();
            FactorScore_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(FactorScore.class).toArray(new FactorScoreBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "FactorScores");
        metaInfo.put ("dbcol", "test_analysis_id");
        metaInfo.put ("name", "TestAnalysis");
        metaInfo.put ("type", "TestAnalysis");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.TestAnalysis:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (SINGLEREFERENCE_TestAnalysis, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Factor()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "factor_number");
        metaInfo.put ("name", "Factor");
        metaInfo.put ("type", "Factor");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Factor:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (SINGLEREFERENCE_Factor, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Level()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "level_number");
        metaInfo.put ("name", "Level");
        metaInfo.put ("type", "Level");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Level:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (SINGLEREFERENCE_Level, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Narrative()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "FactorScores");
        metaInfo.put ("dbcol", "narrative_id");
        metaInfo.put ("name", "Narrative");
        metaInfo.put ("type", "Narrative");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Narrative:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (SINGLEREFERENCE_Narrative, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Score(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "score_number");
        metaInfo.put ("name", "Score");
        metaInfo.put ("type", "Integer");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Score:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (FIELD_Score, Collections.unmodifiableMap (metaInfo));

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

        return validators;
    }
    
    private static List setupAttribMetaData_ColorCode(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "color_code");
        metaInfo.put ("name", "ColorCode");
        metaInfo.put ("type", "ColorCode");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.ColorCode:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (FIELD_ColorCode, Collections.unmodifiableMap (metaInfo));

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

        return validators;
    }
    
    private static List setupAttribMetaData_WghtdScore(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "wghtd_score");
        metaInfo.put ("name", "WghtdScore");
        metaInfo.put ("type", "Integer");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_score");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.WghtdScore:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (FIELD_WghtdScore, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _Score = (Integer)(HELPER_Score.initialise (_Score));
        _ColorCode = (ColorCode)(HELPER_ColorCode.initialise (_ColorCode));
        _WghtdScore = (Integer)(HELPER_WghtdScore.initialise (_WghtdScore));
    }


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

        _TestAnalysis = new SingleAssociation<FactorScore, TestAnalysis> (this, SINGLEREFERENCE_TestAnalysis, TestAnalysis.MULTIPLEREFERENCE_FactorScores, TestAnalysis.REFERENCE_TestAnalysis, "tl_score");
        _Factor = new SingleAssociation<FactorScore, Factor> (this, SINGLEREFERENCE_Factor, null, Factor.REFERENCE_Factor, "tl_score");
        _Level = new SingleAssociation<FactorScore, Level> (this, SINGLEREFERENCE_Level, null, Level.REFERENCE_Level, "tl_score");
        _Narrative = new SingleAssociation<FactorScore, Narrative> (this, SINGLEREFERENCE_Narrative, Narrative.MULTIPLEREFERENCE_FactorScores, Narrative.REFERENCE_Narrative, "tl_score");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _TestAnalysis = new SingleAssociation<FactorScore, TestAnalysis> (this, SINGLEREFERENCE_TestAnalysis, TestAnalysis.MULTIPLEREFERENCE_FactorScores, TestAnalysis.REFERENCE_TestAnalysis, "tl_score");
        _Factor = new SingleAssociation<FactorScore, Factor> (this, SINGLEREFERENCE_Factor, null, Factor.REFERENCE_Factor, "tl_score");
        _Level = new SingleAssociation<FactorScore, Level> (this, SINGLEREFERENCE_Level, null, Level.REFERENCE_Level, "tl_score");
        _Narrative = new SingleAssociation<FactorScore, Narrative> (this, SINGLEREFERENCE_Narrative, Narrative.MULTIPLEREFERENCE_FactorScores, Narrative.REFERENCE_Narrative, "tl_score");
        
        
        return this;
    }


    /**
     * Attribute Score
     */
    public Integer getScore ()
    {
        assertValid();
        Integer valToReturn = AttributeDecoratorUtils.getValue (FIELD_Score_Decorators, (FactorScore)this, FIELD_Score, _Score);

        
        for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
        {
            valToReturn = bhd.getScore ((FactorScore)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 preScoreChange (Integer newScore) 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 postScoreChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Score.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setScore (Integer newScore) throws FieldException
    {
        newScore = AttributeDecoratorUtils.setValue (FIELD_Score_Decorators, (FactorScore)this, FIELD_Score, newScore);

        boolean oldAndNewIdentical = HELPER_Score.compare (_Score, newScore);
        
        try
        {
            for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
            {
                newScore = bhd.setScore ((FactorScore)this, newScore);
                oldAndNewIdentical = HELPER_Score.compare (_Score, newScore);
            }

            

            if (FIELD_Score_Validators.length > 0)
            {
                Object newScoreObj = HELPER_Score.toObject (newScore);

                if (newScoreObj != null)
                {
                    int     loopMax = FIELD_Score_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScore.get (FIELD_Score);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Score_Decorators, (FactorScore)this, FIELD_Score ,getWriteability_Score ()) != FieldWriteability.FALSE, "Field  Score is not writeable");
            preScoreChange (newScore);
            markFieldChange (FIELD_Score);
            _Score = newScore;            
            postFieldChange (FIELD_Score);
            postScoreChange ();
        }
    }

    /**
     * Attribute ColorCode
     */
    public ColorCode getColorCode ()
    {
        assertValid();
        ColorCode valToReturn = AttributeDecoratorUtils.getValue (FIELD_ColorCode_Decorators, (FactorScore)this, FIELD_ColorCode, _ColorCode);

        
        for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
        {
            valToReturn = bhd.getColorCode ((FactorScore)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 preColorCodeChange (ColorCode newColorCode) 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 postColorCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ColorCode.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setColorCode (ColorCode newColorCode) throws FieldException
    {
        newColorCode = AttributeDecoratorUtils.setValue (FIELD_ColorCode_Decorators, (FactorScore)this, FIELD_ColorCode, newColorCode);

        boolean oldAndNewIdentical = HELPER_ColorCode.compare (_ColorCode, newColorCode);
        
        try
        {
            for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
            {
                newColorCode = bhd.setColorCode ((FactorScore)this, newColorCode);
                oldAndNewIdentical = HELPER_ColorCode.compare (_ColorCode, newColorCode);
            }

            

            if (FIELD_ColorCode_Validators.length > 0)
            {
                Object newColorCodeObj = HELPER_ColorCode.toObject (newColorCode);

                if (newColorCodeObj != null)
                {
                    int     loopMax = FIELD_ColorCode_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScore.get (FIELD_ColorCode);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_ColorCode_Decorators, (FactorScore)this, FIELD_ColorCode ,getWriteability_ColorCode ()) != FieldWriteability.FALSE, "Field  ColorCode is not writeable");
            preColorCodeChange (newColorCode);
            markFieldChange (FIELD_ColorCode);
            _ColorCode = newColorCode;            
            postFieldChange (FIELD_ColorCode);
            postColorCodeChange ();
        }
    }

    /**
     * Attribute WghtdScore
     */
    public Integer getWghtdScore ()
    {
        assertValid();
        Integer valToReturn = AttributeDecoratorUtils.getValue (FIELD_WghtdScore_Decorators, (FactorScore)this, FIELD_WghtdScore, _WghtdScore);

        
        for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
        {
            valToReturn = bhd.getWghtdScore ((FactorScore)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 preWghtdScoreChange (Integer newWghtdScore) 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 postWghtdScoreChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute WghtdScore.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setWghtdScore (Integer newWghtdScore) throws FieldException
    {
        newWghtdScore = AttributeDecoratorUtils.setValue (FIELD_WghtdScore_Decorators, (FactorScore)this, FIELD_WghtdScore, newWghtdScore);

        boolean oldAndNewIdentical = HELPER_WghtdScore.compare (_WghtdScore, newWghtdScore);
        
        try
        {
            for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
            {
                newWghtdScore = bhd.setWghtdScore ((FactorScore)this, newWghtdScore);
                oldAndNewIdentical = HELPER_WghtdScore.compare (_WghtdScore, newWghtdScore);
            }

            

            if (FIELD_WghtdScore_Validators.length > 0)
            {
                Object newWghtdScoreObj = HELPER_WghtdScore.toObject (newWghtdScore);

                if (newWghtdScoreObj != null)
                {
                    int     loopMax = FIELD_WghtdScore_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScore.get (FIELD_WghtdScore);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_WghtdScore_Decorators, (FactorScore)this, FIELD_WghtdScore ,getWriteability_WghtdScore ()) != FieldWriteability.FALSE, "Field  WghtdScore is not writeable");
            preWghtdScoreChange (newWghtdScore);
            markFieldChange (FIELD_WghtdScore);
            _WghtdScore = newWghtdScore;            
            postFieldChange (FIELD_WghtdScore);
            postWghtdScoreChange ();
        }
    }



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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return _TestAnalysis.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return _Factor.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return _Level.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return _Narrative.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_TestAnalysis))
        {
            return TestAnalysis.MULTIPLEREFERENCE_FactorScores ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return Narrative.MULTIPLEREFERENCE_FactorScores ;
        }
        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_TestAnalysis))
        {
            return getTestAnalysis ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactor ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return getLevel ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return getNarrative ();
        }
        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_TestAnalysis))
        {
            return getTestAnalysis (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactor (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return getLevel (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return getNarrative (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_TestAnalysis))
        {
            return getTestAnalysisID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactorID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return getLevelID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return getNarrativeID ();
        }
        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_TestAnalysis))
        {
            setTestAnalysis ((TestAnalysis)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            setFactor ((Factor)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            setLevel ((Level)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            setNarrative ((Narrative)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getTestAnalysisID ()
    {
        assertValid();
        
        if (_TestAnalysis == null)
        {
            return null;
        }
        else
        {
            return _TestAnalysis.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 preTestAnalysisChange (TestAnalysis newTestAnalysis) 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 postTestAnalysisChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference TestAnalysis.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setTestAnalysis (TestAnalysis newTestAnalysis) throws StorageException, FieldException
    {
        if (_TestAnalysis.wouldReferencedChange (newTestAnalysis))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_TestAnalysis_Decorators, (FactorScore)this, SINGLEREFERENCE_TestAnalysis ,getWriteability_TestAnalysis ()) != FieldWriteability.FALSE, "Assoc TestAnalysis is not writeable");
            preTestAnalysisChange (newTestAnalysis);
            TestAnalysis oldTestAnalysis = getTestAnalysis ();

            if (oldTestAnalysis != null)
            {
                // This is to stop validation from triggering when we are removed
                _TestAnalysis.set (null);
                oldTestAnalysis.removeFromFactorScores ((FactorScore)(this));
            }

            _TestAnalysis.set (newTestAnalysis);

            if (newTestAnalysis != null)
            {
                newTestAnalysis.addToFactorScores ((FactorScore)(this));
            }
                
            postTestAnalysisChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getFactorID ()
    {
        assertValid();
        
        if (_Factor == null)
        {
            return null;
        }
        else
        {
            return _Factor.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 preFactorChange (Factor newFactor) 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 postFactorChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference Factor.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setFactor (Factor newFactor) throws StorageException, FieldException
    {
        if (_Factor.wouldReferencedChange (newFactor))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Factor_Decorators, (FactorScore)this, SINGLEREFERENCE_Factor ,getWriteability_Factor ()) != FieldWriteability.FALSE, "Assoc Factor is not writeable");
            preFactorChange (newFactor);
            
            _Factor.set (newFactor);
                
            postFactorChange ();
        }
    }

    /**
     * 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 FactorScore:", 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 (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Level_Decorators, (FactorScore)this, SINGLEREFERENCE_Level ,getWriteability_Level ()) != FieldWriteability.FALSE, "Assoc Level is not writeable");
            preLevelChange (newLevel);
            
            _Level.set (newLevel);
                
            postLevelChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getNarrativeID ()
    {
        assertValid();
        
        if (_Narrative == null)
        {
            return null;
        }
        else
        {
            return _Narrative.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 preNarrativeChange (Narrative newNarrative) 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 postNarrativeChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference Narrative.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setNarrative (Narrative newNarrative) throws StorageException, FieldException
    {
        if (_Narrative.wouldReferencedChange (newNarrative))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Narrative_Decorators, (FactorScore)this, SINGLEREFERENCE_Narrative ,getWriteability_Narrative ()) != FieldWriteability.FALSE, "Assoc Narrative is not writeable");
            preNarrativeChange (newNarrative);
            Narrative oldNarrative = getNarrative ();

            if (oldNarrative != null)
            {
                // This is to stop validation from triggering when we are removed
                _Narrative.set (null);
                oldNarrative.removeFromFactorScores ((FactorScore)(this));
            }

            _Narrative.set (newNarrative);

            if (newNarrative != null)
            {
                newNarrative.addToFactorScores ((FactorScore)(this));
            }
                
            postNarrativeChange ();
        }
    }

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

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


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

        return super.getMultiAssocAt(attribName, index);
    }


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

        super.addToMultiAssoc(attribName, newElement);
    }

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

        super.removeFromMultiAssoc(attribName, oldElement);
    }


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

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {

        return super.__isMultiAssocLoaded(attribName);
    }




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

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null FactorScores from ", getObjectID (), " to ", referenced.getObjectID ());
                    _TestAnalysis.set (null);
                    referenced.removeFromFactorScores ((FactorScore)this);
                }
            }
        
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_Narrative.isLoaded () || getTransaction ().isObjectLoaded (_Narrative.getReferencedType (), getNarrativeID ()))
            {
                Narrative  referenced = getNarrative ();

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

        super.onDelete ();
    }


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


    public FactorScore referenceInstance ()
    {
        return REFERENCE_FactorScore;
    }


    public FactorScore getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getFactorScoreByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_FactorScore;
    }


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



    /**
     * This is where an object returns the Persistent sets that will
     * store it into the database.
     * The should be entered into allSets
     */
    public void getPersistentSets (PersistentSetCollection allSets)
    {
        ObjectStatus        myStatus = getStatus ();
        PersistentSetStatus myPSetStatus = myStatus.getPSetStatus();
        ObjectID            myID = getID();

        super.getPersistentSets (allSets);
        
        PersistentSet   tl_scorePSet = allSets.getPersistentSet (myID, "tl_score", myPSetStatus);

        tl_scorePSet.setAttrib (FIELD_ObjectID, myID);
        tl_scorePSet.setAttrib (FIELD_Score, HELPER_Score.toObject (_Score)); //
        tl_scorePSet.setAttrib (FIELD_ColorCode, HELPER_ColorCode.toObject (_ColorCode)); //
        tl_scorePSet.setAttrib (FIELD_WghtdScore, HELPER_WghtdScore.toObject (_WghtdScore)); //
        _TestAnalysis.getPersistentSets (allSets);
        _Factor.getPersistentSets (allSets);
        _Level.getPersistentSets (allSets);
        _Narrative.getPersistentSets (allSets);
        
    }


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

        _Score = (Integer)(HELPER_Score.fromObject (_Score, tl_scorePSet.getAttrib (FIELD_Score))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, tl_scorePSet.getAttrib (FIELD_ColorCode))); //
        _WghtdScore = (Integer)(HELPER_WghtdScore.fromObject (_WghtdScore, tl_scorePSet.getAttrib (FIELD_WghtdScore))); //
        _TestAnalysis.setFromPersistentSets (objectID, allSets);
        _Factor.setFromPersistentSets (objectID, allSets);
        _Level.setFromPersistentSets (objectID, allSets);
        _Narrative.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof FactorScore)
        {
            FactorScore otherFactorScore = (FactorScore)other;
            

            try
            {
                setScore (otherFactorScore.getScore ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setColorCode (otherFactorScore.getColorCode ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setWghtdScore (otherFactorScore.getWghtdScore ());
            }
            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 BaseFactorScore)
        {
            BaseFactorScore sourceFactorScore = (BaseFactorScore)(source);

            _Score = sourceFactorScore._Score;
            _ColorCode = sourceFactorScore._ColorCode;
            _WghtdScore = sourceFactorScore._WghtdScore;
            
        }
    }


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

            _TestAnalysis.copyFrom (sourceFactorScore._TestAnalysis, linkToGhosts);
            _Factor.copyFrom (sourceFactorScore._Factor, linkToGhosts);
            _Level.copyFrom (sourceFactorScore._Level, linkToGhosts);
            _Narrative.copyFrom (sourceFactorScore._Narrative, 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 BaseFactorScore)
        {
            BaseFactorScore sourceFactorScore = (BaseFactorScore)(source);

            
        }
    }


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

        
    }


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

        _Score = (Integer)(HELPER_Score.readExternal (_Score, vals.get(FIELD_Score))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.readExternal (_ColorCode, vals.get(FIELD_ColorCode))); //
        _WghtdScore = (Integer)(HELPER_WghtdScore.readExternal (_WghtdScore, vals.get(FIELD_WghtdScore))); //
        _TestAnalysis.readExternalData(vals.get(SINGLEREFERENCE_TestAnalysis));
        _Factor.readExternalData(vals.get(SINGLEREFERENCE_Factor));
        _Level.readExternalData(vals.get(SINGLEREFERENCE_Level));
        _Narrative.readExternalData(vals.get(SINGLEREFERENCE_Narrative));
        
    }


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

        vals.put (FIELD_Score, HELPER_Score.writeExternal (_Score));
        vals.put (FIELD_ColorCode, HELPER_ColorCode.writeExternal (_ColorCode));
        vals.put (FIELD_WghtdScore, HELPER_WghtdScore.writeExternal (_WghtdScore));
        vals.put (SINGLEREFERENCE_TestAnalysis, _TestAnalysis.writeExternalData());
        vals.put (SINGLEREFERENCE_Factor, _Factor.writeExternalData());
        vals.put (SINGLEREFERENCE_Level, _Level.writeExternalData());
        vals.put (SINGLEREFERENCE_Narrative, _Narrative.writeExternalData());
        
    }


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

        if (other instanceof BaseFactorScore)
        {
            BaseFactorScore otherFactorScore = (BaseFactorScore)(other);

            
            if (!HELPER_Score.compare(this._Score, otherFactorScore._Score))
            {
                listener.notifyFieldChange(this, other, FIELD_Score, HELPER_Score.toObject(this._Score), HELPER_Score.toObject(otherFactorScore._Score));
            }
            if (!HELPER_ColorCode.compare(this._ColorCode, otherFactorScore._ColorCode))
            {
                listener.notifyFieldChange(this, other, FIELD_ColorCode, HELPER_ColorCode.toObject(this._ColorCode), HELPER_ColorCode.toObject(otherFactorScore._ColorCode));
            }
            if (!HELPER_WghtdScore.compare(this._WghtdScore, otherFactorScore._WghtdScore))
            {
                listener.notifyFieldChange(this, other, FIELD_WghtdScore, HELPER_WghtdScore.toObject(this._WghtdScore), HELPER_WghtdScore.toObject(otherFactorScore._WghtdScore));
            }

            // Compare single assocs
            _TestAnalysis.compare (otherFactorScore._TestAnalysis, listener);
            _Factor.compare (otherFactorScore._Factor, listener);
            _Level.compare (otherFactorScore._Level, listener);
            _Narrative.compare (otherFactorScore._Narrative, listener);
            

            // Compare multiple assocs
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_Score, HELPER_Score.toObject(getScore()));
        visitor.visitField(this, FIELD_ColorCode, HELPER_ColorCode.toObject(getColorCode()));
        visitor.visitField(this, FIELD_WghtdScore, HELPER_WghtdScore.toObject(getWghtdScore()));
        visitor.visitAssociation (_TestAnalysis);
        visitor.visitAssociation (_Factor);
        visitor.visitAssociation (_Level);
        visitor.visitAssociation (_Narrative);
        
    }


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

        if (scope.includes (_TestAnalysis))
        {
            visitor.visit (_TestAnalysis);
        }
        if (scope.includes (_Factor))
        {
            visitor.visit (_Factor);
        }
        if (scope.includes (_Level))
        {
            visitor.visit (_Level);
        }
        if (scope.includes (_Narrative))
        {
            visitor.visit (_Narrative);
        }
        
    }


    public static FactorScore createFactorScore (ObjectTransaction transaction) throws StorageException
    {
        FactorScore     result = new FactorScore ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static FactorScore getFactorScoreByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (FactorScore)(transaction.getObjectByID (REFERENCE_FactorScore, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Score))
        {
            return filter.matches (getScore ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return filter.matches (getColorCode ());
        }
        else if (attribName.equals (FIELD_WghtdScore))
        {
            return filter.matches (getWghtdScore ());
        }
        else if (attribName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return filter.matches (getTestAnalysis ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Factor))
        {
            return filter.matches (getFactor ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Level))
        {
            return filter.matches (getLevel ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Narrative))
        {
            return filter.matches (getNarrative ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
        public SearchAll andScore (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_score.score_number", "Score");
            return this;
        }
            
        public SearchAll andColorCode (QueryFilter<ColorCode> filter)
        {
            filter.addFilter (context, "tl_score.color_code", "ColorCode");
            return this;
        }
            
        public SearchAll andWghtdScore (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_score.wghtd_score", "WghtdScore");
            return this;
        }
            
        public SearchAll andTestAnalysis (QueryFilter<TestAnalysis> filter)
        {
            filter.addFilter (context, "tl_score.test_analysis_id", "TestAnalysis");
            return this;
        }
            
        public SearchAll andFactor (QueryFilter<Factor> filter)
        {
            filter.addFilter (context, "tl_score.factor_number", "Factor");
            return this;
        }
            
        public SearchAll andLevel (QueryFilter<Level> filter)
        {
            filter.addFilter (context, "tl_score.level_number", "Level");
            return this;
        }
            
        public SearchAll andNarrative (QueryFilter<Narrative> filter)
        {
            filter.addFilter (context, "tl_score.narrative_id", "Narrative");
            return this;
        }
            
        public FactorScore[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_FactorScore, SEARCH_All, criteria);
            Set<FactorScore>   typedResults = new LinkedHashSet <FactorScore> ();
            for (BaseBusinessClass bbcResult : results)
            {
                FactorScore aResult = (FactorScore)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new FactorScore[0]);
                            
        }
    }

        
    public static FactorScore[] 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_Score))
        {
            return HELPER_Score.toObject (getScore ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode.toObject (getColorCode ());
        }
        else if (attribName.equals (FIELD_WghtdScore))
        {
            return HELPER_WghtdScore.toObject (getWghtdScore ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Score))
        {
            return HELPER_Score;
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode;
        }
        else if (attribName.equals (FIELD_WghtdScore))
        {
            return HELPER_WghtdScore;
        }
        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_Score))
        {
            setScore ((Integer)(HELPER_Score.fromObject (_Score, attribValue)));            
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            setColorCode ((ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, attribValue)));            
        }
        else if (attribName.equals (FIELD_WghtdScore))
        {
            setWghtdScore ((Integer)(HELPER_WghtdScore.fromObject (_WghtdScore, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }

    

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

    public boolean isReadable ()
    {
        return super.isReadable();
    }

    public boolean isReadable (String fieldName)
    {
        return super.isReadable(fieldName);
    }


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_Score))
        {
            return getWriteability_Score ();
        }
        else if (fieldName.equals (FIELD_ColorCode))
        {
            return getWriteability_ColorCode ();
        }
        else if (fieldName.equals (FIELD_WghtdScore))
        {
            return getWriteability_WghtdScore ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return getWriteability_TestAnalysis ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Factor))
        {
            return getWriteability_Factor ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Level))
        {
            return getWriteability_Level ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Narrative))
        {
            return getWriteability_Narrative ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Score () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Score);
        }
        
        if (getWriteability_ColorCode () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ColorCode);
        }
        
        if (getWriteability_WghtdScore () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_WghtdScore);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_Score.getAttribObject (getClass (), _Score, false, FIELD_Score));
        result.add(HELPER_ColorCode.getAttribObject (getClass (), _ColorCode, false, FIELD_ColorCode));
        result.add(HELPER_WghtdScore.getAttribObject (getClass (), _WghtdScore, false, FIELD_WghtdScore));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_FactorScore);
    }
            

    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 FactorScoreBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<FactorScore>
    {

    /**
     * Get the attribute Score
     */
    public Integer getScore (FactorScore obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Score.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setScore (FactorScore obj, Integer newScore) throws FieldException
    {
        return newScore;
    }

    /**
     * Get the attribute ColorCode
     */
    public ColorCode getColorCode (FactorScore obj, ColorCode original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ColorCode.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public ColorCode setColorCode (FactorScore obj, ColorCode newColorCode) throws FieldException
    {
        return newColorCode;
    }

    /**
     * Get the attribute WghtdScore
     */
    public Integer getWghtdScore (FactorScore obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute WghtdScore.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setWghtdScore (FactorScore obj, Integer newWghtdScore) throws FieldException
    {
        return newWghtdScore;
    }

    }

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

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

        public FactorScorePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Score"))
            {
                return toScore ();
            }                
            if (name.equals ("ColorCode"))
            {
                return toColorCode ();
            }                
            if (name.equals ("WghtdScore"))
            {
                return toWghtdScore ();
            }                
            if (name.equals ("TestAnalysis"))
            {
                return toTestAnalysis ();
            }                
            if (name.equals ("Factor"))
            {
                return toFactor ();
            }                
            if (name.equals ("Level"))
            {
                return toLevel ();
            }                
            if (name.equals ("Narrative"))
            {
                return toNarrative ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Integer> toScore () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_Score));  }
        
        public ColorCode.ColorCodePipeLineFactory<From, ColorCode> toColorCode () 
        { 
            return new ColorCode.ColorCodePipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_ColorCode));
        }
        
        public PipeLine<From, Integer> toWghtdScore () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_WghtdScore));  }

        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysis () { return toTestAnalysis (Filter.ALL); }

        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysis (Filter<TestAnalysis> filter) 
        { 
            return TestAnalysis.REFERENCE_TestAnalysis.new TestAnalysisPipeLineFactory<From, TestAnalysis> (this, new ORMSingleAssocPipe<Me, TestAnalysis>(SINGLEREFERENCE_TestAnalysis, filter)); 
        }

        public Factor.FactorPipeLineFactory<From, Factor> toFactor () { return toFactor (Filter.ALL); }

        public Factor.FactorPipeLineFactory<From, Factor> toFactor (Filter<Factor> filter) 
        { 
            return Factor.REFERENCE_Factor.new FactorPipeLineFactory<From, Factor> (this, new ORMSingleAssocPipe<Me, Factor>(SINGLEREFERENCE_Factor, filter)); 
        }

        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 Narrative.NarrativePipeLineFactory<From, Narrative> toNarrative () { return toNarrative (Filter.ALL); }

        public Narrative.NarrativePipeLineFactory<From, Narrative> toNarrative (Filter<Narrative> filter) 
        { 
            return Narrative.REFERENCE_Narrative.new NarrativePipeLineFactory<From, Narrative> (this, new ORMSingleAssocPipe<Me, Narrative>(SINGLEREFERENCE_Narrative, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public TestAnalysis getTestAnalysis () throws StorageException
    {
        return (TestAnalysis)(TestAnalysis.DUMMY_TestAnalysis);
    }


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

    public Factor getFactor () throws StorageException
    {
        return (Factor)(Factor.DUMMY_Factor);
    }


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

    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 Narrative getNarrative () throws StorageException
    {
        return (Narrative)(Narrative.DUMMY_Narrative);
    }


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

}

    
