Sun Java System Mobile Enterprise Platform 1.0 Developer's Guide for Client Applications

Working with Business Objects on the File System

The MIDlet code typically allows users to create new objects and to edit or delete existing objects in disconnected mode, using the mobile device's file system without being connected to a server. The code commonly uses a combination of BusinessObject and BusinessObjectStorage methods to perform the following tasks:

Typically, a user on a client device performs a number of operations on the client device in disconnected mode, then logs in to the server and synchronizes the data.

Retrieving Objects for Editing

To allow users to view existing objects, the code commonly displays a list of names returned by the BusinessObjectStorage.listBusinessObjectNames method. This method retrieves a list of the names of all the business objects that have the file extension specified by the SyncManager constructor method. For example, the SecureJdbcMIDlet code calls the following method before populating a form with a list of albums:

Vector v = boStorage.listBusinessObjectNames();

To display a selected album, the SecureJdbcMIDlet code instantiates an Album object, using a name argument that represents the filename stripped of its ".alb" extension. The code then calls the BusinessObjectStorage.readBusinessObject method to read the data for the selected album from the file system into the Album object.

Album a = new Album(selectedAlbum.substring(0, selectedAlbum.length()-4));
boStorage.readBusinessObject(a);

The SecureJdbcMIDlet code then calls the getter methods for Album objects to retrieve the selected album's property values and display them in a form for editing.

Deleting Objects

To allow users to delete a selected album, the SecureJdbcMIDlet code calls the BusinessObjectStorage.deleteBusinessObject method with a String argument, the name of the album:

boStorage.deleteBusinessObject(selectedAlbum);

Saving Objects

To save a newly created or edited album, the SecureJdbcMIDlet code calls its saveAlbum method. This method instantiates an Album object and then calls the methods that set the album's properties, using Java ME GUI code to retrieve the values. Finally, the saveAlbum method calls the BusinessObjectStorage.writeBusinessObject method to save the album to the file system:

Album a = new Album();
...
boStorage.writeBusinessObject(a);