// // TestClient.java // // WELD Java Client Persistent Object Management Package // Copyright Francis Chan (fchan@ic.eecs.berkeley.edu), 1997 // University of California, Berkeley // // // This program is in the public domain. // Permission to use, copy, modify, and distribute this software // and its documentation for NON-COMMERCIAL purposes and // without fee is hereby granted, as long as credit is given. /** * A applet to test some of the functionality * of the WELD client package */ import java.applet.Applet; import java.util.Vector; import java.net.Socket; import java.io.*; public class TestClient extends Applet{ int port = 7010; boolean debug = false; boolean testSave = false; boolean testLoad = false; String loc = new String(); // location for save/load tests boolean testLocal = false; // true - test as Java app // false - test as Java applet public static void main(String argv[]){ System.out.println("Test WELD Client Package Applet"); TestClient tc = new TestClient(); if (argv[0].compareTo("7010") == 0) tc.port = 7010; if (argv[0].compareTo("7011") == 0) tc.port = 7011; if (argv[0].compareTo("7012") == 0) tc.port = 7012; if (argv[0].compareTo("7013") == 0) tc.port = 7013; if (argv[0].compareTo("7014") == 0) tc.port = 7014; if (argv[0].compareTo("7015") == 0) tc.port = 7015; if (argv[1].compareTo("Y") == 0) tc.debug = true; if (argv[2].compareTo("Y") == 0) tc.testLocal = true; if (argv[3].compareTo("Y") == 0) tc.testSave = true; if (argv[4].compareTo("Y") == 0) tc.testLoad = true; tc.loc = argv[5]; tc.init(); tc.stop(); } public void init(){ DirObject dSetup = new DirObject(); if (testLocal != true){ if (getParameter("Debug") != null) if (getParameter("Debug").compareTo("Y") == 0) debug = true; if (getParameter("Server") != null) dSetup.setServer(getParameter("Server")); // sets up the server // default as yoyodyne.eecs.berkeley.edu if (getParameter("TestSave") != null) if (getParameter("TestSave").compareTo("Y") == 0) testSave = true; if (getParameter("TestLoad") != null) if (getParameter("TestLoad").compareTo("Y") == 0) testLoad = true; if (getParameter("LocName") != null){ loc = getParameter("LocName"); } else { System.out.println("No Parameter LocName supplied for testing -- exiting..."); System.exit(0); } } /* System.out.println("debug, server, testSave, testLoad, loc:\n" + getParameter("Debug") + "\n" + getParameter("Server") + "\n" + testSave + "\n" + testLoad + "\n" + loc); */ dSetup.setPort(port); // sets the port number dSetup.setDebug(debug); // sets the debug (message) flag if (testSave == true){ String testSaveStr = new String(); for (int i=0; i<1500; i++){ testSaveStr += TestData.data.charAt(i); } DataObject testSaveDataObject = new DataObject(loc, testSaveStr); DirObject rootDir = new DirObject(); // creates "hollow" Directory DirObject tempDir = new DirObject(); // objects rootDir.getRoot(); // load root directory tempDir.load("/temp"); // load temp directory // which is situated below // root, as indicated by the // "/" prefix rootDir.attach(tempDir); // attach the dir to root tempDir.attach(testSaveDataObject); // attach the target DataObject rootDir.save(); // save root directory // the save propogates to // all the objects attached } if (testLoad == true){ DataObject testLoadDataObject = new DataObject(); testLoadDataObject.load("/temp/" + loc); // loads the object at /temp/some_name // (root->temp->object_name System.out.println("\n" + testLoadDataObject.getContent()); } } }