/*
 * 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 BaseTestInput extends NonPersistentBO
{
    // Reference instance for the object
    public static final TestInput REFERENCE_TestInput = new TestInput ();

    // Reference instance for the object
    public static final TestInput DUMMY_TestInput = new DummyTestInput ();

    // Static constants corresponding to field names
    
    public static final String FIELD_CSV = "CSV";

    // Static constants corresponding to searches
    

    // Static constants corresponding to attribute helpers
    private static final BLOBAttributeHelper HELPER_CSV = BLOBAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private BinaryContent _CSV;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    

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

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

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

            FIELD_CSV_Validators = (AttributeValidator[])setupAttribMetaData_CSV(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_TestInput.initialiseReference ();
            DUMMY_TestInput.initialiseReference ();
            TestInput_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(TestInput.class).toArray(new TestInputBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("attribHelper", "BLOBAttributeHelper");
        metaInfo.put ("attribHelperInstance", "BLOBAttributeHelper.INSTANCE");
        metaInfo.put ("binaryHandler", "loggedin");
        metaInfo.put ("dbcol", "xxxx");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CSV");
        metaInfo.put ("type", "BinaryContent");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for TestInput.CSV:", metaInfo);
        ATTRIBUTES_METADATA_TestInput.put (FIELD_CSV, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _CSV = (BinaryContent)(HELPER_CSV.initialise (_CSV));
    }


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

        
    }


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

    

    /**
     * Get the attribute CSV
     */
    public BinaryContent getCSV ()
    {
        assertValid();
        BinaryContent valToReturn = _CSV;

            for (TestInputBehaviourDecorator bhd : TestInput_BehaviourDecorators)
            {
                valToReturn = bhd.getCSV ((TestInput)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 preCSVChange (BinaryContent newCSV) 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 postCSVChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CSV.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCSV (BinaryContent newCSV) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CSV.compare (_CSV, newCSV);
        
        try
        {
            for (TestInputBehaviourDecorator bhd : TestInput_BehaviourDecorators)
            {
                newCSV = bhd.setCSV ((TestInput)this, newCSV);
                oldAndNewIdentical = HELPER_CSV.compare (_CSV, newCSV);
            }

            BusinessObjectParser.assertFieldCondition (newCSV != null, this, FIELD_CSV, "mandatory");
            

            if (FIELD_CSV_Validators.length > 0)
            {
                Object newCSVObj = HELPER_CSV.toObject (newCSV);

                if (newCSVObj != null)
                {
                    int     loopMax = FIELD_CSV_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_TestInput.get (FIELD_CSV);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CSV () != FieldWriteability.FALSE, "Field  CSV is not writeable");
            preCSVChange (newCSV);
            markFieldChange (FIELD_CSV);
            _CSV = newCSV;            
            postFieldChange (FIELD_CSV);
            postCSVChange ();
        }
    }



    /**
     * 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 TestInput newInstance ()
    {
        return new TestInput ();
    }


    public TestInput referenceInstance ()
    {
        return REFERENCE_TestInput;
    }


    public TestInput getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getTestInputByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_TestInput;
    }


    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_CSV, HELPER_CSV.toObject (_CSV)); //
        
    }


    /**
     * 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");

        _CSV = (BinaryContent)(HELPER_CSV.fromObject (_CSV, it_does_not_matterPSet.getAttrib (FIELD_CSV))); //
        
    }





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

        if (other instanceof TestInput)
        {
            TestInput otherTestInput = (TestInput)other;
            
            try
            {
                setCSV (otherTestInput.getCSV ());
            }
            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 BaseTestInput)
        {
            BaseTestInput sourceTestInput = (BaseTestInput)(source);

            _CSV = sourceTestInput._CSV;
            
        }
    }


    /**
     * 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 BaseTestInput)
        {
            BaseTestInput sourceTestInput = (BaseTestInput)(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 BaseTestInput)
        {
            BaseTestInput sourceTestInput = (BaseTestInput)(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);

        _CSV = (BinaryContent)(HELPER_CSV.readExternal (_CSV, vals.get(FIELD_CSV))); //
        
    }


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

        vals.put (FIELD_CSV, HELPER_CSV.writeExternal (_CSV));
        
    }


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

        if (other instanceof BaseTestInput)
        {
            BaseTestInput otherTestInput = (BaseTestInput)(other);

            
            if (!HELPER_CSV.compare(this._CSV, otherTestInput._CSV))
            {
                listener.notifyFieldChange(this, other, FIELD_CSV, HELPER_CSV.toObject(this._CSV), HELPER_CSV.toObject(otherTestInput._CSV));
            }

            // 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_CSV, HELPER_CSV.toObject(getCSV()));
        
    }


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

        
    }


    public static TestInput createTestInput (ObjectTransaction transaction) throws StorageException
    {
        TestInput     result = new TestInput ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static TestInput getTestInputByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (TestInput)(transaction.getObjectByID (REFERENCE_TestInput, objectID));
    }

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




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


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_CSV))
        {
            return HELPER_CSV;
        }
        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_CSV))
        {
            setCSV ((BinaryContent)(HELPER_CSV.fromObject (_CSV, 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_CSV))
        {
            return getWriteability_CSV ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


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

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_CSV.getAttribObject (getClass (), _CSV, true, FIELD_CSV));

        return result;
    }


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


    public Object getAttributeMetadata (String attribute, String metadata)
    {
        if (ATTRIBUTES_METADATA_TestInput.containsKey (attribute))
        {
            return ((Map)ATTRIBUTES_METADATA_TestInput.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, "CSV");
            }
            else
            {
                LogMgr.log(BUSINESS_OBJECTS, LogLevel.SYSTEMWARNING, "Unknown BinaryContentHandler loggedin on attribute CSV");
            }
          }
          
        }
    }

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

    public static class TestInputBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<TestInput>
    {

    /**
     * Get the attribute CSV
     */
    public BinaryContent getCSV (TestInput obj, BinaryContent original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CSV.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public BinaryContent setCSV (TestInput obj, BinaryContent newCSV) throws FieldException
    {
        return newCSV;
    }

    }

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

        public TestInputPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("CSV"))
            {
                return toCSV ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, BinaryContent> toCSV () { return pipe(new ORMAttributePipe<Me, BinaryContent>(FIELD_CSV));  }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


}

