Java™-based development framework for PalmOS™ devices (PDAs) Copyright© 2000 by Bernd R. Fix. All Rights Reserved. |
|
DynaWorks TutorialHow to write applications with the DynaWorks framework |
Conduit development in Java for DynaWorks databases |
||||
Writing an application for the Palm that uses custom DynaWorks
databases is just half of the job - you usually want to save these databases during a HotSync
process to your desktop machine for further processing. The module that links to the HotSync™ Manager and that is activated during a HotSync™ process is called a conduit. The Palm HotSync Manager allows us developers to write custom conduits so you can transfer the data from and to your custom databases on the Palm device. If you use the "Conduit Development Kit for Java" you can even write these conduits in the Java programming language. The following sections describe how to write a conduit for your custom DynaWorks database and how to re-use your Record class for the desktop-side conduit.
|
|
Neccessary preparations |
||||
Before you can start to use the DynaWorks framework for the conduit development, you have to prepare your machine for that: | ||||
A conduit skeleton |
||||
Developing a conduit in Java is fairly easy. Let's have a look on a minimal (compilable) conduit: |
import palm.conduit.*; public class PalmSync implements Conduit { public void open (SyncProperties props){ } public String name() { return "MyConduit"; } public int configure (ConfigureConduitInfo info) { return 0; } } |
There are three methods that must be implemented:
// open custom database byte flags = (byte)(SyncManager.OPEN_READ | SyncManager.OPEN_WRITE | SyncManager.OPEN_EXCLUSIVE); int db = SyncManager.openDB (props.remoteNames[0], (short)0, flags); // find out how many memo records there are int count = SyncManager.getDBRecordCount (db); |
Please notice: I had quite a bit of trouble on my developer machine - the source code above compiled fine but I got an exception during HotSync (read the protocol!) because the 'props.remoteNames[]' array is always empty. And the registry variable "Remote0" is definitely set and correct. I could fix that problem on my machine only by replacing the argument 'props.remoteNames[0]' by "Test" (the actual database name). If you encounter a similar behaviour, please let me know.
A record that can be retrieved from such a SyncManager database must confirm to the palm.conduit.Record interface. This interface defines a set of methods you have to implement for your own record classes.
If you want to access build-in databases you can use the classes that come with the CDK4J. If you have developed custom databases with the DynaDb framework, the easiest way is to re-use your record class you used in the Palm application.
What we need to do is to "wrap" another class around MyRecord so that the new class behaves like a record that can be managed by the SyncManager class. The wrapper also make sure that the MyRecord part is always up-to-date.
The following code shows this "wrapper" process for the class MyRecord:
public class CMyRecord extends MyRecord implements Record { ///////////////////////////////////////////////////////////////// /** * inner class that implements the basic Record methods. */ private class Delegate extends AbstractRecord { : /** * instance of the delegation class. */ private Delegate theDelegate; } |
Look at the full source code |
The AbstractRecord is part of the Conduit Development Kit for Java, so make sute you have downloaded and installed that software package.
public void open (SyncProperties props){ // Tell the log we are starting Log.startSync(); : } |
Look at the full source code |
So, a CMyRecord behaves like a MyRecord when it comes to data retreival. This makes it easy to exchange data between Palm an Desktop because you can use the same Record class on both platforms.
One last advice: Make sure that your dialog runs in a separate thread; otherwise it would lock the SyncManager thread, leading to 'irritating' redraw problems in the dialog of the HotSync Manager.
In order to use the conduit with the desktop HotSync Manager you will have to register it. Please terminate any running HotSync Manager on the desktop machine and insert the following definitions into the Windows registry (adapt to your directory structure). You find these settings in the file Conduit.reg:
REGEDIT4 [HKEY_CURRENT_USER\Software\U.S. Robotics\Pilot Desktop\ApplicationMyDbApp] "Name"="MyDbApp Conduit" "Conduit"="jsync.dll" "ClassName"="PalmSync" "ClassPath"="c:\\pilot\\MyDbApp\\Conduit.jar" "VM"="SUN" "Creator"=dword:4D594150 "Directory"="c:\\pilot\\MyDbApp" "File0"="MyDbApp.txt" "Priority"=dword:00000001 "Remote0"="Test" |
Restart the HotSync Manager. If the conduit is correctly registered, you will see it in the conduit list of the HotSync Manager.
Now you are ready to try out the conduit.