com.micromail
Class AddressBook

java.lang.Object
  extended bycom.micromail.AddressBook

public class AddressBook
extends java.lang.Object

Represents the user's address book in the SQL database. Each user's address book occupies a single table with a name formed from the user's login name, prefixed by "addr_", and with dots replaced by dollar signs ('$'). Entries in the table are read and cached by this object. Additions or updates are written through to the database


Nested Class Summary
 class AddressBook.Address
          Represents an individual address book entry
 
Constructor Summary
AddressBook()
           
AddressBook(java.lang.String userId, java.lang.String username, javax.sql.DataSource dataSource)
          Creates an AddressBook.
 
Method Summary
 void addAddress(java.lang.String name, java.lang.String email, java.lang.String additionalInfo)
          Adds a new address to the address book, or overwrites an old version
 boolean addressExists(java.lang.String name)
          Determines if an address book entry exists for a specified name
 void deleteAddress(java.lang.String name)
          Removes the address book entry for a spcified name
 AddressBook.Address getAddress(java.lang.String name)
          Gets the Address object for a specified name
 java.util.Iterator getAddresses()
          Gets an Iterator across the map of Address objects
 java.lang.String getMyAddress()
          Gets the email address of the logged in user
 java.lang.String getMyName()
          Gets the personal name of the logged in user
 boolean isNew()
          Determines if the address book is a new empty one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddressBook

public AddressBook()

AddressBook

public AddressBook(java.lang.String userId,
                   java.lang.String username,
                   javax.sql.DataSource dataSource)
            throws javax.servlet.ServletException
Creates an AddressBook. If the database table containin the address book does not yet exists, it is created

Parameters:
userId - the login name of the user with special characters replaced by '$'
username - the user's login name, which is their email address
Method Detail

isNew

public boolean isNew()
Determines if the address book is a new empty one.

Returns:
true if it is new

getAddresses

public java.util.Iterator getAddresses()
Gets an Iterator across the map of Address objects

Returns:
the iterator

getAddress

public AddressBook.Address getAddress(java.lang.String name)
Gets the Address object for a specified name

Parameters:
name - the name

addressExists

public boolean addressExists(java.lang.String name)
Determines if an address book entry exists for a specified name

Parameters:
name - the name
Returns:
true if there is an entry for the name

deleteAddress

public void deleteAddress(java.lang.String name)
                   throws java.sql.SQLException
Removes the address book entry for a spcified name

Parameters:
name - the name
Throws:
java.sql.SQLException

addAddress

public void addAddress(java.lang.String name,
                       java.lang.String email,
                       java.lang.String additionalInfo)
                throws java.sql.SQLException
Adds a new address to the address book, or overwrites an old version

Parameters:
name - the name
email - the email address
additionalInfo - optional additional information
Throws:
java.sql.SQLException

getMyAddress

public java.lang.String getMyAddress()
Gets the email address of the logged in user

Returns:
a string containing the email address

getMyName

public java.lang.String getMyName()
Gets the personal name of the logged in user

Returns:
a string containing the personal name