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


    package performa.orm;

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

import oneit.security.*;



public abstract class BaseCultureCriteriaTemplate extends BaseBusinessClass
{
    // Reference instance for the object
    public static final CultureCriteriaTemplate REFERENCE_CultureCriteriaTemplate = new CultureCriteriaTemplate ();

    // Reference instance for the object
    public static final CultureCriteriaTemplate DUMMY_CultureCriteriaTemplate = new DummyCultureCriteriaTemplate ();

    // Static constants corresponding to field names
    
    public static final String FIELD_TemplateName = "TemplateName";
    public static final String SINGLEREFERENCE_User = "User";
    public static final String MULTIPLEREFERENCE_CultureCriterias = "CultureCriterias";
    public static final String BACKREF_CultureCriterias = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<CultureCriteriaTemplate> HELPER_TemplateName = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _TemplateName;
    

    // Private attributes corresponding to single references
    private SingleAssociation<CultureCriteriaTemplate, SecUser> _User;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<CultureCriteriaTemplate, CultureCriteria> _CultureCriterias;
    

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

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

    // Arrays of behaviour decorators
    private static final CultureCriteriaTemplateBehaviourDecorator[] CultureCriteriaTemplate_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_CultureCriterias = CultureCriteria.BACKREF_Template;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_CultureCriterias();
            setupAssocMetaData_User();
            FIELD_TemplateName_Validators = (AttributeValidator[])setupAttribMetaData_TemplateName(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_CultureCriteriaTemplate.initialiseReference ();
            DUMMY_CultureCriteriaTemplate.initialiseReference ();
            CultureCriteriaTemplate_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CultureCriteriaTemplate.class).toArray(new CultureCriteriaTemplateBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Template");
        metaInfo.put ("name", "CultureCriterias");
        metaInfo.put ("type", "CultureCriteria");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaTemplate.CultureCriterias:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaTemplate.put (MULTIPLEREFERENCE_CultureCriterias, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_User()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "user_id");
        metaInfo.put ("name", "User");
        metaInfo.put ("type", "SecUser");
        metaInfo.put ("uniqueGroup", "TemplateName");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaTemplate.User:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaTemplate.put (SINGLEREFERENCE_User, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_TemplateName(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "template_name");
        metaInfo.put ("length", "100");
        metaInfo.put ("name", "TemplateName");
        metaInfo.put ("type", "String");
        metaInfo.put ("uniqueGroup", "TemplateName");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaTemplate.TemplateName:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaTemplate.put (FIELD_TemplateName, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _TemplateName = (String)(HELPER_TemplateName.initialise (_TemplateName));
    }


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

        _User = new SingleAssociation<CultureCriteriaTemplate, SecUser> (this, SINGLEREFERENCE_User, null, SecUser.REFERENCE_SecUser, "tl_culture_template");
        _CultureCriterias = new MultipleAssociation<CultureCriteriaTemplate, CultureCriteria> (this, MULTIPLEREFERENCE_CultureCriterias, CultureCriteria.SINGLEREFERENCE_Template, CultureCriteria.REFERENCE_CultureCriteria);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _User = new SingleAssociation<CultureCriteriaTemplate, SecUser> (this, SINGLEREFERENCE_User, null, SecUser.REFERENCE_SecUser, "tl_culture_template");
        _CultureCriterias = new MultipleAssociation<CultureCriteriaTemplate, CultureCriteria> (this, MULTIPLEREFERENCE_CultureCriterias, CultureCriteria.SINGLEREFERENCE_Template, CultureCriteria.REFERENCE_CultureCriteria);
        
        
        return this;
    }

    

    /**
     * Get the attribute TemplateName
     */
    public String getTemplateName ()
    {
        assertValid();
        String valToReturn = _TemplateName;

            for (CultureCriteriaTemplateBehaviourDecorator bhd : CultureCriteriaTemplate_BehaviourDecorators)
            {
                valToReturn = bhd.getTemplateName ((CultureCriteriaTemplate)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 preTemplateNameChange (String newTemplateName) 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 postTemplateNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute TemplateName.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setTemplateName (String newTemplateName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_TemplateName.compare (_TemplateName, newTemplateName);
        
        try
        {
            for (CultureCriteriaTemplateBehaviourDecorator bhd : CultureCriteriaTemplate_BehaviourDecorators)
            {
                newTemplateName = bhd.setTemplateName ((CultureCriteriaTemplate)this, newTemplateName);
                oldAndNewIdentical = HELPER_TemplateName.compare (_TemplateName, newTemplateName);
            }

            

            if (FIELD_TemplateName_Validators.length > 0)
            {
                Object newTemplateNameObj = HELPER_TemplateName.toObject (newTemplateName);

                if (newTemplateNameObj != null)
                {
                    int     loopMax = FIELD_TemplateName_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CultureCriteriaTemplate.get (FIELD_TemplateName);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_TemplateName () != FieldWriteability.FALSE, "Field  TemplateName is not writeable");
            preTemplateNameChange (newTemplateName);
            markFieldChange (FIELD_TemplateName);
            _TemplateName = newTemplateName;            
            postFieldChange (FIELD_TemplateName);
            postTemplateNameChange ();
        }
    }



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

        
        result.add("User");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_User))
        {
            return _User.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_User))
        {
            return null ;
        }
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_User))
        {
            return getUser ();
        }
        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_User))
        {
            return getUser (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_User))
        {
            return getUserID ();
        }
        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_User))
        {
            setUser ((SecUser)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference User
     */
    public SecUser getUser () throws StorageException
    {
        assertValid();
        
        try
        {
            return (SecUser)(_User.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in CultureCriteriaTemplate:", this.getObjectID (), ", was trying to get SecUser:",  getUserID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _User.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getUserID ()
    {
        assertValid();
        
        if (_User == null)
        {
            return null;
        }
        else
        {
            return _User.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 preUserChange (SecUser newUser) 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 postUserChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_User ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference User.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setUser (SecUser newUser) throws StorageException, FieldException
    {
        

        if (_User.wouldReferencedChange (newUser))
        {
            assertValid();
            Debug.assertion (getWriteability_User () != FieldWriteability.FALSE, "Assoc User is not writeable");
            preUserChange (newUser);
            
                    _User.set (newUser);
                
            postUserChange ();
        }
    }

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

        
        result.add("CultureCriterias");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            return CultureCriteria.REFERENCE_CultureCriteria ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            return CultureCriteria.SINGLEREFERENCE_Template ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            return this.getCultureCriteriasCount();
        }
        

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            return this.getCultureCriteriasAt(index);
        }
        

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            addToCultureCriterias((CultureCriteria)newElement);

            return;
        }
        

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            removeFromCultureCriterias((CultureCriteria)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            _CultureCriterias.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_CultureCriterias.equals(attribName))
        {
            return _CultureCriterias.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_CultureCriterias ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getCultureCriteriasCount () throws StorageException
    {
        assertValid();
        return _CultureCriterias.getReferencedObjectsCount ();
    }


    public void addToCultureCriterias (CultureCriteria newElement) throws StorageException
    {
        if (_CultureCriterias.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_CultureCriterias () != FieldWriteability.FALSE, "MultiAssoc CultureCriterias is not writeable (add)");
            _CultureCriterias.appendElement (newElement);

            try
            {
                if (newElement.getTemplate () != this)
                {
                    newElement.setTemplate ((CultureCriteriaTemplate)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromCultureCriterias (CultureCriteria elementToRemove) throws StorageException
    {
        if (_CultureCriterias.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_CultureCriterias () != FieldWriteability.FALSE, "MultiAssoc CultureCriterias is not writeable (remove)");
            _CultureCriterias.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getTemplate () != null)
                {
                    elementToRemove.setTemplate (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public CultureCriteria getCultureCriteriasAt (int index) throws StorageException
    {
        return (CultureCriteria)(_CultureCriterias.getElementAt (index));
    }


    public SortedSet<CultureCriteria> getCultureCriteriasSet () throws StorageException
    {
        return _CultureCriterias.getSet ();
    }



    public void onDelete ()
    {
        try 
        {
            for(CultureCriteria referenced : CollectionUtils.reverse(getCultureCriteriasSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Template from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setTemplate(null);
            }

        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public CultureCriteriaTemplate referenceInstance ()
    {
        return REFERENCE_CultureCriteriaTemplate;
    }


    public CultureCriteriaTemplate getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCultureCriteriaTemplateByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CultureCriteriaTemplate;
    }


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





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

        tl_culture_templatePSet.setAttrib (FIELD_ObjectID, myID);
        tl_culture_templatePSet.setAttrib (FIELD_TemplateName, HELPER_TemplateName.toObject (_TemplateName)); //
        _User.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_culture_templatePSet = allSets.getPersistentSet (objectID, "tl_culture_template");

        _TemplateName = (String)(HELPER_TemplateName.fromObject (_TemplateName, tl_culture_templatePSet.getAttrib (FIELD_TemplateName))); //
        _User.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof CultureCriteriaTemplate)
        {
            CultureCriteriaTemplate otherCultureCriteriaTemplate = (CultureCriteriaTemplate)other;
            
            try
            {
                setTemplateName (otherCultureCriteriaTemplate.getTemplateName ());
            }
            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 BaseCultureCriteriaTemplate)
        {
            BaseCultureCriteriaTemplate sourceCultureCriteriaTemplate = (BaseCultureCriteriaTemplate)(source);

            _TemplateName = sourceCultureCriteriaTemplate._TemplateName;
            
        }
    }


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

            _User.copyFrom (sourceCultureCriteriaTemplate._User, 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 BaseCultureCriteriaTemplate)
        {
            BaseCultureCriteriaTemplate sourceCultureCriteriaTemplate = (BaseCultureCriteriaTemplate)(source);

            _CultureCriterias.copyFrom (sourceCultureCriteriaTemplate._CultureCriterias, linkToGhosts);
            
        }
    }


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

        _TemplateName = (String)(HELPER_TemplateName.readExternal (_TemplateName, vals.get(FIELD_TemplateName))); //
        _User.readExternalData(vals.get(SINGLEREFERENCE_User));
        _CultureCriterias.readExternalData(vals.get(MULTIPLEREFERENCE_CultureCriterias));
        
    }


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

        vals.put (FIELD_TemplateName, HELPER_TemplateName.writeExternal (_TemplateName));
        vals.put (SINGLEREFERENCE_User, _User.writeExternalData());
        vals.put (MULTIPLEREFERENCE_CultureCriterias, _CultureCriterias.writeExternalData());
        
    }


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

        if (other instanceof BaseCultureCriteriaTemplate)
        {
            BaseCultureCriteriaTemplate otherCultureCriteriaTemplate = (BaseCultureCriteriaTemplate)(other);

            
            if (!HELPER_TemplateName.compare(this._TemplateName, otherCultureCriteriaTemplate._TemplateName))
            {
                listener.notifyFieldChange(this, other, FIELD_TemplateName, HELPER_TemplateName.toObject(this._TemplateName), HELPER_TemplateName.toObject(otherCultureCriteriaTemplate._TemplateName));
            }

            // Compare single assocs
            _User.compare (otherCultureCriteriaTemplate._User, listener);
            

            // Compare multiple assocs
            _CultureCriterias.compare (otherCultureCriteriaTemplate._CultureCriterias, listener);
            
        }
    }


    public void visitTransients (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        
    }


    public void visitAttributes (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        visitor.visitField(this, FIELD_TemplateName, HELPER_TemplateName.toObject(getTemplateName()));
        visitor.visitAssociation (_User);
        visitor.visitAssociation (_CultureCriterias);
        
    }


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

        if (scope.includes (_User))
        {
            visitor.visit (_User);
        }
        if (scope.includes (_CultureCriterias))
        {
            visitor.visit (_CultureCriterias);
        }
        
    }


    public static CultureCriteriaTemplate createCultureCriteriaTemplate (ObjectTransaction transaction) throws StorageException
    {
        CultureCriteriaTemplate     result = new CultureCriteriaTemplate ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CultureCriteriaTemplate getCultureCriteriaTemplateByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CultureCriteriaTemplate)(transaction.getObjectByID (REFERENCE_CultureCriteriaTemplate, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_TemplateName))
        {
            return filter.matches (getTemplateName ());
        }
        else if (attribName.equals (SINGLEREFERENCE_User))
        {
            return filter.matches (getUser ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andTemplateName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_culture_template.template_name", "TemplateName");
                return this;
            }
            
            public SearchAll andUser (QueryFilter<SecUser> filter)
            {
                filter.addFilter (context, "tl_culture_template.user_id", "User");
                return this;
            }
            
                public CultureCriteriaTemplate[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_CultureCriteriaTemplate, SEARCH_All, criteria);
            Set<CultureCriteriaTemplate>   typedResults = new LinkedHashSet <CultureCriteriaTemplate> ();
            for (BaseBusinessClass bbcResult : results)
            {
                CultureCriteriaTemplate aResult = (CultureCriteriaTemplate)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new CultureCriteriaTemplate[0]);
                            
        }
    }

        
                public static CultureCriteriaTemplate[]
             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_TemplateName))
        {
            return HELPER_TemplateName.toObject (getTemplateName ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_TemplateName))
        {
            return HELPER_TemplateName;
        }
        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_TemplateName))
        {
            setTemplateName ((String)(HELPER_TemplateName.fromObject (_TemplateName, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }



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


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_TemplateName))
        {
            return getWriteability_TemplateName ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_CultureCriterias))
        {
            return getWriteability_CultureCriterias ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_User))
        {
            return getWriteability_User ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_TemplateName () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_TemplateName);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_TemplateName.getAttribObject (getClass (), _TemplateName, false, FIELD_TemplateName));

        return result;
    }


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


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

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

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

    public static class CultureCriteriaTemplateBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<CultureCriteriaTemplate>
    {

    /**
     * Get the attribute TemplateName
     */
    public String getTemplateName (CultureCriteriaTemplate obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute TemplateName.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setTemplateName (CultureCriteriaTemplate obj, String newTemplateName) throws FieldException
    {
        return newTemplateName;
    }

    }

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

        public CultureCriteriaTemplatePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("CultureCriterias"))
            {
                return toCultureCriterias ();
            }                
            if (name.equals ("TemplateName"))
            {
                return toTemplateName ();
            }                
            if (name.equals ("User"))
            {
                return toUser ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toTemplateName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_TemplateName));  }
        public SecUser.SecUserPipeLineFactory<From, SecUser> toUser () { return toUser (Filter.ALL); }

        public SecUser.SecUserPipeLineFactory<From, SecUser> toUser (Filter<SecUser> filter) 
        { 
            return SecUser.REFERENCE_SecUser.new SecUserPipeLineFactory<From, SecUser> (this, new ORMSingleAssocPipe<Me, SecUser>(SINGLEREFERENCE_User, filter)); 
        }
        public CultureCriteria.CultureCriteriaPipeLineFactory<From, CultureCriteria> toCultureCriterias () { return toCultureCriterias(Filter.ALL); }        

        public CultureCriteria.CultureCriteriaPipeLineFactory<From, CultureCriteria> toCultureCriterias (Filter<CultureCriteria> filter)
        {
            return CultureCriteria.REFERENCE_CultureCriteria.new CultureCriteriaPipeLineFactory<From, CultureCriteria> (this, new ORMMultiAssocPipe<Me, CultureCriteria>(MULTIPLEREFERENCE_CultureCriterias, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public SecUser getUser () throws StorageException
    {
        return (SecUser)(SecUser.DUMMY_SecUser);
    }


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

    public int getCultureCriteriasCount () throws StorageException
    {
        return 0;
    }


    public CultureCriteria getCultureCriteriasAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association CultureCriterias");
    }


    public SortedSet getCultureCriteriasSet () throws StorageException
    {
        return new TreeSet();
    }

}

    
