/*
 * 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_FactorLinks = "FactorLinks";
    public static final String BACKREF_FactorLinks = "";

    // Static constants corresponding to searches
    

    // 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> _FactorLinks;
    

    // 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_FactorLinks = FactorLevelLink.BACKREF_Level;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_FactorLinks();
            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_FactorLinks()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Level");
        metaInfo.put ("name", "FactorLinks");
        metaInfo.put ("type", "FactorLevelLink");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Level.FactorLinks:", metaInfo);
        ATTRIBUTES_METADATA_Level.put (MULTIPLEREFERENCE_FactorLinks, 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 ();

        _FactorLinks = new MultipleAssociation<Level, FactorLevelLink> (this, MULTIPLEREFERENCE_FactorLinks, FactorLevelLink.SINGLEREFERENCE_Level, FactorLevelLink.REFERENCE_FactorLevelLink);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _FactorLinks = new MultipleAssociation<Level, FactorLevelLink> (this, MULTIPLEREFERENCE_FactorLinks, FactorLevelLink.SINGLEREFERENCE_Level, FactorLevelLink.REFERENCE_FactorLevelLink);
        
        
        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("FactorLinks");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorLinks.equals(attribName))
        {
            return FactorLevelLink.REFERENCE_FactorLevelLink ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorLinks.equals(attribName))
        {
            return FactorLevelLink.SINGLEREFERENCE_Level ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_FactorLinks.equals(attribName))
        {
            return this.getFactorLinksAt(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_FactorLinks.equals(attribName))
        {
            addToFactorLinks((FactorLevelLink)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_FactorLinks.equals(attribName))
        {
            removeFromFactorLinks((FactorLevelLink)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_FactorLinks.equals(attribName))
        {
            _FactorLinks.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorLinks.equals(attribName))
        {
            return _FactorLinks.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_FactorLinks ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getFactorLinksCount () throws StorageException
    {
        assertValid();
        return _FactorLinks.getReferencedObjectsCount ();
    }


    public void addToFactorLinks (FactorLevelLink newElement) throws StorageException
    {
        if (_FactorLinks.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_FactorLinks () != FieldWriteability.FALSE, "MultiAssoc FactorLinks is not writeable (add)");
            _FactorLinks.appendElement (newElement);

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


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


    public FactorLevelLink getFactorLinksAt (int index) throws StorageException
    {
        return (FactorLevelLink)(_FactorLinks.getElementAt (index));
    }


    public SortedSet<FactorLevelLink> getFactorLinksSet () throws StorageException
    {
        return _FactorLinks.getSet ();
    }



    public void onDelete ()
    {
        try 
        {
            for(FactorLevelLink referenced : CollectionUtils.reverse(getFactorLinksSet()))
            { 
                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 "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   levelPSet = allSets.getPersistentSet (myID, "level", myPSetStatus);

        levelPSet.setAttrib (FIELD_ObjectID, myID);
        levelPSet.setAttrib (FIELD_LevelDescription, HELPER_LevelDescription.toObject (_LevelDescription)); //
        levelPSet.setAttrib (FIELD_LevelNotes, HELPER_LevelNotes.toObject (_LevelNotes)); //
        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   levelPSet = allSets.getPersistentSet (objectID, "level");

        _LevelDescription = (String)(HELPER_LevelDescription.fromObject (_LevelDescription, levelPSet.getAttrib (FIELD_LevelDescription))); //
        _LevelNotes = (String)(HELPER_LevelNotes.fromObject (_LevelNotes, levelPSet.getAttrib (FIELD_LevelNotes))); //
        _ReportHeader = (String)(HELPER_ReportHeader.fromObject (_ReportHeader, 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);

            _FactorLinks.copyFrom (sourceLevel._FactorLinks, 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))); //
        _FactorLinks.readExternalData(vals.get(MULTIPLEREFERENCE_FactorLinks));
        
    }


    /**
     * 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_FactorLinks, _FactorLinks.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
            _FactorLinks.compare (otherLevel._FactorLinks, 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 (_FactorLinks);
        
    }


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

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


    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 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_FactorLinks))
        {
            return getWriteability_FactorLinks ();
        }
        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 ("FactorLinks"))
            {
                return toFactorLinks ();
            }                
            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> toFactorLinks () { return toFactorLinks(Filter.ALL); }        

        public FactorLevelLink.FactorLevelLinkPipeLineFactory<From, FactorLevelLink> toFactorLinks (Filter<FactorLevelLink> filter)
        {
            return FactorLevelLink.REFERENCE_FactorLevelLink.new FactorLevelLinkPipeLineFactory<From, FactorLevelLink> (this, new ORMMultiAssocPipe<Me, FactorLevelLink>(MULTIPLEREFERENCE_FactorLinks, 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 getFactorLinksCount () throws StorageException
    {
        return 0;
    }


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


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

}

    
