/** * * The OctObject class is the class which all OCT objects will * inherit (extend) * * @see PeristentObject * @version 1.2 Oct 1996 * @author Francis Chan * */ import java.util.*; abstract public class OctObject extends PersistentObject{ /** * The Name of the Class that inherits OctObject */ public String className; /** * OctObjectType * */ int type; /** * Unique object Id generated by the data server after a Save() * */ protected int objectId = OCT.NULL_ID; /** * Number of fields in the OctObject */ protected int octFields; /** * Vector which contains all object that are attached as containers */ protected Vector containers; /** * Vector which contains all object that are attached as contents */ protected Vector contents; // this is the Id that the data backend, may need to generate it during // object creation // (retrievable through OctExternalId p9) // Design Decision // generate in using time during creation // will get an "authentic" id from the data backend after a save /** * ID generated by the program during dynamic construction */ public long externalId; // we need this variable to identify those OctObjects which have // externalId generated from the data backend /** * Determines whether the object requires saving */ public boolean dirty = true; // public boolean inMemory = false; /* * The object's current OctCell */ public OctCell octCell; /* * Indicates the port (of the server) for network transactions */ // can to set to (not) print out error/debug messages private boolean errorFlag = true; /** * Constructor of an OctObject * Initializes internal data structures * Never gets called explicitly */ public OctObject() { containers = new Vector(); contents = new Vector(); // need to set up unique id during object creation (for attach and stuff), // even if we don't load and save // unique externalId by date/time of local objects Date date = new Date(); this.externalId = date.getTime(); containersInMem = true; contentsInMem = true; dirty = true; } /** * Add the obj to the contents Vector * Returns OCT.OK * @param obj OctObject to be added */ public int Attach(OctObject obj) { if (octCell.Policy(this, obj) != OCT.OK) { return ERROR; } // attach obj to current objects contents contents.addElement(obj); // attach current object to obj's conatiners obj.AddAttachTo(this); octCell.SetDirty(this); this.dirty = true; return OCT.OK; } /** * Add the obj to the containers Vector * Should only be called internally or by the system * @param oObj OctObject to be added */ public void AddAttachTo(OctObject oObj) { containers.addElement(oObj); } /** * Attached the obj to the current object only if it's not already attached * Return OCT.OK is operation is completed successfully, * OCT.ALREADY_ATTACHED otherwise * * @param obj The object to check whether it's attached */ public int AttachOnce(OctObject obj) { if (isAttached(obj) == OCT.NOT_ATTACHED) { Attach(obj); return OCT.OK; } return OCT.ALREADY_ATTACHED; } /** * * Checks to see whether the obj is attached to the current OctObject * Returns OCT.OK if so, OCT.NOT_ATTACHED otherwise * @param cnt The container to delete from */ public int isAttached(OctObject obj) { OctObject oObj; for (int i=0; i