AddressBook Stores a Contact

Listing 2. This code is effectively the reverse of the code shown in Listing 1. The object's separate members must be added individually to fields in the ContactDatabase.

public boolean  createContact(
  ContactDetail theDetails)
{
  try
  {
    // Name in the order: Family name, given name
    AggregateField name = new AggregateField(
      ContactDatabase.N);
    name.addField(new ItemField(ContactDatabase.N,
      theDetails.getSurname())); 
    name.addField(new ItemField(ContactDatabase.N,
      theDetails.getName()));	

    // ROLE 
    ItemField role = new ItemField(
      ContactDatabase.ROLE,
      theDetails.getRole());

    // Work telephone number - TEL; TYPE=WORK
    ItemField workTel = new ItemField(
      ContactDatabase.TEL,
      theDetails.getWorkTel());
    workTel.addParameter(new Parameter(
      ContactDatabase.TYPE,
      ContactDatabase.WORK));
    workTel.addParameter(new Parameter(
      ContactDatabase.TYPE,
      ContactDatabase.VOICE));
    ... the code goes on for awhile ...