Getting Personal with J2ME's PIM API
by Tom Thompson

Listing One

PIM          pim;
try {
    ContactList cl = (ContactList)
        PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
    } catch (Exception ex) {
     System.out.println ("Error on getting list\n");
} // end catch


Listing Two

PIM             pim;
ContactList     cList;
EventList       eList;
ToDoList        tList;

try {
    pim = PIM.getInstance();    // get instance of PIM
// Open all default PIM lists
    cList = (ContactList) pim.getInstance().openPIMList(PIM.CONTACT_LIST,
                                                        PIM.READ_WRITE);
    eList = (EventList) pim.getInstance().openPIMList(PIM.EVENT_LIST,
                                                      PIM.READ_WRITE);
    tList = (ToDoList) pim.getInstance().openPIMList(PIM.TODO_LIST,
                                                      PIM.READ_WRITE);
} catch (Exception ex) {
     System.out.println ("Error on getting lists\n");
} // end catch


Listing 3

// Open the default ContactList, read/write mode
PIMList thisList = PIM.getInstance().openPIMList(PIM.CONTACT_LIST,
                                                  PIM.READ_WRITE);

// Loop to gather up the ContactList's Contacts
for (Enumeration items = thisList.items(); items.hasMoreElements();) {
    PIMItem item = (PIMItem) items.nextElement();  // Get the Contact
    int fieldCode = Contact.FORMATTED_NAME;              // Supply the field
name
    String label = null;

    if (item.countValues(fieldCode) != 0) {        // Check for a value
        String s = item.getString(fieldCode, 0);   // Fetch the value
        if (s != null && s.trim().length() != 0) { // Clean it up
            label = s;
        } // end if
    } // end if

// Warn of missing data
    if (label == null) {
        label = "<Incomplete data>";
    } // end if
} // end for


