Search |
||
Developing MEP Client Applications - Part 1Posted by ryan_shoemaker on August 20, 2008 at 8:25 AM PDT
In my previous post, we took a closer look at the MCBO API and all of its features. Now it is time to show how to use the APIs to develop an MEP client application.
In Part 1, we will focus on the fundamentals of the API: creating a SyncManager, initiating a sync, and examining the sync results. In part 2, we will study the security features provided in the client API.
MusicDB Sample AppWe'll be examining the MCBO API within the context of the "MusicDB" sample app that ships with MEP v1.0. This sample client is able to synchronize basic music album data with a JDBC back-end. For more information about how the MEP connector was developed for this sample app, please follow Santiago's blog about using the ECBO API to develop MEP connectors. The source code for the MusicDB client application is available for download in the MEP client bundle.
Data ModelOne of MEP's strongest features is that it is completely agnostic about your data model. As long as you can figure out how to serialize your BusinessObjects, MEP will be able to sync the data with the MEP gateway server. In the case of the MusicDB sample app, we are sending some very basic album data back and forth to the JDBC back-end: album name, artist name, date, and rating. Let's take a look at how to implement a BusinessObject to manage this data model.
Implementing A BusinessObjectThere are only a few steps required to implement your business object:
The class definition and bean properties look like this:
Each business object must have a unique name which is stored in the 'name' field of the BusinessObject base-class. Since the business objects are stored on the mobile device's filesystem, there is a restriction that the name must be a unique identifier that can be used as a file name. In order to differentiate between different kinds of business objects, you must also assign a unique extension. For the "Album" business object type, we've choosen ".alb" by implementing the getExtension() method like this:
The combination of the unique name of each instance of Album and the extension will determine the name of the object stored on the mobile device's filesystem. Implementing the getters and setters for the bean properties is as simple as:
The business object's name field is immutable - once you set the object's name, you can not change it. All business objects must provide the ability to serialize and deserialized to a byte array. The actual format used for serialization is open ended, but must be part of the contract between the connector and the mobile client application. For music albums, serialization is implemented using DataOutputStream and DataInputStream:
You can see that there is a special token 'DEFAULT_VALUE' which is used to determine when Album fields are not set. There is also some helper code for parsing the date format. Reading and Writing Business ObjectsIn order to store and retrieve instances of your business objects on the mobile device, you must use the BusinessObjectStorage class. It provides some high-level APIs to read, write, enumerate, and delete business object instances.In the MusicDB sample, business objects are read like this: and written like this:
SyncManagerSyncManager is responsible for mangining the synchronization of a particular class of business objects with the MEP gateway server. There is a 1:1 relationship between instances of SyncManager and classes of business objects. In the case of MusicDB, we only have one kind of business object - Album (*.alb). To create the SyncManager, you simply construct it and specify the business object extension. SyncManager also serves as a factory for BusinessObjectStorage and it also manages the MEP gateway server address and sync credentials:
Performing a SynchronizationWhen you're ready to perform a synchronization, all you have to do is call the sync method on SyncManager and tell it which kind of synchronization to perform. The different kinds of sync types are available in an enum called SyncType. Initiating a fast sync would look like this:
Looking at the SyncResultsAssuming the call to sync returns without throwing an exception, you can now examine the sync results which are contained in an instance of SyncResults and draw them on the UI:That wraps up all of the basic functionality provided in the MCBO API. In the next entry, we will take a closer look at all of the security features available in the API. Stay tuned... »
Related Topics >>
Glassfish Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|