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

    // Reference instance for the object
    public static final WorkFlowStep DUMMY_WorkFlowStep = new DummyWorkFlowStep ();

    // Static constants corresponding to field names
    
    public static final String FIELD_SortOrder = "SortOrder";
    public static final String FIELD_StepType = "StepType";
    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<WorkFlowStep> HELPER_SortOrder = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<WorkFlowStep, StepType> HELPER_StepType =  new EnumeratedAttributeHelper<WorkFlowStep, StepType> (StepType.FACTORY_StepType);
    

    // Private attributes corresponding to business object data
    private Integer _SortOrder;
    private StepType _StepType;
    

    // Private attributes corresponding to single references
    private SingleAssociation<WorkFlowStep, WorkFlowStage> _WorkFlowStage;
    

    // Private attributes corresponding to multiple references
    

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

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

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<WorkFlowStep, Integer>[] FIELD_SortOrder_Decorators;
    private static final AttributeDecorator<WorkFlowStep, StepType>[] FIELD_StepType_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<WorkFlowStep, WorkFlowStage>[] SINGLEREFERENCE_WorkFlowStage_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

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

            setupAssocMetaData_WorkFlowStage();
            FIELD_SortOrder_Validators = (AttributeValidator[])setupAttribMetaData_SortOrder(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_StepType_Validators = (AttributeValidator[])setupAttribMetaData_StepType(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_SortOrder_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowStep, FIELD_SortOrder).toArray (new AttributeDecorator[0]);
            FIELD_StepType_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_WorkFlowStep, FIELD_StepType).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_WorkFlowStage_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_WorkFlowStep, SINGLEREFERENCE_WorkFlowStage).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_WorkFlowStep.initialiseReference ();
            DUMMY_WorkFlowStep.initialiseReference ();
            WorkFlowStep_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(WorkFlowStep.class).toArray(new WorkFlowStepBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Steps");
        metaInfo.put ("dbcol", "work_flow_stage_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "WorkFlowStage");
        metaInfo.put ("type", "WorkFlowStage");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_step");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowStep.WorkFlowStage:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowStep.put (SINGLEREFERENCE_WorkFlowStage, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_SortOrder(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

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

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "step_type");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "StepType");
        metaInfo.put ("type", "StepType");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_work_flow_step");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for WorkFlowStep.StepType:", metaInfo);
        ATTRIBUTES_METADATA_WorkFlowStep.put (FIELD_StepType, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _SortOrder = (Integer)(HELPER_SortOrder.initialise (_SortOrder));
        _StepType = (StepType)(HELPER_StepType.initialise (_StepType));
    }


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

        _WorkFlowStage = new SingleAssociation<WorkFlowStep, WorkFlowStage> (this, SINGLEREFERENCE_WorkFlowStage, WorkFlowStage.MULTIPLEREFERENCE_Steps, WorkFlowStage.REFERENCE_WorkFlowStage, "tl_work_flow_step");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _WorkFlowStage = new SingleAssociation<WorkFlowStep, WorkFlowStage> (this, SINGLEREFERENCE_WorkFlowStage, WorkFlowStage.MULTIPLEREFERENCE_Steps, WorkFlowStage.REFERENCE_WorkFlowStage, "tl_work_flow_step");
        
        
        return this;
    }


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

        
        for (WorkFlowStepBehaviourDecorator bhd : WorkFlowStep_BehaviourDecorators)
        {
            valToReturn = bhd.getSortOrder ((WorkFlowStep)this, valToReturn);
        }

        return valToReturn;
    }


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


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

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

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

        boolean oldAndNewIdentical = HELPER_SortOrder.compare (_SortOrder, newSortOrder);
        
        try
        {
            for (WorkFlowStepBehaviourDecorator bhd : WorkFlowStep_BehaviourDecorators)
            {
                newSortOrder = bhd.setSortOrder ((WorkFlowStep)this, newSortOrder);
                oldAndNewIdentical = HELPER_SortOrder.compare (_SortOrder, newSortOrder);
            }

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

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

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

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

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

    /**
     * Attribute StepType
     */
    public StepType getStepType ()
    {
        assertValid();
        StepType valToReturn = AttributeDecoratorUtils.getValue (FIELD_StepType_Decorators, (WorkFlowStep)this, FIELD_StepType, _StepType);

        
        for (WorkFlowStepBehaviourDecorator bhd : WorkFlowStep_BehaviourDecorators)
        {
            valToReturn = bhd.getStepType ((WorkFlowStep)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 preStepTypeChange (StepType newStepType) 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 postStepTypeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute StepType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setStepType (StepType newStepType) throws FieldException
    {
        newStepType = AttributeDecoratorUtils.setValue (FIELD_StepType_Decorators, (WorkFlowStep)this, FIELD_StepType, newStepType);

        boolean oldAndNewIdentical = HELPER_StepType.compare (_StepType, newStepType);
        
        try
        {
            for (WorkFlowStepBehaviourDecorator bhd : WorkFlowStep_BehaviourDecorators)
            {
                newStepType = bhd.setStepType ((WorkFlowStep)this, newStepType);
                oldAndNewIdentical = HELPER_StepType.compare (_StepType, newStepType);
            }

            BusinessObjectParser.assertFieldCondition (newStepType != null, this, FIELD_StepType, "mandatory");
            

            if (FIELD_StepType_Validators.length > 0)
            {
                Object newStepTypeObj = HELPER_StepType.toObject (newStepType);

                if (newStepTypeObj != null)
                {
                    int     loopMax = FIELD_StepType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_WorkFlowStep.get (FIELD_StepType);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_StepType_Decorators, (WorkFlowStep)this, FIELD_StepType ,getWriteability_StepType ()) != FieldWriteability.FALSE, "Field  StepType is not writeable");
            preStepTypeChange (newStepType);
            markFieldChange (FIELD_StepType);
            _StepType = newStepType;            
            postFieldChange (FIELD_StepType);
            postStepTypeChange ();
        }
    }



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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        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_WorkFlowStage))
        {
            return WorkFlowStage.MULTIPLEREFERENCE_Steps ;
        }
        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_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_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_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_WorkFlowStage))
        {
            setWorkFlowStage ((WorkFlowStage)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * 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 WorkFlowStep:", 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
    {
        BusinessObjectParser.assertFieldCondition (newWorkFlowStage != null, this, SINGLEREFERENCE_WorkFlowStage, "mandatory");

        if (_WorkFlowStage.wouldReferencedChange (newWorkFlowStage))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_WorkFlowStage_Decorators, (WorkFlowStep)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.removeFromSteps ((WorkFlowStep)(this));
            }

            _WorkFlowStage.set (newWorkFlowStage);

            if (newWorkFlowStage != null)
            {
                newWorkFlowStage.addToSteps ((WorkFlowStep)(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 Steps from ", getObjectID (), " to ", referenced.getObjectID ());
                    _WorkFlowStage.set (null);
                    referenced.removeFromSteps ((WorkFlowStep)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public WorkFlowStep referenceInstance ()
    {
        return REFERENCE_WorkFlowStep;
    }


    public WorkFlowStep getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getWorkFlowStepByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_WorkFlowStep;
    }


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



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

        tl_work_flow_stepPSet.setAttrib (FIELD_ObjectID, myID);
        tl_work_flow_stepPSet.setAttrib (FIELD_SortOrder, HELPER_SortOrder.toObject (_SortOrder)); //
        tl_work_flow_stepPSet.setAttrib (FIELD_StepType, HELPER_StepType.toObject (_StepType)); //
        _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_stepPSet = allSets.getPersistentSet (objectID, "tl_work_flow_step");

        _SortOrder = (Integer)(HELPER_SortOrder.fromObject (_SortOrder, tl_work_flow_stepPSet.getAttrib (FIELD_SortOrder))); //
        _StepType = (StepType)(HELPER_StepType.fromObject (_StepType, tl_work_flow_stepPSet.getAttrib (FIELD_StepType))); //
        _WorkFlowStage.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof WorkFlowStep)
        {
            WorkFlowStep otherWorkFlowStep = (WorkFlowStep)other;
            

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

            try
            {
                setStepType (otherWorkFlowStep.getStepType ());
            }
            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 BaseWorkFlowStep)
        {
            BaseWorkFlowStep sourceWorkFlowStep = (BaseWorkFlowStep)(source);

            _SortOrder = sourceWorkFlowStep._SortOrder;
            _StepType = sourceWorkFlowStep._StepType;
            
        }
    }


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

            _WorkFlowStage.copyFrom (sourceWorkFlowStep._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 BaseWorkFlowStep)
        {
            BaseWorkFlowStep sourceWorkFlowStep = (BaseWorkFlowStep)(source);

            
        }
    }


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

        
        context.check (getWorkFlowStageID() != null, this, SINGLEREFERENCE_WorkFlowStage, "mandatory");
        
    }


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

        _SortOrder = (Integer)(HELPER_SortOrder.readExternal (_SortOrder, vals.get(FIELD_SortOrder))); //
        _StepType = (StepType)(HELPER_StepType.readExternal (_StepType, vals.get(FIELD_StepType))); //
        _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_SortOrder, HELPER_SortOrder.writeExternal (_SortOrder));
        vals.put (FIELD_StepType, HELPER_StepType.writeExternal (_StepType));
        vals.put (SINGLEREFERENCE_WorkFlowStage, _WorkFlowStage.writeExternalData());
        
    }


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

        if (other instanceof BaseWorkFlowStep)
        {
            BaseWorkFlowStep otherWorkFlowStep = (BaseWorkFlowStep)(other);

            
            if (!HELPER_SortOrder.compare(this._SortOrder, otherWorkFlowStep._SortOrder))
            {
                listener.notifyFieldChange(this, other, FIELD_SortOrder, HELPER_SortOrder.toObject(this._SortOrder), HELPER_SortOrder.toObject(otherWorkFlowStep._SortOrder));
            }
            if (!HELPER_StepType.compare(this._StepType, otherWorkFlowStep._StepType))
            {
                listener.notifyFieldChange(this, other, FIELD_StepType, HELPER_StepType.toObject(this._StepType), HELPER_StepType.toObject(otherWorkFlowStep._StepType));
            }

            // Compare single assocs
            _WorkFlowStage.compare (otherWorkFlowStep._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_SortOrder, HELPER_SortOrder.toObject(getSortOrder()));
        visitor.visitField(this, FIELD_StepType, HELPER_StepType.toObject(getStepType()));
        visitor.visitAssociation (_WorkFlowStage);
        
    }


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

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


    public static WorkFlowStep createWorkFlowStep (ObjectTransaction transaction) throws StorageException
    {
        WorkFlowStep     result = new WorkFlowStep ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static WorkFlowStep getWorkFlowStepByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (WorkFlowStep)(transaction.getObjectByID (REFERENCE_WorkFlowStep, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_SortOrder))
        {
            return filter.matches (getSortOrder ());
        }
        else if (attribName.equals (FIELD_StepType))
        {
            return filter.matches (getStepType ());
        }
        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<WorkFlowStep>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_work_flow_step.object_id", FIELD_ObjectID);
            return this;
        }

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

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

            
        public SearchAll andSortOrder (QueryFilter<Integer> filter)
        {
            filter.addFilter (context, "tl_work_flow_step.sort_order", "SortOrder");
            return this;
        }
            
        public SearchAll andStepType (QueryFilter<StepType> filter)
        {
            filter.addFilter (context, "tl_work_flow_step.step_type", "StepType");
            return this;
        }
            
        public SearchAll andWorkFlowStage (QueryFilter<WorkFlowStage> filter)
        {
            filter.addFilter (context, "tl_work_flow_step.work_flow_stage_id", "WorkFlowStage");
            return this;
        }
            
        public WorkFlowStep[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_WorkFlowStep, SEARCH_All, criteria);
            Set<WorkFlowStep>   typedResults = new LinkedHashSet <WorkFlowStep> ();
            for (BaseBusinessClass bbcResult : results)
            {
                WorkFlowStep aResult = (WorkFlowStep)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new WorkFlowStep[0]);
                            
        }
    }

        
    public static WorkFlowStep[] 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_SortOrder))
        {
            return HELPER_SortOrder.toObject (getSortOrder ());
        }
        else if (attribName.equals (FIELD_StepType))
        {
            return HELPER_StepType.toObject (getStepType ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_SortOrder))
        {
            return HELPER_SortOrder;
        }
        else if (attribName.equals (FIELD_StepType))
        {
            return HELPER_StepType;
        }
        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_SortOrder))
        {
            setSortOrder ((Integer)(HELPER_SortOrder.fromObject (_SortOrder, attribValue)));            
        }
        else if (attribName.equals (FIELD_StepType))
        {
            setStepType ((StepType)(HELPER_StepType.fromObject (_StepType, 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_SortOrder))
        {
            return getWriteability_SortOrder ();
        }
        else if (fieldName.equals (FIELD_StepType))
        {
            return getWriteability_StepType ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_WorkFlowStage))
        {
            return getWriteability_WorkFlowStage ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_SortOrder () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_SortOrder);
        }
        
        if (getWriteability_StepType () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_StepType);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_SortOrder.getAttribObject (getClass (), _SortOrder, true, FIELD_SortOrder));
        result.add(HELPER_StepType.getAttribObject (getClass (), _StepType, true, FIELD_StepType));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_WorkFlowStep);
    }
            

    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 WorkFlowStepBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<WorkFlowStep>
    {

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

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

    /**
     * Get the attribute StepType
     */
    public StepType getStepType (WorkFlowStep obj, StepType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute StepType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public StepType setStepType (WorkFlowStep obj, StepType newStepType) throws FieldException
    {
        return newStepType;
    }

    }

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

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

        public WorkFlowStepPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("SortOrder"))
            {
                return toSortOrder ();
            }                
            if (name.equals ("StepType"))
            {
                return toStepType ();
            }                
            if (name.equals ("WorkFlowStage"))
            {
                return toWorkFlowStage ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Integer> toSortOrder () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_SortOrder));  }
        
        public StepType.StepTypePipeLineFactory<From, StepType> toStepType () 
        { 
            return new StepType.StepTypePipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_StepType));
        }

        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 DummyWorkFlowStep extends WorkFlowStep
{
    // Default constructor primarily to support Externalisable
    public DummyWorkFlowStep()
    {
        super();
    }

    public void assertValid ()
    {
    }


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

}

    
