Sun GlassFish Mobility Platform 1.1 Developer's Guide for Client Applications

The SyncManager Class

Table 4–10 lists the constructors and methods belonging to the SyncManager class. This class is responsible for managing synchronizations with the gateway server for a particular kind of BusinessObject (classified by a particular extension). There is a one-to-one mapping between SyncManager and kinds of BusinessObject instances. If you have an application that deals with two different BusinessObject types, then you would have an instance of SyncManager for each type.

You must specify a unique extension for your BusinessObject when you construct this class. The name field in the BusinessObject, combined with the extension, will determine the entire name of the file on the device's filesystem. For example, you might pass the string ".act" for account or ".ord" for orders, but it can be anything legally allowed in a file name.

You may optionally enable on-device security features by supplying an instance of SecurityManager during construction.

An invocation of the sync(SyncType) method initiates a synchronization session with the gateway server. During this session, only BusinessObject instances whose extension fields match will be synchronized.

The default encoding type used in the SyncML protocol messages is EncodingType.XML, but you can select EncodingType.WBXML by using the setEncoding method.

You should explicitly specify a file system root (see FileSystemRegistry.listRoots() in JSR-75: Optional Packages for the J2ME Platform for a discussion of roots). If you do not, a default root will be selected for you.

Table 4–10 Class com.sun.mep.client.api.SyncManager

Method 

Description 

public SyncManager(java.lang.String extension)

Constructor that creates a new SyncManager for the specified business object type (extension) with no SecurityManager. This method is the equivalent of calling new SyncManager(extension, null).

public SyncManager(java.lang.String extension, SecurityManager sm)

Constructor that creates a new SyncManager for the specified business object type (extension) and uses the specified SecurityManager.

public SyncManager(java.lang.String extension, SecurityManager sm, java.lang.String fsRoot)

Constructor that creates a new SyncManager for the specified business object type (extension) with the specified SecurityManager and device-specific file system root. The file system root must follow the syntax described in FileSystemRegistry.listRoots in JSR-75 (the root should not include the file:/// protocol).

public SyncManager(java.lang.String extension, java.lang.String fsRoot)

Constructor that creates a new SyncManager for the specified business object type (extension) with no SecurityManager using the specified device-specific file system root. The file system root must follow the syntax described inFileSystemRegistry.listRoots in JSR-75 (the root should not include the file:/// protocol).

public void enableLogging(boolean value)

Enables or disables debug logging in the MEP client APIs. If enabled, the MEP implementation library writes logging information to stdout and also to a log file (named meplog.txt) on the device. Logging is disabled by default.

public BusinessObjectStorage getBusinessObjectStorage()

Returns the BusinessObjectStorage manager associated with this SyncManager. There is a strict 1:1 relationship between SyncManager and BusinessObjectStorage.

public EncodingType getEncoding()

Returns the current transport encoding type. 

public java.lang.String getExtension()

Returns the extension type associated with this SyncManager.

public java.lang.String getFilesystemRoot()

Returns the file system root being used by this SyncManager to store business objects.

public java.util.Hashtable getProperties()

Return a live Hashtable containing application Experimental Meta Information (EMI) SyncML properties. Any modifications to the hashtable will be immediately applied to the underlying storage; you are not operating on a clone. You should treat the return type as Hashtable<String,String>. The properties will be serialized as key.toString() + "=" + value.toString().

Refer to the SyncML protocol specifications for more information on EMI. 

public static final SecurityManager getSecurityManager()

Returns a reference to the security manager, or null if one has not been set. 

public SyncResults getSyncResults()

Returns the sync results for the latest successful sync. 

public long getTimeOfLastSync()

Returns a time stamp of the last successful sync. This time stamp is recorded by calling System.currentTimeMillis(), so it is an offset from January 1, 1970 UTC. If a sync has not been performed yet, the method returns a negative value.

public void setCredentials(java.lang.String username, java.lang.String password, java.lang.String url)

Sets the credentials used during the synchronization process. 

public void setEncoding(EncodingType encoding)

Sets the transport encoding type. The encoding must be one of the fields defined in EncodingType; it must not be null.

public void sync(SyncType syncType)

Performs the specified type of synchronization.