import Worker; import java.lang.*; /** * This class encodes Database requests that the GUI will pass to the TCP/IP. * @version 1.0 * @author Graham Gelling * @author Heather Cougar * @author Thomas Barnhart * @date 04-26-99 * $Id: GUIEncoder.java,v 1.4 1999/05/10 01:47:20 barnhart Exp $ */ public class GUIEncoder { /** *This methods encodes a request for information as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"listByField1\nobjectType\nfieldname\npattern" */ public String listByField(int objectType, String fieldName, String pattern) { String str = new String(); String str2 = new String(); str = "listByField1"; str = str.concat("\n"); str = str.concat(str2.valueOf(objectType)); str = str.concat("\n"); str = str.concat(fieldName); str = str.concat("\n"); str = str.concat(pattern); return str; }//listByField(int, String, String) /** *This methods encodes a request for information as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"listByField2\nobjectType\nfieldname\npattern\noptional" */ public String listByField(int objectType, String fieldName, String pattern , String optional){ String str = new String(); String str2 = new String(); str = "listByField2"; str = str.concat("\n"); str = str.concat(str2.valueOf(objectType)); str = str.concat("\n"); str = str.concat(fieldName); str = str.concat("\n"); str = str.concat(pattern); str = str.concat("\n"); str = str.concat(optional); return str; }//listByField(int, String String String) /** *This methods encodes a request for all information as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"listAll\nobjectType\nfieldname" */ public String listAll(int objectType, String fieldName){ String str = new String(); String str2 = new String(); str = "listAll"; str = str.concat("\n"); str = str.concat(str2.valueOf(objectType)); str = str.concat("\n"); str = str.concat(fieldName); return str; }//listAll /** *This methods encodes a request for a DatabaseEntry as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"lookup\nkey" */ public String lookup(String key){ String str = new String(); str = "lookUp"; str = str.concat("\n"); str = str.concat(key); return str; }//lookup /** *These methods encodes an update to the Database as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"update\n...data..." */ public String update2(Artist newValues) throws Exception{ String str = new String(); Worker marx = new Worker(); str = "update2"; str = str.concat("\n"); str = str.concat(marx.artistToString(newValues)); return str; }//update(Artist) public String update1(Art newValues){ String str = new String(); Worker marx = new Worker(); str = "update1"; str = str.concat("\n"); str = str.concat(marx.artToString(newValues)); return str; }//update(Art) public String update3(Bidder newValues){ String str = new String(); Worker marx = new Worker(); str = "update3"; str = str.concat("\n"); str = str.concat(marx.bidderToString(newValues)); return str; }//update(Bidder) /** *This methods encodes an addition to the Database as a string. *pre: Parameters are properly initialized. *post: the initial data and fieldname are not changed *post: String returned in format *"add\nobjectType\n...data..." */ public String add(int objectType, DatabaseEntry newObject) throws Exception{ String str = new String(); Worker lenin = new Worker(); str = "add"; str = str.concat("\n"); switch(objectType){ case 2: str = str.concat("2"); str = str.concat("\n"); str = str.concat(lenin.artToString((Art)newObject)); break; case 11: str = str.concat("11"); str = str.concat("\n"); str = str.concat(lenin.artistToString((Artist)newObject)); break; case 12: str = str.concat("12"); str = str.concat("\n"); str = str.concat(lenin.bidderToString((Bidder)newObject)); break; }//switch return str; }//add }//public class GUIEncoder