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


    package performa.orm;

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

import performa.orm.types.*;

import oneit.business.shopping.orm.*;



public abstract class BaseClient extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Client REFERENCE_Client = new Client ();

    // Reference instance for the object
    public static final Client DUMMY_Client = new DummyClient ();

    // Static constants corresponding to field names
    
    public static final String FIELD_ClientName = "ClientName";
    public static final String FIELD_ClientLogo = "ClientLogo";
    public static final String FIELD_Email = "Email";
    public static final String FIELD_ContactName = "ContactName";
    public static final String FIELD_ContactSurname = "ContactSurname";
    public static final String FIELD_Phone = "Phone";
    public static final String FIELD_State = "State";
    public static final String FIELD_Country = "Country";
    public static final String FIELD_PostCode = "PostCode";
    public static final String SINGLEREFERENCE_Company = "Company";
    public static final String BACKREF_Company = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Client> HELPER_ClientName = DefaultAttributeHelper.INSTANCE;
    private static final BLOBAttributeHelper HELPER_ClientLogo = BLOBAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Client> HELPER_Email = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Client> HELPER_ContactName = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Client> HELPER_ContactSurname = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<Client> HELPER_Phone = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<Client, State> HELPER_State =  new EnumeratedAttributeHelper<Client, State> (State.FACTORY_State);
    private static final EnumeratedAttributeHelper<Client, Countries> HELPER_Country =  new EnumeratedAttributeHelper<Client, Countries> (Countries.FACTORY_Countries);
    private static final DefaultAttributeHelper<Client> HELPER_PostCode = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _ClientName;
    private BinaryContent _ClientLogo;
    private String _Email;
    private String _ContactName;
    private String _ContactSurname;
    private String _Phone;
    private State _State;
    private Countries _Country;
    private String _PostCode;
    

    // Private attributes corresponding to single references
    private SingleAssociation<Client, Company> _Company;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_ClientName_Validators;
    private static final AttributeValidator[] FIELD_ClientLogo_Validators;
    private static final AttributeValidator[] FIELD_Email_Validators;
    private static final AttributeValidator[] FIELD_ContactName_Validators;
    private static final AttributeValidator[] FIELD_ContactSurname_Validators;
    private static final AttributeValidator[] FIELD_Phone_Validators;
    private static final AttributeValidator[] FIELD_State_Validators;
    private static final AttributeValidator[] FIELD_Country_Validators;
    private static final AttributeValidator[] FIELD_PostCode_Validators;
    

    // Arrays of behaviour decorators
    private static final ClientBehaviourDecorator[] Client_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Company = Company.BACKREF_Clients;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Company();
            FIELD_ClientName_Validators = (AttributeValidator[])setupAttribMetaData_ClientName(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ClientLogo_Validators = (AttributeValidator[])setupAttribMetaData_ClientLogo(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Email_Validators = (AttributeValidator[])setupAttribMetaData_Email(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ContactName_Validators = (AttributeValidator[])setupAttribMetaData_ContactName(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ContactSurname_Validators = (AttributeValidator[])setupAttribMetaData_ContactSurname(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Phone_Validators = (AttributeValidator[])setupAttribMetaData_Phone(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_State_Validators = (AttributeValidator[])setupAttribMetaData_State(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Country_Validators = (AttributeValidator[])setupAttribMetaData_Country(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_PostCode_Validators = (AttributeValidator[])setupAttribMetaData_PostCode(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_Client.initialiseReference ();
            DUMMY_Client.initialiseReference ();
            Client_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Client.class).toArray(new ClientBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Clients");
        metaInfo.put ("dbcol", "company_id");
        metaInfo.put ("name", "Company");
        metaInfo.put ("type", "Company");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.Company:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (SINGLEREFERENCE_Company, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_ClientName(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "client_name");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "ClientName");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.ClientName:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_ClientName, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "BLOBAttributeHelper");
        metaInfo.put ("attribHelperInstance", "BLOBAttributeHelper.INSTANCE");
        metaInfo.put ("binaryHandler", "loggedin");
        metaInfo.put ("dbcol", "client_logo");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "ClientLogo");
        metaInfo.put ("type", "BinaryContent");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.ClientLogo:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_ClientLogo, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "email");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Email");
        metaInfo.put ("type", "String");
        metaInfo.put ("validators", "Email");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.Email:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_Email, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "contact_name");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "ContactName");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.ContactName:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_ContactName, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "contact_surname");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "ContactSurname");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.ContactSurname:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_ContactSurname, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "phone");
        metaInfo.put ("length", "30");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Phone");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.Phone:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_Phone, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "state");
        metaInfo.put ("defaultValue", "State.WA");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "State");
        metaInfo.put ("type", "State");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.State:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_State, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "country");
        metaInfo.put ("defaultValue", "Countries.AU");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Country");
        metaInfo.put ("type", "Countries");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.Country:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_Country, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "post_code");
        metaInfo.put ("length", "10");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "PostCode");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Client.PostCode:", metaInfo);
        ATTRIBUTES_METADATA_Client.put (FIELD_PostCode, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _ClientName = (String)(HELPER_ClientName.initialise (_ClientName));
        _ClientLogo = (BinaryContent)(HELPER_ClientLogo.initialise (_ClientLogo));
        _Email = (String)(HELPER_Email.initialise (_Email));
        _ContactName = (String)(HELPER_ContactName.initialise (_ContactName));
        _ContactSurname = (String)(HELPER_ContactSurname.initialise (_ContactSurname));
        _Phone = (String)(HELPER_Phone.initialise (_Phone));
        _State = (State)(State.WA);
        _Country = (Countries)(Countries.AU);
        _PostCode = (String)(HELPER_PostCode.initialise (_PostCode));
    }


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

        _Company = new SingleAssociation<Client, Company> (this, SINGLEREFERENCE_Company, Company.MULTIPLEREFERENCE_Clients, Company.REFERENCE_Company, "tl_client");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Company = new SingleAssociation<Client, Company> (this, SINGLEREFERENCE_Company, Company.MULTIPLEREFERENCE_Clients, Company.REFERENCE_Company, "tl_client");
        
        
        return this;
    }

    

    /**
     * Get the attribute ClientName
     */
    public String getClientName ()
    {
        assertValid();
        String valToReturn = _ClientName;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getClientName ((Client)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 preClientNameChange (String newClientName) 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 postClientNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ClientName.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setClientName (String newClientName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ClientName.compare (_ClientName, newClientName);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newClientName = bhd.setClientName ((Client)this, newClientName);
                oldAndNewIdentical = HELPER_ClientName.compare (_ClientName, newClientName);
            }

            BusinessObjectParser.assertFieldCondition (newClientName != null, this, FIELD_ClientName, "mandatory");
            

            if (FIELD_ClientName_Validators.length > 0)
            {
                Object newClientNameObj = HELPER_ClientName.toObject (newClientName);

                if (newClientNameObj != null)
                {
                    int     loopMax = FIELD_ClientName_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_ClientName);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ClientName () != FieldWriteability.FALSE, "Field  ClientName is not writeable");
            preClientNameChange (newClientName);
            markFieldChange (FIELD_ClientName);
            _ClientName = newClientName;            
            postFieldChange (FIELD_ClientName);
            postClientNameChange ();
        }
    }

    /**
     * Get the attribute ClientLogo
     */
    public BinaryContent getClientLogo ()
    {
        assertValid();
        BinaryContent valToReturn = _ClientLogo;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getClientLogo ((Client)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 preClientLogoChange (BinaryContent newClientLogo) 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 postClientLogoChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ClientLogo.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setClientLogo (BinaryContent newClientLogo) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ClientLogo.compare (_ClientLogo, newClientLogo);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newClientLogo = bhd.setClientLogo ((Client)this, newClientLogo);
                oldAndNewIdentical = HELPER_ClientLogo.compare (_ClientLogo, newClientLogo);
            }

            

            if (FIELD_ClientLogo_Validators.length > 0)
            {
                Object newClientLogoObj = HELPER_ClientLogo.toObject (newClientLogo);

                if (newClientLogoObj != null)
                {
                    int     loopMax = FIELD_ClientLogo_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_ClientLogo);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ClientLogo () != FieldWriteability.FALSE, "Field  ClientLogo is not writeable");
            preClientLogoChange (newClientLogo);
            markFieldChange (FIELD_ClientLogo);
            _ClientLogo = newClientLogo;            
            postFieldChange (FIELD_ClientLogo);
            postClientLogoChange ();
        }
    }

    /**
     * Get the attribute Email
     */
    public String getEmail ()
    {
        assertValid();
        String valToReturn = _Email;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getEmail ((Client)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 preEmailChange (String newEmail) 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 postEmailChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Email.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setEmail (String newEmail) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Email.compare (_Email, newEmail);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newEmail = bhd.setEmail ((Client)this, newEmail);
                oldAndNewIdentical = HELPER_Email.compare (_Email, newEmail);
            }

            

            if (FIELD_Email_Validators.length > 0)
            {
                Object newEmailObj = HELPER_Email.toObject (newEmail);

                if (newEmailObj != null)
                {
                    int     loopMax = FIELD_Email_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_Email);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Email () != FieldWriteability.FALSE, "Field  Email is not writeable");
            preEmailChange (newEmail);
            markFieldChange (FIELD_Email);
            _Email = newEmail;            
            postFieldChange (FIELD_Email);
            postEmailChange ();
        }
    }

    /**
     * Get the attribute ContactName
     */
    public String getContactName ()
    {
        assertValid();
        String valToReturn = _ContactName;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getContactName ((Client)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 preContactNameChange (String newContactName) 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 postContactNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ContactName.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setContactName (String newContactName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ContactName.compare (_ContactName, newContactName);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newContactName = bhd.setContactName ((Client)this, newContactName);
                oldAndNewIdentical = HELPER_ContactName.compare (_ContactName, newContactName);
            }

            

            if (FIELD_ContactName_Validators.length > 0)
            {
                Object newContactNameObj = HELPER_ContactName.toObject (newContactName);

                if (newContactNameObj != null)
                {
                    int     loopMax = FIELD_ContactName_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_ContactName);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ContactName () != FieldWriteability.FALSE, "Field  ContactName is not writeable");
            preContactNameChange (newContactName);
            markFieldChange (FIELD_ContactName);
            _ContactName = newContactName;            
            postFieldChange (FIELD_ContactName);
            postContactNameChange ();
        }
    }

    /**
     * Get the attribute ContactSurname
     */
    public String getContactSurname ()
    {
        assertValid();
        String valToReturn = _ContactSurname;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getContactSurname ((Client)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 preContactSurnameChange (String newContactSurname) 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 postContactSurnameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute ContactSurname.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setContactSurname (String newContactSurname) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_ContactSurname.compare (_ContactSurname, newContactSurname);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newContactSurname = bhd.setContactSurname ((Client)this, newContactSurname);
                oldAndNewIdentical = HELPER_ContactSurname.compare (_ContactSurname, newContactSurname);
            }

            

            if (FIELD_ContactSurname_Validators.length > 0)
            {
                Object newContactSurnameObj = HELPER_ContactSurname.toObject (newContactSurname);

                if (newContactSurnameObj != null)
                {
                    int     loopMax = FIELD_ContactSurname_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_ContactSurname);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_ContactSurname () != FieldWriteability.FALSE, "Field  ContactSurname is not writeable");
            preContactSurnameChange (newContactSurname);
            markFieldChange (FIELD_ContactSurname);
            _ContactSurname = newContactSurname;            
            postFieldChange (FIELD_ContactSurname);
            postContactSurnameChange ();
        }
    }

    /**
     * Get the attribute Phone
     */
    public String getPhone ()
    {
        assertValid();
        String valToReturn = _Phone;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getPhone ((Client)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 prePhoneChange (String newPhone) 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 postPhoneChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Phone.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setPhone (String newPhone) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Phone.compare (_Phone, newPhone);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newPhone = bhd.setPhone ((Client)this, newPhone);
                oldAndNewIdentical = HELPER_Phone.compare (_Phone, newPhone);
            }

            

            if (FIELD_Phone_Validators.length > 0)
            {
                Object newPhoneObj = HELPER_Phone.toObject (newPhone);

                if (newPhoneObj != null)
                {
                    int     loopMax = FIELD_Phone_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_Phone);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Phone () != FieldWriteability.FALSE, "Field  Phone is not writeable");
            prePhoneChange (newPhone);
            markFieldChange (FIELD_Phone);
            _Phone = newPhone;            
            postFieldChange (FIELD_Phone);
            postPhoneChange ();
        }
    }

    /**
     * Get the attribute State
     */
    public State getState ()
    {
        assertValid();
        State valToReturn = _State;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getState ((Client)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 preStateChange (State newState) 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 postStateChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute State.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setState (State newState) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_State.compare (_State, newState);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newState = bhd.setState ((Client)this, newState);
                oldAndNewIdentical = HELPER_State.compare (_State, newState);
            }

            

            if (FIELD_State_Validators.length > 0)
            {
                Object newStateObj = HELPER_State.toObject (newState);

                if (newStateObj != null)
                {
                    int     loopMax = FIELD_State_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_State);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_State () != FieldWriteability.FALSE, "Field  State is not writeable");
            preStateChange (newState);
            markFieldChange (FIELD_State);
            _State = newState;            
            postFieldChange (FIELD_State);
            postStateChange ();
        }
    }

    /**
     * Get the attribute Country
     */
    public Countries getCountry ()
    {
        assertValid();
        Countries valToReturn = _Country;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getCountry ((Client)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 preCountryChange (Countries newCountry) 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 postCountryChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Country.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCountry (Countries newCountry) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Country.compare (_Country, newCountry);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newCountry = bhd.setCountry ((Client)this, newCountry);
                oldAndNewIdentical = HELPER_Country.compare (_Country, newCountry);
            }

            

            if (FIELD_Country_Validators.length > 0)
            {
                Object newCountryObj = HELPER_Country.toObject (newCountry);

                if (newCountryObj != null)
                {
                    int     loopMax = FIELD_Country_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_Country);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Country () != FieldWriteability.FALSE, "Field  Country is not writeable");
            preCountryChange (newCountry);
            markFieldChange (FIELD_Country);
            _Country = newCountry;            
            postFieldChange (FIELD_Country);
            postCountryChange ();
        }
    }

    /**
     * Get the attribute PostCode
     */
    public String getPostCode ()
    {
        assertValid();
        String valToReturn = _PostCode;

            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                valToReturn = bhd.getPostCode ((Client)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 prePostCodeChange (String newPostCode) 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 postPostCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute PostCode.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setPostCode (String newPostCode) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_PostCode.compare (_PostCode, newPostCode);
        
        try
        {
            for (ClientBehaviourDecorator bhd : Client_BehaviourDecorators)
            {
                newPostCode = bhd.setPostCode ((Client)this, newPostCode);
                oldAndNewIdentical = HELPER_PostCode.compare (_PostCode, newPostCode);
            }

            

            if (FIELD_PostCode_Validators.length > 0)
            {
                Object newPostCodeObj = HELPER_PostCode.toObject (newPostCode);

                if (newPostCodeObj != null)
                {
                    int     loopMax = FIELD_PostCode_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Client.get (FIELD_PostCode);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_PostCode () != FieldWriteability.FALSE, "Field  PostCode is not writeable");
            prePostCodeChange (newPostCode);
            markFieldChange (FIELD_PostCode);
            _PostCode = newPostCode;            
            postFieldChange (FIELD_PostCode);
            postPostCodeChange ();
        }
    }



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

        
        result.add("Company");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Company))
        {
            return _Company.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_Company))
        {
            return Company.MULTIPLEREFERENCE_Clients ;
        }
        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_Company))
        {
            return getCompany ();
        }
        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_Company))
        {
            return getCompany (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_Company))
        {
            return getCompanyID ();
        }
        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_Company))
        {
            setCompany ((Company)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCompanyID ()
    {
        assertValid();
        
        if (_Company == null)
        {
            return null;
        }
        else
        {
            return _Company.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 preCompanyChange (Company newCompany) 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 postCompanyChange () throws FieldException
    {
    }



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

        if (_Company.wouldReferencedChange (newCompany))
        {
            assertValid();
            Debug.assertion (getWriteability_Company () != FieldWriteability.FALSE, "Assoc Company is not writeable");
            preCompanyChange (newCompany);
            Company oldCompany = getCompany ();

                    if (oldCompany != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Company.set (null);
                        oldCompany.removeFromClients ((Client)(this));
                    }

                    _Company.set (newCompany);

                    if (newCompany != null)
                    {
                        newCompany.addToClients ((Client)(this));
                    }
                
            postCompanyChange ();
        }
    }

    /**
     * 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 (_Company.isLoaded () || getTransaction ().isObjectLoaded (_Company.getReferencedType (), getCompanyID ()))
            {
                Company  referenced = getCompany ();

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

        super.onDelete ();
    }


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


    public Client referenceInstance ()
    {
        return REFERENCE_Client;
    }


    public Client getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getClientByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Client;
    }


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





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

        tl_clientPSet.setAttrib (FIELD_ObjectID, myID);
        tl_clientPSet.setAttrib (FIELD_ClientName, HELPER_ClientName.toObject (_ClientName)); //
        tl_clientPSet.setAttrib (FIELD_ClientLogo, HELPER_ClientLogo.toObject (_ClientLogo)); //
        tl_clientPSet.setAttrib (FIELD_Email, HELPER_Email.toObject (_Email)); //
        tl_clientPSet.setAttrib (FIELD_ContactName, HELPER_ContactName.toObject (_ContactName)); //
        tl_clientPSet.setAttrib (FIELD_ContactSurname, HELPER_ContactSurname.toObject (_ContactSurname)); //
        tl_clientPSet.setAttrib (FIELD_Phone, HELPER_Phone.toObject (_Phone)); //
        tl_clientPSet.setAttrib (FIELD_State, HELPER_State.toObject (_State)); //
        tl_clientPSet.setAttrib (FIELD_Country, HELPER_Country.toObject (_Country)); //
        tl_clientPSet.setAttrib (FIELD_PostCode, HELPER_PostCode.toObject (_PostCode)); //
        _Company.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_clientPSet = allSets.getPersistentSet (objectID, "tl_client");

        _ClientName = (String)(HELPER_ClientName.fromObject (_ClientName, tl_clientPSet.getAttrib (FIELD_ClientName))); //
        _ClientLogo = (BinaryContent)(HELPER_ClientLogo.fromObject (_ClientLogo, tl_clientPSet.getAttrib (FIELD_ClientLogo))); //
        _Email = (String)(HELPER_Email.fromObject (_Email, tl_clientPSet.getAttrib (FIELD_Email))); //
        _ContactName = (String)(HELPER_ContactName.fromObject (_ContactName, tl_clientPSet.getAttrib (FIELD_ContactName))); //
        _ContactSurname = (String)(HELPER_ContactSurname.fromObject (_ContactSurname, tl_clientPSet.getAttrib (FIELD_ContactSurname))); //
        _Phone = (String)(HELPER_Phone.fromObject (_Phone, tl_clientPSet.getAttrib (FIELD_Phone))); //
        _State = (State)(HELPER_State.fromObject (_State, tl_clientPSet.getAttrib (FIELD_State))); //
        _Country = (Countries)(HELPER_Country.fromObject (_Country, tl_clientPSet.getAttrib (FIELD_Country))); //
        _PostCode = (String)(HELPER_PostCode.fromObject (_PostCode, tl_clientPSet.getAttrib (FIELD_PostCode))); //
        _Company.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof Client)
        {
            Client otherClient = (Client)other;
            
            try
            {
                setClientName (otherClient.getClientName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setClientLogo (otherClient.getClientLogo ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setEmail (otherClient.getEmail ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setContactName (otherClient.getContactName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setContactSurname (otherClient.getContactSurname ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setPhone (otherClient.getPhone ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setState (otherClient.getState ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setCountry (otherClient.getCountry ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setPostCode (otherClient.getPostCode ());
            }
            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 BaseClient)
        {
            BaseClient sourceClient = (BaseClient)(source);

            _ClientName = sourceClient._ClientName;
            _ClientLogo = sourceClient._ClientLogo;
            _Email = sourceClient._Email;
            _ContactName = sourceClient._ContactName;
            _ContactSurname = sourceClient._ContactSurname;
            _Phone = sourceClient._Phone;
            _State = sourceClient._State;
            _Country = sourceClient._Country;
            _PostCode = sourceClient._PostCode;
            
        }
    }


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

            _Company.copyFrom (sourceClient._Company, 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 BaseClient)
        {
            BaseClient sourceClient = (BaseClient)(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);

        _ClientName = (String)(HELPER_ClientName.readExternal (_ClientName, vals.get(FIELD_ClientName))); //
        _ClientLogo = (BinaryContent)(HELPER_ClientLogo.readExternal (_ClientLogo, vals.get(FIELD_ClientLogo))); //
        _Email = (String)(HELPER_Email.readExternal (_Email, vals.get(FIELD_Email))); //
        _ContactName = (String)(HELPER_ContactName.readExternal (_ContactName, vals.get(FIELD_ContactName))); //
        _ContactSurname = (String)(HELPER_ContactSurname.readExternal (_ContactSurname, vals.get(FIELD_ContactSurname))); //
        _Phone = (String)(HELPER_Phone.readExternal (_Phone, vals.get(FIELD_Phone))); //
        _State = (State)(HELPER_State.readExternal (_State, vals.get(FIELD_State))); //
        _Country = (Countries)(HELPER_Country.readExternal (_Country, vals.get(FIELD_Country))); //
        _PostCode = (String)(HELPER_PostCode.readExternal (_PostCode, vals.get(FIELD_PostCode))); //
        _Company.readExternalData(vals.get(SINGLEREFERENCE_Company));
        
    }


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

        vals.put (FIELD_ClientName, HELPER_ClientName.writeExternal (_ClientName));
        vals.put (FIELD_ClientLogo, HELPER_ClientLogo.writeExternal (_ClientLogo));
        vals.put (FIELD_Email, HELPER_Email.writeExternal (_Email));
        vals.put (FIELD_ContactName, HELPER_ContactName.writeExternal (_ContactName));
        vals.put (FIELD_ContactSurname, HELPER_ContactSurname.writeExternal (_ContactSurname));
        vals.put (FIELD_Phone, HELPER_Phone.writeExternal (_Phone));
        vals.put (FIELD_State, HELPER_State.writeExternal (_State));
        vals.put (FIELD_Country, HELPER_Country.writeExternal (_Country));
        vals.put (FIELD_PostCode, HELPER_PostCode.writeExternal (_PostCode));
        vals.put (SINGLEREFERENCE_Company, _Company.writeExternalData());
        
    }


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

        if (other instanceof BaseClient)
        {
            BaseClient otherClient = (BaseClient)(other);

            
            if (!HELPER_ClientName.compare(this._ClientName, otherClient._ClientName))
            {
                listener.notifyFieldChange(this, other, FIELD_ClientName, HELPER_ClientName.toObject(this._ClientName), HELPER_ClientName.toObject(otherClient._ClientName));
            }
            if (!HELPER_ClientLogo.compare(this._ClientLogo, otherClient._ClientLogo))
            {
                listener.notifyFieldChange(this, other, FIELD_ClientLogo, HELPER_ClientLogo.toObject(this._ClientLogo), HELPER_ClientLogo.toObject(otherClient._ClientLogo));
            }
            if (!HELPER_Email.compare(this._Email, otherClient._Email))
            {
                listener.notifyFieldChange(this, other, FIELD_Email, HELPER_Email.toObject(this._Email), HELPER_Email.toObject(otherClient._Email));
            }
            if (!HELPER_ContactName.compare(this._ContactName, otherClient._ContactName))
            {
                listener.notifyFieldChange(this, other, FIELD_ContactName, HELPER_ContactName.toObject(this._ContactName), HELPER_ContactName.toObject(otherClient._ContactName));
            }
            if (!HELPER_ContactSurname.compare(this._ContactSurname, otherClient._ContactSurname))
            {
                listener.notifyFieldChange(this, other, FIELD_ContactSurname, HELPER_ContactSurname.toObject(this._ContactSurname), HELPER_ContactSurname.toObject(otherClient._ContactSurname));
            }
            if (!HELPER_Phone.compare(this._Phone, otherClient._Phone))
            {
                listener.notifyFieldChange(this, other, FIELD_Phone, HELPER_Phone.toObject(this._Phone), HELPER_Phone.toObject(otherClient._Phone));
            }
            if (!HELPER_State.compare(this._State, otherClient._State))
            {
                listener.notifyFieldChange(this, other, FIELD_State, HELPER_State.toObject(this._State), HELPER_State.toObject(otherClient._State));
            }
            if (!HELPER_Country.compare(this._Country, otherClient._Country))
            {
                listener.notifyFieldChange(this, other, FIELD_Country, HELPER_Country.toObject(this._Country), HELPER_Country.toObject(otherClient._Country));
            }
            if (!HELPER_PostCode.compare(this._PostCode, otherClient._PostCode))
            {
                listener.notifyFieldChange(this, other, FIELD_PostCode, HELPER_PostCode.toObject(this._PostCode), HELPER_PostCode.toObject(otherClient._PostCode));
            }

            // Compare single assocs
            _Company.compare (otherClient._Company, 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_ClientName, HELPER_ClientName.toObject(getClientName()));
        visitor.visitField(this, FIELD_ClientLogo, HELPER_ClientLogo.toObject(getClientLogo()));
        visitor.visitField(this, FIELD_Email, HELPER_Email.toObject(getEmail()));
        visitor.visitField(this, FIELD_ContactName, HELPER_ContactName.toObject(getContactName()));
        visitor.visitField(this, FIELD_ContactSurname, HELPER_ContactSurname.toObject(getContactSurname()));
        visitor.visitField(this, FIELD_Phone, HELPER_Phone.toObject(getPhone()));
        visitor.visitField(this, FIELD_State, HELPER_State.toObject(getState()));
        visitor.visitField(this, FIELD_Country, HELPER_Country.toObject(getCountry()));
        visitor.visitField(this, FIELD_PostCode, HELPER_PostCode.toObject(getPostCode()));
        visitor.visitAssociation (_Company);
        
    }


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

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


    public static Client createClient (ObjectTransaction transaction) throws StorageException
    {
        Client     result = new Client ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Client getClientByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Client)(transaction.getObjectByID (REFERENCE_Client, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_ClientName))
        {
            return filter.matches (getClientName ());
        }
        else if (attribName.equals (FIELD_ClientLogo))
        {
            return filter.matches (getClientLogo ());
        }
        else if (attribName.equals (FIELD_Email))
        {
            return filter.matches (getEmail ());
        }
        else if (attribName.equals (FIELD_ContactName))
        {
            return filter.matches (getContactName ());
        }
        else if (attribName.equals (FIELD_ContactSurname))
        {
            return filter.matches (getContactSurname ());
        }
        else if (attribName.equals (FIELD_Phone))
        {
            return filter.matches (getPhone ());
        }
        else if (attribName.equals (FIELD_State))
        {
            return filter.matches (getState ());
        }
        else if (attribName.equals (FIELD_Country))
        {
            return filter.matches (getCountry ());
        }
        else if (attribName.equals (FIELD_PostCode))
        {
            return filter.matches (getPostCode ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Company))
        {
            return filter.matches (getCompany ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andClientName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.client_name", "ClientName");
                return this;
            }
            
            public SearchAll andClientLogo (QueryFilter<BinaryContent> filter)
            {
                filter.addFilter (context, "tl_client.client_logo", "ClientLogo");
                return this;
            }
            
            public SearchAll andEmail (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.email", "Email");
                return this;
            }
            
            public SearchAll andContactName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.contact_name", "ContactName");
                return this;
            }
            
            public SearchAll andContactSurname (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.contact_surname", "ContactSurname");
                return this;
            }
            
            public SearchAll andPhone (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.phone", "Phone");
                return this;
            }
            
            public SearchAll andState (QueryFilter<State> filter)
            {
                filter.addFilter (context, "tl_client.state", "State");
                return this;
            }
            
            public SearchAll andCountry (QueryFilter<Countries> filter)
            {
                filter.addFilter (context, "tl_client.country", "Country");
                return this;
            }
            
            public SearchAll andPostCode (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_client.post_code", "PostCode");
                return this;
            }
            
            public SearchAll andCompany (QueryFilter<Company> filter)
            {
                filter.addFilter (context, "tl_client.company_id", "Company");
                return this;
            }
            
                public Client[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Client, SEARCH_All, criteria);
            Set<Client>   typedResults = new LinkedHashSet <Client> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Client aResult = (Client)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Client[0]);
                            
        }
    }

        
                public static Client[]
             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_ClientName))
        {
            return HELPER_ClientName.toObject (getClientName ());
        }
        else if (attribName.equals (FIELD_ClientLogo))
        {
            return HELPER_ClientLogo.toObject (getClientLogo ());
        }
        else if (attribName.equals (FIELD_Email))
        {
            return HELPER_Email.toObject (getEmail ());
        }
        else if (attribName.equals (FIELD_ContactName))
        {
            return HELPER_ContactName.toObject (getContactName ());
        }
        else if (attribName.equals (FIELD_ContactSurname))
        {
            return HELPER_ContactSurname.toObject (getContactSurname ());
        }
        else if (attribName.equals (FIELD_Phone))
        {
            return HELPER_Phone.toObject (getPhone ());
        }
        else if (attribName.equals (FIELD_State))
        {
            return HELPER_State.toObject (getState ());
        }
        else if (attribName.equals (FIELD_Country))
        {
            return HELPER_Country.toObject (getCountry ());
        }
        else if (attribName.equals (FIELD_PostCode))
        {
            return HELPER_PostCode.toObject (getPostCode ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_ClientName))
        {
            return HELPER_ClientName;
        }
        else if (attribName.equals (FIELD_ClientLogo))
        {
            return HELPER_ClientLogo;
        }
        else if (attribName.equals (FIELD_Email))
        {
            return HELPER_Email;
        }
        else if (attribName.equals (FIELD_ContactName))
        {
            return HELPER_ContactName;
        }
        else if (attribName.equals (FIELD_ContactSurname))
        {
            return HELPER_ContactSurname;
        }
        else if (attribName.equals (FIELD_Phone))
        {
            return HELPER_Phone;
        }
        else if (attribName.equals (FIELD_State))
        {
            return HELPER_State;
        }
        else if (attribName.equals (FIELD_Country))
        {
            return HELPER_Country;
        }
        else if (attribName.equals (FIELD_PostCode))
        {
            return HELPER_PostCode;
        }
        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_ClientName))
        {
            setClientName ((String)(HELPER_ClientName.fromObject (_ClientName, attribValue)));            
        }
        else if (attribName.equals (FIELD_ClientLogo))
        {
            setClientLogo ((BinaryContent)(HELPER_ClientLogo.fromObject (_ClientLogo, attribValue)));            
        }
        else if (attribName.equals (FIELD_Email))
        {
            setEmail ((String)(HELPER_Email.fromObject (_Email, attribValue)));            
        }
        else if (attribName.equals (FIELD_ContactName))
        {
            setContactName ((String)(HELPER_ContactName.fromObject (_ContactName, attribValue)));            
        }
        else if (attribName.equals (FIELD_ContactSurname))
        {
            setContactSurname ((String)(HELPER_ContactSurname.fromObject (_ContactSurname, attribValue)));            
        }
        else if (attribName.equals (FIELD_Phone))
        {
            setPhone ((String)(HELPER_Phone.fromObject (_Phone, attribValue)));            
        }
        else if (attribName.equals (FIELD_State))
        {
            setState ((State)(HELPER_State.fromObject (_State, attribValue)));            
        }
        else if (attribName.equals (FIELD_Country))
        {
            setCountry ((Countries)(HELPER_Country.fromObject (_Country, attribValue)));            
        }
        else if (attribName.equals (FIELD_PostCode))
        {
            setPostCode ((String)(HELPER_PostCode.fromObject (_PostCode, 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_ClientName))
        {
            return getWriteability_ClientName ();
        }
        else if (fieldName.equals (FIELD_ClientLogo))
        {
            return getWriteability_ClientLogo ();
        }
        else if (fieldName.equals (FIELD_Email))
        {
            return getWriteability_Email ();
        }
        else if (fieldName.equals (FIELD_ContactName))
        {
            return getWriteability_ContactName ();
        }
        else if (fieldName.equals (FIELD_ContactSurname))
        {
            return getWriteability_ContactSurname ();
        }
        else if (fieldName.equals (FIELD_Phone))
        {
            return getWriteability_Phone ();
        }
        else if (fieldName.equals (FIELD_State))
        {
            return getWriteability_State ();
        }
        else if (fieldName.equals (FIELD_Country))
        {
            return getWriteability_Country ();
        }
        else if (fieldName.equals (FIELD_PostCode))
        {
            return getWriteability_PostCode ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Company))
        {
            return getWriteability_Company ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_ClientName () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ClientName);
            }
        
            if (getWriteability_ClientLogo () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ClientLogo);
            }
        
            if (getWriteability_Email () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Email);
            }
        
            if (getWriteability_ContactName () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ContactName);
            }
        
            if (getWriteability_ContactSurname () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_ContactSurname);
            }
        
            if (getWriteability_Phone () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Phone);
            }
        
            if (getWriteability_State () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_State);
            }
        
            if (getWriteability_Country () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Country);
            }
        
            if (getWriteability_PostCode () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_PostCode);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_ClientName.getAttribObject (getClass (), _ClientName, true, FIELD_ClientName));
        result.add(HELPER_ClientLogo.getAttribObject (getClass (), _ClientLogo, false, FIELD_ClientLogo));
        result.add(HELPER_Email.getAttribObject (getClass (), _Email, false, FIELD_Email));
        result.add(HELPER_ContactName.getAttribObject (getClass (), _ContactName, false, FIELD_ContactName));
        result.add(HELPER_ContactSurname.getAttribObject (getClass (), _ContactSurname, false, FIELD_ContactSurname));
        result.add(HELPER_Phone.getAttribObject (getClass (), _Phone, false, FIELD_Phone));
        result.add(HELPER_State.getAttribObject (getClass (), _State, false, FIELD_State));
        result.add(HELPER_Country.getAttribObject (getClass (), _Country, false, FIELD_Country));
        result.add(HELPER_PostCode.getAttribObject (getClass (), _PostCode, false, FIELD_PostCode));

        return result;
    }


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


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

    public void preCommit (boolean willBeStored) throws Exception
    {
        super.preCommit(willBeStored);
        
        if(willBeStored)
        {
        
          {  
            oneit.servlets.objstore.binary.BinaryContentHandler bchandler = oneit.servlets.objstore.binary.BinaryContentServlet.getHandler("loggedin");
              
            if(bchandler != null)
            {
                bchandler.preCommit(willBeStored, this, "ClientLogo");
            }
            else
            {
                LogMgr.log(BUSINESS_OBJECTS, LogLevel.SYSTEMWARNING, "Unknown BinaryContentHandler loggedin on attribute ClientLogo");
            }
          }
          
        }
    }

    public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
    {
        
        if(CollectionUtils.equals(attribName, "ClientLogo"))      
        {  
            return oneit.servlets.objstore.binary.BinaryContentServlet.getHandler("loggedin");
        }     
          
        
        return super.getBinaryContentHandler(attribName);
    }

    public static class ClientBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<Client>
    {

    /**
     * Get the attribute ClientName
     */
    public String getClientName (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ClientName.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setClientName (Client obj, String newClientName) throws FieldException
    {
        return newClientName;
    }

    /**
     * Get the attribute ClientLogo
     */
    public BinaryContent getClientLogo (Client obj, BinaryContent original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ClientLogo.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public BinaryContent setClientLogo (Client obj, BinaryContent newClientLogo) throws FieldException
    {
        return newClientLogo;
    }

    /**
     * Get the attribute Email
     */
    public String getEmail (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Email.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setEmail (Client obj, String newEmail) throws FieldException
    {
        return newEmail;
    }

    /**
     * Get the attribute ContactName
     */
    public String getContactName (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ContactName.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setContactName (Client obj, String newContactName) throws FieldException
    {
        return newContactName;
    }

    /**
     * Get the attribute ContactSurname
     */
    public String getContactSurname (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ContactSurname.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setContactSurname (Client obj, String newContactSurname) throws FieldException
    {
        return newContactSurname;
    }

    /**
     * Get the attribute Phone
     */
    public String getPhone (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Phone.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setPhone (Client obj, String newPhone) throws FieldException
    {
        return newPhone;
    }

    /**
     * Get the attribute State
     */
    public State getState (Client obj, State original)
    {
        return original;
    }

    /**
     * Change the value set for attribute State.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public State setState (Client obj, State newState) throws FieldException
    {
        return newState;
    }

    /**
     * Get the attribute Country
     */
    public Countries getCountry (Client obj, Countries original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Country.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Countries setCountry (Client obj, Countries newCountry) throws FieldException
    {
        return newCountry;
    }

    /**
     * Get the attribute PostCode
     */
    public String getPostCode (Client obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute PostCode.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setPostCode (Client obj, String newPostCode) throws FieldException
    {
        return newPostCode;
    }

    }

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

        public ClientPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("ClientName"))
            {
                return toClientName ();
            }                
            if (name.equals ("ClientLogo"))
            {
                return toClientLogo ();
            }                
            if (name.equals ("Email"))
            {
                return toEmail ();
            }                
            if (name.equals ("ContactName"))
            {
                return toContactName ();
            }                
            if (name.equals ("ContactSurname"))
            {
                return toContactSurname ();
            }                
            if (name.equals ("Phone"))
            {
                return toPhone ();
            }                
            if (name.equals ("State"))
            {
                return toState ();
            }                
            if (name.equals ("Country"))
            {
                return toCountry ();
            }                
            if (name.equals ("PostCode"))
            {
                return toPostCode ();
            }                
            if (name.equals ("Company"))
            {
                return toCompany ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toClientName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_ClientName));  }
        
        public PipeLine<From, BinaryContent> toClientLogo () { return pipe(new ORMAttributePipe<Me, BinaryContent>(FIELD_ClientLogo));  }
        
        public PipeLine<From, String> toEmail () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Email));  }
        
        public PipeLine<From, String> toContactName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_ContactName));  }
        
        public PipeLine<From, String> toContactSurname () { return pipe(new ORMAttributePipe<Me, String>(FIELD_ContactSurname));  }
        
        public PipeLine<From, String> toPhone () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Phone));  }
        
        public PipeLine<From, State> toState () { return pipe(new ORMAttributePipe<Me, State>(FIELD_State));  }
        
        public PipeLine<From, Countries> toCountry () { return pipe(new ORMAttributePipe<Me, Countries>(FIELD_Country));  }
        
        public PipeLine<From, String> toPostCode () { return pipe(new ORMAttributePipe<Me, String>(FIELD_PostCode));  }
        public Company.CompanyPipeLineFactory<From, Company> toCompany () { return toCompany (Filter.ALL); }

        public Company.CompanyPipeLineFactory<From, Company> toCompany (Filter<Company> filter) 
        { 
            return Company.REFERENCE_Company.new CompanyPipeLineFactory<From, Company> (this, new ORMSingleAssocPipe<Me, Company>(SINGLEREFERENCE_Company, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Company getCompany () throws StorageException
    {
        return (Company)(Company.DUMMY_Company);
    }


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

}

    
