On completion of this lab you should be able to:
Store objects into XML files and retrieve them from XML files (using ShopV4.0 as a starting point).
Apply this XML knowledge to another domain i.e. the DVD library.
Include Exception handling for invalid user input.
In this practical, you will create a new project called ShopV4.0 in Eclipse and refactor the code so that persistence is fully implemented for the prodcuts collection. This will be the menu you will finally end up with:
Create a new project called ShopV4.0 and copy the three java files from ShopV3.0 into it.
The solution to the ShopV3.0 exercise is here should you need it.
Download the xstream-1.4.8.jar component.
In Eclipse Package Explorer, create a new folder "lib“ (select "File->New->Folder“)
Drag the xstream-1.4.8.jar component into the lib folder (choose the option to copy the file).
Your project structure should now look like this:
Right click on the xstream-1.4.8.jar file and select: "Build Path->Add to Build Path".
Your project structure should now look like this:
import java.io.FileReader;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
Create a new project in Eclipse, called DVDLibraryV3.0.
Copy the src java code from DVDLibraryV2.0 into it.
You will now extend the code to allow the user to save and load DVDs (note that the solution to DVD version 2 is in the solutions tab, should you need it).
Download the xstream-1.4.8.jar component.
In Eclipse Package Explorer, create a new folder "lib“ (select "File->New->Folder“)
Drag the xstream-1.4.8.jar component into the lib folder (choose the option to copy the file).
import java.io.FileReader;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;