//package Persistent_Object; import java.util.Vector; /** * * PO_CommandConstructor Class * * This is a class which prepares the command/instructions * that are sent to the network server. * * @version 1.3 Mar 1997 * @author Francis Chan */ public class PO_CommandConstructor{ private String commandStr = null; //private PersistentObject po; private boolean debugFlag = true; /** * Constructor for PO_CommandConstructor */ public PO_CommandConstructor(){ //this.po = po; } /** * * Handles the construction of strings for multiple commands * * @param mode Mode of operation * @param userId DB identifier string * @param objectClassName Class Name of the object * @param objId Integer Id of the object * @param objectStrId String Id of the object * @param childId Id of the child object * @param relationship PO.PARENTS or PO.CHILDREN * @param version Versiong of the object requested, * A.B, or * "R" for last-Release or * "L" for latest version */ public String prepareCommandString(int mode, String userId, String objectClassName, int objId, String objectStrId, int childId, int relationship, String version){ switch (mode) { case PO.GETSTR: commandStr = "GETSTR\n\r"; break; case PO.GETID: commandStr = "GETID\n\r"; break; case PO.GETVERID: commandStr = "GETVERID\n\r"; break; case PO.DELETE: commandStr = "DELETE\n\r"; break; case PO.CONNECT: commandStr = "CONNECT\n\r"; break; case PO.DISCONNECT: commandStr = "DISCONNECT\n\r"; break; case PO.GETATTINFO: commandStr = "GETATTINFO\n\r"; break; } commandStr += userId; commandStr += "\n\r"; // slight differences for the Connect and Disconnect commands if ((mode == PO.CONNECT) || (mode == PO.DISCONNECT)) commandStr += objId; else commandStr += objectClassName; commandStr += "\n\r"; if ((mode == PO.CONNECT) || (mode == PO.DISCONNECT)) commandStr += childId; else if (mode == PO.GETSTR) commandStr += objectStrId; else commandStr += objId; // added information needed for the GetAttInfo command if (mode == PO.GETATTINFO) { if (relationship == PO.PARENTS) commandStr += "\n\rCONTAINER\n\r"; else commandStr += "\n\rCONTENTS\n\r"; commandStr += childId; } // added information needed for the GetVerId command if (mode == PO.GETVERID) { commandStr += "\n\r"; commandStr += version; } commandStr += "\n\r\n\r"; DEBUG("\n" + commandStr); return commandStr; } /** * * Prepare a Stream that contains the processed fields of the * object, used primary for saving objects * * @param mode Mode of operation (see PO.java) * @param userId DB identifier string * @param objectClassName Class Name of the object * @param objId Integer Id of the object * @param objectStrId String Id of the object * @param fieldVector Vector of the Object's fields info * @param fieldTypeArray Array of the Object's fields' types */ public String prepareSaveString(int mode, String userId, String objectClassName, int objId, String objectStrId, Vector fieldVector, int[] fieldTypeArray, int versionFlag){ // will use simple String for now // will investigate the use of more complicated structures // such as DataInputStream in the future switch (mode) { case PO.PUT: commandStr = "PUT\n\r"; break; case PO.MODIFY: commandStr = "MODIFY\n\r"; break; case PO.PUTVER: commandStr = "PUTVER\n\r"; break; } commandStr += userId; commandStr += "\n\r"; commandStr += objectClassName; commandStr += "\n\r"; if (mode == PO.MODIFY){ commandStr += objId; commandStr += "\n\r"; } // processing the fieldVector for (int i=0; i