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

    // Reference instance for the object
    public static final WorkFlowMessage DUMMY_WorkFlowMessage = new DummyWorkFlowMessage ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Delay = "Delay";
    public static final String FIELD_Variance = "Variance";
    public static final String FIELD_BusinessHoursOnly = "BusinessHoursOnly";
    public static final String FIELD_IsWithdrawalMessage = "IsWithdrawalMessage";
    public static final String SINGLEREFERENCE_MessageTemplate = "MessageTemplate";
    public static final String SINGLEREFERENCE_WorkFlowStage = "WorkFlowStage";
    public static final String BACKREF_WorkFlowStage = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<WorkFlowMessage> HELPER_Delay = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<WorkFlowMessage> HELPER_Variance = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<WorkFlowMessage> HELPER_BusinessHoursOnly = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<WorkFlowMessage> HELPER_IsWithdrawalMessage = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _Delay;
    private String _Variance;
    private Boolean _BusinessHoursOnly;
    private Boolean _IsWithdrawalMessage;
    

    // Private attributes corresponding to single references
    private SingleAssociation<WorkFlowMessage, MessageTemplate> _MessageTemplate;
    private SingleAssociation<WorkFlowMessage, WorkFlowStage> _WorkFlowStage;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Delay_Validators;
    private static final AttributeValidator[] FIELD_Variance_Validators;
    private static final AttributeValidator[] FIELD_BusinessHoursOnly_Validators;
    private static final AttributeValidator[] FIELD_IsWithdrawalMessage_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<WorkFlowMessage, String>[] FIELD_Delay_Decorators;
    private static final AttributeDecorator<WorkFlowMessage, String>[] FIELD_Variance_Decorators;
    private static final AttributeDecorator<WorkFlowMessage, Boolean>[] FIELD_BusinessHoursOnly_Decorators;
    private static final AttributeDecorator<WorkFlowMessage, Boolean>[] FIELD_IsWithdrawalMessage_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<WorkFlowMessage, MessageTemplate>[] SINGLEREFERENCE_MessageTemplate_Decorators;
    private static final SingleAssocDecorator<WorkFlowMessage, WorkFlowStage>[] SINGLEREFERENCE_WorkFlowStage_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final WorkFlowMessageBehaviourDecorator[] WorkFlowMessage_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_WorkFlowStage = WorkFlowStage.BACKREF_WorkFlowMessages;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_MessageTemplate();
            setupAssocMetaData_WorkFlowStage();
            FIELD_Delay_Validators = (AttributeValidator[])setupAttribMetaData_Delay(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Variance_Validators = (AttributeValidator[])setupAttribMetaData_Variance(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_BusinessHoursOnly_Validators = (AttributeValidator[])setupAttribMetaData_BusinessHoursOnly(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_IsWithdrawalMessage_Validators = (AttributeValidator[])setupAttribMetaData_IsWithdrawalMessage(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Delay_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowMessage, FIELD_Delay).toArray (new AttributeDecorator[0]);
            FIELD_Variance_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowMessage, FIELD_Variance).toArray (new AttributeDecorator[0]);
            FIELD_BusinessHoursOnly_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowMessage, FIELD_BusinessHoursOnly).toArray (new AttributeDecorator[0]);
            FIELD_IsWithdrawalMessage_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowMessage, FIELD_IsWithdrawalMessage).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_MessageTemplate_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_WorkFlowMessage, SINGLEREFERENCE_MessageTemplate).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_WorkFlowStage_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_WorkFlowMessage, SINGLEREFERENCE_WorkFlowStage).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_WorkFlowMessage.initialiseReference ();
            DUMMY_WorkFlowMessage.initialiseReference ();
            WorkFlowMessage_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(WorkFlowMessage.class).toArray(new WorkFlowMessageBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("dbcol", "message_template_id");
        metaInfo.put ("name", "MessageTemplate");
        metaInfo.put ("type", "MessageTemplate");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.MessageTemplate:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (SINGLEREFERENCE_MessageTemplate, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_WorkFlowStage()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "WorkFlowMessages");
        metaInfo.put ("dbcol", "work_flow_stage_id");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "WorkFlowStage");
        metaInfo.put ("type", "WorkFlowStage");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.WorkFlowStage:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (SINGLEREFERENCE_WorkFlowStage, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Delay(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "delay");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Delay");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.Delay:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (FIELD_Delay, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "variance");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Variance");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.Variance:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (FIELD_Variance, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "business_hours_only");
        metaInfo.put ("defaultValue", "Boolean.FALSE");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "BusinessHoursOnly");
        metaInfo.put ("type", "Boolean");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.BusinessHoursOnly:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (FIELD_BusinessHoursOnly, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "is_withdrawal_message");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "IsWithdrawalMessage");
        metaInfo.put ("type", "Boolean");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_message");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowMessage.IsWithdrawalMessage:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowMessage.put (FIELD_IsWithdrawalMessage, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _Delay = (String)(HELPER_Delay.initialise (_Delay));
        _Variance = (String)(HELPER_Variance.initialise (_Variance));
        _BusinessHoursOnly = (Boolean)(Boolean.FALSE);
        _IsWithdrawalMessage = (Boolean)(HELPER_IsWithdrawalMessage.initialise (_IsWithdrawalMessage));
    }


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

        _MessageTemplate = new SingleAssociation<WorkFlowMessage, MessageTemplate> (this, SINGLEREFERENCE_MessageTemplate, null, MessageTemplate.REFERENCE_MessageTemplate, "tl_work_flow_message");
        _WorkFlowStage = new SingleAssociation<WorkFlowMessage, WorkFlowStage> (this, SINGLEREFERENCE_WorkFlowStage, WorkFlowStage.MULTIPLEREFERENCE_WorkFlowMessages, WorkFlowStage.REFERENCE_WorkFlowStage, "tl_work_flow_message");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _MessageTemplate = new SingleAssociation<WorkFlowMessage, MessageTemplate> (this, SINGLEREFERENCE_MessageTemplate, null, MessageTemplate.REFERENCE_MessageTemplate, "tl_work_flow_message");
        _WorkFlowStage = new SingleAssociation<WorkFlowMessage, WorkFlowStage> (this, SINGLEREFERENCE_WorkFlowStage, WorkFlowStage.MULTIPLEREFERENCE_WorkFlowMessages, WorkFlowStage.REFERENCE_WorkFlowStage, "tl_work_flow_message");
        
        
        return this;
    }


    /**
     * Attribute Delay
     */
    public String getDelay ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Delay_Decorators, (WorkFlowMessage)this, FIELD_Delay, _Delay);

        
        for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
        {
            valToReturn = bhd.getDelay ((WorkFlowMessage)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 preDelayChange (String newDelay) 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 postDelayChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Delay.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setDelay (String newDelay) throws FieldException
    {
        newDelay = AttributeDecoratorUtils.setValue (FIELD_Delay_Decorators, (WorkFlowMessage)this, FIELD_Delay, newDelay);

        boolean oldAndNewIdentical = HELPER_Delay.compare (_Delay, newDelay);
        
        try
        {
            for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
            {
                newDelay = bhd.setDelay ((WorkFlowMessage)this, newDelay);
                oldAndNewIdentical = HELPER_Delay.compare (_Delay, newDelay);
            }

            

            if (FIELD_Delay_Validators.length > 0)
            {
                Object newDelayObj = HELPER_Delay.toObject (newDelay);

                if (newDelayObj != null)
                {
                    int     loopMax = FIELD_Delay_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlowMessage.get (FIELD_Delay);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Delay_Decorators, (WorkFlowMessage)this, FIELD_Delay ,getWriteability_Delay ()) != FieldWriteability.FALSE, "Field  Delay is not writeable");
            preDelayChange (newDelay);
            markFieldChange (FIELD_Delay);
            _Delay = newDelay;            
            postFieldChange (FIELD_Delay);
            postDelayChange ();
        }
    }

    /**
     * Attribute Variance
     */
    public String getVariance ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Variance_Decorators, (WorkFlowMessage)this, FIELD_Variance, _Variance);

        
        for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
        {
            valToReturn = bhd.getVariance ((WorkFlowMessage)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 preVarianceChange (String newVariance) 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 postVarianceChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Variance.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setVariance (String newVariance) throws FieldException
    {
        newVariance = AttributeDecoratorUtils.setValue (FIELD_Variance_Decorators, (WorkFlowMessage)this, FIELD_Variance, newVariance);

        boolean oldAndNewIdentical = HELPER_Variance.compare (_Variance, newVariance);
        
        try
        {
            for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
            {
                newVariance = bhd.setVariance ((WorkFlowMessage)this, newVariance);
                oldAndNewIdentical = HELPER_Variance.compare (_Variance, newVariance);
            }

            

            if (FIELD_Variance_Validators.length > 0)
            {
                Object newVarianceObj = HELPER_Variance.toObject (newVariance);

                if (newVarianceObj != null)
                {
                    int     loopMax = FIELD_Variance_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlowMessage.get (FIELD_Variance);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Variance_Decorators, (WorkFlowMessage)this, FIELD_Variance ,getWriteability_Variance ()) != FieldWriteability.FALSE, "Field  Variance is not writeable");
            preVarianceChange (newVariance);
            markFieldChange (FIELD_Variance);
            _Variance = newVariance;            
            postFieldChange (FIELD_Variance);
            postVarianceChange ();
        }
    }

    /**
     * Attribute BusinessHoursOnly
     */
    public Boolean getBusinessHoursOnly ()
    {
        assertValid();
        Boolean valToReturn = AttributeDecoratorUtils.getValue (FIELD_BusinessHoursOnly_Decorators, (WorkFlowMessage)this, FIELD_BusinessHoursOnly, _BusinessHoursOnly);

        
        for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
        {
            valToReturn = bhd.getBusinessHoursOnly ((WorkFlowMessage)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 preBusinessHoursOnlyChange (Boolean newBusinessHoursOnly) 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 postBusinessHoursOnlyChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute BusinessHoursOnly.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setBusinessHoursOnly (Boolean newBusinessHoursOnly) throws FieldException
    {
        newBusinessHoursOnly = AttributeDecoratorUtils.setValue (FIELD_BusinessHoursOnly_Decorators, (WorkFlowMessage)this, FIELD_BusinessHoursOnly, newBusinessHoursOnly);

        boolean oldAndNewIdentical = HELPER_BusinessHoursOnly.compare (_BusinessHoursOnly, newBusinessHoursOnly);
        
        try
        {
            for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
            {
                newBusinessHoursOnly = bhd.setBusinessHoursOnly ((WorkFlowMessage)this, newBusinessHoursOnly);
                oldAndNewIdentical = HELPER_BusinessHoursOnly.compare (_BusinessHoursOnly, newBusinessHoursOnly);
            }

            

            if (FIELD_BusinessHoursOnly_Validators.length > 0)
            {
                Object newBusinessHoursOnlyObj = HELPER_BusinessHoursOnly.toObject (newBusinessHoursOnly);

                if (newBusinessHoursOnlyObj != null)
                {
                    int     loopMax = FIELD_BusinessHoursOnly_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlowMessage.get (FIELD_BusinessHoursOnly);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_BusinessHoursOnly_Decorators, (WorkFlowMessage)this, FIELD_BusinessHoursOnly ,getWriteability_BusinessHoursOnly ()) != FieldWriteability.FALSE, "Field  BusinessHoursOnly is not writeable");
            preBusinessHoursOnlyChange (newBusinessHoursOnly);
            markFieldChange (FIELD_BusinessHoursOnly);
            _BusinessHoursOnly = newBusinessHoursOnly;            
            postFieldChange (FIELD_BusinessHoursOnly);
            postBusinessHoursOnlyChange ();
        }
    }

    /**
     * Attribute IsWithdrawalMessage
     */
    public Boolean getIsWithdrawalMessage ()
    {
        assertValid();
        Boolean valToReturn = AttributeDecoratorUtils.getValue (FIELD_IsWithdrawalMessage_Decorators, (WorkFlowMessage)this, FIELD_IsWithdrawalMessage, _IsWithdrawalMessage);

        
        for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
        {
            valToReturn = bhd.getIsWithdrawalMessage ((WorkFlowMessage)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 preIsWithdrawalMessageChange (Boolean newIsWithdrawalMessage) 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 postIsWithdrawalMessageChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute IsWithdrawalMessage.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setIsWithdrawalMessage (Boolean newIsWithdrawalMessage) throws FieldException
    {
        newIsWithdrawalMessage = AttributeDecoratorUtils.setValue (FIELD_IsWithdrawalMessage_Decorators, (WorkFlowMessage)this, FIELD_IsWithdrawalMessage, newIsWithdrawalMessage);

        boolean oldAndNewIdentical = HELPER_IsWithdrawalMessage.compare (_IsWithdrawalMessage, newIsWithdrawalMessage);
        
        try
        {
            for (WorkFlowMessageBehaviourDecorator bhd : WorkFlowMessage_BehaviourDecorators)
            {
                newIsWithdrawalMessage = bhd.setIsWithdrawalMessage ((WorkFlowMessage)this, newIsWithdrawalMessage);
                oldAndNewIdentical = HELPER_IsWithdrawalMessage.compare (_IsWithdrawalMessage, newIsWithdrawalMessage);
            }

            

            if (FIELD_IsWithdrawalMessage_Validators.length > 0)
            {
                Object newIsWithdrawalMessageObj = HELPER_IsWithdrawalMessage.toObject (newIsWithdrawalMessage);

                if (newIsWithdrawalMessageObj != null)
                {
                    int     loopMax = FIELD_IsWithdrawalMessage_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlowMessage.get (FIELD_IsWithdrawalMessage);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_IsWithdrawalMessage_Decorators, (WorkFlowMessage)this, FIELD_IsWithdrawalMessage ,getWriteability_IsWithdrawalMessage ()) != FieldWriteability.FALSE, "Field  IsWithdrawalMessage is not writeable");
            preIsWithdrawalMessageChange (newIsWithdrawalMessage);
            markFieldChange (FIELD_IsWithdrawalMessage);
            _IsWithdrawalMessage = newIsWithdrawalMessage;            
            postFieldChange (FIELD_IsWithdrawalMessage);
            postIsWithdrawalMessageChange ();
        }
    }



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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return _MessageTemplate.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return _WorkFlowStage.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_MessageTemplate))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return WorkFlowStage.MULTIPLEREFERENCE_WorkFlowMessages ;
        }
        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_MessageTemplate))
        {
            return getMessageTemplate ();
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return getWorkFlowStage ();
        }
        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_MessageTemplate))
        {
            return getMessageTemplate (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return getWorkFlowStage (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_MessageTemplate))
        {
            return getMessageTemplateID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return getWorkFlowStageID ();
        }
        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_MessageTemplate))
        {
            setMessageTemplate ((MessageTemplate)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            setWorkFlowStage ((WorkFlowStage)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getMessageTemplateID ()
    {
        assertValid();
        
        if (_MessageTemplate == null)
        {
            return null;
        }
        else
        {
            return _MessageTemplate.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 preMessageTemplateChange (MessageTemplate newMessageTemplate) 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 postMessageTemplateChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference MessageTemplate.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setMessageTemplate (MessageTemplate newMessageTemplate) throws StorageException, FieldException
    {
        if (_MessageTemplate.wouldReferencedChange (newMessageTemplate))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_MessageTemplate_Decorators, (WorkFlowMessage)this, SINGLEREFERENCE_MessageTemplate ,getWriteability_MessageTemplate ()) != FieldWriteability.FALSE, "Assoc MessageTemplate is not writeable");
            preMessageTemplateChange (newMessageTemplate);
            
            _MessageTemplate.set (newMessageTemplate);
                
            postMessageTemplateChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getWorkFlowStageID ()
    {
        assertValid();
        
        if (_WorkFlowStage == null)
        {
            return null;
        }
        else
        {
            return _WorkFlowStage.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 preWorkFlowStageChange (WorkFlowStage newWorkFlowStage) 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 postWorkFlowStageChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference WorkFlowStage.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setWorkFlowStage (WorkFlowStage newWorkFlowStage) throws StorageException, FieldException
    {
        if (_WorkFlowStage.wouldReferencedChange (newWorkFlowStage))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_WorkFlowStage_Decorators, (WorkFlowMessage)this, SINGLEREFERENCE_WorkFlowStage ,getWriteability_WorkFlowStage ()) != FieldWriteability.FALSE, "Assoc WorkFlowStage is not writeable");
            preWorkFlowStageChange (newWorkFlowStage);
            WorkFlowStage oldWorkFlowStage = getWorkFlowStage ();

            if (oldWorkFlowStage != null)
            {
                // This is to stop validation from triggering when we are removed
                _WorkFlowStage.set (null);
                oldWorkFlowStage.removeFromWorkFlowMessages ((WorkFlowMessage)(this));
            }

            _WorkFlowStage.set (newWorkFlowStage);

            if (newWorkFlowStage != null)
            {
                newWorkFlowStage.addToWorkFlowMessages ((WorkFlowMessage)(this));
            }
                
            postWorkFlowStageChange ();
        }
    }

    /**
     * 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 (_WorkFlowStage.isLoaded () || getTransaction ().isObjectLoaded (_WorkFlowStage.getReferencedType (), getWorkFlowStageID ()))
            {
                WorkFlowStage  referenced = getWorkFlowStage ();

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

        super.onDelete ();
    }


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


    public WorkFlowMessage referenceInstance ()
    {
        return REFERENCE_WorkFlowMessage;
    }


    public WorkFlowMessage getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getWorkFlowMessageByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_WorkFlowMessage;
    }


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



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

        tl_work_flow_messagePSet.setAttrib (FIELD_ObjectID, myID);
        tl_work_flow_messagePSet.setAttrib (FIELD_Delay, HELPER_Delay.toObject (_Delay)); //
        tl_work_flow_messagePSet.setAttrib (FIELD_Variance, HELPER_Variance.toObject (_Variance)); //
        tl_work_flow_messagePSet.setAttrib (FIELD_BusinessHoursOnly, HELPER_BusinessHoursOnly.toObject (_BusinessHoursOnly)); //
        tl_work_flow_messagePSet.setAttrib (FIELD_IsWithdrawalMessage, HELPER_IsWithdrawalMessage.toObject (_IsWithdrawalMessage)); //
        _MessageTemplate.getPersistentSets (allSets);
        _WorkFlowStage.getPersistentSets (allSets);
        
    }


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

        _Delay = (String)(HELPER_Delay.fromObject (_Delay, tl_work_flow_messagePSet.getAttrib (FIELD_Delay))); //
        _Variance = (String)(HELPER_Variance.fromObject (_Variance, tl_work_flow_messagePSet.getAttrib (FIELD_Variance))); //
        _BusinessHoursOnly = (Boolean)(HELPER_BusinessHoursOnly.fromObject (_BusinessHoursOnly, tl_work_flow_messagePSet.getAttrib (FIELD_BusinessHoursOnly))); //
        _IsWithdrawalMessage = (Boolean)(HELPER_IsWithdrawalMessage.fromObject (_IsWithdrawalMessage, tl_work_flow_messagePSet.getAttrib (FIELD_IsWithdrawalMessage))); //
        _MessageTemplate.setFromPersistentSets (objectID, allSets);
        _WorkFlowStage.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof WorkFlowMessage)
        {
            WorkFlowMessage otherWorkFlowMessage = (WorkFlowMessage)other;
            

            try
            {
                setDelay (otherWorkFlowMessage.getDelay ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setVariance (otherWorkFlowMessage.getVariance ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setBusinessHoursOnly (otherWorkFlowMessage.getBusinessHoursOnly ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setIsWithdrawalMessage (otherWorkFlowMessage.getIsWithdrawalMessage ());
            }
            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 BaseWorkFlowMessage)
        {
            BaseWorkFlowMessage sourceWorkFlowMessage = (BaseWorkFlowMessage)(source);

            _Delay = sourceWorkFlowMessage._Delay;
            _Variance = sourceWorkFlowMessage._Variance;
            _BusinessHoursOnly = sourceWorkFlowMessage._BusinessHoursOnly;
            _IsWithdrawalMessage = sourceWorkFlowMessage._IsWithdrawalMessage;
            
        }
    }


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

            _MessageTemplate.copyFrom (sourceWorkFlowMessage._MessageTemplate, linkToGhosts);
            _WorkFlowStage.copyFrom (sourceWorkFlowMessage._WorkFlowStage, 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 BaseWorkFlowMessage)
        {
            BaseWorkFlowMessage sourceWorkFlowMessage = (BaseWorkFlowMessage)(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);

        _Delay = (String)(HELPER_Delay.readExternal (_Delay, vals.get(FIELD_Delay))); //
        _Variance = (String)(HELPER_Variance.readExternal (_Variance, vals.get(FIELD_Variance))); //
        _BusinessHoursOnly = (Boolean)(HELPER_BusinessHoursOnly.readExternal (_BusinessHoursOnly, vals.get(FIELD_BusinessHoursOnly))); //
        _IsWithdrawalMessage = (Boolean)(HELPER_IsWithdrawalMessage.readExternal (_IsWithdrawalMessage, vals.get(FIELD_IsWithdrawalMessage))); //
        _MessageTemplate.readExternalData(vals.get(SINGLEREFERENCE_MessageTemplate));
        _WorkFlowStage.readExternalData(vals.get(SINGLEREFERENCE_WorkFlowStage));
        
    }


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

        vals.put (FIELD_Delay, HELPER_Delay.writeExternal (_Delay));
        vals.put (FIELD_Variance, HELPER_Variance.writeExternal (_Variance));
        vals.put (FIELD_BusinessHoursOnly, HELPER_BusinessHoursOnly.writeExternal (_BusinessHoursOnly));
        vals.put (FIELD_IsWithdrawalMessage, HELPER_IsWithdrawalMessage.writeExternal (_IsWithdrawalMessage));
        vals.put (SINGLEREFERENCE_MessageTemplate, _MessageTemplate.writeExternalData());
        vals.put (SINGLEREFERENCE_WorkFlowStage, _WorkFlowStage.writeExternalData());
        
    }


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

        if (other instanceof BaseWorkFlowMessage)
        {
            BaseWorkFlowMessage otherWorkFlowMessage = (BaseWorkFlowMessage)(other);

            
            if (!HELPER_Delay.compare(this._Delay, otherWorkFlowMessage._Delay))
            {
                listener.notifyFieldChange(this, other, FIELD_Delay, HELPER_Delay.toObject(this._Delay), HELPER_Delay.toObject(otherWorkFlowMessage._Delay));
            }
            if (!HELPER_Variance.compare(this._Variance, otherWorkFlowMessage._Variance))
            {
                listener.notifyFieldChange(this, other, FIELD_Variance, HELPER_Variance.toObject(this._Variance), HELPER_Variance.toObject(otherWorkFlowMessage._Variance));
            }
            if (!HELPER_BusinessHoursOnly.compare(this._BusinessHoursOnly, otherWorkFlowMessage._BusinessHoursOnly))
            {
                listener.notifyFieldChange(this, other, FIELD_BusinessHoursOnly, HELPER_BusinessHoursOnly.toObject(this._BusinessHoursOnly), HELPER_BusinessHoursOnly.toObject(otherWorkFlowMessage._BusinessHoursOnly));
            }
            if (!HELPER_IsWithdrawalMessage.compare(this._IsWithdrawalMessage, otherWorkFlowMessage._IsWithdrawalMessage))
            {
                listener.notifyFieldChange(this, other, FIELD_IsWithdrawalMessage, HELPER_IsWithdrawalMessage.toObject(this._IsWithdrawalMessage), HELPER_IsWithdrawalMessage.toObject(otherWorkFlowMessage._IsWithdrawalMessage));
            }

            // Compare single assocs
            _MessageTemplate.compare (otherWorkFlowMessage._MessageTemplate, listener);
            _WorkFlowStage.compare (otherWorkFlowMessage._WorkFlowStage, 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_Delay, HELPER_Delay.toObject(getDelay()));
        visitor.visitField(this, FIELD_Variance, HELPER_Variance.toObject(getVariance()));
        visitor.visitField(this, FIELD_BusinessHoursOnly, HELPER_BusinessHoursOnly.toObject(getBusinessHoursOnly()));
        visitor.visitField(this, FIELD_IsWithdrawalMessage, HELPER_IsWithdrawalMessage.toObject(getIsWithdrawalMessage()));
        visitor.visitAssociation (_MessageTemplate);
        visitor.visitAssociation (_WorkFlowStage);
        
    }


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

        if (scope.includes (_MessageTemplate))
        {
            visitor.visit (_MessageTemplate);
        }
        if (scope.includes (_WorkFlowStage))
        {
            visitor.visit (_WorkFlowStage);
        }
        
    }


    public static WorkFlowMessage createWorkFlowMessage (ObjectTransaction transaction) throws StorageException
    {
        WorkFlowMessage     result = new WorkFlowMessage ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static WorkFlowMessage getWorkFlowMessageByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (WorkFlowMessage)(transaction.getObjectByID (REFERENCE_WorkFlowMessage, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Delay))
        {
            return filter.matches (getDelay ());
        }
        else if (attribName.equals (FIELD_Variance))
        {
            return filter.matches (getVariance ());
        }
        else if (attribName.equals (FIELD_BusinessHoursOnly))
        {
            return filter.matches (getBusinessHoursOnly ());
        }
        else if (attribName.equals (FIELD_IsWithdrawalMessage))
        {
            return filter.matches (getIsWithdrawalMessage ());
        }
        else if (attribName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return filter.matches (getMessageTemplate ());
        }
        else if (attribName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return filter.matches (getWorkFlowStage ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
        public SearchAll andDelay (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.delay", "Delay");
            return this;
        }
            
        public SearchAll andVariance (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.variance", "Variance");
            return this;
        }
            
        public SearchAll andBusinessHoursOnly (QueryFilter<Boolean> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.business_hours_only", "BusinessHoursOnly");
            return this;
        }
            
        public SearchAll andIsWithdrawalMessage (QueryFilter<Boolean> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.is_withdrawal_message", "IsWithdrawalMessage");
            return this;
        }
            
        public SearchAll andMessageTemplate (QueryFilter<MessageTemplate> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.message_template_id", "MessageTemplate");
            return this;
        }
            
        public SearchAll andWorkFlowStage (QueryFilter<WorkFlowStage> filter)
        {
            filter.addFilter (context, "tl_work_flow_message.work_flow_stage_id", "WorkFlowStage");
            return this;
        }
            
        public WorkFlowMessage[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_WorkFlowMessage, SEARCH_All, criteria);
            Set<WorkFlowMessage>   typedResults = new LinkedHashSet <WorkFlowMessage> ();
            for (BaseBusinessClass bbcResult : results)
            {
                WorkFlowMessage aResult = (WorkFlowMessage)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new WorkFlowMessage[0]);
                            
        }
    }

        
    public static WorkFlowMessage[] 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_Delay))
        {
            return HELPER_Delay.toObject (getDelay ());
        }
        else if (attribName.equals (FIELD_Variance))
        {
            return HELPER_Variance.toObject (getVariance ());
        }
        else if (attribName.equals (FIELD_BusinessHoursOnly))
        {
            return HELPER_BusinessHoursOnly.toObject (getBusinessHoursOnly ());
        }
        else if (attribName.equals (FIELD_IsWithdrawalMessage))
        {
            return HELPER_IsWithdrawalMessage.toObject (getIsWithdrawalMessage ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Delay))
        {
            return HELPER_Delay;
        }
        else if (attribName.equals (FIELD_Variance))
        {
            return HELPER_Variance;
        }
        else if (attribName.equals (FIELD_BusinessHoursOnly))
        {
            return HELPER_BusinessHoursOnly;
        }
        else if (attribName.equals (FIELD_IsWithdrawalMessage))
        {
            return HELPER_IsWithdrawalMessage;
        }
        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_Delay))
        {
            setDelay ((String)(HELPER_Delay.fromObject (_Delay, attribValue)));            
        }
        else if (attribName.equals (FIELD_Variance))
        {
            setVariance ((String)(HELPER_Variance.fromObject (_Variance, attribValue)));            
        }
        else if (attribName.equals (FIELD_BusinessHoursOnly))
        {
            setBusinessHoursOnly ((Boolean)(HELPER_BusinessHoursOnly.fromObject (_BusinessHoursOnly, attribValue)));            
        }
        else if (attribName.equals (FIELD_IsWithdrawalMessage))
        {
            setIsWithdrawalMessage ((Boolean)(HELPER_IsWithdrawalMessage.fromObject (_IsWithdrawalMessage, 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_Delay))
        {
            return getWriteability_Delay ();
        }
        else if (fieldName.equals (FIELD_Variance))
        {
            return getWriteability_Variance ();
        }
        else if (fieldName.equals (FIELD_BusinessHoursOnly))
        {
            return getWriteability_BusinessHoursOnly ();
        }
        else if (fieldName.equals (FIELD_IsWithdrawalMessage))
        {
            return getWriteability_IsWithdrawalMessage ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return getWriteability_MessageTemplate ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return getWriteability_WorkFlowStage ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Delay () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Delay);
        }
        
        if (getWriteability_Variance () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Variance);
        }
        
        if (getWriteability_BusinessHoursOnly () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_BusinessHoursOnly);
        }
        
        if (getWriteability_IsWithdrawalMessage () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_IsWithdrawalMessage);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_Delay.getAttribObject (getClass (), _Delay, false, FIELD_Delay));
        result.add(HELPER_Variance.getAttribObject (getClass (), _Variance, false, FIELD_Variance));
        result.add(HELPER_BusinessHoursOnly.getAttribObject (getClass (), _BusinessHoursOnly, false, FIELD_BusinessHoursOnly));
        result.add(HELPER_IsWithdrawalMessage.getAttribObject (getClass (), _IsWithdrawalMessage, false, FIELD_IsWithdrawalMessage));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_WorkFlowMessage);
    }
            

    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 WorkFlowMessageBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<WorkFlowMessage>
    {

    /**
     * Get the attribute Delay
     */
    public String getDelay (WorkFlowMessage obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Delay.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setDelay (WorkFlowMessage obj, String newDelay) throws FieldException
    {
        return newDelay;
    }

    /**
     * Get the attribute Variance
     */
    public String getVariance (WorkFlowMessage obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Variance.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setVariance (WorkFlowMessage obj, String newVariance) throws FieldException
    {
        return newVariance;
    }

    /**
     * Get the attribute BusinessHoursOnly
     */
    public Boolean getBusinessHoursOnly (WorkFlowMessage obj, Boolean original)
    {
        return original;
    }

    /**
     * Change the value set for attribute BusinessHoursOnly.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Boolean setBusinessHoursOnly (WorkFlowMessage obj, Boolean newBusinessHoursOnly) throws FieldException
    {
        return newBusinessHoursOnly;
    }

    /**
     * Get the attribute IsWithdrawalMessage
     */
    public Boolean getIsWithdrawalMessage (WorkFlowMessage obj, Boolean original)
    {
        return original;
    }

    /**
     * Change the value set for attribute IsWithdrawalMessage.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Boolean setIsWithdrawalMessage (WorkFlowMessage obj, Boolean newIsWithdrawalMessage) throws FieldException
    {
        return newIsWithdrawalMessage;
    }

    }

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

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

        public WorkFlowMessagePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Delay"))
            {
                return toDelay ();
            }                
            if (name.equals ("Variance"))
            {
                return toVariance ();
            }                
            if (name.equals ("BusinessHoursOnly"))
            {
                return toBusinessHoursOnly ();
            }                
            if (name.equals ("IsWithdrawalMessage"))
            {
                return toIsWithdrawalMessage ();
            }                
            if (name.equals ("MessageTemplate"))
            {
                return toMessageTemplate ();
            }                
            if (name.equals ("WorkFlowStage"))
            {
                return toWorkFlowStage ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toDelay () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Delay));  }
        
        public PipeLine<From, String> toVariance () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Variance));  }
        
        public PipeLine<From, Boolean> toBusinessHoursOnly () { return pipe(new ORMAttributePipe<Me, Boolean>(FIELD_BusinessHoursOnly));  }
        
        public PipeLine<From, Boolean> toIsWithdrawalMessage () { return pipe(new ORMAttributePipe<Me, Boolean>(FIELD_IsWithdrawalMessage));  }

        public MessageTemplate.MessageTemplatePipeLineFactory<From, MessageTemplate> toMessageTemplate () { return toMessageTemplate (Filter.ALL); }

        public MessageTemplate.MessageTemplatePipeLineFactory<From, MessageTemplate> toMessageTemplate (Filter<MessageTemplate> filter) 
        { 
            return MessageTemplate.REFERENCE_MessageTemplate.new MessageTemplatePipeLineFactory<From, MessageTemplate> (this, new ORMSingleAssocPipe<Me, MessageTemplate>(SINGLEREFERENCE_MessageTemplate, filter)); 
        }

        public WorkFlowStage.WorkFlowStagePipeLineFactory<From, WorkFlowStage> toWorkFlowStage () { return toWorkFlowStage (Filter.ALL); }

        public WorkFlowStage.WorkFlowStagePipeLineFactory<From, WorkFlowStage> toWorkFlowStage (Filter<WorkFlowStage> filter) 
        { 
            return WorkFlowStage.REFERENCE_WorkFlowStage.new WorkFlowStagePipeLineFactory<From, WorkFlowStage> (this, new ORMSingleAssocPipe<Me, WorkFlowStage>(SINGLEREFERENCE_WorkFlowStage, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public MessageTemplate getMessageTemplate () throws StorageException
    {
        return (MessageTemplate)(MessageTemplate.DUMMY_MessageTemplate);
    }


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

    public WorkFlowStage getWorkFlowStage () throws StorageException
    {
        return (WorkFlowStage)(WorkFlowStage.DUMMY_WorkFlowStage);
    }


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

}

    
