/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure9.0 [oneit.objstore.BusinessObjectTemplate.xsl]
 *   Vendor: Apache Software Foundation (Xalan XSLTC) (Version: 1.0)
 */

    
package performa.orm;

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

import performa.orm.types.*;


public abstract class BaseWorkFlow extends BaseBusinessClass
{
    // Reference instance for the object
    public static final WorkFlow REFERENCE_WorkFlow = new WorkFlow ();

    // Reference instance for the object
    public static final WorkFlow DUMMY_WorkFlow = new DummyWorkFlow ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Name = "Name";
    public static final String FIELD_SortOrder = "SortOrder";
    public static final String FIELD_ApplicationStatus = "ApplicationStatus";
    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 = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<WorkFlow> HELPER_Name = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<WorkFlow> HELPER_SortOrder = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<WorkFlow, ApplicationStatus> HELPER_ApplicationStatus =  new EnumeratedAttributeHelper<WorkFlow, ApplicationStatus> (ApplicationStatus.FACTORY_ApplicationStatus);
    

    // Private attributes corresponding to business object data
    private String _Name;
    private Integer _SortOrder;
    private ApplicationStatus _ApplicationStatus;
    

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

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Name_Validators;
    private static final AttributeValidator[] FIELD_SortOrder_Validators;
    private static final AttributeValidator[] FIELD_ApplicationStatus_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<WorkFlow, String>[] FIELD_Name_Decorators;
    private static final AttributeDecorator<WorkFlow, Integer>[] FIELD_SortOrder_Decorators;
    private static final AttributeDecorator<WorkFlow, ApplicationStatus>[] FIELD_ApplicationStatus_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<WorkFlow, Job>[] SINGLEREFERENCE_Job_Decorators;
    private static final SingleAssocDecorator<WorkFlow, AssessmentCriteriaTemplate>[] SINGLEREFERENCE_Template_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final WorkFlowBehaviourDecorator[] WorkFlow_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Job = Job.BACKREF_WorkFlows;
            String tmp_Template = AssessmentCriteriaTemplate.BACKREF_WorkFlows;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Job();
            setupAssocMetaData_Template();
            FIELD_Name_Validators = (AttributeValidator[])setupAttribMetaData_Name(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_SortOrder_Validators = (AttributeValidator[])setupAttribMetaData_SortOrder(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ApplicationStatus_Validators = (AttributeValidator[])setupAttribMetaData_ApplicationStatus(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Name_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlow, FIELD_Name).toArray (new AttributeDecorator[0]);
            FIELD_SortOrder_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlow, FIELD_SortOrder).toArray (new AttributeDecorator[0]);
            FIELD_ApplicationStatus_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlow, FIELD_ApplicationStatus).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_Job_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_WorkFlow, SINGLEREFERENCE_Job).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Template_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_WorkFlow, SINGLEREFERENCE_Template).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_WorkFlow.initialiseReference ();
            DUMMY_WorkFlow.initialiseReference ();
            WorkFlow_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(WorkFlow.class).toArray(new WorkFlowBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "WorkFlows");
        metaInfo.put ("dbcol", "job_id");
        metaInfo.put ("name", "Job");
        metaInfo.put ("type", "Job");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlow.Job:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlow.put (SINGLEREFERENCE_Job, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Template()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "WorkFlows");
        metaInfo.put ("dbcol", "template_id");
        metaInfo.put ("name", "Template");
        metaInfo.put ("type", "AssessmentCriteriaTemplate");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlow.Template:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlow.put (SINGLEREFERENCE_Template, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Name(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "name");
        metaInfo.put ("length", "20");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Name");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlow.Name:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlow.put (FIELD_Name, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "sort_order");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "SortOrder");
        metaInfo.put ("type", "Integer");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlow.SortOrder:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlow.put (FIELD_SortOrder, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "application_status");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "ApplicationStatus");
        metaInfo.put ("type", "ApplicationStatus");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlow.ApplicationStatus:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlow.put (FIELD_ApplicationStatus, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _Name = (String)(HELPER_Name.initialise (_Name));
        _SortOrder = (Integer)(HELPER_SortOrder.initialise (_SortOrder));
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.initialise (_ApplicationStatus));
    }


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

        _Job = new SingleAssociation<WorkFlow, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_WorkFlows, Job.REFERENCE_Job, "tl_work_flow");
        _Template = new SingleAssociation<WorkFlow, AssessmentCriteriaTemplate> (this, SINGLEREFERENCE_Template, AssessmentCriteriaTemplate.MULTIPLEREFERENCE_WorkFlows, AssessmentCriteriaTemplate.REFERENCE_AssessmentCriteriaTemplate, "tl_work_flow");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Job = new SingleAssociation<WorkFlow, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_WorkFlows, Job.REFERENCE_Job, "tl_work_flow");
        _Template = new SingleAssociation<WorkFlow, AssessmentCriteriaTemplate> (this, SINGLEREFERENCE_Template, AssessmentCriteriaTemplate.MULTIPLEREFERENCE_WorkFlows, AssessmentCriteriaTemplate.REFERENCE_AssessmentCriteriaTemplate, "tl_work_flow");
        
        
        return this;
    }


    /**
     * Attribute Name
     */
    public String getName ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Name_Decorators, (WorkFlow)this, FIELD_Name, _Name);

        
        for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
        {
            valToReturn = bhd.getName ((WorkFlow)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
    {
        newName = AttributeDecoratorUtils.setValue (FIELD_Name_Decorators, (WorkFlow)this, FIELD_Name, newName);

        boolean oldAndNewIdentical = HELPER_Name.compare (_Name, newName);
        
        try
        {
            for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
            {
                newName = bhd.setName ((WorkFlow)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_WorkFlow.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 (AttributeDecoratorUtils.getWriteability (FIELD_Name_Decorators, (WorkFlow)this, FIELD_Name ,getWriteability_Name ()) != FieldWriteability.FALSE, "Field  Name is not writeable");
            preNameChange (newName);
            markFieldChange (FIELD_Name);
            _Name = newName;            
            postFieldChange (FIELD_Name);
            postNameChange ();
        }
    }

    /**
     * Attribute SortOrder
     */
    public Integer getSortOrder ()
    {
        assertValid();
        Integer valToReturn = AttributeDecoratorUtils.getValue (FIELD_SortOrder_Decorators, (WorkFlow)this, FIELD_SortOrder, _SortOrder);

        
        for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
        {
            valToReturn = bhd.getSortOrder ((WorkFlow)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 preSortOrderChange (Integer newSortOrder) 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 postSortOrderChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute SortOrder.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setSortOrder (Integer newSortOrder) throws FieldException
    {
        newSortOrder = AttributeDecoratorUtils.setValue (FIELD_SortOrder_Decorators, (WorkFlow)this, FIELD_SortOrder, newSortOrder);

        boolean oldAndNewIdentical = HELPER_SortOrder.compare (_SortOrder, newSortOrder);
        
        try
        {
            for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
            {
                newSortOrder = bhd.setSortOrder ((WorkFlow)this, newSortOrder);
                oldAndNewIdentical = HELPER_SortOrder.compare (_SortOrder, newSortOrder);
            }

            BusinessObjectParser.assertFieldCondition (newSortOrder != null, this, FIELD_SortOrder, "mandatory");
            

            if (FIELD_SortOrder_Validators.length > 0)
            {
                Object newSortOrderObj = HELPER_SortOrder.toObject (newSortOrder);

                if (newSortOrderObj != null)
                {
                    int     loopMax = FIELD_SortOrder_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlow.get (FIELD_SortOrder);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_SortOrder_Decorators, (WorkFlow)this, FIELD_SortOrder ,getWriteability_SortOrder ()) != FieldWriteability.FALSE, "Field  SortOrder is not writeable");
            preSortOrderChange (newSortOrder);
            markFieldChange (FIELD_SortOrder);
            _SortOrder = newSortOrder;            
            postFieldChange (FIELD_SortOrder);
            postSortOrderChange ();
        }
    }

    /**
     * Attribute ApplicationStatus
     */
    public ApplicationStatus getApplicationStatus ()
    {
        assertValid();
        ApplicationStatus valToReturn = AttributeDecoratorUtils.getValue (FIELD_ApplicationStatus_Decorators, (WorkFlow)this, FIELD_ApplicationStatus, _ApplicationStatus);

        
        for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
        {
            valToReturn = bhd.getApplicationStatus ((WorkFlow)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 preApplicationStatusChange (ApplicationStatus newApplicationStatus) 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 postApplicationStatusChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ApplicationStatus.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setApplicationStatus (ApplicationStatus newApplicationStatus) throws FieldException
    {
        newApplicationStatus = AttributeDecoratorUtils.setValue (FIELD_ApplicationStatus_Decorators, (WorkFlow)this, FIELD_ApplicationStatus, newApplicationStatus);

        boolean oldAndNewIdentical = HELPER_ApplicationStatus.compare (_ApplicationStatus, newApplicationStatus);
        
        try
        {
            for (WorkFlowBehaviourDecorator bhd : WorkFlow_BehaviourDecorators)
            {
                newApplicationStatus = bhd.setApplicationStatus ((WorkFlow)this, newApplicationStatus);
                oldAndNewIdentical = HELPER_ApplicationStatus.compare (_ApplicationStatus, newApplicationStatus);
            }

            BusinessObjectParser.assertFieldCondition (newApplicationStatus != null, this, FIELD_ApplicationStatus, "mandatory");
            

            if (FIELD_ApplicationStatus_Validators.length > 0)
            {
                Object newApplicationStatusObj = HELPER_ApplicationStatus.toObject (newApplicationStatus);

                if (newApplicationStatusObj != null)
                {
                    int     loopMax = FIELD_ApplicationStatus_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlow.get (FIELD_ApplicationStatus);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_ApplicationStatus_Decorators, (WorkFlow)this, FIELD_ApplicationStatus ,getWriteability_ApplicationStatus ()) != FieldWriteability.FALSE, "Field  ApplicationStatus is not writeable");
            preApplicationStatusChange (newApplicationStatus);
            markFieldChange (FIELD_ApplicationStatus);
            _ApplicationStatus = newApplicationStatus;            
            postFieldChange (FIELD_ApplicationStatus);
            postApplicationStatusChange ();
        }
    }



    /**
     * 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_WorkFlows ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Template))
        {
            return AssessmentCriteriaTemplate.MULTIPLEREFERENCE_WorkFlows ;
        }
        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 WorkFlow:", 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 (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Job_Decorators, (WorkFlow)this, SINGLEREFERENCE_Job ,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.removeFromWorkFlows ((WorkFlow)(this));
            }

            _Job.set (newJob);

            if (newJob != null)
            {
                newJob.addToWorkFlows ((WorkFlow)(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 WorkFlow:", 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 (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Template_Decorators, (WorkFlow)this, SINGLEREFERENCE_Template ,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.removeFromWorkFlows ((WorkFlow)(this));
            }

            _Template.set (newTemplate);

            if (newTemplate != null)
            {
                newTemplate.addToWorkFlows ((WorkFlow)(this));
            }
                
            postTemplateChange ();
        }
    }

    /**
     * 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 (_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 WorkFlows from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Job.set (null);
                    referenced.removeFromWorkFlows ((WorkFlow)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 WorkFlows from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Template.set (null);
                    referenced.removeFromWorkFlows ((WorkFlow)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public WorkFlow referenceInstance ()
    {
        return REFERENCE_WorkFlow;
    }


    public WorkFlow getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getWorkFlowByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_WorkFlow;
    }


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



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

        tl_work_flowPSet.setAttrib (FIELD_ObjectID, myID);
        tl_work_flowPSet.setAttrib (FIELD_Name, HELPER_Name.toObject (_Name)); //
        tl_work_flowPSet.setAttrib (FIELD_SortOrder, HELPER_SortOrder.toObject (_SortOrder)); //
        tl_work_flowPSet.setAttrib (FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject (_ApplicationStatus)); //
        _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_work_flowPSet = allSets.getPersistentSet (objectID, "tl_work_flow");

        _Name = (String)(HELPER_Name.fromObject (_Name, tl_work_flowPSet.getAttrib (FIELD_Name))); //
        _SortOrder = (Integer)(HELPER_SortOrder.fromObject (_SortOrder, tl_work_flowPSet.getAttrib (FIELD_SortOrder))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, tl_work_flowPSet.getAttrib (FIELD_ApplicationStatus))); //
        _Job.setFromPersistentSets (objectID, allSets);
        _Template.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof WorkFlow)
        {
            WorkFlow otherWorkFlow = (WorkFlow)other;
            

            try
            {
                setName (otherWorkFlow.getName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setSortOrder (otherWorkFlow.getSortOrder ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setApplicationStatus (otherWorkFlow.getApplicationStatus ());
            }
            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 BaseWorkFlow)
        {
            BaseWorkFlow sourceWorkFlow = (BaseWorkFlow)(source);

            _Name = sourceWorkFlow._Name;
            _SortOrder = sourceWorkFlow._SortOrder;
            _ApplicationStatus = sourceWorkFlow._ApplicationStatus;
            
        }
    }


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

            _Job.copyFrom (sourceWorkFlow._Job, linkToGhosts);
            _Template.copyFrom (sourceWorkFlow._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 BaseWorkFlow)
        {
            BaseWorkFlow sourceWorkFlow = (BaseWorkFlow)(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);

        _Name = (String)(HELPER_Name.readExternal (_Name, vals.get(FIELD_Name))); //
        _SortOrder = (Integer)(HELPER_SortOrder.readExternal (_SortOrder, vals.get(FIELD_SortOrder))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.readExternal (_ApplicationStatus, vals.get(FIELD_ApplicationStatus))); //
        _Job.readExternalData(vals.get(SINGLEREFERENCE_Job));
        _Template.readExternalData(vals.get(SINGLEREFERENCE_Template));
        
    }


    /**
     * 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_SortOrder, HELPER_SortOrder.writeExternal (_SortOrder));
        vals.put (FIELD_ApplicationStatus, HELPER_ApplicationStatus.writeExternal (_ApplicationStatus));
        vals.put (SINGLEREFERENCE_Job, _Job.writeExternalData());
        vals.put (SINGLEREFERENCE_Template, _Template.writeExternalData());
        
    }


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

        if (other instanceof BaseWorkFlow)
        {
            BaseWorkFlow otherWorkFlow = (BaseWorkFlow)(other);

            
            if (!HELPER_Name.compare(this._Name, otherWorkFlow._Name))
            {
                listener.notifyFieldChange(this, other, FIELD_Name, HELPER_Name.toObject(this._Name), HELPER_Name.toObject(otherWorkFlow._Name));
            }
            if (!HELPER_SortOrder.compare(this._SortOrder, otherWorkFlow._SortOrder))
            {
                listener.notifyFieldChange(this, other, FIELD_SortOrder, HELPER_SortOrder.toObject(this._SortOrder), HELPER_SortOrder.toObject(otherWorkFlow._SortOrder));
            }
            if (!HELPER_ApplicationStatus.compare(this._ApplicationStatus, otherWorkFlow._ApplicationStatus))
            {
                listener.notifyFieldChange(this, other, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(this._ApplicationStatus), HELPER_ApplicationStatus.toObject(otherWorkFlow._ApplicationStatus));
            }

            // Compare single assocs
            _Job.compare (otherWorkFlow._Job, listener);
            _Template.compare (otherWorkFlow._Template, 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_Name, HELPER_Name.toObject(getName()));
        visitor.visitField(this, FIELD_SortOrder, HELPER_SortOrder.toObject(getSortOrder()));
        visitor.visitField(this, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(getApplicationStatus()));
        visitor.visitAssociation (_Job);
        visitor.visitAssociation (_Template);
        
    }


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


    public static WorkFlow createWorkFlow (ObjectTransaction transaction) throws StorageException
    {
        WorkFlow     result = new WorkFlow ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static WorkFlow getWorkFlowByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (WorkFlow)(transaction.getObjectByID (REFERENCE_WorkFlow, 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_SortOrder))
        {
            return filter.matches (getSortOrder ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return filter.matches (getApplicationStatus ());
        }
        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<WorkFlow>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_work_flow.object_id", FIELD_ObjectID);
            return this;
        }

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

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

            
        public SearchAll andName (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_work_flow.name", "Name");
            return this;
        }
            
        public SearchAll andSortOrder (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_work_flow.sort_order", "SortOrder");
            return this;
        }
            
        public SearchAll andApplicationStatus (QueryFilter<ApplicationStatus> filter)
        {
            filter.addFilter (context, "tl_work_flow.application_status", "ApplicationStatus");
            return this;
        }
            
        public SearchAll andJob (QueryFilter<Job> filter)
        {
            filter.addFilter (context, "tl_work_flow.job_id", "Job");
            return this;
        }
            
        public SearchAll andTemplate (QueryFilter<AssessmentCriteriaTemplate> filter)
        {
            filter.addFilter (context, "tl_work_flow.template_id", "Template");
            return this;
        }
            
        public WorkFlow[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_WorkFlow, SEARCH_All, criteria);
            Set<WorkFlow>   typedResults = new LinkedHashSet <WorkFlow> ();
            for (BaseBusinessClass bbcResult : results)
            {
                WorkFlow aResult = (WorkFlow)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new WorkFlow[0]);
                            
        }
    }

        
    public static WorkFlow[] 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_SortOrder))
        {
            return HELPER_SortOrder.toObject (getSortOrder ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus.toObject (getApplicationStatus ());
        }
        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_SortOrder))
        {
            return HELPER_SortOrder;
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus;
        }
        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_SortOrder))
        {
            setSortOrder ((Integer)(HELPER_SortOrder.fromObject (_SortOrder, attribValue)));            
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            setApplicationStatus ((ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }

    

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

    public boolean isReadable ()
    {
        return super.isReadable();
    }

    public boolean isReadable (String fieldName)
    {
        return super.isReadable(fieldName);
    }


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_Name))
        {
            return getWriteability_Name ();
        }
        else if (fieldName.equals (FIELD_SortOrder))
        {
            return getWriteability_SortOrder ();
        }
        else if (fieldName.equals (FIELD_ApplicationStatus))
        {
            return getWriteability_ApplicationStatus ();
        }
        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_SortOrder () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_SortOrder);
        }
        
        if (getWriteability_ApplicationStatus () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ApplicationStatus);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_Name.getAttribObject (getClass (), _Name, true, FIELD_Name));
        result.add(HELPER_SortOrder.getAttribObject (getClass (), _SortOrder, true, FIELD_SortOrder));
        result.add(HELPER_ApplicationStatus.getAttribObject (getClass (), _ApplicationStatus, true, FIELD_ApplicationStatus));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_WorkFlow);
    }
            

    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 WorkFlowBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<WorkFlow>
    {

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

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

    /**
     * Get the attribute SortOrder
     */
    public Integer getSortOrder (WorkFlow obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute SortOrder.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setSortOrder (WorkFlow obj, Integer newSortOrder) throws FieldException
    {
        return newSortOrder;
    }

    /**
     * Get the attribute ApplicationStatus
     */
    public ApplicationStatus getApplicationStatus (WorkFlow obj, ApplicationStatus original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ApplicationStatus.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public ApplicationStatus setApplicationStatus (WorkFlow obj, ApplicationStatus newApplicationStatus) throws FieldException
    {
        return newApplicationStatus;
    }

    }

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

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

        public WorkFlowPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Name"))
            {
                return toName ();
            }                
            if (name.equals ("SortOrder"))
            {
                return toSortOrder ();
            }                
            if (name.equals ("ApplicationStatus"))
            {
                return toApplicationStatus ();
            }                
            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, Integer> toSortOrder () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_SortOrder));  }
        
        public ApplicationStatus.ApplicationStatusPipeLineFactory<From, ApplicationStatus> toApplicationStatus () 
        { 
            return new ApplicationStatus.ApplicationStatusPipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_ApplicationStatus));
        }

        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 boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

class DummyWorkFlow extends WorkFlow
{
    // Default constructor primarily to support Externalisable
    public DummyWorkFlow()
    {
        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();
    }

}

    
