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

import performa.orm.types.*;



public abstract class BaseLevelClassCriteria extends BaseBusinessClass
{
    // Reference instance for the object
    public static final LevelClassCriteria REFERENCE_LevelClassCriteria = new LevelClassCriteria ();

    // Reference instance for the object
    public static final LevelClassCriteria DUMMY_LevelClassCriteria = new DummyLevelClassCriteria ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Importance = "Importance";
    public static final String FIELD_FactorClass = "FactorClass";
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String BACKREF_Level = "";

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

    // Static constants corresponding to attribute helpers
    private static final EnumeratedAttributeHelper<LevelClassCriteria, Importance> HELPER_Importance =  new EnumeratedAttributeHelper<LevelClassCriteria, Importance> (Importance.FACTORY_Importance);
    private static final EnumeratedAttributeHelper<LevelClassCriteria, FactorClass> HELPER_FactorClass =  new EnumeratedAttributeHelper<LevelClassCriteria, FactorClass> (FactorClass.FACTORY_FactorClass);
    

    // Private attributes corresponding to business object data
    private Importance _Importance;
    private FactorClass _FactorClass;
    

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

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Importance_Validators;
    private static final AttributeValidator[] FIELD_FactorClass_Validators;
    

    // Arrays of behaviour decorators
    private static final LevelClassCriteriaBehaviourDecorator[] LevelClassCriteria_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Level = Level.BACKREF_LevelClassCriterias;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Level();
            FIELD_Importance_Validators = (AttributeValidator[])setupAttribMetaData_Importance(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_FactorClass_Validators = (AttributeValidator[])setupAttribMetaData_FactorClass(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_LevelClassCriteria.initialiseReference ();
            DUMMY_LevelClassCriteria.initialiseReference ();
            LevelClassCriteria_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(LevelClassCriteria.class).toArray(new LevelClassCriteriaBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "weighting");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Importance");
        metaInfo.put ("type", "Importance");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for LevelClassCriteria.Importance:", metaInfo);
        ATTRIBUTES_METADATA_LevelClassCriteria.put (FIELD_Importance, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "class_code");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "FactorClass");
        metaInfo.put ("type", "FactorClass");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for LevelClassCriteria.FactorClass:", metaInfo);
        ATTRIBUTES_METADATA_LevelClassCriteria.put (FIELD_FactorClass, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Importance = (Importance)(HELPER_Importance.initialise (_Importance));
        _FactorClass = (FactorClass)(HELPER_FactorClass.initialise (_FactorClass));
    }


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

        _Level = new SingleAssociation<LevelClassCriteria, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_LevelClassCriterias, Level.REFERENCE_Level, "tl_level_class_criteria");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Level = new SingleAssociation<LevelClassCriteria, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_LevelClassCriterias, Level.REFERENCE_Level, "tl_level_class_criteria");
        
        
        return this;
    }

    

    /**
     * Get the attribute Importance
     */
    public Importance getImportance ()
    {
        assertValid();
        Importance valToReturn = _Importance;

            for (LevelClassCriteriaBehaviourDecorator bhd : LevelClassCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getImportance ((LevelClassCriteria)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 preImportanceChange (Importance newImportance) 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 postImportanceChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Importance.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setImportance (Importance newImportance) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Importance.compare (_Importance, newImportance);
        
        try
        {
            for (LevelClassCriteriaBehaviourDecorator bhd : LevelClassCriteria_BehaviourDecorators)
            {
                newImportance = bhd.setImportance ((LevelClassCriteria)this, newImportance);
                oldAndNewIdentical = HELPER_Importance.compare (_Importance, newImportance);
            }

            BusinessObjectParser.assertFieldCondition (newImportance != null, this, FIELD_Importance, "mandatory");
            

            if (FIELD_Importance_Validators.length > 0)
            {
                Object newImportanceObj = HELPER_Importance.toObject (newImportance);

                if (newImportanceObj != null)
                {
                    int     loopMax = FIELD_Importance_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_LevelClassCriteria.get (FIELD_Importance);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Importance () != FieldWriteability.FALSE, "Field  Importance is not writeable");
            preImportanceChange (newImportance);
            markFieldChange (FIELD_Importance);
            _Importance = newImportance;            
            postFieldChange (FIELD_Importance);
            postImportanceChange ();
        }
    }

    /**
     * Get the attribute FactorClass
     */
    public FactorClass getFactorClass ()
    {
        assertValid();
        FactorClass valToReturn = _FactorClass;

            for (LevelClassCriteriaBehaviourDecorator bhd : LevelClassCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getFactorClass ((LevelClassCriteria)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 preFactorClassChange (FactorClass newFactorClass) 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 postFactorClassChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute FactorClass.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setFactorClass (FactorClass newFactorClass) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_FactorClass.compare (_FactorClass, newFactorClass);
        
        try
        {
            for (LevelClassCriteriaBehaviourDecorator bhd : LevelClassCriteria_BehaviourDecorators)
            {
                newFactorClass = bhd.setFactorClass ((LevelClassCriteria)this, newFactorClass);
                oldAndNewIdentical = HELPER_FactorClass.compare (_FactorClass, newFactorClass);
            }

            BusinessObjectParser.assertFieldCondition (newFactorClass != null, this, FIELD_FactorClass, "mandatory");
            

            if (FIELD_FactorClass_Validators.length > 0)
            {
                Object newFactorClassObj = HELPER_FactorClass.toObject (newFactorClass);

                if (newFactorClassObj != null)
                {
                    int     loopMax = FIELD_FactorClass_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_LevelClassCriteria.get (FIELD_FactorClass);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_FactorClass () != FieldWriteability.FALSE, "Field  FactorClass is not writeable");
            preFactorClassChange (newFactorClass);
            markFieldChange (FIELD_FactorClass);
            _FactorClass = newFactorClass;            
            postFieldChange (FIELD_FactorClass);
            postFactorClassChange ();
        }
    }



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

        
        result.add("Level");
        

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


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


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


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


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



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getLevelID ()
    {
        assertValid();
        
        if (_Level == null)
        {
            return null;
        }
        else
        {
            return _Level.getID ();
        }
    }

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


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



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

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

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

                    _Level.set (newLevel);

                    if (newLevel != null)
                    {
                        newLevel.addToLevelClassCriterias ((LevelClassCriteria)(this));
                    }
                
            postLevelChange ();
        }
    }

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

        

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


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

        return super.getMultiAssocAt(attribName, index);
    }


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

        super.addToMultiAssoc(attribName, newElement);
    }

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

        super.removeFromMultiAssoc(attribName, oldElement);
    }


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

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        

        return super.__isMultiAssocLoaded(attribName);
    }

    



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

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

        super.onDelete ();
    }


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


    public LevelClassCriteria referenceInstance ()
    {
        return REFERENCE_LevelClassCriteria;
    }


    public LevelClassCriteria getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getLevelClassCriteriaByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_LevelClassCriteria;
    }


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





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

        super.getPersistentSets (allSets);

        
        PersistentSet   tl_level_class_criteriaPSet = allSets.getPersistentSet (myID, "tl_level_class_criteria", myPSetStatus);

        tl_level_class_criteriaPSet.setAttrib (FIELD_ObjectID, myID);
        tl_level_class_criteriaPSet.setAttrib (FIELD_Importance, HELPER_Importance.toObject (_Importance)); //
        tl_level_class_criteriaPSet.setAttrib (FIELD_FactorClass, HELPER_FactorClass.toObject (_FactorClass)); //
        _Level.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_level_class_criteriaPSet = allSets.getPersistentSet (objectID, "tl_level_class_criteria");

        _Importance = (Importance)(HELPER_Importance.fromObject (_Importance, tl_level_class_criteriaPSet.getAttrib (FIELD_Importance))); //
        _FactorClass = (FactorClass)(HELPER_FactorClass.fromObject (_FactorClass, tl_level_class_criteriaPSet.getAttrib (FIELD_FactorClass))); //
        _Level.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof LevelClassCriteria)
        {
            LevelClassCriteria otherLevelClassCriteria = (LevelClassCriteria)other;
            
            try
            {
                setImportance (otherLevelClassCriteria.getImportance ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setFactorClass (otherLevelClassCriteria.getFactorClass ());
            }
            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 BaseLevelClassCriteria)
        {
            BaseLevelClassCriteria sourceLevelClassCriteria = (BaseLevelClassCriteria)(source);

            _Importance = sourceLevelClassCriteria._Importance;
            _FactorClass = sourceLevelClassCriteria._FactorClass;
            
        }
    }


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

            _Level.copyFrom (sourceLevelClassCriteria._Level, linkToGhosts);
            
        }
    }


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

        if (source instanceof BaseLevelClassCriteria)
        {
            BaseLevelClassCriteria sourceLevelClassCriteria = (BaseLevelClassCriteria)(source);

            
        }
    }


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

        
    }


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

        _Importance = (Importance)(HELPER_Importance.readExternal (_Importance, vals.get(FIELD_Importance))); //
        _FactorClass = (FactorClass)(HELPER_FactorClass.readExternal (_FactorClass, vals.get(FIELD_FactorClass))); //
        _Level.readExternalData(vals.get(SINGLEREFERENCE_Level));
        
    }


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

        vals.put (FIELD_Importance, HELPER_Importance.writeExternal (_Importance));
        vals.put (FIELD_FactorClass, HELPER_FactorClass.writeExternal (_FactorClass));
        vals.put (SINGLEREFERENCE_Level, _Level.writeExternalData());
        
    }


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

        if (other instanceof BaseLevelClassCriteria)
        {
            BaseLevelClassCriteria otherLevelClassCriteria = (BaseLevelClassCriteria)(other);

            
            if (!HELPER_Importance.compare(this._Importance, otherLevelClassCriteria._Importance))
            {
                listener.notifyFieldChange(this, other, FIELD_Importance, HELPER_Importance.toObject(this._Importance), HELPER_Importance.toObject(otherLevelClassCriteria._Importance));
            }
            if (!HELPER_FactorClass.compare(this._FactorClass, otherLevelClassCriteria._FactorClass))
            {
                listener.notifyFieldChange(this, other, FIELD_FactorClass, HELPER_FactorClass.toObject(this._FactorClass), HELPER_FactorClass.toObject(otherLevelClassCriteria._FactorClass));
            }

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

            // Compare multiple assocs
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_Importance, HELPER_Importance.toObject(getImportance()));
        visitor.visitField(this, FIELD_FactorClass, HELPER_FactorClass.toObject(getFactorClass()));
        visitor.visitAssociation (_Level);
        
    }


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

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


    public static LevelClassCriteria createLevelClassCriteria (ObjectTransaction transaction) throws StorageException
    {
        LevelClassCriteria     result = new LevelClassCriteria ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static LevelClassCriteria getLevelClassCriteriaByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (LevelClassCriteria)(transaction.getObjectByID (REFERENCE_LevelClassCriteria, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return filter.matches (getImportance ());
        }
        else if (attribName.equals (FIELD_FactorClass))
        {
            return filter.matches (getFactorClass ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Level))
        {
            return filter.matches (getLevel ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andImportance (QueryFilter<Importance> filter)
            {
                filter.addFilter (context, "tl_level_class_criteria.weighting", "Importance");
                return this;
            }
            
            public SearchAll andFactorClass (QueryFilter<FactorClass> filter)
            {
                filter.addFilter (context, "tl_level_class_criteria.class_code", "FactorClass");
                return this;
            }
            
            public SearchAll andLevel (QueryFilter<Level> filter)
            {
                filter.addFilter (context, "tl_level_class_criteria.level_number", "Level");
                return this;
            }
            
                public LevelClassCriteria[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_LevelClassCriteria, SEARCH_All, criteria);
            Set<LevelClassCriteria>   typedResults = new LinkedHashSet <LevelClassCriteria> ();
            for (BaseBusinessClass bbcResult : results)
            {
                LevelClassCriteria aResult = (LevelClassCriteria)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new LevelClassCriteria[0]);
                            
        }
    }

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



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance.toObject (getImportance ());
        }
        else if (attribName.equals (FIELD_FactorClass))
        {
            return HELPER_FactorClass.toObject (getFactorClass ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance;
        }
        else if (attribName.equals (FIELD_FactorClass))
        {
            return HELPER_FactorClass;
        }
        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_Importance))
        {
            setImportance ((Importance)(HELPER_Importance.fromObject (_Importance, attribValue)));            
        }
        else if (attribName.equals (FIELD_FactorClass))
        {
            setFactorClass ((FactorClass)(HELPER_FactorClass.fromObject (_FactorClass, 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_Importance))
        {
            return getWriteability_Importance ();
        }
        else if (fieldName.equals (FIELD_FactorClass))
        {
            return getWriteability_FactorClass ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Level))
        {
            return getWriteability_Level ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Importance () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Importance);
            }
        
            if (getWriteability_FactorClass () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_FactorClass);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Importance.getAttribObject (getClass (), _Importance, true, FIELD_Importance));
        result.add(HELPER_FactorClass.getAttribObject (getClass (), _FactorClass, true, FIELD_FactorClass));

        return result;
    }


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


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

    /**
     * Get the attribute Importance
     */
    public Importance getImportance (LevelClassCriteria obj, Importance original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Importance.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Importance setImportance (LevelClassCriteria obj, Importance newImportance) throws FieldException
    {
        return newImportance;
    }

    /**
     * Get the attribute FactorClass
     */
    public FactorClass getFactorClass (LevelClassCriteria obj, FactorClass original)
    {
        return original;
    }

    /**
     * Change the value set for attribute FactorClass.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public FactorClass setFactorClass (LevelClassCriteria obj, FactorClass newFactorClass) throws FieldException
    {
        return newFactorClass;
    }

    }

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

        public LevelClassCriteriaPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Importance"))
            {
                return toImportance ();
            }                
            if (name.equals ("FactorClass"))
            {
                return toFactorClass ();
            }                
            if (name.equals ("Level"))
            {
                return toLevel ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Importance> toImportance () { return pipe(new ORMAttributePipe<Me, Importance>(FIELD_Importance));  }
        
        public PipeLine<From, FactorClass> toFactorClass () { return pipe(new ORMAttributePipe<Me, FactorClass>(FIELD_FactorClass));  }
        public Level.LevelPipeLineFactory<From, Level> toLevel () { return toLevel (Filter.ALL); }

        public Level.LevelPipeLineFactory<From, Level> toLevel (Filter<Level> filter) 
        { 
            return Level.REFERENCE_Level.new LevelPipeLineFactory<From, Level> (this, new ORMSingleAssocPipe<Me, Level>(SINGLEREFERENCE_Level, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


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


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

}

    
