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

    // Reference instance for the object
    public static final AssessmentCriteria DUMMY_AssessmentCriteria = new DummyAssessmentCriteria ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Name = "Name";
    public static final String FIELD_Importance = "Importance";
    public static final String FIELD_CriteriaType = "CriteriaType";
    public static final String SINGLEREFERENCE_Job = "Job";
    public static final String BACKREF_Job = "";
    public static final String SINGLEREFERENCE_Template = "Template";
    public static final String BACKREF_Template = "";
    public static final String MULTIPLEREFERENCE_Answers = "Answers";
    public static final String BACKREF_Answers = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<AssessmentCriteria> HELPER_Name = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<AssessmentCriteria, Importance> HELPER_Importance =  new EnumeratedAttributeHelper<AssessmentCriteria, Importance> (Importance.FACTORY_Importance);
    private static final EnumeratedAttributeHelper<AssessmentCriteria, CriteriaType> HELPER_CriteriaType =  new EnumeratedAttributeHelper<AssessmentCriteria, CriteriaType> (CriteriaType.FACTORY_CriteriaType);
    

    // Private attributes corresponding to business object data
    private String _Name;
    private Importance _Importance;
    private CriteriaType _CriteriaType;
    

    // Private attributes corresponding to single references
    private SingleAssociation<AssessmentCriteria, Job> _Job;
    private SingleAssociation<AssessmentCriteria, AssessmentCriteriaTemplate> _Template;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<AssessmentCriteria, AssessmentCriteriaAnswer> _Answers;
    

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

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

    // Arrays of behaviour decorators
    private static final AssessmentCriteriaBehaviourDecorator[] AssessmentCriteria_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Answers = AssessmentCriteriaAnswer.BACKREF_AssessmentCriteria;
            String tmp_Job = Job.BACKREF_AssessmentCriterias;
            String tmp_Template = AssessmentCriteriaTemplate.BACKREF_AssessmentCriterias;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Answers();
            setupAssocMetaData_Job();
            setupAssocMetaData_Template();
            FIELD_Name_Validators = (AttributeValidator[])setupAttribMetaData_Name(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Importance_Validators = (AttributeValidator[])setupAttribMetaData_Importance(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_CriteriaType_Validators = (AttributeValidator[])setupAttribMetaData_CriteriaType(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_AssessmentCriteria.initialiseReference ();
            DUMMY_AssessmentCriteria.initialiseReference ();
            AssessmentCriteria_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(AssessmentCriteria.class).toArray(new AssessmentCriteriaBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "AssessmentCriteria");
        metaInfo.put ("name", "Answers");
        metaInfo.put ("type", "AssessmentCriteriaAnswer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Answers:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (MULTIPLEREFERENCE_Answers, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Job()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "AssessmentCriterias");
        metaInfo.put ("dbcol", "job_id");
        metaInfo.put ("name", "Job");
        metaInfo.put ("type", "Job");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Job:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (SINGLEREFERENCE_Job, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Template()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "AssessmentCriterias");
        metaInfo.put ("dbcol", "template_id");
        metaInfo.put ("name", "Template");
        metaInfo.put ("type", "AssessmentCriteriaTemplate");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Template:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (SINGLEREFERENCE_Template, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Name(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "name");
        metaInfo.put ("length", "200");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Name");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Name:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_Name, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "importance");
        metaInfo.put ("defaultValue", "Importance.DESIRABLE");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Importance");
        metaInfo.put ("type", "Importance");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Importance:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_Importance, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "assessment_type");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CriteriaType");
        metaInfo.put ("type", "CriteriaType");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.CriteriaType:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_CriteriaType, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Name = (String)(HELPER_Name.initialise (_Name));
        _Importance = (Importance)(Importance.DESIRABLE);
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.initialise (_CriteriaType));
    }


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

        _Job = new SingleAssociation<AssessmentCriteria, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_AssessmentCriterias, Job.REFERENCE_Job, "tl_assessment_criteria");
        _Template = new SingleAssociation<AssessmentCriteria, AssessmentCriteriaTemplate> (this, SINGLEREFERENCE_Template, AssessmentCriteriaTemplate.MULTIPLEREFERENCE_AssessmentCriterias, AssessmentCriteriaTemplate.REFERENCE_AssessmentCriteriaTemplate, "tl_assessment_criteria");
        _Answers = new MultipleAssociation<AssessmentCriteria, AssessmentCriteriaAnswer> (this, MULTIPLEREFERENCE_Answers, AssessmentCriteriaAnswer.SINGLEREFERENCE_AssessmentCriteria, AssessmentCriteriaAnswer.REFERENCE_AssessmentCriteriaAnswer);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Job = new SingleAssociation<AssessmentCriteria, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_AssessmentCriterias, Job.REFERENCE_Job, "tl_assessment_criteria");
        _Template = new SingleAssociation<AssessmentCriteria, AssessmentCriteriaTemplate> (this, SINGLEREFERENCE_Template, AssessmentCriteriaTemplate.MULTIPLEREFERENCE_AssessmentCriterias, AssessmentCriteriaTemplate.REFERENCE_AssessmentCriteriaTemplate, "tl_assessment_criteria");
        _Answers = new MultipleAssociation<AssessmentCriteria, AssessmentCriteriaAnswer> (this, MULTIPLEREFERENCE_Answers, AssessmentCriteriaAnswer.SINGLEREFERENCE_AssessmentCriteria, AssessmentCriteriaAnswer.REFERENCE_AssessmentCriteriaAnswer);
        
        
        return this;
    }

    

    /**
     * Get the attribute Name
     */
    public String getName ()
    {
        assertValid();
        String valToReturn = _Name;

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getName ((AssessmentCriteria)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 preNameChange (String newName) 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 postNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Name.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setName (String newName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Name.compare (_Name, newName);
        
        try
        {
            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newName = bhd.setName ((AssessmentCriteria)this, newName);
                oldAndNewIdentical = HELPER_Name.compare (_Name, newName);
            }

            BusinessObjectParser.assertFieldCondition (newName != null, this, FIELD_Name, "mandatory");
            

            if (FIELD_Name_Validators.length > 0)
            {
                Object newNameObj = HELPER_Name.toObject (newName);

                if (newNameObj != null)
                {
                    int     loopMax = FIELD_Name_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_AssessmentCriteria.get (FIELD_Name);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Name () != FieldWriteability.FALSE, "Field  Name is not writeable");
            preNameChange (newName);
            markFieldChange (FIELD_Name);
            _Name = newName;            
            postFieldChange (FIELD_Name);
            postNameChange ();
        }
    }

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

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getImportance ((AssessmentCriteria)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 (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newImportance = bhd.setImportance ((AssessmentCriteria)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_AssessmentCriteria.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 CriteriaType
     */
    public CriteriaType getCriteriaType ()
    {
        assertValid();
        CriteriaType valToReturn = _CriteriaType;

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getCriteriaType ((AssessmentCriteria)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 preCriteriaTypeChange (CriteriaType newCriteriaType) 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 postCriteriaTypeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CriteriaType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCriteriaType (CriteriaType newCriteriaType) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CriteriaType.compare (_CriteriaType, newCriteriaType);
        
        try
        {
            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newCriteriaType = bhd.setCriteriaType ((AssessmentCriteria)this, newCriteriaType);
                oldAndNewIdentical = HELPER_CriteriaType.compare (_CriteriaType, newCriteriaType);
            }

            BusinessObjectParser.assertFieldCondition (newCriteriaType != null, this, FIELD_CriteriaType, "mandatory");
            

            if (FIELD_CriteriaType_Validators.length > 0)
            {
                Object newCriteriaTypeObj = HELPER_CriteriaType.toObject (newCriteriaType);

                if (newCriteriaTypeObj != null)
                {
                    int     loopMax = FIELD_CriteriaType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_AssessmentCriteria.get (FIELD_CriteriaType);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CriteriaType () != FieldWriteability.FALSE, "Field  CriteriaType is not writeable");
            preCriteriaTypeChange (newCriteriaType);
            markFieldChange (FIELD_CriteriaType);
            _CriteriaType = newCriteriaType;            
            postFieldChange (FIELD_CriteriaType);
            postCriteriaTypeChange ();
        }
    }



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

        
        result.add("Job");
        
        result.add("Template");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Job))
        {
            return _Job.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return _Template.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_Job))
        {
            return Job.MULTIPLEREFERENCE_AssessmentCriterias ;
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return AssessmentCriteriaTemplate.MULTIPLEREFERENCE_AssessmentCriterias ;
        }
        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_Job))
        {
            return getJob ();
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return getTemplate ();
        }
        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_Job))
        {
            return getJob (getType);
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return getTemplate (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_Job))
        {
            return getJobID ();
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return getTemplateID ();
        }
        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_Job))
        {
            setJob ((Job)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            setTemplate ((AssessmentCriteriaTemplate)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobID ()
    {
        assertValid();
        
        if (_Job == null)
        {
            return null;
        }
        else
        {
            return _Job.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 preJobChange (Job newJob) 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 postJobChange () throws FieldException
    {
    }



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

        if (_Job.wouldReferencedChange (newJob))
        {
            assertValid();
            Debug.assertion (getWriteability_Job () != FieldWriteability.FALSE, "Assoc Job is not writeable");
            preJobChange (newJob);
            Job oldJob = getJob ();

                    if (oldJob != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Job.set (null);
                        oldJob.removeFromAssessmentCriterias ((AssessmentCriteria)(this));
                    }

                    _Job.set (newJob);

                    if (newJob != null)
                    {
                        newJob.addToAssessmentCriterias ((AssessmentCriteria)(this));
                    }
                
            postJobChange ();
        }
    }

    /**
     * Get the reference Template
     */
    public AssessmentCriteriaTemplate getTemplate () throws StorageException
    {
        assertValid();
        
        try
        {
            return (AssessmentCriteriaTemplate)(_Template.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in AssessmentCriteria:", this.getObjectID (), ", was trying to get AssessmentCriteriaTemplate:",  getTemplateID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _Template.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getTemplateID ()
    {
        assertValid();
        
        if (_Template == null)
        {
            return null;
        }
        else
        {
            return _Template.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 preTemplateChange (AssessmentCriteriaTemplate newTemplate) 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 postTemplateChange () throws FieldException
    {
    }



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

        if (_Template.wouldReferencedChange (newTemplate))
        {
            assertValid();
            Debug.assertion (getWriteability_Template () != FieldWriteability.FALSE, "Assoc Template is not writeable");
            preTemplateChange (newTemplate);
            AssessmentCriteriaTemplate oldTemplate = getTemplate ();

                    if (oldTemplate != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Template.set (null);
                        oldTemplate.removeFromAssessmentCriterias ((AssessmentCriteria)(this));
                    }

                    _Template.set (newTemplate);

                    if (newTemplate != null)
                    {
                        newTemplate.addToAssessmentCriterias ((AssessmentCriteria)(this));
                    }
                
            postTemplateChange ();
        }
    }

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

        
        result.add("Answers");
        

        return result;
    }


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

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return AssessmentCriteriaAnswer.SINGLEREFERENCE_AssessmentCriteria ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return this.getAnswersAt(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_Answers.equals(attribName))
        {
            addToAnswers((AssessmentCriteriaAnswer)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_Answers.equals(attribName))
        {
            removeFromAnswers((AssessmentCriteriaAnswer)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


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

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_Answers.equals(attribName))
        {
            return _Answers.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_Answers ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getAnswersCount () throws StorageException
    {
        assertValid();
        return _Answers.getReferencedObjectsCount ();
    }


    public void addToAnswers (AssessmentCriteriaAnswer newElement) throws StorageException
    {
        if (_Answers.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Answers () != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (add)");
            _Answers.appendElement (newElement);

            try
            {
                if (newElement.getAssessmentCriteria () != this)
                {
                    newElement.setAssessmentCriteria ((AssessmentCriteria)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromAnswers (AssessmentCriteriaAnswer elementToRemove) throws StorageException
    {
        if (_Answers.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Answers () != FieldWriteability.FALSE, "MultiAssoc Answers is not writeable (remove)");
            _Answers.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getAssessmentCriteria () != null)
                {
                    elementToRemove.setAssessmentCriteria (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public AssessmentCriteriaAnswer getAnswersAt (int index) throws StorageException
    {
        return (AssessmentCriteriaAnswer)(_Answers.getElementAt (index));
    }


    public SortedSet<AssessmentCriteriaAnswer> getAnswersSet () throws StorageException
    {
        return _Answers.getSet ();
    }



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

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null AssessmentCriterias from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Job.set (null);
                    referenced.removeFromAssessmentCriterias ((AssessmentCriteria)this);
                }
            }
        
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_Template.isLoaded () || getTransaction ().isObjectLoaded (_Template.getReferencedType (), getTemplateID ()))
            {
                AssessmentCriteriaTemplate  referenced = getTemplate ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null AssessmentCriterias from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Template.set (null);
                    referenced.removeFromAssessmentCriterias ((AssessmentCriteria)this);
                }
            }
        
            for(AssessmentCriteriaAnswer referenced : CollectionUtils.reverse(getAnswersSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null AssessmentCriteria from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setAssessmentCriteria(null);
            }

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

        super.onDelete ();
    }


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


    public AssessmentCriteria referenceInstance ()
    {
        return REFERENCE_AssessmentCriteria;
    }


    public AssessmentCriteria getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getAssessmentCriteriaByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_AssessmentCriteria;
    }


    public String getBaseSetName ()
    {
        return "tl_assessment_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_assessment_criteriaPSet = allSets.getPersistentSet (myID, "tl_assessment_criteria", myPSetStatus);

        tl_assessment_criteriaPSet.setAttrib (FIELD_ObjectID, myID);
        tl_assessment_criteriaPSet.setAttrib (FIELD_Name, HELPER_Name.toObject (_Name)); //
        tl_assessment_criteriaPSet.setAttrib (FIELD_Importance, HELPER_Importance.toObject (_Importance)); //
        tl_assessment_criteriaPSet.setAttrib (FIELD_CriteriaType, HELPER_CriteriaType.toObject (_CriteriaType)); //
        _Job.getPersistentSets (allSets);
        _Template.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_assessment_criteriaPSet = allSets.getPersistentSet (objectID, "tl_assessment_criteria");

        _Name = (String)(HELPER_Name.fromObject (_Name, tl_assessment_criteriaPSet.getAttrib (FIELD_Name))); //
        _Importance = (Importance)(HELPER_Importance.fromObject (_Importance, tl_assessment_criteriaPSet.getAttrib (FIELD_Importance))); //
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.fromObject (_CriteriaType, tl_assessment_criteriaPSet.getAttrib (FIELD_CriteriaType))); //
        _Job.setFromPersistentSets (objectID, allSets);
        _Template.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof AssessmentCriteria)
        {
            AssessmentCriteria otherAssessmentCriteria = (AssessmentCriteria)other;
            
            try
            {
                setName (otherAssessmentCriteria.getName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setImportance (otherAssessmentCriteria.getImportance ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setCriteriaType (otherAssessmentCriteria.getCriteriaType ());
            }
            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 BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria sourceAssessmentCriteria = (BaseAssessmentCriteria)(source);

            _Name = sourceAssessmentCriteria._Name;
            _Importance = sourceAssessmentCriteria._Importance;
            _CriteriaType = sourceAssessmentCriteria._CriteriaType;
            
        }
    }


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

            _Job.copyFrom (sourceAssessmentCriteria._Job, linkToGhosts);
            _Template.copyFrom (sourceAssessmentCriteria._Template, 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 BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria sourceAssessmentCriteria = (BaseAssessmentCriteria)(source);

            _Answers.copyFrom (sourceAssessmentCriteria._Answers, 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);

        _Name = (String)(HELPER_Name.readExternal (_Name, vals.get(FIELD_Name))); //
        _Importance = (Importance)(HELPER_Importance.readExternal (_Importance, vals.get(FIELD_Importance))); //
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.readExternal (_CriteriaType, vals.get(FIELD_CriteriaType))); //
        _Job.readExternalData(vals.get(SINGLEREFERENCE_Job));
        _Template.readExternalData(vals.get(SINGLEREFERENCE_Template));
        _Answers.readExternalData(vals.get(MULTIPLEREFERENCE_Answers));
        
    }


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

        vals.put (FIELD_Name, HELPER_Name.writeExternal (_Name));
        vals.put (FIELD_Importance, HELPER_Importance.writeExternal (_Importance));
        vals.put (FIELD_CriteriaType, HELPER_CriteriaType.writeExternal (_CriteriaType));
        vals.put (SINGLEREFERENCE_Job, _Job.writeExternalData());
        vals.put (SINGLEREFERENCE_Template, _Template.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Answers, _Answers.writeExternalData());
        
    }


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

        if (other instanceof BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria otherAssessmentCriteria = (BaseAssessmentCriteria)(other);

            
            if (!HELPER_Name.compare(this._Name, otherAssessmentCriteria._Name))
            {
                listener.notifyFieldChange(this, other, FIELD_Name, HELPER_Name.toObject(this._Name), HELPER_Name.toObject(otherAssessmentCriteria._Name));
            }
            if (!HELPER_Importance.compare(this._Importance, otherAssessmentCriteria._Importance))
            {
                listener.notifyFieldChange(this, other, FIELD_Importance, HELPER_Importance.toObject(this._Importance), HELPER_Importance.toObject(otherAssessmentCriteria._Importance));
            }
            if (!HELPER_CriteriaType.compare(this._CriteriaType, otherAssessmentCriteria._CriteriaType))
            {
                listener.notifyFieldChange(this, other, FIELD_CriteriaType, HELPER_CriteriaType.toObject(this._CriteriaType), HELPER_CriteriaType.toObject(otherAssessmentCriteria._CriteriaType));
            }

            // Compare single assocs
            _Job.compare (otherAssessmentCriteria._Job, listener);
            _Template.compare (otherAssessmentCriteria._Template, listener);
            

            // Compare multiple assocs
            _Answers.compare (otherAssessmentCriteria._Answers, 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_Name, HELPER_Name.toObject(getName()));
        visitor.visitField(this, FIELD_Importance, HELPER_Importance.toObject(getImportance()));
        visitor.visitField(this, FIELD_CriteriaType, HELPER_CriteriaType.toObject(getCriteriaType()));
        visitor.visitAssociation (_Job);
        visitor.visitAssociation (_Template);
        visitor.visitAssociation (_Answers);
        
    }


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

        if (scope.includes (_Job))
        {
            visitor.visit (_Job);
        }
        if (scope.includes (_Template))
        {
            visitor.visit (_Template);
        }
        if (scope.includes (_Answers))
        {
            visitor.visit (_Answers);
        }
        
    }


    public static AssessmentCriteria createAssessmentCriteria (ObjectTransaction transaction) throws StorageException
    {
        AssessmentCriteria     result = new AssessmentCriteria ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static AssessmentCriteria getAssessmentCriteriaByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (AssessmentCriteria)(transaction.getObjectByID (REFERENCE_AssessmentCriteria, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Name))
        {
            return filter.matches (getName ());
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return filter.matches (getImportance ());
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return filter.matches (getCriteriaType ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Job))
        {
            return filter.matches (getJob ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Template))
        {
            return filter.matches (getTemplate ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.name", "Name");
                return this;
            }
            
            public SearchAll andImportance (QueryFilter<Importance> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.importance", "Importance");
                return this;
            }
            
            public SearchAll andCriteriaType (QueryFilter<CriteriaType> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.assessment_type", "CriteriaType");
                return this;
            }
            
            public SearchAll andJob (QueryFilter<Job> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.job_id", "Job");
                return this;
            }
            
            public SearchAll andTemplate (QueryFilter<AssessmentCriteriaTemplate> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.template_id", "Template");
                return this;
            }
            
                public AssessmentCriteria[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_AssessmentCriteria, SEARCH_All, criteria);
            Set<AssessmentCriteria>   typedResults = new LinkedHashSet <AssessmentCriteria> ();
            for (BaseBusinessClass bbcResult : results)
            {
                AssessmentCriteria aResult = (AssessmentCriteria)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new AssessmentCriteria[0]);
                            
        }
    }

        
                public static AssessmentCriteria[]
             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_Name))
        {
            return HELPER_Name.toObject (getName ());
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance.toObject (getImportance ());
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return HELPER_CriteriaType.toObject (getCriteriaType ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Name))
        {
            return HELPER_Name;
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance;
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return HELPER_CriteriaType;
        }
        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_Name))
        {
            setName ((String)(HELPER_Name.fromObject (_Name, attribValue)));            
        }
        else if (attribName.equals (FIELD_Importance))
        {
            setImportance ((Importance)(HELPER_Importance.fromObject (_Importance, attribValue)));            
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            setCriteriaType ((CriteriaType)(HELPER_CriteriaType.fromObject (_CriteriaType, 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_Name))
        {
            return getWriteability_Name ();
        }
        else if (fieldName.equals (FIELD_Importance))
        {
            return getWriteability_Importance ();
        }
        else if (fieldName.equals (FIELD_CriteriaType))
        {
            return getWriteability_CriteriaType ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Answers))
        {
            return getWriteability_Answers ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Job))
        {
            return getWriteability_Job ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Template))
        {
            return getWriteability_Template ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Name () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Name);
            }
        
            if (getWriteability_Importance () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Importance);
            }
        
            if (getWriteability_CriteriaType () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CriteriaType);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Name.getAttribObject (getClass (), _Name, true, FIELD_Name));
        result.add(HELPER_Importance.getAttribObject (getClass (), _Importance, true, FIELD_Importance));
        result.add(HELPER_CriteriaType.getAttribObject (getClass (), _CriteriaType, true, FIELD_CriteriaType));

        return result;
    }


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


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

    /**
     * Get the attribute Name
     */
    public String getName (AssessmentCriteria obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Name.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setName (AssessmentCriteria obj, String newName) throws FieldException
    {
        return newName;
    }

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

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

    /**
     * Get the attribute CriteriaType
     */
    public CriteriaType getCriteriaType (AssessmentCriteria obj, CriteriaType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CriteriaType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public CriteriaType setCriteriaType (AssessmentCriteria obj, CriteriaType newCriteriaType) throws FieldException
    {
        return newCriteriaType;
    }

    }

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

        public AssessmentCriteriaPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Answers"))
            {
                return toAnswers ();
            }                
            if (name.equals ("Name"))
            {
                return toName ();
            }                
            if (name.equals ("Importance"))
            {
                return toImportance ();
            }                
            if (name.equals ("CriteriaType"))
            {
                return toCriteriaType ();
            }                
            if (name.equals ("Job"))
            {
                return toJob ();
            }                
            if (name.equals ("Template"))
            {
                return toTemplate ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Name));  }
        
        public PipeLine<From, Importance> toImportance () { return pipe(new ORMAttributePipe<Me, Importance>(FIELD_Importance));  }
        
        public PipeLine<From, CriteriaType> toCriteriaType () { return pipe(new ORMAttributePipe<Me, CriteriaType>(FIELD_CriteriaType));  }
        public Job.JobPipeLineFactory<From, Job> toJob () { return toJob (Filter.ALL); }

        public Job.JobPipeLineFactory<From, Job> toJob (Filter<Job> filter) 
        { 
            return Job.REFERENCE_Job.new JobPipeLineFactory<From, Job> (this, new ORMSingleAssocPipe<Me, Job>(SINGLEREFERENCE_Job, filter)); 
        }
        public AssessmentCriteriaTemplate.AssessmentCriteriaTemplatePipeLineFactory<From, AssessmentCriteriaTemplate> toTemplate () { return toTemplate (Filter.ALL); }

        public AssessmentCriteriaTemplate.AssessmentCriteriaTemplatePipeLineFactory<From, AssessmentCriteriaTemplate> toTemplate (Filter<AssessmentCriteriaTemplate> filter) 
        { 
            return AssessmentCriteriaTemplate.REFERENCE_AssessmentCriteriaTemplate.new AssessmentCriteriaTemplatePipeLineFactory<From, AssessmentCriteriaTemplate> (this, new ORMSingleAssocPipe<Me, AssessmentCriteriaTemplate>(SINGLEREFERENCE_Template, filter)); 
        }
        public AssessmentCriteriaAnswer.AssessmentCriteriaAnswerPipeLineFactory<From, AssessmentCriteriaAnswer> toAnswers () { return toAnswers(Filter.ALL); }        

        public AssessmentCriteriaAnswer.AssessmentCriteriaAnswerPipeLineFactory<From, AssessmentCriteriaAnswer> toAnswers (Filter<AssessmentCriteriaAnswer> filter)
        {
            return AssessmentCriteriaAnswer.REFERENCE_AssessmentCriteriaAnswer.new AssessmentCriteriaAnswerPipeLineFactory<From, AssessmentCriteriaAnswer> (this, new ORMMultiAssocPipe<Me, AssessmentCriteriaAnswer>(MULTIPLEREFERENCE_Answers, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Job getJob () throws StorageException
    {
        return (Job)(Job.DUMMY_Job);
    }


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

    public AssessmentCriteriaTemplate getTemplate () throws StorageException
    {
        return (AssessmentCriteriaTemplate)(AssessmentCriteriaTemplate.DUMMY_AssessmentCriteriaTemplate);
    }


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

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


    public AssessmentCriteriaAnswer getAnswersAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Answers");
    }


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

}

    
