Home > Writing Samples > Coding Samples > AddressBook Manager [CS 277]

AddressBook Manager [Final Project]

December 2004

Source code summary
Background

Requirements: Use the AddressBook XML schema [AddressBook.xsd developed previously during the semester] and use Java to create a mechanism to add and edit contacts the AddressBook.xml XML file. [AddressBook.xsl is AddressBook’s stylesheet.]

Implementation

The project was implemented in Java as JavaServer Pages (JSPs) that parsed and managed the file as a DOM structure. The starting menu (ContactManagerHome.jsp) parses the AddressBook.xml and generates a list of names (first name, last name) from the addressbook and displays a link to Edit or Delete the contact, as shown in the following screenshot.

Teasing out the data from the XML file required many nested if statements due to the XML Schema and the wide variety of elements that might make up any Contact. For example, a contact might be married and have one (or more) children, and a single person might also have children. The code must also tease out multiple business addresses and other such variety that can make up a Contact. See findContact.jsp program listing for details.

Another issue was getting a contact’s children to display properly in the output form. I couldn't get the Children to display in the output form where I wanted them to, so you'll see that if a contact has children, the names and birthdays are at the top of the output, rather than at the bottom as I'd like them to be, as in the Add contact HTML page.

The project is contained in the addressbook.war file. To deploy on Tomcat, drop addressbook.war into the \webapps directory of a Tomcat server. Doing so creates an addressbook directory and all other structures for the application. Restart the Tomcat server if necessary.

Extra credit: In addition to JSP, implemented back-end as a Java Servlet (Servlet) that could be accessed by users from an HTML front page.

Conclusion

Choosing an approach was challenging. For user interface, should I use Swing components and create a full-fledged client, or create a Web-based UI? For the XML file itself, which of the many mechanisms is best? DOM? SAX? JAXB? The AddressBook project is a natural fit for SQL and an RDBMS, such as MySQL or PostgreSQL, and it would have been relatively easy to implement as such. But using XML as the basis was a great learning exercise, with hands-on experience with DTDs, XML Schema, Web Services (WSDL, SOAP), and creating Java (and Web) clients to invoke Web services and process results.