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

    // Reference instance for the object
    public static final CultureNarrative DUMMY_CultureNarrative = new DummyCultureNarrative ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Notes = "Notes";
    public static final String FIELD_ColorCode = "ColorCode";
    public static final String SINGLEREFERENCE_CultureElement = "CultureElement";
    public static final String BACKREF_CultureElement = "";
    public static final String SINGLEREFERENCE_CultureElementQuestion = "CultureElementQuestion";
    public static final String BACKREF_CultureElementQuestion = "";
    public static final String SINGLEREFERENCE_CultureElementRating = "CultureElementRating";
    public static final String BACKREF_CultureElementRating = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<CultureNarrative> HELPER_Notes = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<CultureNarrative, ColorCode> HELPER_ColorCode =  new EnumeratedAttributeHelper<CultureNarrative, ColorCode> (ColorCode.FACTORY_ColorCode);
    

    // Private attributes corresponding to business object data
    private String _Notes;
    private ColorCode _ColorCode;
    

    // Private attributes corresponding to single references
    private SingleAssociation<CultureNarrative, CultureElement> _CultureElement;
    private SingleAssociation<CultureNarrative, CultureElementQuestion> _CultureElementQuestion;
    private SingleAssociation<CultureNarrative, CultureElementRating> _CultureElementRating;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Notes_Validators;
    private static final AttributeValidator[] FIELD_ColorCode_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<CultureNarrative, String>[] FIELD_Notes_Decorators;
    private static final AttributeDecorator<CultureNarrative, ColorCode>[] FIELD_ColorCode_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<CultureNarrative, CultureElement>[] SINGLEREFERENCE_CultureElement_Decorators;
    private static final SingleAssocDecorator<CultureNarrative, CultureElementQuestion>[] SINGLEREFERENCE_CultureElementQuestion_Decorators;
    private static final SingleAssocDecorator<CultureNarrative, CultureElementRating>[] SINGLEREFERENCE_CultureElementRating_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final CultureNarrativeBehaviourDecorator[] CultureNarrative_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_CultureElement = CultureElement.BACKREF_Narratives;
            String tmp_CultureElementQuestion = CultureElementQuestion.BACKREF_Narratives;
            String tmp_CultureElementRating = CultureElementRating.BACKREF_Narratives;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_CultureElement();
            setupAssocMetaData_CultureElementQuestion();
            setupAssocMetaData_CultureElementRating();
            FIELD_Notes_Validators = (AttributeValidator[])setupAttribMetaData_Notes(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ColorCode_Validators = (AttributeValidator[])setupAttribMetaData_ColorCode(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Notes_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_CultureNarrative, FIELD_Notes).toArray (new AttributeDecorator[0]);
            FIELD_ColorCode_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_CultureNarrative, FIELD_ColorCode).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_CultureElement_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureNarrative, SINGLEREFERENCE_CultureElement).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_CultureElementQuestion_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureNarrative, SINGLEREFERENCE_CultureElementQuestion).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_CultureElementRating_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureNarrative, SINGLEREFERENCE_CultureElementRating).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_CultureNarrative.initialiseReference ();
            DUMMY_CultureNarrative.initialiseReference ();
            CultureNarrative_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CultureNarrative.class).toArray(new CultureNarrativeBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Narratives");
        metaInfo.put ("dbcol", "culture_element_number");
        metaInfo.put ("name", "CultureElement");
        metaInfo.put ("type", "CultureElement");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_narrative");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureNarrative.CultureElement:", metaInfo);
        ATTRIBUTES_METADATA_CultureNarrative.put (SINGLEREFERENCE_CultureElement, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_CultureElementQuestion()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Narratives");
        metaInfo.put ("dbcol", "culture_element_quest_id");
        metaInfo.put ("name", "CultureElementQuestion");
        metaInfo.put ("type", "CultureElementQuestion");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_narrative");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureNarrative.CultureElementQuestion:", metaInfo);
        ATTRIBUTES_METADATA_CultureNarrative.put (SINGLEREFERENCE_CultureElementQuestion, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_CultureElementRating()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Narratives");
        metaInfo.put ("dbcol", "culture_element_rating_id");
        metaInfo.put ("name", "CultureElementRating");
        metaInfo.put ("type", "CultureElementRating");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_narrative");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureNarrative.CultureElementRating:", metaInfo);
        ATTRIBUTES_METADATA_CultureNarrative.put (SINGLEREFERENCE_CultureElementRating, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Notes(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "narrative_notes");
        metaInfo.put ("name", "Notes");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_narrative");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureNarrative.Notes:", metaInfo);
        ATTRIBUTES_METADATA_CultureNarrative.put (FIELD_Notes, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "color_code");
        metaInfo.put ("name", "ColorCode");
        metaInfo.put ("type", "ColorCode");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_narrative");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureNarrative.ColorCode:", metaInfo);
        ATTRIBUTES_METADATA_CultureNarrative.put (FIELD_ColorCode, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _Notes = (String)(HELPER_Notes.initialise (_Notes));
        _ColorCode = (ColorCode)(HELPER_ColorCode.initialise (_ColorCode));
    }


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

        _CultureElement = new SingleAssociation<CultureNarrative, CultureElement> (this, SINGLEREFERENCE_CultureElement, CultureElement.MULTIPLEREFERENCE_Narratives, CultureElement.REFERENCE_CultureElement, "tl_culture_narrative");
        _CultureElementQuestion = new SingleAssociation<CultureNarrative, CultureElementQuestion> (this, SINGLEREFERENCE_CultureElementQuestion, CultureElementQuestion.MULTIPLEREFERENCE_Narratives, CultureElementQuestion.REFERENCE_CultureElementQuestion, "tl_culture_narrative");
        _CultureElementRating = new SingleAssociation<CultureNarrative, CultureElementRating> (this, SINGLEREFERENCE_CultureElementRating, CultureElementRating.MULTIPLEREFERENCE_Narratives, CultureElementRating.REFERENCE_CultureElementRating, "tl_culture_narrative");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _CultureElement = new SingleAssociation<CultureNarrative, CultureElement> (this, SINGLEREFERENCE_CultureElement, CultureElement.MULTIPLEREFERENCE_Narratives, CultureElement.REFERENCE_CultureElement, "tl_culture_narrative");
        _CultureElementQuestion = new SingleAssociation<CultureNarrative, CultureElementQuestion> (this, SINGLEREFERENCE_CultureElementQuestion, CultureElementQuestion.MULTIPLEREFERENCE_Narratives, CultureElementQuestion.REFERENCE_CultureElementQuestion, "tl_culture_narrative");
        _CultureElementRating = new SingleAssociation<CultureNarrative, CultureElementRating> (this, SINGLEREFERENCE_CultureElementRating, CultureElementRating.MULTIPLEREFERENCE_Narratives, CultureElementRating.REFERENCE_CultureElementRating, "tl_culture_narrative");
        
        
        return this;
    }


    /**
     * Attribute Notes
     */
    public String getNotes ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Notes_Decorators, (CultureNarrative)this, FIELD_Notes, _Notes);

        
        for (CultureNarrativeBehaviourDecorator bhd : CultureNarrative_BehaviourDecorators)
        {
            valToReturn = bhd.getNotes ((CultureNarrative)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 preNotesChange (String newNotes) 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 postNotesChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Notes.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setNotes (String newNotes) throws FieldException
    {
        newNotes = AttributeDecoratorUtils.setValue (FIELD_Notes_Decorators, (CultureNarrative)this, FIELD_Notes, newNotes);

        boolean oldAndNewIdentical = HELPER_Notes.compare (_Notes, newNotes);
        
        try
        {
            for (CultureNarrativeBehaviourDecorator bhd : CultureNarrative_BehaviourDecorators)
            {
                newNotes = bhd.setNotes ((CultureNarrative)this, newNotes);
                oldAndNewIdentical = HELPER_Notes.compare (_Notes, newNotes);
            }

            

            if (FIELD_Notes_Validators.length > 0)
            {
                Object newNotesObj = HELPER_Notes.toObject (newNotes);

                if (newNotesObj != null)
                {
                    int     loopMax = FIELD_Notes_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CultureNarrative.get (FIELD_Notes);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Notes_Decorators, (CultureNarrative)this, FIELD_Notes ,getWriteability_Notes ()) != FieldWriteability.FALSE, "Field  Notes is not writeable");
            preNotesChange (newNotes);
            markFieldChange (FIELD_Notes);
            _Notes = newNotes;            
            postFieldChange (FIELD_Notes);
            postNotesChange ();
        }
    }

    /**
     * Attribute ColorCode
     */
    public ColorCode getColorCode ()
    {
        assertValid();
        ColorCode valToReturn = AttributeDecoratorUtils.getValue (FIELD_ColorCode_Decorators, (CultureNarrative)this, FIELD_ColorCode, _ColorCode);

        
        for (CultureNarrativeBehaviourDecorator bhd : CultureNarrative_BehaviourDecorators)
        {
            valToReturn = bhd.getColorCode ((CultureNarrative)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 preColorCodeChange (ColorCode newColorCode) 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 postColorCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ColorCode.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setColorCode (ColorCode newColorCode) throws FieldException
    {
        newColorCode = AttributeDecoratorUtils.setValue (FIELD_ColorCode_Decorators, (CultureNarrative)this, FIELD_ColorCode, newColorCode);

        boolean oldAndNewIdentical = HELPER_ColorCode.compare (_ColorCode, newColorCode);
        
        try
        {
            for (CultureNarrativeBehaviourDecorator bhd : CultureNarrative_BehaviourDecorators)
            {
                newColorCode = bhd.setColorCode ((CultureNarrative)this, newColorCode);
                oldAndNewIdentical = HELPER_ColorCode.compare (_ColorCode, newColorCode);
            }

            

            if (FIELD_ColorCode_Validators.length > 0)
            {
                Object newColorCodeObj = HELPER_ColorCode.toObject (newColorCode);

                if (newColorCodeObj != null)
                {
                    int     loopMax = FIELD_ColorCode_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CultureNarrative.get (FIELD_ColorCode);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_ColorCode_Decorators, (CultureNarrative)this, FIELD_ColorCode ,getWriteability_ColorCode ()) != FieldWriteability.FALSE, "Field  ColorCode is not writeable");
            preColorCodeChange (newColorCode);
            markFieldChange (FIELD_ColorCode);
            _ColorCode = newColorCode;            
            postFieldChange (FIELD_ColorCode);
            postColorCodeChange ();
        }
    }



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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElement))
        {
            return _CultureElement.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return _CultureElementQuestion.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return _CultureElementRating.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_CultureElement))
        {
            return CultureElement.MULTIPLEREFERENCE_Narratives ;
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return CultureElementQuestion.MULTIPLEREFERENCE_Narratives ;
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return CultureElementRating.MULTIPLEREFERENCE_Narratives ;
        }
        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_CultureElement))
        {
            return getCultureElement ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return getCultureElementQuestion ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return getCultureElementRating ();
        }
        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_CultureElement))
        {
            return getCultureElement (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return getCultureElementQuestion (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return getCultureElementRating (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_CultureElement))
        {
            return getCultureElementID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return getCultureElementQuestionID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return getCultureElementRatingID ();
        }
        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_CultureElement))
        {
            setCultureElement ((CultureElement)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            setCultureElementQuestion ((CultureElementQuestion)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            setCultureElementRating ((CultureElementRating)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCultureElementID ()
    {
        assertValid();
        
        if (_CultureElement == null)
        {
            return null;
        }
        else
        {
            return _CultureElement.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 preCultureElementChange (CultureElement newCultureElement) 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 postCultureElementChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference CultureElement.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setCultureElement (CultureElement newCultureElement) throws StorageException, FieldException
    {
        if (_CultureElement.wouldReferencedChange (newCultureElement))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_CultureElement_Decorators, (CultureNarrative)this, SINGLEREFERENCE_CultureElement ,getWriteability_CultureElement ()) != FieldWriteability.FALSE, "Assoc CultureElement is not writeable");
            preCultureElementChange (newCultureElement);
            CultureElement oldCultureElement = getCultureElement ();

            if (oldCultureElement != null)
            {
                // This is to stop validation from triggering when we are removed
                _CultureElement.set (null);
                oldCultureElement.removeFromNarratives ((CultureNarrative)(this));
            }

            _CultureElement.set (newCultureElement);

            if (newCultureElement != null)
            {
                newCultureElement.addToNarratives ((CultureNarrative)(this));
            }
                
            postCultureElementChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCultureElementQuestionID ()
    {
        assertValid();
        
        if (_CultureElementQuestion == null)
        {
            return null;
        }
        else
        {
            return _CultureElementQuestion.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 preCultureElementQuestionChange (CultureElementQuestion newCultureElementQuestion) 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 postCultureElementQuestionChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference CultureElementQuestion.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setCultureElementQuestion (CultureElementQuestion newCultureElementQuestion) throws StorageException, FieldException
    {
        if (_CultureElementQuestion.wouldReferencedChange (newCultureElementQuestion))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_CultureElementQuestion_Decorators, (CultureNarrative)this, SINGLEREFERENCE_CultureElementQuestion ,getWriteability_CultureElementQuestion ()) != FieldWriteability.FALSE, "Assoc CultureElementQuestion is not writeable");
            preCultureElementQuestionChange (newCultureElementQuestion);
            CultureElementQuestion oldCultureElementQuestion = getCultureElementQuestion ();

            if (oldCultureElementQuestion != null)
            {
                // This is to stop validation from triggering when we are removed
                _CultureElementQuestion.set (null);
                oldCultureElementQuestion.removeFromNarratives ((CultureNarrative)(this));
            }

            _CultureElementQuestion.set (newCultureElementQuestion);

            if (newCultureElementQuestion != null)
            {
                newCultureElementQuestion.addToNarratives ((CultureNarrative)(this));
            }
                
            postCultureElementQuestionChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCultureElementRatingID ()
    {
        assertValid();
        
        if (_CultureElementRating == null)
        {
            return null;
        }
        else
        {
            return _CultureElementRating.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 preCultureElementRatingChange (CultureElementRating newCultureElementRating) 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 postCultureElementRatingChange () throws FieldException
    {
    }


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

        
    /**
     * Set the reference CultureElementRating.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setCultureElementRating (CultureElementRating newCultureElementRating) throws StorageException, FieldException
    {
        if (_CultureElementRating.wouldReferencedChange (newCultureElementRating))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_CultureElementRating_Decorators, (CultureNarrative)this, SINGLEREFERENCE_CultureElementRating ,getWriteability_CultureElementRating ()) != FieldWriteability.FALSE, "Assoc CultureElementRating is not writeable");
            preCultureElementRatingChange (newCultureElementRating);
            CultureElementRating oldCultureElementRating = getCultureElementRating ();

            if (oldCultureElementRating != null)
            {
                // This is to stop validation from triggering when we are removed
                _CultureElementRating.set (null);
                oldCultureElementRating.removeFromNarratives ((CultureNarrative)(this));
            }

            _CultureElementRating.set (newCultureElementRating);

            if (newCultureElementRating != null)
            {
                newCultureElementRating.addToNarratives ((CultureNarrative)(this));
            }
                
            postCultureElementRatingChange ();
        }
    }

    /**
     * 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 (_CultureElement.isLoaded () || getTransaction ().isObjectLoaded (_CultureElement.getReferencedType (), getCultureElementID ()))
            {
                CultureElement  referenced = getCultureElement ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Narratives from ", getObjectID (), " to ", referenced.getObjectID ());
                    _CultureElement.set (null);
                    referenced.removeFromNarratives ((CultureNarrative)this);
                }
            }
        
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_CultureElementQuestion.isLoaded () || getTransaction ().isObjectLoaded (_CultureElementQuestion.getReferencedType (), getCultureElementQuestionID ()))
            {
                CultureElementQuestion  referenced = getCultureElementQuestion ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Narratives from ", getObjectID (), " to ", referenced.getObjectID ());
                    _CultureElementQuestion.set (null);
                    referenced.removeFromNarratives ((CultureNarrative)this);
                }
            }
        
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_CultureElementRating.isLoaded () || getTransaction ().isObjectLoaded (_CultureElementRating.getReferencedType (), getCultureElementRatingID ()))
            {
                CultureElementRating  referenced = getCultureElementRating ();

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

        super.onDelete ();
    }


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


    public CultureNarrative referenceInstance ()
    {
        return REFERENCE_CultureNarrative;
    }


    public CultureNarrative getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCultureNarrativeByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CultureNarrative;
    }


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



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

        tl_culture_narrativePSet.setAttrib (FIELD_ObjectID, myID);
        tl_culture_narrativePSet.setAttrib (FIELD_Notes, HELPER_Notes.toObject (_Notes)); //
        tl_culture_narrativePSet.setAttrib (FIELD_ColorCode, HELPER_ColorCode.toObject (_ColorCode)); //
        _CultureElement.getPersistentSets (allSets);
        _CultureElementQuestion.getPersistentSets (allSets);
        _CultureElementRating.getPersistentSets (allSets);
        
    }


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

        _Notes = (String)(HELPER_Notes.fromObject (_Notes, tl_culture_narrativePSet.getAttrib (FIELD_Notes))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, tl_culture_narrativePSet.getAttrib (FIELD_ColorCode))); //
        _CultureElement.setFromPersistentSets (objectID, allSets);
        _CultureElementQuestion.setFromPersistentSets (objectID, allSets);
        _CultureElementRating.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof CultureNarrative)
        {
            CultureNarrative otherCultureNarrative = (CultureNarrative)other;
            

            try
            {
                setNotes (otherCultureNarrative.getNotes ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setColorCode (otherCultureNarrative.getColorCode ());
            }
            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 BaseCultureNarrative)
        {
            BaseCultureNarrative sourceCultureNarrative = (BaseCultureNarrative)(source);

            _Notes = sourceCultureNarrative._Notes;
            _ColorCode = sourceCultureNarrative._ColorCode;
            
        }
    }


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

            _CultureElement.copyFrom (sourceCultureNarrative._CultureElement, linkToGhosts);
            _CultureElementQuestion.copyFrom (sourceCultureNarrative._CultureElementQuestion, linkToGhosts);
            _CultureElementRating.copyFrom (sourceCultureNarrative._CultureElementRating, 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 BaseCultureNarrative)
        {
            BaseCultureNarrative sourceCultureNarrative = (BaseCultureNarrative)(source);

            
        }
    }


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

        
    }


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

        _Notes = (String)(HELPER_Notes.readExternal (_Notes, vals.get(FIELD_Notes))); //
        _ColorCode = (ColorCode)(HELPER_ColorCode.readExternal (_ColorCode, vals.get(FIELD_ColorCode))); //
        _CultureElement.readExternalData(vals.get(SINGLEREFERENCE_CultureElement));
        _CultureElementQuestion.readExternalData(vals.get(SINGLEREFERENCE_CultureElementQuestion));
        _CultureElementRating.readExternalData(vals.get(SINGLEREFERENCE_CultureElementRating));
        
    }


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

        vals.put (FIELD_Notes, HELPER_Notes.writeExternal (_Notes));
        vals.put (FIELD_ColorCode, HELPER_ColorCode.writeExternal (_ColorCode));
        vals.put (SINGLEREFERENCE_CultureElement, _CultureElement.writeExternalData());
        vals.put (SINGLEREFERENCE_CultureElementQuestion, _CultureElementQuestion.writeExternalData());
        vals.put (SINGLEREFERENCE_CultureElementRating, _CultureElementRating.writeExternalData());
        
    }


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

        if (other instanceof BaseCultureNarrative)
        {
            BaseCultureNarrative otherCultureNarrative = (BaseCultureNarrative)(other);

            
            if (!HELPER_Notes.compare(this._Notes, otherCultureNarrative._Notes))
            {
                listener.notifyFieldChange(this, other, FIELD_Notes, HELPER_Notes.toObject(this._Notes), HELPER_Notes.toObject(otherCultureNarrative._Notes));
            }
            if (!HELPER_ColorCode.compare(this._ColorCode, otherCultureNarrative._ColorCode))
            {
                listener.notifyFieldChange(this, other, FIELD_ColorCode, HELPER_ColorCode.toObject(this._ColorCode), HELPER_ColorCode.toObject(otherCultureNarrative._ColorCode));
            }

            // Compare single assocs
            _CultureElement.compare (otherCultureNarrative._CultureElement, listener);
            _CultureElementQuestion.compare (otherCultureNarrative._CultureElementQuestion, listener);
            _CultureElementRating.compare (otherCultureNarrative._CultureElementRating, 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_Notes, HELPER_Notes.toObject(getNotes()));
        visitor.visitField(this, FIELD_ColorCode, HELPER_ColorCode.toObject(getColorCode()));
        visitor.visitAssociation (_CultureElement);
        visitor.visitAssociation (_CultureElementQuestion);
        visitor.visitAssociation (_CultureElementRating);
        
    }


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

        if (scope.includes (_CultureElement))
        {
            visitor.visit (_CultureElement);
        }
        if (scope.includes (_CultureElementQuestion))
        {
            visitor.visit (_CultureElementQuestion);
        }
        if (scope.includes (_CultureElementRating))
        {
            visitor.visit (_CultureElementRating);
        }
        
    }


    public static CultureNarrative createCultureNarrative (ObjectTransaction transaction) throws StorageException
    {
        CultureNarrative     result = new CultureNarrative ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CultureNarrative getCultureNarrativeByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CultureNarrative)(transaction.getObjectByID (REFERENCE_CultureNarrative, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Notes))
        {
            return filter.matches (getNotes ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return filter.matches (getColorCode ());
        }
        else if (attribName.equals (SINGLEREFERENCE_CultureElement))
        {
            return filter.matches (getCultureElement ());
        }
        else if (attribName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return filter.matches (getCultureElementQuestion ());
        }
        else if (attribName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return filter.matches (getCultureElementRating ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
        public SearchAll andNotes (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_culture_narrative.narrative_notes", "Notes");
            return this;
        }
            
        public SearchAll andColorCode (QueryFilter<ColorCode> filter)
        {
            filter.addFilter (context, "tl_culture_narrative.color_code", "ColorCode");
            return this;
        }
            
        public SearchAll andCultureElement (QueryFilter<CultureElement> filter)
        {
            filter.addFilter (context, "tl_culture_narrative.culture_element_number", "CultureElement");
            return this;
        }
            
        public SearchAll andCultureElementQuestion (QueryFilter<CultureElementQuestion> filter)
        {
            filter.addFilter (context, "tl_culture_narrative.culture_element_quest_id", "CultureElementQuestion");
            return this;
        }
            
        public SearchAll andCultureElementRating (QueryFilter<CultureElementRating> filter)
        {
            filter.addFilter (context, "tl_culture_narrative.culture_element_rating_id", "CultureElementRating");
            return this;
        }
            
        public CultureNarrative[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_CultureNarrative, SEARCH_All, criteria);
            Set<CultureNarrative>   typedResults = new LinkedHashSet <CultureNarrative> ();
            for (BaseBusinessClass bbcResult : results)
            {
                CultureNarrative aResult = (CultureNarrative)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new CultureNarrative[0]);
                            
        }
    }

        
    public static CultureNarrative[] 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_Notes))
        {
            return HELPER_Notes.toObject (getNotes ());
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode.toObject (getColorCode ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Notes))
        {
            return HELPER_Notes;
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            return HELPER_ColorCode;
        }
        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_Notes))
        {
            setNotes ((String)(HELPER_Notes.fromObject (_Notes, attribValue)));            
        }
        else if (attribName.equals (FIELD_ColorCode))
        {
            setColorCode ((ColorCode)(HELPER_ColorCode.fromObject (_ColorCode, 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_Notes))
        {
            return getWriteability_Notes ();
        }
        else if (fieldName.equals (FIELD_ColorCode))
        {
            return getWriteability_ColorCode ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_CultureElement))
        {
            return getWriteability_CultureElement ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_CultureElementQuestion))
        {
            return getWriteability_CultureElementQuestion ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_CultureElementRating))
        {
            return getWriteability_CultureElementRating ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Notes () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Notes);
        }
        
        if (getWriteability_ColorCode () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ColorCode);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_Notes.getAttribObject (getClass (), _Notes, false, FIELD_Notes));
        result.add(HELPER_ColorCode.getAttribObject (getClass (), _ColorCode, false, FIELD_ColorCode));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_CultureNarrative);
    }
            

    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 CultureNarrativeBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<CultureNarrative>
    {

    /**
     * Get the attribute Notes
     */
    public String getNotes (CultureNarrative obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Notes.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setNotes (CultureNarrative obj, String newNotes) throws FieldException
    {
        return newNotes;
    }

    /**
     * Get the attribute ColorCode
     */
    public ColorCode getColorCode (CultureNarrative obj, ColorCode original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ColorCode.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public ColorCode setColorCode (CultureNarrative obj, ColorCode newColorCode) throws FieldException
    {
        return newColorCode;
    }

    }

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

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

        public CultureNarrativePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Notes"))
            {
                return toNotes ();
            }                
            if (name.equals ("ColorCode"))
            {
                return toColorCode ();
            }                
            if (name.equals ("CultureElement"))
            {
                return toCultureElement ();
            }                
            if (name.equals ("CultureElementQuestion"))
            {
                return toCultureElementQuestion ();
            }                
            if (name.equals ("CultureElementRating"))
            {
                return toCultureElementRating ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toNotes () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Notes));  }
        
        public ColorCode.ColorCodePipeLineFactory<From, ColorCode> toColorCode () 
        { 
            return new ColorCode.ColorCodePipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_ColorCode));
        }

        public CultureElement.CultureElementPipeLineFactory<From, CultureElement> toCultureElement () { return toCultureElement (Filter.ALL); }

        public CultureElement.CultureElementPipeLineFactory<From, CultureElement> toCultureElement (Filter<CultureElement> filter) 
        { 
            return CultureElement.REFERENCE_CultureElement.new CultureElementPipeLineFactory<From, CultureElement> (this, new ORMSingleAssocPipe<Me, CultureElement>(SINGLEREFERENCE_CultureElement, filter)); 
        }

        public CultureElementQuestion.CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> toCultureElementQuestion () { return toCultureElementQuestion (Filter.ALL); }

        public CultureElementQuestion.CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> toCultureElementQuestion (Filter<CultureElementQuestion> filter) 
        { 
            return CultureElementQuestion.REFERENCE_CultureElementQuestion.new CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> (this, new ORMSingleAssocPipe<Me, CultureElementQuestion>(SINGLEREFERENCE_CultureElementQuestion, filter)); 
        }

        public CultureElementRating.CultureElementRatingPipeLineFactory<From, CultureElementRating> toCultureElementRating () { return toCultureElementRating (Filter.ALL); }

        public CultureElementRating.CultureElementRatingPipeLineFactory<From, CultureElementRating> toCultureElementRating (Filter<CultureElementRating> filter) 
        { 
            return CultureElementRating.REFERENCE_CultureElementRating.new CultureElementRatingPipeLineFactory<From, CultureElementRating> (this, new ORMSingleAssocPipe<Me, CultureElementRating>(SINGLEREFERENCE_CultureElementRating, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public CultureElement getCultureElement () throws StorageException
    {
        return (CultureElement)(CultureElement.DUMMY_CultureElement);
    }


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

    public CultureElementQuestion getCultureElementQuestion () throws StorageException
    {
        return (CultureElementQuestion)(CultureElementQuestion.DUMMY_CultureElementQuestion);
    }


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

    public CultureElementRating getCultureElementRating () throws StorageException
    {
        return (CultureElementRating)(CultureElementRating.DUMMY_CultureElementRating);
    }


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

}

    
