com.funambol.common.pim
Class PIMSyncSource

java.lang.Object
  extended by TrackableSyncSource
      extended by com.funambol.common.pim.PIMSyncSource
Direct Known Subclasses:
ContactSyncSource, EventSyncSource

public abstract class PIMSyncSource
extends TrackableSyncSource

Basic sync source for PIM sync management. This class is the base class for all classes manipulating JSR75 PIM data (such as Contact, Calendar and so on). The class is a TrackableSyncSource, so that the tracking mechanism can be easily customized by clients (default is CacheTracking, based on items finger prints).


Field Summary
protected  int globalStatus
          Status of the sync source summarized in an integer value.
protected  PIMList list
           
protected  int totalAdded
           
protected  int totalDeleted
           
protected  int totalDeletedSent
           
protected  int totalNewSent
           
protected  int totalUpdated
           
protected  int totalUpdatedSent
           
 
Constructor Summary
PIMSyncSource(SourceConfig config, PIMList list, ChangesTracker tracker)
           
 
Method Summary
 int addItem(SyncItem item)
           
 void beginSync(int syncMode)
           
protected  void clearItem(PIMItem item)
           
protected abstract  PIMItem createItem(java.lang.String content)
          Creates a single item in the proper PIMList
 void dataReceived(java.lang.String date, int size)
           
 void deleteAllItems()
           
 int deleteItem(java.lang.String key)
           
 void endSync()
          Called just before committing the synchronization process by the SyncManager.
protected abstract  void fillItem(PIMItem pitem, java.lang.String content)
          Fills an item according to a textual representation of the same item.
protected  PIMItem findItem(java.lang.String key)
          Finds an item in the source.
protected abstract  byte[] formatItem(PIMItem item)
          Formats an item according to the format supported by the sync source.
protected  java.util.Enumeration getAllItemsKeys()
           
protected  SyncItem getItemContent(SyncItem item)
           
protected  java.lang.String getLuidFromUID(java.lang.String uid)
          By default UID and Luid are the same.
protected abstract  int[] getSupportedFields()
          Get the list of supported fields.
protected  java.lang.String getUID(PIMItem item)
           
protected abstract  int getUIDField()
          Get the value of the UID field.
 int updateItem(SyncItem item)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalAdded

protected int totalAdded

totalUpdated

protected int totalUpdated

totalDeleted

protected int totalDeleted

totalNewSent

protected int totalNewSent

totalUpdatedSent

protected int totalUpdatedSent

totalDeletedSent

protected int totalDeletedSent

globalStatus

protected int globalStatus
Status of the sync source summarized in an integer value. See constants defined in SyncSource


list

protected PIMList list
Constructor Detail

PIMSyncSource

public PIMSyncSource(SourceConfig config,
                     PIMList list,
                     ChangesTracker tracker)
Method Detail

beginSync

public void beginSync(int syncMode)
               throws SyncException
Throws:
SyncException

endSync

public void endSync()
             throws SyncException
Called just before committing the synchronization process by the SyncManager. The SyncSource can stop the commit phase raising an exception here.

Throws:
SyncException - in case of error, to stop the commit.

dataReceived

public void dataReceived(java.lang.String date,
                         int size)

addItem

public int addItem(SyncItem item)
            throws SyncException
Throws:
SyncException

updateItem

public int updateItem(SyncItem item)
               throws SyncException
Throws:
SyncException

deleteItem

public int deleteItem(java.lang.String key)
               throws SyncException
Throws:
SyncException

deleteAllItems

public void deleteAllItems()
                    throws SyncException
Throws:
SyncException

getItemContent

protected SyncItem getItemContent(SyncItem item)
                           throws SyncException
Throws:
SyncException

getAllItemsKeys

protected java.util.Enumeration getAllItemsKeys()
                                         throws SyncException
Throws:
SyncException

clearItem

protected void clearItem(PIMItem item)
                  throws PIMException
Throws:
PIMException

findItem

protected PIMItem findItem(java.lang.String key)
                    throws PIMException
Finds an item in the source. The item is searched by its key.

Returns:
the item PIM representation or null if not found
Throws:
PIMException - on error, for example if the list of items cannot be accessed

getLuidFromUID

protected java.lang.String getLuidFromUID(java.lang.String uid)
By default UID and Luid are the same. This method can be overloaded by subclasses that want different values for luids and uids


getUID

protected java.lang.String getUID(PIMItem item)
                           throws PIMException
Throws:
PIMException

createItem

protected abstract PIMItem createItem(java.lang.String content)
                               throws PIMException
Creates a single item in the proper PIMList

Parameters:
content - is the item in the sync source standard format (could be a vCard, SIF-C or any other valid format).
Returns:
a PIMItem representing the given item
Throws:
PIMException - if the PIMItem cannot be created (for example if the textual representation is invalid, or no new items can be added to the list)

getSupportedFields

protected abstract int[] getSupportedFields()
Get the list of supported fields. This method is needed by the clearItem method. If a derived class redefines the clearItem, then it does not need to give a meaningful implementation of this method (may return null).


getUIDField

protected abstract int getUIDField()
Get the value of the UID field. Each PIM Item has the concept of UID which distinguish each PIMItem. This method returns the UID field id. This method is needed by the clearItem method. If a derived class redefines the clearItem, then it does not need to give a meaningful implementation of this method (may return null).


formatItem

protected abstract byte[] formatItem(PIMItem item)
                              throws PIMException
Formats an item according to the format supported by the sync source. The item is formatted as a stream of bytes ready to be exchanged with the DS server.

Parameters:
item - the item (cannot be null)
Returns:
an array of byte representing the incoming item
Throws:
PIMException - if the item cannot be formatted

fillItem

protected abstract void fillItem(PIMItem pitem,
                                 java.lang.String content)
                          throws PIMException
Fills an item according to a textual representation of the same item. The actual format depends on the sync source. A contact could be for example represented as a vCard and thus parsed to geneate a Contact object.

Parameters:
pitem - is the object to be filled
content - is the item textual representation
Throws:
PIMException - if the item cannot be parsed


Copyright © 2001-2009 Funambol.