You will be implementing an object-oriented database: that is, all of the data will be stored as Java objects. As you know, Java objects are not normally persistent: they disappear when the execution environment terminates.
In order to use Java objects as a database, you will have to somehow make them persistent. In this assignment, you will do this in two different ways.
One approach to object persistence is to store the objects in some
encoded-text form. XML provides a reasonable framework for doing this,
with a simple tag-pair and parameter syntax. I have written a Java class
that will read in an object description in a simple XML-structured file
and return the parsed results in a collection of objects that may be easily
traversed to create a new instance of the object described by the XML.
I have also written an example program showing how to use the XML parser
to reconstruct objects from the parsed descriptions.
Here is a simple object class for storing customer information:
public class Customer
{
public String name; // Customer name
public String address; // Customer address
public Vector phoneNumbers; // Contains String objects
}
We need a place to put all of the customers:
public class Database
{
public Vector customers; // Contains Customer objects
}
Here is the tar file with everything in it. Please use this:
Here is the example code:
Here is a test dataset to use with the example code:
John Smith; 123 Main St, New Brunswick, NJ; 555-1223, 555-1234 June Allen; 112 New St, Piscataway, NJ; 555-2212 Robert Jones; 121 First St, So. Plainfield, NJ; 555-1919, 555-3333, 555-2231 Julie Patel; 443 Last Rd, Washington, NJ; 555-9233
Java provides a method for storing and retrieving objects using
so-called ``lightweight persistence''. Here is an example of this from
the Eckel book, chapter 10: