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


    package performa.orm;

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

import oneit.servlets.orm.*;



public abstract class BaseCompanyUserNPO extends NonPersistentBO
{
    // Reference instance for the object
    public static final CompanyUserNPO REFERENCE_CompanyUserNPO = new CompanyUserNPO ();

    // Reference instance for the object
    public static final CompanyUserNPO DUMMY_CompanyUserNPO = new DummyCompanyUserNPO ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Email = "Email";

    // Static constants corresponding to searches
    

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

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

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    

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

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

    // Arrays of behaviour decorators
    private static final CompanyUserNPOBehaviourDecorator[] CompanyUserNPO_BehaviourDecorators;
    
    static
    {
        try
        {
            
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            FIELD_Email_Validators = (AttributeValidator[])setupAttribMetaData_Email(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_CompanyUserNPO.initialiseReference ();
            DUMMY_CompanyUserNPO.initialiseReference ();
            CompanyUserNPO_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CompanyUserNPO.class).toArray(new CompanyUserNPOBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("name", "Email");
        metaInfo.put ("type", "String");
        metaInfo.put ("validators", "Email");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CompanyUserNPO.Email:", metaInfo);
        ATTRIBUTES_METADATA_CompanyUserNPO.put (FIELD_Email, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Email = (String)(HELPER_Email.initialise (_Email));
    }


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

        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        
        
        return this;
    }

    

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

            for (CompanyUserNPOBehaviourDecorator bhd : CompanyUserNPO_BehaviourDecorators)
            {
                valToReturn = bhd.getEmail ((CompanyUserNPO)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 (CompanyUserNPOBehaviourDecorator bhd : CompanyUserNPO_BehaviourDecorators)
            {
                newEmail = bhd.setEmail ((CompanyUserNPO)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_CompanyUserNPO.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 ();
        }
    }



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

        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssocReferenceInstance (assocName);
        }
    }


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


    public BaseBusinessClass getSingleAssoc (String assocName, Get getType) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssoc (assocName, getType);
        }
    }


    public Long getSingleAssocID (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        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
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * 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 
        {
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public CompanyUserNPO referenceInstance ()
    {
        return REFERENCE_CompanyUserNPO;
    }


    public CompanyUserNPO getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCompanyUserNPOByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CompanyUserNPO;
    }


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





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

        it_does_not_matterPSet.setAttrib (FIELD_ObjectID, myID);
        it_does_not_matterPSet.setAttrib (FIELD_Email, HELPER_Email.toObject (_Email)); //
        
    }


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

        
        PersistentSet   it_does_not_matterPSet = allSets.getPersistentSet (objectID, "it_does_not_matter");

        _Email = (String)(HELPER_Email.fromObject (_Email, it_does_not_matterPSet.getAttrib (FIELD_Email))); //
        
    }





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

        if (other instanceof CompanyUserNPO)
        {
            CompanyUserNPO otherCompanyUserNPO = (CompanyUserNPO)other;
            
            try
            {
                setEmail (otherCompanyUserNPO.getEmail ());
            }
            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 BaseCompanyUserNPO)
        {
            BaseCompanyUserNPO sourceCompanyUserNPO = (BaseCompanyUserNPO)(source);

            _Email = sourceCompanyUserNPO._Email;
            
        }
    }


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

            
        }
    }


    /**
     * 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 BaseCompanyUserNPO)
        {
            BaseCompanyUserNPO sourceCompanyUserNPO = (BaseCompanyUserNPO)(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);

        _Email = (String)(HELPER_Email.readExternal (_Email, vals.get(FIELD_Email))); //
        
    }


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

        vals.put (FIELD_Email, HELPER_Email.writeExternal (_Email));
        
    }


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

        if (other instanceof BaseCompanyUserNPO)
        {
            BaseCompanyUserNPO otherCompanyUserNPO = (BaseCompanyUserNPO)(other);

            
            if (!HELPER_Email.compare(this._Email, otherCompanyUserNPO._Email))
            {
                listener.notifyFieldChange(this, other, FIELD_Email, HELPER_Email.toObject(this._Email), HELPER_Email.toObject(otherCompanyUserNPO._Email));
            }

            // Compare single assocs
            

            // 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_Email, HELPER_Email.toObject(getEmail()));
        
    }


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

        
    }


    public static CompanyUserNPO createCompanyUserNPO (ObjectTransaction transaction) throws StorageException
    {
        CompanyUserNPO     result = new CompanyUserNPO ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CompanyUserNPO getCompanyUserNPOByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CompanyUserNPO)(transaction.getObjectByID (REFERENCE_CompanyUserNPO, objectID));
    }

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




    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Email))
        {
            return HELPER_Email.toObject (getEmail ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Email))
        {
            return HELPER_Email;
        }
        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_Email))
        {
            setEmail ((String)(HELPER_Email.fromObject (_Email, 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_Email))
        {
            return getWriteability_Email ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


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

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Email.getAttribObject (getClass (), _Email, false, FIELD_Email));

        return result;
    }


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


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

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

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

    public static class CompanyUserNPOBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<CompanyUserNPO>
    {

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

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

    }

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

        public CompanyUserNPOPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Email"))
            {
                return toEmail ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toEmail () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Email));  }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


}

    
