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

    // Reference instance for the object
    public static final FactorScoreResult DUMMY_FactorScoreResult = new DummyFactorScoreResult ();

    // Static constants corresponding to field names
    
    public static final String FIELD_FromScore = "FromScore";
    public static final String FIELD_ToScore = "ToScore";
    public static final String FIELD_ColorCode = "ColorCode";
    public static final String SINGLEREFERENCE_Factor = "Factor";
    public static final String BACKREF_Factor = "";
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String BACKREF_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<FactorScoreResult> HELPER_FromScore = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<FactorScoreResult> HELPER_ToScore = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<FactorScoreResult, ColorCode> HELPER_ColorCode =  new EnumeratedAttributeHelper<FactorScoreResult, ColorCode> (ColorCode.FACTORY_ColorCode);
    

    // Private attributes corresponding to business object data
    private Integer _FromScore;
    private Integer _ToScore;
    private ColorCode _ColorCode;
    

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

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_FromScore_Validators;
    private static final AttributeValidator[] FIELD_ToScore_Validators;
    private static final AttributeValidator[] FIELD_ColorCode_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<FactorScoreResult, Integer>[] FIELD_FromScore_Decorators;
    private static final AttributeDecorator<FactorScoreResult, Integer>[] FIELD_ToScore_Decorators;
    private static final AttributeDecorator<FactorScoreResult, ColorCode>[] FIELD_ColorCode_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<FactorScoreResult, Factor>[] SINGLEREFERENCE_Factor_Decorators;
    private static final SingleAssocDecorator<FactorScoreResult, Level>[] SINGLEREFERENCE_Level_Decorators;
    private static final SingleAssocDecorator<FactorScoreResult, Narrative>[] SINGLEREFERENCE_Narrative_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final FactorScoreResultBehaviourDecorator[] FactorScoreResult_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Factor = Factor.BACKREF_Results;
            String tmp_Level = Level.BACKREF_Results;
            String tmp_Narrative = Narrative.BACKREF_Results;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Factor();
            setupAssocMetaData_Level();
            setupAssocMetaData_Narrative();
            FIELD_FromScore_Validators = (AttributeValidator[])setupAttribMetaData_FromScore(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ToScore_Validators = (AttributeValidator[])setupAttribMetaData_ToScore(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ColorCode_Validators = (AttributeValidator[])setupAttribMetaData_ColorCode(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_FromScore_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScoreResult, FIELD_FromScore).toArray (new AttributeDecorator[0]);
            FIELD_ToScore_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScoreResult, FIELD_ToScore).toArray (new AttributeDecorator[0]);
            FIELD_ColorCode_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_FactorScoreResult, FIELD_ColorCode).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_Factor_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScoreResult, SINGLEREFERENCE_Factor).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Level_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScoreResult, SINGLEREFERENCE_Level).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Narrative_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_FactorScoreResult, SINGLEREFERENCE_Narrative).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_FactorScoreResult.initialiseReference ();
            DUMMY_FactorScoreResult.initialiseReference ();
            FactorScoreResult_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(FactorScoreResult.class).toArray(new FactorScoreResultBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

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

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

        metaInfo.put ("backreferenceName", "Results");
        metaInfo.put ("dbcol", "narrative_id");
        metaInfo.put ("name", "Narrative");
        metaInfo.put ("type", "Narrative");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_level_factor");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScoreResult.Narrative:", metaInfo);
        ATTRIBUTES_METADATA_FactorScoreResult.put (SINGLEREFERENCE_Narrative, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_FromScore(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "from_score");
        metaInfo.put ("name", "FromScore");
        metaInfo.put ("type", "Integer");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_level_factor");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScoreResult.FromScore:", metaInfo);
        ATTRIBUTES_METADATA_FactorScoreResult.put (FIELD_FromScore, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "to_score");
        metaInfo.put ("name", "ToScore");
        metaInfo.put ("type", "Integer");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_level_factor");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScoreResult.ToScore:", metaInfo);
        ATTRIBUTES_METADATA_FactorScoreResult.put (FIELD_ToScore, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(FactorScoreResult.class, "ToScore", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for FactorScoreResult.ToScore:", 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_level_factor");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScoreResult.ColorCode:", metaInfo);
        ATTRIBUTES_METADATA_FactorScoreResult.put (FIELD_ColorCode, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _FromScore = (Integer)(HELPER_FromScore.initialise (_FromScore));
        _ToScore = (Integer)(HELPER_ToScore.initialise (_ToScore));
        _ColorCode = (ColorCode)(HELPER_ColorCode.initialise (_ColorCode));
    }


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

        _Factor = new SingleAssociation<FactorScoreResult, Factor> (this, SINGLEREFERENCE_Factor, Factor.MULTIPLEREFERENCE_Results, Factor.REFERENCE_Factor, "tl_level_factor");
        _Level = new SingleAssociation<FactorScoreResult, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_Results, Level.REFERENCE_Level, "tl_level_factor");
        _Narrative = new SingleAssociation<FactorScoreResult, Narrative> (this, SINGLEREFERENCE_Narrative, Narrative.MULTIPLEREFERENCE_Results, Narrative.REFERENCE_Narrative, "tl_level_factor");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Factor = new SingleAssociation<FactorScoreResult, Factor> (this, SINGLEREFERENCE_Factor, Factor.MULTIPLEREFERENCE_Results, Factor.REFERENCE_Factor, "tl_level_factor");
        _Level = new SingleAssociation<FactorScoreResult, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_Results, Level.REFERENCE_Level, "tl_level_factor");
        _Narrative = new SingleAssociation<FactorScoreResult, Narrative> (this, SINGLEREFERENCE_Narrative, Narrative.MULTIPLEREFERENCE_Results, Narrative.REFERENCE_Narrative, "tl_level_factor");
        
        
        return this;
    }


    /**
     * Attribute FromScore
     */
    public Integer getFromScore ()
    {
        assertValid();
        Integer valToReturn = AttributeDecoratorUtils.getValue (FIELD_FromScore_Decorators, (FactorScoreResult)this, FIELD_FromScore, _FromScore);

        
        for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
        {
            valToReturn = bhd.getFromScore ((FactorScoreResult)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 preFromScoreChange (Integer newFromScore) 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 postFromScoreChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute FromScore.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setFromScore (Integer newFromScore) throws FieldException
    {
        newFromScore = AttributeDecoratorUtils.setValue (FIELD_FromScore_Decorators, (FactorScoreResult)this, FIELD_FromScore, newFromScore);

        boolean oldAndNewIdentical = HELPER_FromScore.compare (_FromScore, newFromScore);
        
        try
        {
            for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
            {
                newFromScore = bhd.setFromScore ((FactorScoreResult)this, newFromScore);
                oldAndNewIdentical = HELPER_FromScore.compare (_FromScore, newFromScore);
            }

            

            if (FIELD_FromScore_Validators.length > 0)
            {
                Object newFromScoreObj = HELPER_FromScore.toObject (newFromScore);

                if (newFromScoreObj != null)
                {
                    int     loopMax = FIELD_FromScore_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScoreResult.get (FIELD_FromScore);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_FromScore_Decorators, (FactorScoreResult)this, FIELD_FromScore ,getWriteability_FromScore ()) != FieldWriteability.FALSE, "Field  FromScore is not writeable");
            preFromScoreChange (newFromScore);
            markFieldChange (FIELD_FromScore);
            _FromScore = newFromScore;            
            postFieldChange (FIELD_FromScore);
            postFromScoreChange ();
        }
    }

    /**
     * Attribute ToScore
     */
    public Integer getToScore ()
    {
        assertValid();
        Integer valToReturn = AttributeDecoratorUtils.getValue (FIELD_ToScore_Decorators, (FactorScoreResult)this, FIELD_ToScore, _ToScore);

        
        for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
        {
            valToReturn = bhd.getToScore ((FactorScoreResult)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 preToScoreChange (Integer newToScore) 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 postToScoreChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ToScore.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setToScore (Integer newToScore) throws FieldException
    {
        newToScore = AttributeDecoratorUtils.setValue (FIELD_ToScore_Decorators, (FactorScoreResult)this, FIELD_ToScore, newToScore);

        boolean oldAndNewIdentical = HELPER_ToScore.compare (_ToScore, newToScore);
        
        try
        {
            for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
            {
                newToScore = bhd.setToScore ((FactorScoreResult)this, newToScore);
                oldAndNewIdentical = HELPER_ToScore.compare (_ToScore, newToScore);
            }

            

            if (FIELD_ToScore_Validators.length > 0)
            {
                Object newToScoreObj = HELPER_ToScore.toObject (newToScore);

                if (newToScoreObj != null)
                {
                    int     loopMax = FIELD_ToScore_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScoreResult.get (FIELD_ToScore);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_ToScore_Decorators, (FactorScoreResult)this, FIELD_ToScore ,getWriteability_ToScore ()) != FieldWriteability.FALSE, "Field  ToScore is not writeable");
            preToScoreChange (newToScore);
            markFieldChange (FIELD_ToScore);
            _ToScore = newToScore;            
            postFieldChange (FIELD_ToScore);
            postToScoreChange ();
        }
    }

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

        
        for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
        {
            valToReturn = bhd.getColorCode ((FactorScoreResult)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, (FactorScoreResult)this, FIELD_ColorCode, newColorCode);

        boolean oldAndNewIdentical = HELPER_ColorCode.compare (_ColorCode, newColorCode);
        
        try
        {
            for (FactorScoreResultBehaviourDecorator bhd : FactorScoreResult_BehaviourDecorators)
            {
                newColorCode = bhd.setColorCode ((FactorScoreResult)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_FactorScoreResult.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, (FactorScoreResult)this, FIELD_ColorCode ,getWriteability_ColorCode ()) != FieldWriteability.FALSE, "Field  ColorCode is not writeable");
            preColorCodeChange (newColorCode);
            markFieldChange (FIELD_ColorCode);
            _ColorCode = newColorCode;            
            postFieldChange (FIELD_ColorCode);
            postColorCodeChange ();
        }
    }



    /**
     * A list of multi assoc names e.g. list of strings.
     */
    public List<String> getSingleAssocs()
    {
        List result = super.getSingleAssocs ();
        
        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_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_Factor))
        {
            return Factor.MULTIPLEREFERENCE_Results ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return Level.MULTIPLEREFERENCE_Results ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Narrative))
        {
            return Narrative.MULTIPLEREFERENCE_Results ;
        }
        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_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_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_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_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 Factor
     */
    public Factor getFactor () throws StorageException
    {
        assertValid();
        
        try
        {
            return (Factor)(_Factor.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in FactorScoreResult:", 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, (FactorScoreResult)this, SINGLEREFERENCE_Factor ,getWriteability_Factor ()) != FieldWriteability.FALSE, "Assoc Factor is not writeable");
            preFactorChange (newFactor);
            Factor oldFactor = getFactor ();

            if (oldFactor != null)
            {
                // This is to stop validation from triggering when we are removed
                _Factor.set (null);
                oldFactor.removeFromResults ((FactorScoreResult)(this));
            }

            _Factor.set (newFactor);

            if (newFactor != null)
            {
                newFactor.addToResults ((FactorScoreResult)(this));
            }
                
            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 FactorScoreResult:", 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, (FactorScoreResult)this, SINGLEREFERENCE_Level ,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.removeFromResults ((FactorScoreResult)(this));
            }

            _Level.set (newLevel);

            if (newLevel != null)
            {
                newLevel.addToResults ((FactorScoreResult)(this));
            }
                
            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 FactorScoreResult:", 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, (FactorScoreResult)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.removeFromResults ((FactorScoreResult)(this));
            }

            _Narrative.set (newNarrative);

            if (newNarrative != null)
            {
                newNarrative.addToResults ((FactorScoreResult)(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 (_Factor.isLoaded () || getTransaction ().isObjectLoaded (_Factor.getReferencedType (), getFactorID ()))
            {
                Factor  referenced = getFactor ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Results from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Factor.set (null);
                    referenced.removeFromResults ((FactorScoreResult)this);
                }
            }
        
            // 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 Results from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Level.set (null);
                    referenced.removeFromResults ((FactorScoreResult)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 Results from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Narrative.set (null);
                    referenced.removeFromResults ((FactorScoreResult)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public FactorScoreResult referenceInstance ()
    {
        return REFERENCE_FactorScoreResult;
    }


    public FactorScoreResult getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getFactorScoreResultByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_FactorScoreResult;
    }


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



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

        tl_level_factorPSet.setAttrib (FIELD_ObjectID, myID);
        tl_level_factorPSet.setAttrib (FIELD_FromScore, HELPER_FromScore.toObject (_FromScore)); //
        tl_level_factorPSet.setAttrib (FIELD_ToScore, HELPER_ToScore.toObject (_ToScore)); //
        tl_level_factorPSet.setAttrib (FIELD_ColorCode, HELPER_ColorCode.toObject (_ColorCode)); //
        _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_level_factorPSet = allSets.getPersistentSet (objectID, "tl_level_factor");

        _FromScore = (Integer)(HELPER_FromScore.fromObject (_FromScore, tl_level_factorPSet.getAttrib (FIELD_FromScore))); //
        _ToScore = (Integer)(HELPER_ToScore.fromObject (_ToScore, tl_level_factorPSet.getAttrib (FIELD_ToScore))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, tl_level_factorPSet.getAttrib (FIELD_ColorCode))); //
        _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 FactorScoreResult)
        {
            FactorScoreResult otherFactorScoreResult = (FactorScoreResult)other;
            

            try
            {
                setFromScore (otherFactorScoreResult.getFromScore ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setToScore (otherFactorScoreResult.getToScore ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setColorCode (otherFactorScoreResult.getColorCode ());
            }
            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 BaseFactorScoreResult)
        {
            BaseFactorScoreResult sourceFactorScoreResult = (BaseFactorScoreResult)(source);

            _FromScore = sourceFactorScoreResult._FromScore;
            _ToScore = sourceFactorScoreResult._ToScore;
            _ColorCode = sourceFactorScoreResult._ColorCode;
            
        }
    }


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

            _Factor.copyFrom (sourceFactorScoreResult._Factor, linkToGhosts);
            _Level.copyFrom (sourceFactorScoreResult._Level, linkToGhosts);
            _Narrative.copyFrom (sourceFactorScoreResult._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 BaseFactorScoreResult)
        {
            BaseFactorScoreResult sourceFactorScoreResult = (BaseFactorScoreResult)(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);

        _FromScore = (Integer)(HELPER_FromScore.readExternal (_FromScore, vals.get(FIELD_FromScore))); //
        _ToScore = (Integer)(HELPER_ToScore.readExternal (_ToScore, vals.get(FIELD_ToScore))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.readExternal (_ColorCode, vals.get(FIELD_ColorCode))); //
        _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_FromScore, HELPER_FromScore.writeExternal (_FromScore));
        vals.put (FIELD_ToScore, HELPER_ToScore.writeExternal (_ToScore));
        vals.put (FIELD_ColorCode, HELPER_ColorCode.writeExternal (_ColorCode));
        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 BaseFactorScoreResult)
        {
            BaseFactorScoreResult otherFactorScoreResult = (BaseFactorScoreResult)(other);

            
            if (!HELPER_FromScore.compare(this._FromScore, otherFactorScoreResult._FromScore))
            {
                listener.notifyFieldChange(this, other, FIELD_FromScore, HELPER_FromScore.toObject(this._FromScore), HELPER_FromScore.toObject(otherFactorScoreResult._FromScore));
            }
            if (!HELPER_ToScore.compare(this._ToScore, otherFactorScoreResult._ToScore))
            {
                listener.notifyFieldChange(this, other, FIELD_ToScore, HELPER_ToScore.toObject(this._ToScore), HELPER_ToScore.toObject(otherFactorScoreResult._ToScore));
            }
            if (!HELPER_ColorCode.compare(this._ColorCode, otherFactorScoreResult._ColorCode))
            {
                listener.notifyFieldChange(this, other, FIELD_ColorCode, HELPER_ColorCode.toObject(this._ColorCode), HELPER_ColorCode.toObject(otherFactorScoreResult._ColorCode));
            }

            // Compare single assocs
            _Factor.compare (otherFactorScoreResult._Factor, listener);
            _Level.compare (otherFactorScoreResult._Level, listener);
            _Narrative.compare (otherFactorScoreResult._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_FromScore, HELPER_FromScore.toObject(getFromScore()));
        visitor.visitField(this, FIELD_ToScore, HELPER_ToScore.toObject(getToScore()));
        visitor.visitField(this, FIELD_ColorCode, HELPER_ColorCode.toObject(getColorCode()));
        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 (_Factor))
        {
            visitor.visit (_Factor);
        }
        if (scope.includes (_Level))
        {
            visitor.visit (_Level);
        }
        if (scope.includes (_Narrative))
        {
            visitor.visit (_Narrative);
        }
        
    }


    public static FactorScoreResult createFactorScoreResult (ObjectTransaction transaction) throws StorageException
    {
        FactorScoreResult     result = new FactorScoreResult ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static FactorScoreResult getFactorScoreResultByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (FactorScoreResult)(transaction.getObjectByID (REFERENCE_FactorScoreResult, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_FromScore))
        {
            return filter.matches (getFromScore ());
        }
        else if (attribName.equals (FIELD_ToScore))
        {
            return filter.matches (getToScore ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return filter.matches (getColorCode ());
        }
        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<FactorScoreResult>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_level_factor.object_id", FIELD_ObjectID);
            return this;
        }

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

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

            
        public SearchAll andFromScore (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_level_factor.from_score", "FromScore");
            return this;
        }
            
        public SearchAll andToScore (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_level_factor.to_score", "ToScore");
            return this;
        }
            
        public SearchAll andColorCode (QueryFilter<ColorCode> filter)
        {
            filter.addFilter (context, "tl_level_factor.color_code", "ColorCode");
            return this;
        }
            
        public SearchAll andFactor (QueryFilter<Factor> filter)
        {
            filter.addFilter (context, "tl_level_factor.factor_number", "Factor");
            return this;
        }
            
        public SearchAll andLevel (QueryFilter<Level> filter)
        {
            filter.addFilter (context, "tl_level_factor.level_number", "Level");
            return this;
        }
            
        public SearchAll andNarrative (QueryFilter<Narrative> filter)
        {
            filter.addFilter (context, "tl_level_factor.narrative_id", "Narrative");
            return this;
        }
            
        public FactorScoreResult[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_FactorScoreResult, SEARCH_All, criteria);
            Set<FactorScoreResult>   typedResults = new LinkedHashSet <FactorScoreResult> ();
            for (BaseBusinessClass bbcResult : results)
            {
                FactorScoreResult aResult = (FactorScoreResult)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new FactorScoreResult[0]);
                            
        }
    }

        
    public static FactorScoreResult[] 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_FromScore))
        {
            return HELPER_FromScore.toObject (getFromScore ());
        }
        else if (attribName.equals (FIELD_ToScore))
        {
            return HELPER_ToScore.toObject (getToScore ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode.toObject (getColorCode ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_FromScore))
        {
            return HELPER_FromScore;
        }
        else if (attribName.equals (FIELD_ToScore))
        {
            return HELPER_ToScore;
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode;
        }
        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_FromScore))
        {
            setFromScore ((Integer)(HELPER_FromScore.fromObject (_FromScore, attribValue)));            
        }
        else if (attribName.equals (FIELD_ToScore))
        {
            setToScore ((Integer)(HELPER_ToScore.fromObject (_ToScore, attribValue)));            
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            setColorCode ((ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, 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_FromScore))
        {
            return getWriteability_FromScore ();
        }
        else if (fieldName.equals (FIELD_ToScore))
        {
            return getWriteability_ToScore ();
        }
        else if (fieldName.equals (FIELD_ColorCode))
        {
            return getWriteability_ColorCode ();
        }
        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_FromScore () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_FromScore);
        }
        
        if (getWriteability_ToScore () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ToScore);
        }
        
        if (getWriteability_ColorCode () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ColorCode);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_FromScore.getAttribObject (getClass (), _FromScore, false, FIELD_FromScore));
        result.add(HELPER_ToScore.getAttribObject (getClass (), _ToScore, false, FIELD_ToScore));
        result.add(HELPER_ColorCode.getAttribObject (getClass (), _ColorCode, false, FIELD_ColorCode));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_FactorScoreResult);
    }
            

    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 FactorScoreResultBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<FactorScoreResult>
    {

    /**
     * Get the attribute FromScore
     */
    public Integer getFromScore (FactorScoreResult obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute FromScore.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setFromScore (FactorScoreResult obj, Integer newFromScore) throws FieldException
    {
        return newFromScore;
    }

    /**
     * Get the attribute ToScore
     */
    public Integer getToScore (FactorScoreResult obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ToScore.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setToScore (FactorScoreResult obj, Integer newToScore) throws FieldException
    {
        return newToScore;
    }

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

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

    }

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

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

        public FactorScoreResultPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("FromScore"))
            {
                return toFromScore ();
            }                
            if (name.equals ("ToScore"))
            {
                return toToScore ();
            }                
            if (name.equals ("ColorCode"))
            {
                return toColorCode ();
            }                
            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> toFromScore () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_FromScore));  }
        
        public PipeLine<From, Integer> toToScore () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_ToScore));  }
        
        public ColorCode.ColorCodePipeLineFactory<From, ColorCode> toColorCode () 
        { 
            return new ColorCode.ColorCodePipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_ColorCode));
        }

        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 DummyFactorScoreResult extends FactorScoreResult
{
    // Default constructor primarily to support Externalisable
    public DummyFactorScoreResult()
    {
        super();
    }

    public void assertValid ()
    {
    }


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

}

    
