/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure8.2 rev3 [oneit.objstore.BusinessObjectTemplate.xsl]
 *
 *   Version: 1.0
 *   Vendor: Apache Software Foundation (Xalan XSLTC)
 *   Vendor URL: http://xml.apache.org/xalan-j
 */


    package performa.orm;

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



public abstract class BaseLevel extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Level REFERENCE_Level = new Level ();

    // Reference instance for the object
    public static final Level DUMMY_Level = new DummyLevel ();

    // Static constants corresponding to field names
    
    public static final String FIELD_LevelDescription = "LevelDescription";
    public static final String FIELD_LevelNotes = "LevelNotes";
    public static final String FIELD_ReportHeader = "ReportHeader";
    public static final String MULTIPLEREFERENCE_Factors = "Factors";
    public static final String BACKREF_Factors = "";
    public static final String MULTIPLEREFERENCE_Results = "Results";
    public static final String BACKREF_Results = "";
    public static final String MULTIPLEREFERENCE_Narratives = "Narratives";
    public static final String BACKREF_Narratives = "";
    public static final String MULTIPLEREFERENCE_TestAnalysises = "TestAnalysises";
    public static final String BACKREF_TestAnalysises = "";
    public static final String MULTIPLEREFERENCE_LevelFactorTypes = "LevelFactorTypes";
    public static final String BACKREF_LevelFactorTypes = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Level> HELPER_LevelDescription = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Level> HELPER_LevelNotes = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Level> HELPER_ReportHeader = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _LevelDescription;
    private String _LevelNotes;
    private String _ReportHeader;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<Level, FactorLevelLink> _Factors;
    private MultipleAssociation<Level, FactorScoreResult> _Results;
    private MultipleAssociation<Level, Narrative> _Narratives;
    private MultipleAssociation<Level, TestAnalysis> _TestAnalysises;
    private MultipleAssociation<Level, LevelFactorType> _LevelFactorTypes;
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_LevelDescription_Validators;
    private static final AttributeValidator[] FIELD_LevelNotes_Validators;
    private static final AttributeValidator[] FIELD_ReportHeader_Validators;
    

    // Arrays of behaviour decorators
    private static final LevelBehaviourDecorator[] Level_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Factors = FactorLevelLink.BACKREF_Level;
            String tmp_Results = FactorScoreResult.BACKREF_Level;
            String tmp_Narratives = Narrative.BACKREF_Level;
            String tmp_TestAnalysises = TestAnalysis.BACKREF_Level;
            String tmp_LevelFactorTypes = LevelFactorType.BACKREF_Level;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Factors();
            setupAssocMetaData_Results();
            setupAssocMetaData_Narratives();
            setupAssocMetaData_TestAnalysises();
            setupAssocMetaData_LevelFactorTypes();
            FIELD_LevelDescription_Validators = (AttributeValidator[])setupAttribMetaData_LevelDescription(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_LevelNotes_Validators = (AttributeValidator[])setupAttribMetaData_LevelNotes(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ReportHeader_Validators = (AttributeValidator[])setupAttribMetaData_ReportHeader(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_Level.initialiseReference ();
            DUMMY_Level.initialiseReference ();
            Level_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Level.class).toArray(new LevelBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Level");
        metaInfo.put ("name", "Factors");
        metaInfo.put ("type", "FactorLevelLink");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.Factors:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (MULTIPLEREFERENCE_Factors, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Results()
    {
        Map metaInfo = new HashMap ();

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

        metaInfo.put ("backreferenceName", "Level");
        metaInfo.put ("name", "Narratives");
        metaInfo.put ("type", "Narrative");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.Narratives:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (MULTIPLEREFERENCE_Narratives, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_TestAnalysises()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Level");
        metaInfo.put ("name", "TestAnalysises");
        metaInfo.put ("type", "TestAnalysis");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.TestAnalysises:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (MULTIPLEREFERENCE_TestAnalysises, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_LevelFactorTypes()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Level");
        metaInfo.put ("name", "LevelFactorTypes");
        metaInfo.put ("type", "LevelFactorType");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.LevelFactorTypes:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (MULTIPLEREFERENCE_LevelFactorTypes, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_LevelDescription(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "level_desc");
        metaInfo.put ("length", "30");
        metaInfo.put ("name", "LevelDescription");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.LevelDescription:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (FIELD_LevelDescription, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "level_notes");
        metaInfo.put ("name", "LevelNotes");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.LevelNotes:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (FIELD_LevelNotes, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "rpt_hdr");
        metaInfo.put ("name", "ReportHeader");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.ReportHeader:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (FIELD_ReportHeader, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _LevelDescription = (String)(HELPER_LevelDescription.initialise (_LevelDescription));
        _LevelNotes = (String)(HELPER_LevelNotes.initialise (_LevelNotes));
        _ReportHeader = (String)(HELPER_ReportHeader.initialise (_ReportHeader));
    }


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

        _Factors = new MultipleAssociation<Level, FactorLevelLink> (this, MULTIPLEREFERENCE_Factors, FactorLevelLink.SINGLEREFERENCE_Level, FactorLevelLink.REFERENCE_FactorLevelLink);
        _Results = new MultipleAssociation<Level, FactorScoreResult> (this, MULTIPLEREFERENCE_Results, FactorScoreResult.SINGLEREFERENCE_Level, FactorScoreResult.REFERENCE_FactorScoreResult);
        _Narratives = new MultipleAssociation<Level, Narrative> (this, MULTIPLEREFERENCE_Narratives, Narrative.SINGLEREFERENCE_Level, Narrative.REFERENCE_Narrative);
        _TestAnalysises = new MultipleAssociation<Level, TestAnalysis> (this, MULTIPLEREFERENCE_TestAnalysises, TestAnalysis.SINGLEREFERENCE_Level, TestAnalysis.REFERENCE_TestAnalysis);
        _LevelFactorTypes = new MultipleAssociation<Level, LevelFactorType> (this, MULTIPLEREFERENCE_LevelFactorTypes, LevelFactorType.SINGLEREFERENCE_Level, LevelFactorType.REFERENCE_LevelFactorType);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Factors = new MultipleAssociation<Level, FactorLevelLink> (this, MULTIPLEREFERENCE_Factors, FactorLevelLink.SINGLEREFERENCE_Level, FactorLevelLink.REFERENCE_FactorLevelLink);
        _Results = new MultipleAssociation<Level, FactorScoreResult> (this, MULTIPLEREFERENCE_Results, FactorScoreResult.SINGLEREFERENCE_Level, FactorScoreResult.REFERENCE_FactorScoreResult);
        _Narratives = new MultipleAssociation<Level, Narrative> (this, MULTIPLEREFERENCE_Narratives, Narrative.SINGLEREFERENCE_Level, Narrative.REFERENCE_Narrative);
        _TestAnalysises = new MultipleAssociation<Level, TestAnalysis> (this, MULTIPLEREFERENCE_TestAnalysises, TestAnalysis.SINGLEREFERENCE_Level, TestAnalysis.REFERENCE_TestAnalysis);
        _LevelFactorTypes = new MultipleAssociation<Level, LevelFactorType> (this, MULTIPLEREFERENCE_LevelFactorTypes, LevelFactorType.SINGLEREFERENCE_Level, LevelFactorType.REFERENCE_LevelFactorType);
        
        
        return this;
    }

    

    /**
     * Get the attribute LevelDescription
     */
    public String getLevelDescription ()
    {
        assertValid();
        String valToReturn = _LevelDescription;

            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                valToReturn = bhd.getLevelDescription ((Level)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 preLevelDescriptionChange (String newLevelDescription) 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 postLevelDescriptionChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute LevelDescription.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setLevelDescription (String newLevelDescription) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_LevelDescription.compare (_LevelDescription, newLevelDescription);
        
        try
        {
            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                newLevelDescription = bhd.setLevelDescription ((Level)this, newLevelDescription);
                oldAndNewIdentical = HELPER_LevelDescription.compare (_LevelDescription, newLevelDescription);
            }

            

            if (FIELD_LevelDescription_Validators.length > 0)
            {
                Object newLevelDescriptionObj = HELPER_LevelDescription.toObject (newLevelDescription);

                if (newLevelDescriptionObj != null)
                {
                    int     loopMax = FIELD_LevelDescription_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Level.get (FIELD_LevelDescription);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_LevelDescription () != FieldWriteability.FALSE, "Field  LevelDescription is not writeable");
            preLevelDescriptionChange (newLevelDescription);
            markFieldChange (FIELD_LevelDescription);
            _LevelDescription = newLevelDescription;            
            postFieldChange (FIELD_LevelDescription);
            postLevelDescriptionChange ();
        }
    }

    /**
     * Get the attribute LevelNotes
     */
    public String getLevelNotes ()
    {
        assertValid();
        String valToReturn = _LevelNotes;

            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                valToReturn = bhd.getLevelNotes ((Level)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 preLevelNotesChange (String newLevelNotes) 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 postLevelNotesChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute LevelNotes.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setLevelNotes (String newLevelNotes) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_LevelNotes.compare (_LevelNotes, newLevelNotes);
        
        try
        {
            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                newLevelNotes = bhd.setLevelNotes ((Level)this, newLevelNotes);
                oldAndNewIdentical = HELPER_LevelNotes.compare (_LevelNotes, newLevelNotes);
            }

            

            if (FIELD_LevelNotes_Validators.length > 0)
            {
                Object newLevelNotesObj = HELPER_LevelNotes.toObject (newLevelNotes);

                if (newLevelNotesObj != null)
                {
                    int     loopMax = FIELD_LevelNotes_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Level.get (FIELD_LevelNotes);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_LevelNotes () != FieldWriteability.FALSE, "Field  LevelNotes is not writeable");
            preLevelNotesChange (newLevelNotes);
            markFieldChange (FIELD_LevelNotes);
            _LevelNotes = newLevelNotes;            
            postFieldChange (FIELD_LevelNotes);
            postLevelNotesChange ();
        }
    }

    /**
     * Get the attribute ReportHeader
     */
    public String getReportHeader ()
    {
        assertValid();
        String valToReturn = _ReportHeader;

            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                valToReturn = bhd.getReportHeader ((Level)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 preReportHeaderChange (String newReportHeader) 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 postReportHeaderChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ReportHeader.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setReportHeader (String newReportHeader) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ReportHeader.compare (_ReportHeader, newReportHeader);
        
        try
        {
            for (LevelBehaviourDecorator bhd : Level_BehaviourDecorators)
            {
                newReportHeader = bhd.setReportHeader ((Level)this, newReportHeader);
                oldAndNewIdentical = HELPER_ReportHeader.compare (_ReportHeader, newReportHeader);
            }

            

            if (FIELD_ReportHeader_Validators.length > 0)
            {
                Object newReportHeaderObj = HELPER_ReportHeader.toObject (newReportHeader);

                if (newReportHeaderObj != null)
                {
                    int     loopMax = FIELD_ReportHeader_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Level.get (FIELD_ReportHeader);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ReportHeader () != FieldWriteability.FALSE, "Field  ReportHeader is not writeable");
            preReportHeaderChange (newReportHeader);
            markFieldChange (FIELD_ReportHeader);
            _ReportHeader = newReportHeader;            
            postFieldChange (FIELD_ReportHeader);
            postReportHeaderChange ();
        }
    }



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

        

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


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


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


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


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



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

        
        result.add("Factors");
        
        result.add("Results");
        
        result.add("Narratives");
        
        result.add("TestAnalysises");
        
        result.add("LevelFactorTypes");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            return FactorLevelLink.REFERENCE_FactorLevelLink ;
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return FactorScoreResult.REFERENCE_FactorScoreResult ;
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            return Narrative.REFERENCE_Narrative ;
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            return TestAnalysis.REFERENCE_TestAnalysis ;
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            return LevelFactorType.REFERENCE_LevelFactorType ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            return FactorLevelLink.SINGLEREFERENCE_Level ;
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return FactorScoreResult.SINGLEREFERENCE_Level ;
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            return Narrative.SINGLEREFERENCE_Level ;
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            return TestAnalysis.SINGLEREFERENCE_Level ;
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            return LevelFactorType.SINGLEREFERENCE_Level ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            return this.getFactorsCount();
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return this.getResultsCount();
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            return this.getNarrativesCount();
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            return this.getTestAnalysisesCount();
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            return this.getLevelFactorTypesCount();
        }
        

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            return this.getFactorsAt(index);
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return this.getResultsAt(index);
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            return this.getNarrativesAt(index);
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            return this.getTestAnalysisesAt(index);
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            return this.getLevelFactorTypesAt(index);
        }
        

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            addToFactors((FactorLevelLink)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            addToResults((FactorScoreResult)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            addToNarratives((Narrative)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            addToTestAnalysises((TestAnalysis)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            addToLevelFactorTypes((LevelFactorType)newElement);

            return;
        }
        

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            removeFromFactors((FactorLevelLink)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            removeFromResults((FactorScoreResult)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            removeFromNarratives((Narrative)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            removeFromTestAnalysises((TestAnalysis)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            removeFromLevelFactorTypes((LevelFactorType)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            _Factors.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            _Results.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            _Narratives.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            _TestAnalysises.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            _LevelFactorTypes.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_Factors.equals(attribName))
        {
            return _Factors.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_Results.equals(attribName))
        {
            return _Results.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_Narratives.equals(attribName))
        {
            return _Narratives.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_TestAnalysises.equals(attribName))
        {
            return _TestAnalysises.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_LevelFactorTypes.equals(attribName))
        {
            return _LevelFactorTypes.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_Factors ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getFactorsCount () throws StorageException
    {
        assertValid();
        return _Factors.getReferencedObjectsCount ();
    }


    public void addToFactors (FactorLevelLink newElement) throws StorageException
    {
        if (_Factors.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Factors () != FieldWriteability.FALSE, "MultiAssoc Factors is not writeable (add)");
            _Factors.appendElement (newElement);

            try
            {
                if (newElement.getLevel () != this)
                {
                    newElement.setLevel ((Level)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromFactors (FactorLevelLink elementToRemove) throws StorageException
    {
        if (_Factors.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Factors () != FieldWriteability.FALSE, "MultiAssoc Factors is not writeable (remove)");
            _Factors.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getLevel () != null)
                {
                    elementToRemove.setLevel (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public FactorLevelLink getFactorsAt (int index) throws StorageException
    {
        return (FactorLevelLink)(_Factors.getElementAt (index));
    }


    public SortedSet<FactorLevelLink> getFactorsSet () throws StorageException
    {
        return _Factors.getSet ();
    }

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


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

            try
            {
                if (newElement.getLevel () != this)
                {
                    newElement.setLevel ((Level)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


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


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


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

    public FieldWriteability getWriteability_Narratives ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getNarrativesCount () throws StorageException
    {
        assertValid();
        return _Narratives.getReferencedObjectsCount ();
    }


    public void addToNarratives (Narrative newElement) throws StorageException
    {
        if (_Narratives.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Narratives () != FieldWriteability.FALSE, "MultiAssoc Narratives is not writeable (add)");
            _Narratives.appendElement (newElement);

            try
            {
                if (newElement.getLevel () != this)
                {
                    newElement.setLevel ((Level)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromNarratives (Narrative elementToRemove) throws StorageException
    {
        if (_Narratives.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Narratives () != FieldWriteability.FALSE, "MultiAssoc Narratives is not writeable (remove)");
            _Narratives.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getLevel () != null)
                {
                    elementToRemove.setLevel (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public Narrative getNarrativesAt (int index) throws StorageException
    {
        return (Narrative)(_Narratives.getElementAt (index));
    }


    public SortedSet<Narrative> getNarrativesSet () throws StorageException
    {
        return _Narratives.getSet ();
    }

    public FieldWriteability getWriteability_TestAnalysises ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getTestAnalysisesCount () throws StorageException
    {
        assertValid();
        return _TestAnalysises.getReferencedObjectsCount ();
    }


    public void addToTestAnalysises (TestAnalysis newElement) throws StorageException
    {
        if (_TestAnalysises.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_TestAnalysises () != FieldWriteability.FALSE, "MultiAssoc TestAnalysises is not writeable (add)");
            _TestAnalysises.appendElement (newElement);

            try
            {
                if (newElement.getLevel () != this)
                {
                    newElement.setLevel ((Level)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromTestAnalysises (TestAnalysis elementToRemove) throws StorageException
    {
        if (_TestAnalysises.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_TestAnalysises () != FieldWriteability.FALSE, "MultiAssoc TestAnalysises is not writeable (remove)");
            _TestAnalysises.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getLevel () != null)
                {
                    elementToRemove.setLevel (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public TestAnalysis getTestAnalysisesAt (int index) throws StorageException
    {
        return (TestAnalysis)(_TestAnalysises.getElementAt (index));
    }


    public SortedSet<TestAnalysis> getTestAnalysisesSet () throws StorageException
    {
        return _TestAnalysises.getSet ();
    }

    public FieldWriteability getWriteability_LevelFactorTypes ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getLevelFactorTypesCount () throws StorageException
    {
        assertValid();
        return _LevelFactorTypes.getReferencedObjectsCount ();
    }


    public void addToLevelFactorTypes (LevelFactorType newElement) throws StorageException
    {
        if (_LevelFactorTypes.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_LevelFactorTypes () != FieldWriteability.FALSE, "MultiAssoc LevelFactorTypes is not writeable (add)");
            _LevelFactorTypes.appendElement (newElement);

            try
            {
                if (newElement.getLevel () != this)
                {
                    newElement.setLevel ((Level)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromLevelFactorTypes (LevelFactorType elementToRemove) throws StorageException
    {
        if (_LevelFactorTypes.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_LevelFactorTypes () != FieldWriteability.FALSE, "MultiAssoc LevelFactorTypes is not writeable (remove)");
            _LevelFactorTypes.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getLevel () != null)
                {
                    elementToRemove.setLevel (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public LevelFactorType getLevelFactorTypesAt (int index) throws StorageException
    {
        return (LevelFactorType)(_LevelFactorTypes.getElementAt (index));
    }


    public SortedSet<LevelFactorType> getLevelFactorTypesSet () throws StorageException
    {
        return _LevelFactorTypes.getSet ();
    }



    public void onDelete ()
    {
        try 
        {
            for(FactorLevelLink referenced : CollectionUtils.reverse(getFactorsSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Level from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setLevel(null);
            }

            for(FactorScoreResult referenced : CollectionUtils.reverse(getResultsSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Level from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setLevel(null);
            }

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

            for(TestAnalysis referenced : CollectionUtils.reverse(getTestAnalysisesSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Level from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setLevel(null);
            }

            for(LevelFactorType referenced : CollectionUtils.reverse(getLevelFactorTypesSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Level from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setLevel(null);
            }

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

        super.onDelete ();
    }


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


    public Level referenceInstance ()
    {
        return REFERENCE_Level;
    }


    public Level getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getLevelByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Level;
    }


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





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

        tl_levelPSet.setAttrib (FIELD_ObjectID, myID);
        tl_levelPSet.setAttrib (FIELD_LevelDescription, HELPER_LevelDescription.toObject (_LevelDescription)); //
        tl_levelPSet.setAttrib (FIELD_LevelNotes, HELPER_LevelNotes.toObject (_LevelNotes)); //
        tl_levelPSet.setAttrib (FIELD_ReportHeader, HELPER_ReportHeader.toObject (_ReportHeader)); //
        
    }


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

        
        PersistentSet   tl_levelPSet = allSets.getPersistentSet (objectID, "tl_level");

        _LevelDescription = (String)(HELPER_LevelDescription.fromObject (_LevelDescription, tl_levelPSet.getAttrib (FIELD_LevelDescription))); //
        _LevelNotes = (String)(HELPER_LevelNotes.fromObject (_LevelNotes, tl_levelPSet.getAttrib (FIELD_LevelNotes))); //
        _ReportHeader = (String)(HELPER_ReportHeader.fromObject (_ReportHeader, tl_levelPSet.getAttrib (FIELD_ReportHeader))); //
        
    }





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

        if (other instanceof Level)
        {
            Level otherLevel = (Level)other;
            
            try
            {
                setLevelDescription (otherLevel.getLevelDescription ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setLevelNotes (otherLevel.getLevelNotes ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setReportHeader (otherLevel.getReportHeader ());
            }
            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 BaseLevel)
        {
            BaseLevel sourceLevel = (BaseLevel)(source);

            _LevelDescription = sourceLevel._LevelDescription;
            _LevelNotes = sourceLevel._LevelNotes;
            _ReportHeader = sourceLevel._ReportHeader;
            
        }
    }


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

            
        }
    }


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

        if (source instanceof BaseLevel)
        {
            BaseLevel sourceLevel = (BaseLevel)(source);

            _Factors.copyFrom (sourceLevel._Factors, linkToGhosts);
            _Results.copyFrom (sourceLevel._Results, linkToGhosts);
            _Narratives.copyFrom (sourceLevel._Narratives, linkToGhosts);
            _TestAnalysises.copyFrom (sourceLevel._TestAnalysises, linkToGhosts);
            _LevelFactorTypes.copyFrom (sourceLevel._LevelFactorTypes, linkToGhosts);
            
        }
    }


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

        
    }


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

        _LevelDescription = (String)(HELPER_LevelDescription.readExternal (_LevelDescription, vals.get(FIELD_LevelDescription))); //
        _LevelNotes = (String)(HELPER_LevelNotes.readExternal (_LevelNotes, vals.get(FIELD_LevelNotes))); //
        _ReportHeader = (String)(HELPER_ReportHeader.readExternal (_ReportHeader, vals.get(FIELD_ReportHeader))); //
        _Factors.readExternalData(vals.get(MULTIPLEREFERENCE_Factors));
        _Results.readExternalData(vals.get(MULTIPLEREFERENCE_Results));
        _Narratives.readExternalData(vals.get(MULTIPLEREFERENCE_Narratives));
        _TestAnalysises.readExternalData(vals.get(MULTIPLEREFERENCE_TestAnalysises));
        _LevelFactorTypes.readExternalData(vals.get(MULTIPLEREFERENCE_LevelFactorTypes));
        
    }


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

        vals.put (FIELD_LevelDescription, HELPER_LevelDescription.writeExternal (_LevelDescription));
        vals.put (FIELD_LevelNotes, HELPER_LevelNotes.writeExternal (_LevelNotes));
        vals.put (FIELD_ReportHeader, HELPER_ReportHeader.writeExternal (_ReportHeader));
        vals.put (MULTIPLEREFERENCE_Factors, _Factors.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Results, _Results.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Narratives, _Narratives.writeExternalData());
        vals.put (MULTIPLEREFERENCE_TestAnalysises, _TestAnalysises.writeExternalData());
        vals.put (MULTIPLEREFERENCE_LevelFactorTypes, _LevelFactorTypes.writeExternalData());
        
    }


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

        if (other instanceof BaseLevel)
        {
            BaseLevel otherLevel = (BaseLevel)(other);

            
            if (!HELPER_LevelDescription.compare(this._LevelDescription, otherLevel._LevelDescription))
            {
                listener.notifyFieldChange(this, other, FIELD_LevelDescription, HELPER_LevelDescription.toObject(this._LevelDescription), HELPER_LevelDescription.toObject(otherLevel._LevelDescription));
            }
            if (!HELPER_LevelNotes.compare(this._LevelNotes, otherLevel._LevelNotes))
            {
                listener.notifyFieldChange(this, other, FIELD_LevelNotes, HELPER_LevelNotes.toObject(this._LevelNotes), HELPER_LevelNotes.toObject(otherLevel._LevelNotes));
            }
            if (!HELPER_ReportHeader.compare(this._ReportHeader, otherLevel._ReportHeader))
            {
                listener.notifyFieldChange(this, other, FIELD_ReportHeader, HELPER_ReportHeader.toObject(this._ReportHeader), HELPER_ReportHeader.toObject(otherLevel._ReportHeader));
            }

            // Compare single assocs
            

            // Compare multiple assocs
            _Factors.compare (otherLevel._Factors, listener);
            _Results.compare (otherLevel._Results, listener);
            _Narratives.compare (otherLevel._Narratives, listener);
            _TestAnalysises.compare (otherLevel._TestAnalysises, listener);
            _LevelFactorTypes.compare (otherLevel._LevelFactorTypes, listener);
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_LevelDescription, HELPER_LevelDescription.toObject(getLevelDescription()));
        visitor.visitField(this, FIELD_LevelNotes, HELPER_LevelNotes.toObject(getLevelNotes()));
        visitor.visitField(this, FIELD_ReportHeader, HELPER_ReportHeader.toObject(getReportHeader()));
        visitor.visitAssociation (_Factors);
        visitor.visitAssociation (_Results);
        visitor.visitAssociation (_Narratives);
        visitor.visitAssociation (_TestAnalysises);
        visitor.visitAssociation (_LevelFactorTypes);
        
    }


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

        if (scope.includes (_Factors))
        {
            visitor.visit (_Factors);
        }
        if (scope.includes (_Results))
        {
            visitor.visit (_Results);
        }
        if (scope.includes (_Narratives))
        {
            visitor.visit (_Narratives);
        }
        if (scope.includes (_TestAnalysises))
        {
            visitor.visit (_TestAnalysises);
        }
        if (scope.includes (_LevelFactorTypes))
        {
            visitor.visit (_LevelFactorTypes);
        }
        
    }


    public static Level createLevel (ObjectTransaction transaction) throws StorageException
    {
        Level     result = new Level ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Level getLevelByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Level)(transaction.getObjectByID (REFERENCE_Level, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_LevelDescription))
        {
            return filter.matches (getLevelDescription ());
        }
        else if (attribName.equals (FIELD_LevelNotes))
        {
            return filter.matches (getLevelNotes ());
        }
        else if (attribName.equals (FIELD_ReportHeader))
        {
            return filter.matches (getReportHeader ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andLevelDescription (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.level_desc", "LevelDescription");
                return this;
            }
            
            public SearchAll andLevelNotes (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.level_notes", "LevelNotes");
                return this;
            }
            
            public SearchAll andReportHeader (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.rpt_hdr", "ReportHeader");
                return this;
            }
            
                public Level[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Level, SEARCH_All, criteria);
            Set<Level>   typedResults = new LinkedHashSet <Level> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Level aResult = (Level)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Level[0]);
                            
        }
    }

        
                public static Level[]
             searchAll (ObjectTransaction transaction) throws StorageException
        {
            return SearchByAll ()
            .search (transaction);
        }

    public static SearchName SearchByName () { return new SearchName (); }

    public static class SearchName extends SearchObject<Level>
    {
        
        public SearchName byName (String Name)
        {
            by ("Name", Name);
            return this;
        }
        
            public SearchName andObjectID (QueryFilter<Long> filter)
            {
                filter.addFilter (context, "tl_level.object_id", FIELD_ObjectID);
                return this;
            }

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

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

            
            public SearchName andLevelDescription (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.level_desc", "LevelDescription");
                return this;
            }
            
            public SearchName andLevelNotes (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.level_notes", "LevelNotes");
                return this;
            }
            
            public SearchName andReportHeader (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_level.rpt_hdr", "ReportHeader");
                return this;
            }
            
                public Level search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Level, SEARCH_Name, criteria);
            Set<Level>   typedResults = new LinkedHashSet <Level> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Level aResult = (Level)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return (Level)singletonResult(ObjstoreUtils.removeDeleted(transaction, typedResults).toArray(new BaseBusinessClass[0]), "Level", "");
                            
        }
    }

        
                public static Level searchName (ObjectTransaction transaction, String Name) throws StorageException
        {
            return SearchByName ()
            .byName  (Name)
            .search (transaction);
        }



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_LevelDescription))
        {
            return HELPER_LevelDescription.toObject (getLevelDescription ());
        }
        else if (attribName.equals (FIELD_LevelNotes))
        {
            return HELPER_LevelNotes.toObject (getLevelNotes ());
        }
        else if (attribName.equals (FIELD_ReportHeader))
        {
            return HELPER_ReportHeader.toObject (getReportHeader ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_LevelDescription))
        {
            return HELPER_LevelDescription;
        }
        else if (attribName.equals (FIELD_LevelNotes))
        {
            return HELPER_LevelNotes;
        }
        else if (attribName.equals (FIELD_ReportHeader))
        {
            return HELPER_ReportHeader;
        }
        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_LevelDescription))
        {
            setLevelDescription ((String)(HELPER_LevelDescription.fromObject (_LevelDescription, attribValue)));            
        }
        else if (attribName.equals (FIELD_LevelNotes))
        {
            setLevelNotes ((String)(HELPER_LevelNotes.fromObject (_LevelNotes, attribValue)));            
        }
        else if (attribName.equals (FIELD_ReportHeader))
        {
            setReportHeader ((String)(HELPER_ReportHeader.fromObject (_ReportHeader, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }



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


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_LevelDescription))
        {
            return getWriteability_LevelDescription ();
        }
        else if (fieldName.equals (FIELD_LevelNotes))
        {
            return getWriteability_LevelNotes ();
        }
        else if (fieldName.equals (FIELD_ReportHeader))
        {
            return getWriteability_ReportHeader ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Factors))
        {
            return getWriteability_Factors ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Results))
        {
            return getWriteability_Results ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Narratives))
        {
            return getWriteability_Narratives ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_TestAnalysises))
        {
            return getWriteability_TestAnalysises ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_LevelFactorTypes))
        {
            return getWriteability_LevelFactorTypes ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_LevelDescription () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_LevelDescription);
            }
        
            if (getWriteability_LevelNotes () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_LevelNotes);
            }
        
            if (getWriteability_ReportHeader () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ReportHeader);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_LevelDescription.getAttribObject (getClass (), _LevelDescription, false, FIELD_LevelDescription));
        result.add(HELPER_LevelNotes.getAttribObject (getClass (), _LevelNotes, false, FIELD_LevelNotes));
        result.add(HELPER_ReportHeader.getAttribObject (getClass (), _ReportHeader, false, FIELD_ReportHeader));

        return result;
    }


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


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

    public void preCommit (boolean willBeStored) throws Exception
    {
        super.preCommit(willBeStored);
        
        if(willBeStored)
        {
        
        }
    }

    public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
    {
        
        
        return super.getBinaryContentHandler(attribName);
    }

    public static class LevelBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<Level>
    {

    /**
     * Get the attribute LevelDescription
     */
    public String getLevelDescription (Level obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute LevelDescription.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setLevelDescription (Level obj, String newLevelDescription) throws FieldException
    {
        return newLevelDescription;
    }

    /**
     * Get the attribute LevelNotes
     */
    public String getLevelNotes (Level obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute LevelNotes.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setLevelNotes (Level obj, String newLevelNotes) throws FieldException
    {
        return newLevelNotes;
    }

    /**
     * Get the attribute ReportHeader
     */
    public String getReportHeader (Level obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ReportHeader.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setReportHeader (Level obj, String newReportHeader) throws FieldException
    {
        return newReportHeader;
    }

    }

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

        public LevelPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Factors"))
            {
                return toFactors ();
            }                
            if (name.equals ("Results"))
            {
                return toResults ();
            }                
            if (name.equals ("Narratives"))
            {
                return toNarratives ();
            }                
            if (name.equals ("TestAnalysises"))
            {
                return toTestAnalysises ();
            }                
            if (name.equals ("LevelFactorTypes"))
            {
                return toLevelFactorTypes ();
            }                
            if (name.equals ("LevelDescription"))
            {
                return toLevelDescription ();
            }                
            if (name.equals ("LevelNotes"))
            {
                return toLevelNotes ();
            }                
            if (name.equals ("ReportHeader"))
            {
                return toReportHeader ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toLevelDescription () { return pipe(new ORMAttributePipe<Me, String>(FIELD_LevelDescription));  }
        
        public PipeLine<From, String> toLevelNotes () { return pipe(new ORMAttributePipe<Me, String>(FIELD_LevelNotes));  }
        
        public PipeLine<From, String> toReportHeader () { return pipe(new ORMAttributePipe<Me, String>(FIELD_ReportHeader));  }
        public FactorLevelLink.FactorLevelLinkPipeLineFactory<From, FactorLevelLink> toFactors () { return toFactors(Filter.ALL); }        

        public FactorLevelLink.FactorLevelLinkPipeLineFactory<From, FactorLevelLink> toFactors (Filter<FactorLevelLink> filter)
        {
            return FactorLevelLink.REFERENCE_FactorLevelLink.new FactorLevelLinkPipeLineFactory<From, FactorLevelLink> (this, new ORMMultiAssocPipe<Me, FactorLevelLink>(MULTIPLEREFERENCE_Factors, filter)); 
        }
        public FactorScoreResult.FactorScoreResultPipeLineFactory<From, FactorScoreResult> toResults () { return toResults(Filter.ALL); }        

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

        public Narrative.NarrativePipeLineFactory<From, Narrative> toNarratives (Filter<Narrative> filter)
        {
            return Narrative.REFERENCE_Narrative.new NarrativePipeLineFactory<From, Narrative> (this, new ORMMultiAssocPipe<Me, Narrative>(MULTIPLEREFERENCE_Narratives, filter)); 
        }
        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysises () { return toTestAnalysises(Filter.ALL); }        

        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysises (Filter<TestAnalysis> filter)
        {
            return TestAnalysis.REFERENCE_TestAnalysis.new TestAnalysisPipeLineFactory<From, TestAnalysis> (this, new ORMMultiAssocPipe<Me, TestAnalysis>(MULTIPLEREFERENCE_TestAnalysises, filter)); 
        }
        public LevelFactorType.LevelFactorTypePipeLineFactory<From, LevelFactorType> toLevelFactorTypes () { return toLevelFactorTypes(Filter.ALL); }        

        public LevelFactorType.LevelFactorTypePipeLineFactory<From, LevelFactorType> toLevelFactorTypes (Filter<LevelFactorType> filter)
        {
            return LevelFactorType.REFERENCE_LevelFactorType.new LevelFactorTypePipeLineFactory<From, LevelFactorType> (this, new ORMMultiAssocPipe<Me, LevelFactorType>(MULTIPLEREFERENCE_LevelFactorTypes, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


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


    public FactorLevelLink getFactorsAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Factors");
    }


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

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


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


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

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


    public Narrative getNarrativesAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Narratives");
    }


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

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


    public TestAnalysis getTestAnalysisesAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association TestAnalysises");
    }


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

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


    public LevelFactorType getLevelFactorTypesAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association LevelFactorTypes");
    }


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

}

    
