/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure8.2 rev3 [oneit.objstore.BusinessObjectTemplate.xsl]
 *
 *   Version: 1.0
 *   Vendor: Apache Software Foundation (Xalan XSLTC)
 *   Vendor URL: http://xml.apache.org/xalan-j
 */


    package performa.orm;

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

import performa.orm.types.*;



public abstract class BaseScheduledEmail extends BaseBusinessClass
{
    // Reference instance for the object
    public static final ScheduledEmail REFERENCE_ScheduledEmail = new ScheduledEmail ();

    // Reference instance for the object
    public static final ScheduledEmail DUMMY_ScheduledEmail = new DummyScheduledEmail ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Subject = "Subject";
    public static final String FIELD_ScheduledDate = "ScheduledDate";
    public static final String FIELD_ApplicationStatus = "ApplicationStatus";
    public static final String FIELD_MessageContent = "MessageContent";
    public static final String SINGLEREFERENCE_JobApplication = "JobApplication";
    public static final String BACKREF_JobApplication = "";
    public static final String SINGLEREFERENCE_MessageTemplate = "MessageTemplate";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<ScheduledEmail> HELPER_Subject = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<ScheduledEmail> HELPER_ScheduledDate = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<ScheduledEmail, ApplicationStatus> HELPER_ApplicationStatus =  new EnumeratedAttributeHelper<ScheduledEmail, ApplicationStatus> (ApplicationStatus.FACTORY_ApplicationStatus);
    private static final DefaultAttributeHelper<ScheduledEmail> HELPER_MessageContent = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _Subject;
    private Date _ScheduledDate;
    private ApplicationStatus _ApplicationStatus;
    private String _MessageContent;
    

    // Private attributes corresponding to single references
    private SingleAssociation<ScheduledEmail, JobApplication> _JobApplication;
    private SingleAssociation<ScheduledEmail, MessageTemplate> _MessageTemplate;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Subject_Validators;
    private static final AttributeValidator[] FIELD_ScheduledDate_Validators;
    private static final AttributeValidator[] FIELD_ApplicationStatus_Validators;
    private static final AttributeValidator[] FIELD_MessageContent_Validators;
    

    // Arrays of behaviour decorators
    private static final ScheduledEmailBehaviourDecorator[] ScheduledEmail_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_JobApplication = JobApplication.BACKREF_ScheduledEmails;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_JobApplication();
            setupAssocMetaData_MessageTemplate();
            FIELD_Subject_Validators = (AttributeValidator[])setupAttribMetaData_Subject(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ScheduledDate_Validators = (AttributeValidator[])setupAttribMetaData_ScheduledDate(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ApplicationStatus_Validators = (AttributeValidator[])setupAttribMetaData_ApplicationStatus(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_MessageContent_Validators = (AttributeValidator[])setupAttribMetaData_MessageContent(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_ScheduledEmail.initialiseReference ();
            DUMMY_ScheduledEmail.initialiseReference ();
            ScheduledEmail_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(ScheduledEmail.class).toArray(new ScheduledEmailBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "ScheduledEmails");
        metaInfo.put ("dbcol", "job_application_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "JobApplication");
        metaInfo.put ("type", "JobApplication");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.JobApplication:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (SINGLEREFERENCE_JobApplication, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_MessageTemplate()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "message_template_id");
        metaInfo.put ("name", "MessageTemplate");
        metaInfo.put ("type", "MessageTemplate");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.MessageTemplate:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (SINGLEREFERENCE_MessageTemplate, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Subject(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "subject");
        metaInfo.put ("length", "200");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Subject");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.Subject:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (FIELD_Subject, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "scheduled_date");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "ScheduledDate");
        metaInfo.put ("type", "Date");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.ScheduledDate:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (FIELD_ScheduledDate, Collections.unmodifiableMap (metaInfo));

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

        return validators;
    }
    
    // Meta Info setup
    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");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.ApplicationStatus:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (FIELD_ApplicationStatus, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "message_content");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "MessageContent");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ScheduledEmail.MessageContent:", metaInfo);
        ATTRIBUTES_METADATA_ScheduledEmail.put (FIELD_MessageContent, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Subject = (String)(HELPER_Subject.initialise (_Subject));
        _ScheduledDate = (Date)(HELPER_ScheduledDate.initialise (_ScheduledDate));
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.initialise (_ApplicationStatus));
        _MessageContent = (String)(HELPER_MessageContent.initialise (_MessageContent));
    }


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

        _JobApplication = new SingleAssociation<ScheduledEmail, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_ScheduledEmails, JobApplication.REFERENCE_JobApplication, "tl_scheduled_email");
        _MessageTemplate = new SingleAssociation<ScheduledEmail, MessageTemplate> (this, SINGLEREFERENCE_MessageTemplate, null, MessageTemplate.REFERENCE_MessageTemplate, "tl_scheduled_email");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _JobApplication = new SingleAssociation<ScheduledEmail, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_ScheduledEmails, JobApplication.REFERENCE_JobApplication, "tl_scheduled_email");
        _MessageTemplate = new SingleAssociation<ScheduledEmail, MessageTemplate> (this, SINGLEREFERENCE_MessageTemplate, null, MessageTemplate.REFERENCE_MessageTemplate, "tl_scheduled_email");
        
        
        return this;
    }

    

    /**
     * Get the attribute Subject
     */
    public String getSubject ()
    {
        assertValid();
        String valToReturn = _Subject;

            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                valToReturn = bhd.getSubject ((ScheduledEmail)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 preSubjectChange (String newSubject) 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 postSubjectChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Subject.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setSubject (String newSubject) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Subject.compare (_Subject, newSubject);
        
        try
        {
            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                newSubject = bhd.setSubject ((ScheduledEmail)this, newSubject);
                oldAndNewIdentical = HELPER_Subject.compare (_Subject, newSubject);
            }

            BusinessObjectParser.assertFieldCondition (newSubject != null, this, FIELD_Subject, "mandatory");
            

            if (FIELD_Subject_Validators.length > 0)
            {
                Object newSubjectObj = HELPER_Subject.toObject (newSubject);

                if (newSubjectObj != null)
                {
                    int     loopMax = FIELD_Subject_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_ScheduledEmail.get (FIELD_Subject);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Subject () != FieldWriteability.FALSE, "Field  Subject is not writeable");
            preSubjectChange (newSubject);
            markFieldChange (FIELD_Subject);
            _Subject = newSubject;            
            postFieldChange (FIELD_Subject);
            postSubjectChange ();
        }
    }

    /**
     * Get the attribute ScheduledDate
     */
    public Date getScheduledDate ()
    {
        assertValid();
        Date valToReturn = _ScheduledDate;

            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                valToReturn = bhd.getScheduledDate ((ScheduledEmail)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 preScheduledDateChange (Date newScheduledDate) 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 postScheduledDateChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ScheduledDate.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setScheduledDate (Date newScheduledDate) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ScheduledDate.compare (_ScheduledDate, newScheduledDate);
        
        try
        {
            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                newScheduledDate = bhd.setScheduledDate ((ScheduledEmail)this, newScheduledDate);
                oldAndNewIdentical = HELPER_ScheduledDate.compare (_ScheduledDate, newScheduledDate);
            }

            BusinessObjectParser.assertFieldCondition (newScheduledDate != null, this, FIELD_ScheduledDate, "mandatory");
            

            if (FIELD_ScheduledDate_Validators.length > 0)
            {
                Object newScheduledDateObj = HELPER_ScheduledDate.toObject (newScheduledDate);

                if (newScheduledDateObj != null)
                {
                    int     loopMax = FIELD_ScheduledDate_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_ScheduledEmail.get (FIELD_ScheduledDate);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ScheduledDate () != FieldWriteability.FALSE, "Field  ScheduledDate is not writeable");
            preScheduledDateChange (newScheduledDate);
            markFieldChange (FIELD_ScheduledDate);
            _ScheduledDate = newScheduledDate;            
            postFieldChange (FIELD_ScheduledDate);
            postScheduledDateChange ();
        }
    }

    /**
     * Get the attribute ApplicationStatus
     */
    public ApplicationStatus getApplicationStatus ()
    {
        assertValid();
        ApplicationStatus valToReturn = _ApplicationStatus;

            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                valToReturn = bhd.getApplicationStatus ((ScheduledEmail)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
    {
        boolean oldAndNewIdentical = HELPER_ApplicationStatus.compare (_ApplicationStatus, newApplicationStatus);
        
        try
        {
            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                newApplicationStatus = bhd.setApplicationStatus ((ScheduledEmail)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_ScheduledEmail.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 (getWriteability_ApplicationStatus () != FieldWriteability.FALSE, "Field  ApplicationStatus is not writeable");
            preApplicationStatusChange (newApplicationStatus);
            markFieldChange (FIELD_ApplicationStatus);
            _ApplicationStatus = newApplicationStatus;            
            postFieldChange (FIELD_ApplicationStatus);
            postApplicationStatusChange ();
        }
    }

    /**
     * Get the attribute MessageContent
     */
    public String getMessageContent ()
    {
        assertValid();
        String valToReturn = _MessageContent;

            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                valToReturn = bhd.getMessageContent ((ScheduledEmail)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 preMessageContentChange (String newMessageContent) 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 postMessageContentChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute MessageContent.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setMessageContent (String newMessageContent) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_MessageContent.compare (_MessageContent, newMessageContent);
        
        try
        {
            for (ScheduledEmailBehaviourDecorator bhd : ScheduledEmail_BehaviourDecorators)
            {
                newMessageContent = bhd.setMessageContent ((ScheduledEmail)this, newMessageContent);
                oldAndNewIdentical = HELPER_MessageContent.compare (_MessageContent, newMessageContent);
            }

            BusinessObjectParser.assertFieldCondition (newMessageContent != null, this, FIELD_MessageContent, "mandatory");
            

            if (FIELD_MessageContent_Validators.length > 0)
            {
                Object newMessageContentObj = HELPER_MessageContent.toObject (newMessageContent);

                if (newMessageContentObj != null)
                {
                    int     loopMax = FIELD_MessageContent_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_ScheduledEmail.get (FIELD_MessageContent);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_MessageContent () != FieldWriteability.FALSE, "Field  MessageContent is not writeable");
            preMessageContentChange (newMessageContent);
            markFieldChange (FIELD_MessageContent);
            _MessageContent = newMessageContent;            
            postFieldChange (FIELD_MessageContent);
            postMessageContentChange ();
        }
    }



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

        
        result.add("JobApplication");
        
        result.add("MessageTemplate");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return _JobApplication.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return _MessageTemplate.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_JobApplication))
        {
            return JobApplication.MULTIPLEREFERENCE_ScheduledEmails ;
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return null ;
        }
        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_JobApplication))
        {
            return getJobApplication ();
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return getMessageTemplate ();
        }
        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_JobApplication))
        {
            return getJobApplication (getType);
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return getMessageTemplate (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_JobApplication))
        {
            return getJobApplicationID ();
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return getMessageTemplateID ();
        }
        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_JobApplication))
        {
            setJobApplication ((JobApplication)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            setMessageTemplate ((MessageTemplate)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobApplicationID ()
    {
        assertValid();
        
        if (_JobApplication == null)
        {
            return null;
        }
        else
        {
            return _JobApplication.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 preJobApplicationChange (JobApplication newJobApplication) 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 postJobApplicationChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_JobApplication ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference JobApplication.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setJobApplication (JobApplication newJobApplication) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newJobApplication != null, this, SINGLEREFERENCE_JobApplication, "mandatory");
        

        if (_JobApplication.wouldReferencedChange (newJobApplication))
        {
            assertValid();
            Debug.assertion (getWriteability_JobApplication () != FieldWriteability.FALSE, "Assoc JobApplication is not writeable");
            preJobApplicationChange (newJobApplication);
            JobApplication oldJobApplication = getJobApplication ();

                    if (oldJobApplication != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _JobApplication.set (null);
                        oldJobApplication.removeFromScheduledEmails ((ScheduledEmail)(this));
                    }

                    _JobApplication.set (newJobApplication);

                    if (newJobApplication != null)
                    {
                        newJobApplication.addToScheduledEmails ((ScheduledEmail)(this));
                    }
                
            postJobApplicationChange ();
        }
    }

    /**
     * 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 ScheduledEmail:", 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 (getWriteability_MessageTemplate () != FieldWriteability.FALSE, "Assoc MessageTemplate is not writeable");
            preMessageTemplateChange (newMessageTemplate);
            
                    _MessageTemplate.set (newMessageTemplate);
                
            postMessageTemplateChange ();
        }
    }

    /**
     * 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 (_JobApplication.isLoaded () || getTransaction ().isObjectLoaded (_JobApplication.getReferencedType (), getJobApplicationID ()))
            {
                JobApplication  referenced = getJobApplication ();

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

        super.onDelete ();
    }


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


    public ScheduledEmail referenceInstance ()
    {
        return REFERENCE_ScheduledEmail;
    }


    public ScheduledEmail getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getScheduledEmailByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_ScheduledEmail;
    }


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





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

        tl_scheduled_emailPSet.setAttrib (FIELD_ObjectID, myID);
        tl_scheduled_emailPSet.setAttrib (FIELD_Subject, HELPER_Subject.toObject (_Subject)); //
        tl_scheduled_emailPSet.setAttrib (FIELD_ScheduledDate, HELPER_ScheduledDate.toObject (_ScheduledDate)); //
        tl_scheduled_emailPSet.setAttrib (FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject (_ApplicationStatus)); //
        tl_scheduled_emailPSet.setAttrib (FIELD_MessageContent, HELPER_MessageContent.toObject (_MessageContent)); //
        _JobApplication.getPersistentSets (allSets);
        _MessageTemplate.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_scheduled_emailPSet = allSets.getPersistentSet (objectID, "tl_scheduled_email");

        _Subject = (String)(HELPER_Subject.fromObject (_Subject, tl_scheduled_emailPSet.getAttrib (FIELD_Subject))); //
        _ScheduledDate = (Date)(HELPER_ScheduledDate.fromObject (_ScheduledDate, tl_scheduled_emailPSet.getAttrib (FIELD_ScheduledDate))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, tl_scheduled_emailPSet.getAttrib (FIELD_ApplicationStatus))); //
        _MessageContent = (String)(HELPER_MessageContent.fromObject (_MessageContent, tl_scheduled_emailPSet.getAttrib (FIELD_MessageContent))); //
        _JobApplication.setFromPersistentSets (objectID, allSets);
        _MessageTemplate.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof ScheduledEmail)
        {
            ScheduledEmail otherScheduledEmail = (ScheduledEmail)other;
            
            try
            {
                setSubject (otherScheduledEmail.getSubject ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setScheduledDate (otherScheduledEmail.getScheduledDate ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setApplicationStatus (otherScheduledEmail.getApplicationStatus ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setMessageContent (otherScheduledEmail.getMessageContent ());
            }
            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 BaseScheduledEmail)
        {
            BaseScheduledEmail sourceScheduledEmail = (BaseScheduledEmail)(source);

            _Subject = sourceScheduledEmail._Subject;
            _ScheduledDate = sourceScheduledEmail._ScheduledDate;
            _ApplicationStatus = sourceScheduledEmail._ApplicationStatus;
            _MessageContent = sourceScheduledEmail._MessageContent;
            
        }
    }


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

            _JobApplication.copyFrom (sourceScheduledEmail._JobApplication, linkToGhosts);
            _MessageTemplate.copyFrom (sourceScheduledEmail._MessageTemplate, 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 BaseScheduledEmail)
        {
            BaseScheduledEmail sourceScheduledEmail = (BaseScheduledEmail)(source);

            
        }
    }


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

        
        context.check (getJobApplicationID() != null, this, SINGLEREFERENCE_JobApplication, "mandatory");
        
    }


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

        _Subject = (String)(HELPER_Subject.readExternal (_Subject, vals.get(FIELD_Subject))); //
        _ScheduledDate = (Date)(HELPER_ScheduledDate.readExternal (_ScheduledDate, vals.get(FIELD_ScheduledDate))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.readExternal (_ApplicationStatus, vals.get(FIELD_ApplicationStatus))); //
        _MessageContent = (String)(HELPER_MessageContent.readExternal (_MessageContent, vals.get(FIELD_MessageContent))); //
        _JobApplication.readExternalData(vals.get(SINGLEREFERENCE_JobApplication));
        _MessageTemplate.readExternalData(vals.get(SINGLEREFERENCE_MessageTemplate));
        
    }


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

        vals.put (FIELD_Subject, HELPER_Subject.writeExternal (_Subject));
        vals.put (FIELD_ScheduledDate, HELPER_ScheduledDate.writeExternal (_ScheduledDate));
        vals.put (FIELD_ApplicationStatus, HELPER_ApplicationStatus.writeExternal (_ApplicationStatus));
        vals.put (FIELD_MessageContent, HELPER_MessageContent.writeExternal (_MessageContent));
        vals.put (SINGLEREFERENCE_JobApplication, _JobApplication.writeExternalData());
        vals.put (SINGLEREFERENCE_MessageTemplate, _MessageTemplate.writeExternalData());
        
    }


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

        if (other instanceof BaseScheduledEmail)
        {
            BaseScheduledEmail otherScheduledEmail = (BaseScheduledEmail)(other);

            
            if (!HELPER_Subject.compare(this._Subject, otherScheduledEmail._Subject))
            {
                listener.notifyFieldChange(this, other, FIELD_Subject, HELPER_Subject.toObject(this._Subject), HELPER_Subject.toObject(otherScheduledEmail._Subject));
            }
            if (!HELPER_ScheduledDate.compare(this._ScheduledDate, otherScheduledEmail._ScheduledDate))
            {
                listener.notifyFieldChange(this, other, FIELD_ScheduledDate, HELPER_ScheduledDate.toObject(this._ScheduledDate), HELPER_ScheduledDate.toObject(otherScheduledEmail._ScheduledDate));
            }
            if (!HELPER_ApplicationStatus.compare(this._ApplicationStatus, otherScheduledEmail._ApplicationStatus))
            {
                listener.notifyFieldChange(this, other, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(this._ApplicationStatus), HELPER_ApplicationStatus.toObject(otherScheduledEmail._ApplicationStatus));
            }
            if (!HELPER_MessageContent.compare(this._MessageContent, otherScheduledEmail._MessageContent))
            {
                listener.notifyFieldChange(this, other, FIELD_MessageContent, HELPER_MessageContent.toObject(this._MessageContent), HELPER_MessageContent.toObject(otherScheduledEmail._MessageContent));
            }

            // Compare single assocs
            _JobApplication.compare (otherScheduledEmail._JobApplication, listener);
            _MessageTemplate.compare (otherScheduledEmail._MessageTemplate, 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_Subject, HELPER_Subject.toObject(getSubject()));
        visitor.visitField(this, FIELD_ScheduledDate, HELPER_ScheduledDate.toObject(getScheduledDate()));
        visitor.visitField(this, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(getApplicationStatus()));
        visitor.visitField(this, FIELD_MessageContent, HELPER_MessageContent.toObject(getMessageContent()));
        visitor.visitAssociation (_JobApplication);
        visitor.visitAssociation (_MessageTemplate);
        
    }


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

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


    public static ScheduledEmail createScheduledEmail (ObjectTransaction transaction) throws StorageException
    {
        ScheduledEmail     result = new ScheduledEmail ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static ScheduledEmail getScheduledEmailByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (ScheduledEmail)(transaction.getObjectByID (REFERENCE_ScheduledEmail, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            return filter.matches (getSubject ());
        }
        else if (attribName.equals (FIELD_ScheduledDate))
        {
            return filter.matches (getScheduledDate ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return filter.matches (getApplicationStatus ());
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return filter.matches (getMessageContent ());
        }
        else if (attribName.equals (SINGLEREFERENCE_JobApplication))
        {
            return filter.matches (getJobApplication ());
        }
        else if (attribName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return filter.matches (getMessageTemplate ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andSubject (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.subject", "Subject");
                return this;
            }
            
            public SearchAll andScheduledDate (QueryFilter<Date> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.scheduled_date", "ScheduledDate");
                return this;
            }
            
            public SearchAll andApplicationStatus (QueryFilter<ApplicationStatus> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.application_status", "ApplicationStatus");
                return this;
            }
            
            public SearchAll andMessageContent (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.message_content", "MessageContent");
                return this;
            }
            
            public SearchAll andJobApplication (QueryFilter<JobApplication> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.job_application_id", "JobApplication");
                return this;
            }
            
            public SearchAll andMessageTemplate (QueryFilter<MessageTemplate> filter)
            {
                filter.addFilter (context, "tl_scheduled_email.message_template_id", "MessageTemplate");
                return this;
            }
            
                public ScheduledEmail[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_ScheduledEmail, SEARCH_All, criteria);
            Set<ScheduledEmail>   typedResults = new LinkedHashSet <ScheduledEmail> ();
            for (BaseBusinessClass bbcResult : results)
            {
                ScheduledEmail aResult = (ScheduledEmail)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new ScheduledEmail[0]);
                            
        }
    }

        
                public static ScheduledEmail[]
             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_Subject))
        {
            return HELPER_Subject.toObject (getSubject ());
        }
        else if (attribName.equals (FIELD_ScheduledDate))
        {
            return HELPER_ScheduledDate.toObject (getScheduledDate ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus.toObject (getApplicationStatus ());
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return HELPER_MessageContent.toObject (getMessageContent ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            return HELPER_Subject;
        }
        else if (attribName.equals (FIELD_ScheduledDate))
        {
            return HELPER_ScheduledDate;
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus;
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return HELPER_MessageContent;
        }
        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_Subject))
        {
            setSubject ((String)(HELPER_Subject.fromObject (_Subject, attribValue)));            
        }
        else if (attribName.equals (FIELD_ScheduledDate))
        {
            setScheduledDate ((Date)(HELPER_ScheduledDate.fromObject (_ScheduledDate, attribValue)));            
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            setApplicationStatus ((ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, attribValue)));            
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            setMessageContent ((String)(HELPER_MessageContent.fromObject (_MessageContent, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }



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


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_Subject))
        {
            return getWriteability_Subject ();
        }
        else if (fieldName.equals (FIELD_ScheduledDate))
        {
            return getWriteability_ScheduledDate ();
        }
        else if (fieldName.equals (FIELD_ApplicationStatus))
        {
            return getWriteability_ApplicationStatus ();
        }
        else if (fieldName.equals (FIELD_MessageContent))
        {
            return getWriteability_MessageContent ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getWriteability_JobApplication ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_MessageTemplate))
        {
            return getWriteability_MessageTemplate ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Subject () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Subject);
            }
        
            if (getWriteability_ScheduledDate () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ScheduledDate);
            }
        
            if (getWriteability_ApplicationStatus () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ApplicationStatus);
            }
        
            if (getWriteability_MessageContent () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_MessageContent);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Subject.getAttribObject (getClass (), _Subject, true, FIELD_Subject));
        result.add(HELPER_ScheduledDate.getAttribObject (getClass (), _ScheduledDate, true, FIELD_ScheduledDate));
        result.add(HELPER_ApplicationStatus.getAttribObject (getClass (), _ApplicationStatus, true, FIELD_ApplicationStatus));
        result.add(HELPER_MessageContent.getAttribObject (getClass (), _MessageContent, true, FIELD_MessageContent));

        return result;
    }


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


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

    public void preCommit (boolean willBeStored) throws Exception
    {
        super.preCommit(willBeStored);
        
        if(willBeStored)
        {
        
        }
    }

    public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
    {
        
        
        return super.getBinaryContentHandler(attribName);
    }

    public static class ScheduledEmailBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<ScheduledEmail>
    {

    /**
     * Get the attribute Subject
     */
    public String getSubject (ScheduledEmail obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Subject.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setSubject (ScheduledEmail obj, String newSubject) throws FieldException
    {
        return newSubject;
    }

    /**
     * Get the attribute ScheduledDate
     */
    public Date getScheduledDate (ScheduledEmail obj, Date original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ScheduledDate.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Date setScheduledDate (ScheduledEmail obj, Date newScheduledDate) throws FieldException
    {
        return newScheduledDate;
    }

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

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

    /**
     * Get the attribute MessageContent
     */
    public String getMessageContent (ScheduledEmail obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute MessageContent.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setMessageContent (ScheduledEmail obj, String newMessageContent) throws FieldException
    {
        return newMessageContent;
    }

    }

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

        public ScheduledEmailPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Subject"))
            {
                return toSubject ();
            }                
            if (name.equals ("ScheduledDate"))
            {
                return toScheduledDate ();
            }                
            if (name.equals ("ApplicationStatus"))
            {
                return toApplicationStatus ();
            }                
            if (name.equals ("MessageContent"))
            {
                return toMessageContent ();
            }                
            if (name.equals ("JobApplication"))
            {
                return toJobApplication ();
            }                
            if (name.equals ("MessageTemplate"))
            {
                return toMessageTemplate ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toSubject () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Subject));  }
        
        public PipeLine<From, Date> toScheduledDate () { return pipe(new ORMAttributePipe<Me, Date>(FIELD_ScheduledDate));  }
        
        public PipeLine<From, ApplicationStatus> toApplicationStatus () { return pipe(new ORMAttributePipe<Me, ApplicationStatus>(FIELD_ApplicationStatus));  }
        
        public PipeLine<From, String> toMessageContent () { return pipe(new ORMAttributePipe<Me, String>(FIELD_MessageContent));  }
        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication () { return toJobApplication (Filter.ALL); }

        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication (Filter<JobApplication> filter) 
        { 
            return JobApplication.REFERENCE_JobApplication.new JobApplicationPipeLineFactory<From, JobApplication> (this, new ORMSingleAssocPipe<Me, JobApplication>(SINGLEREFERENCE_JobApplication, filter)); 
        }
        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 boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public JobApplication getJobApplication () throws StorageException
    {
        return (JobApplication)(JobApplication.DUMMY_JobApplication);
    }


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

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

}

    
