/** * * OctCell is where the Oct user enters and * inits the whole environment. It is the highest level object in * an Oct System. * * Has link and keeps track of the dirty bits of each OctObject in the * system for save/load purposes. * * Implements the policies of the Oct environment * * Gives the user an option to save any dirty bit before leaving the * system. * * @version a1 Oct 1996 * @author Francis Chan */ import java.util.Vector; public class OctCell extends OctObject{ /** * Class Name */ public static final String className= "OctCell"; /** * Number of fields */ public static final int octFields = 3; private String name; private String password; private String permission; /** * Keeps track of all OctObjects in the present environment */ public Vector elements; /** * Constructor of an OctCell (for dynamic creation). * The name of password parameters of an OctCell cannot be changed * after the instantiation of the OctCell. * * @param name The name of the OctCell * @param password The password of OctCell * @param permission The permission of OctCell * "W" for write, "R" for read-only */ public OctCell(String name, String password, String permission) { this.name = name; this.password = password; this.permission = permission; elements = new Vector(); AddElement(this); this.octCell = this; OctObjSetup(this.port, octFields, className); } /** * Constructor of an OctCell (for loading from data back-end server) * * @param port Port number of remote server */ public OctCell(String name, int port) { this.name = name; elements = new Vector(); AddElement(this); this.octCell = this; this.port = port; OctObjSetup(this.port, octFields, className); } /*----------------------------------------------------------- * * the code below is for data backend management * *-----------------------------------------------------------*/ /** * Constructor of an OctCell (for loading from data back-end server) * */ public OctCell(String name) { this.name = name; this.octCell = this; elements = new Vector(); OctObjSetup(port, octFields, className); } /** * Performs the neccessary overhead to allow this object to be * manipulated over the network */ protected void SetObjFields() { SetField(0, this.name, PersistentObject.STRING); SetField(1, this.password, PersistentObject.STRING); SetField(2, this.permission, PersistentObject.STRING); OctSetField(octFields); } /** * Loads the fields of an OctCell from data back-end * @param objectId The String Id for the object * @param intId The integer (unique) Id for the object */ public boolean Load(String strId) { if (LoadObject(this.objectClassName, strId, 0) == false) { System.out.println("Couldn't load object " + className + " with StringId " + strId); return false; } // sets up paramVector so it's ready for field assignment // this.name = GetField(0, PersistentObject.STRING_INDICATOR); this.password = GetField(1, PersistentObject.STRING_INDICATOR); this.permission = GetField(2, PersistentObject.STRING_INDICATOR); OctGetField(octFields); AddElement(this); OctObjSetup(port, octFields, className); return true; } /** * Should never be called */ public boolean Load(int intId) { return false; } /** * Does not require filling since the object has no object fields */ protected int GetObjFields() { return OCT.OK; } /*------------------------------------- * * Methods of OctCell * *-------------------------------------*/ /** * Returns the name of the OctCell */ public String GetName() { return this.name; } /** * Sets the permission of the OctCell * * @param perm The permission of the OctCell, * "W" for write, "R" for read-only */ public void SetPermission(String perm) { this.permission = perm; } /** * Returns OctObject with the ObjectId intId. * Returns null if the Object with intId is not found in memory * * @param intId The objectId of OctObject for look-up */ public OctObject GetById(int intId) { OctObject oObj = null; // if the OctObject's in memory/OctCell, return it for (int i=0; iOctView if (((cnt.objectClassName.compareTo("OctCell") == 0) && (obj.objectClassName.compareTo("OctView") != 0)) || ((obj.objectClassName.compareTo("OctView") == 0) && (cnt.objectClassName.compareTo("OctCell") != 0))) { System.out.println("OctViews must and can only be attached to OctCells"); return OCT.ERROR; } // OctView->OctFacet if (((cnt.objectClassName.compareTo("OctView") == 0) && (obj.objectClassName.compareTo("OctFacet") != 0)) || ((obj.objectClassName.compareTo("OctFacet") == 0) && (cnt.objectClassName.compareTo("OctView") != 0))) { System.out.println("OctFacets must and can only be attached to OctViews"); return OCT.ERROR; } return OCT.OK; } /** * Prints out debugging message if the debugFlag is set to true */ protected void Debug(String message) { if (debugFlag == true) System.out.println("OctCell: " + message); } }