com.funambol.syncml.client
Class TwoPhasesFileSyncSource

java.lang.Object
  extended by com.funambol.syncml.client.TrackableSyncSource
      extended by com.funambol.syncml.client.FileSyncSource
          extended by com.funambol.syncml.client.TwoPhasesFileSyncSource
All Implemented Interfaces:
SyncSource

public class TwoPhasesFileSyncSource
extends FileSyncSource

An implementation of TrackableSyncSource, providing the ability to sync briefcases (files). The source can handle both raw files and OMA files (file objects). By default the source formats items according to the OMA file object spec, but it is capable of receiving also raw files, if their MIME type is not OMA file objects.


Nested Class Summary
protected  class TwoPhasesFileSyncSource.EmptyFileSyncItem
           
protected  class TwoPhasesFileSyncSource.FileProperties
           
protected  class TwoPhasesFileSyncSource.ProxySyncListener
           
 
Nested classes/interfaces inherited from class com.funambol.syncml.client.FileSyncSource
FileSyncSource.FileSyncItem
 
Field Summary
protected  java.lang.String directory
           
protected  java.util.Hashtable itemsToDelete
           
protected  java.util.Vector itemsToUpload
           
protected  int numRetries
           
protected  TwoPhasesFileSyncSource.ProxySyncListener proxyListener
           
protected  SyncConfig syncConfig
           
protected  java.lang.String uploadUrl
           
 
Fields inherited from class com.funambol.syncml.client.FileSyncSource
extensions
 
Fields inherited from class com.funambol.syncml.client.TrackableSyncSource
allItems, config, delItems, filter, globalStatus, newItems, syncMode, tracker, updItems
 
Fields inherited from interface com.funambol.syncml.spds.SyncSource
ENCODING_B64, ENCODING_NONE, STATUS_CONNECTION_ERROR, STATUS_RECV_ERROR, STATUS_SEND_ERROR, STATUS_SERVER_ERROR, STATUS_SUCCESS
 
Constructor Summary
TwoPhasesFileSyncSource(SourceConfig config, ChangesTracker tracker, java.lang.String directory, SyncConfig syncConfig, java.lang.String uploadUrl)
          FileSyncSource constructor: initialize source config.
 
Method Summary
 int addItem(SyncItem item)
          Add an item to the local store.
 void beginSync(int syncMode)
          Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource.
protected  void closeFileProperties(TwoPhasesFileSyncSource.FileProperties fProp)
           
protected  HttpUploader createUploader(SyncConfig config, java.lang.String uploadUrl, java.lang.String sourceUri, SyncListener listener)
           
 void endSync()
          Called just before committing the synchronization process by the SyncManager.
protected  SyncItem getItemContent(SyncItem item)
          TODO: is this still needed? This is still kind of strange, we don't really need to get the item content any longer but we just need to create a proper item from which the content can be read
 SyncItem getNextDeletedItem()
          Returns a SyncItem containing the key of the first/next deleted item of the store (locally removed after the last sync, but not yet deleted on server)
protected  TwoPhasesFileSyncSource.FileProperties openFile(java.lang.String fileName)
          This method opens a file and store its input stream and size into a FileProperties object.
 void setItemStatus(java.lang.String key, int status)
          Tell the SyncSource the status returned by the server for an Item previously sent.
 int updateItem(SyncItem item)
          Update an item in the local store.
protected  void uploadItems()
           
 
Methods inherited from class com.funambol.syncml.client.FileSyncSource
applyFileObjectProperties, createSyncItem, deleteAllItems, deleteItem, filterFile, getAllItemsKeys, setSupportedExtensions
 
Methods inherited from class com.funambol.syncml.client.TrackableSyncSource
dataReceived, getClientAddNumber, getClientDeleteNumber, getClientItemsNumber, getClientReplaceNumber, getConfig, getEncoding, getFilter, getLastAnchor, getListener, getName, getNextAnchor, getNextItem, getNextNewItem, getNextUpdatedItem, getServerItemsNumber, getSourceUri, getStatus, getSyncMode, getTracker, getType, setConfig, setFilter, setLastAnchor, setListener, setNextAnchor, setServerItemsNumber, setTracker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numRetries

protected int numRetries

directory

protected java.lang.String directory

itemsToUpload

protected java.util.Vector itemsToUpload

uploadUrl

protected java.lang.String uploadUrl

proxyListener

protected TwoPhasesFileSyncSource.ProxySyncListener proxyListener

syncConfig

protected SyncConfig syncConfig

itemsToDelete

protected java.util.Hashtable itemsToDelete
Constructor Detail

TwoPhasesFileSyncSource

public TwoPhasesFileSyncSource(SourceConfig config,
                               ChangesTracker tracker,
                               java.lang.String directory,
                               SyncConfig syncConfig,
                               java.lang.String uploadUrl)
FileSyncSource constructor: initialize source config.

Parameters:
config - the source configuration
tracker - the changes tracker
directory - the directory containing the files
syncConfig - the SyncConfig. Note that this must be updated with the current credentials of the user. If this is not the case, then the method createUploader shall be redefined so that the HttpUploader is created with an updated SyncConfig
uploadUrl - the upload url suffix (this is added to the sync url)
Method Detail

beginSync

public void beginSync(int syncMode)
               throws SyncException
Description copied from interface: SyncSource
Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource. The implementation must reset the all/new/upd/del item lists when this method is called by the sync engine.

Specified by:
beginSync in interface SyncSource
Overrides:
beginSync in class FileSyncSource
Parameters:
syncMode - the synchronization type: one of the values in sync4j.framework.core.AlertCode
Throws:
SyncException - in case of error. This will stop the sync process

addItem

public int addItem(SyncItem item)
            throws SyncException
Add an item to the local store. The item has already been received and the content written into the output stream. The purpose of this method is to simply apply the file object meta data properties to the file used to store the output stream. In particular we set the proper name and modification timestamp.

Specified by:
addItem in interface SyncSource
Overrides:
addItem in class FileSyncSource
Parameters:
item - the received item
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if an error occurs while applying the file attributes

updateItem

public int updateItem(SyncItem item)
               throws SyncException
Update an item in the local store. The item has already been received and the content written into the output stream. The purpose of this method is to simply apply the file object meta data properties to the file used to store the output stream. In particular we set the proper name and modification timestamp.

Specified by:
updateItem in interface SyncSource
Overrides:
updateItem in class FileSyncSource
Parameters:
item - the received item
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if an error occurs while applying the file attributes

setItemStatus

public void setItemStatus(java.lang.String key,
                          int status)
                   throws SyncException
Description copied from interface: SyncSource
Tell the SyncSource the status returned by the server for an Item previously sent.

Specified by:
setItemStatus in interface SyncSource
Overrides:
setItemStatus in class TrackableSyncSource
Parameters:
key - the key of the item
status - the status code received for that item
Throws:
SyncException - if the SyncSource wants to stop the sync

getNextDeletedItem

public SyncItem getNextDeletedItem()
                            throws SyncException
Description copied from interface: SyncSource
Returns a SyncItem containing the key of the first/next deleted item of the store (locally removed after the last sync, but not yet deleted on server)

Specified by:
getNextDeletedItem in interface SyncSource
Overrides:
getNextDeletedItem in class TrackableSyncSource
Returns:
the first deleted item, in a SyncItem object, or null if no deleted items are present.
Throws:
SyncException

endSync

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

Specified by:
endSync in interface SyncSource
Overrides:
endSync in class TrackableSyncSource
Throws:
SyncException - in case of error, to stop the commit.

uploadItems

protected void uploadItems()
                    throws SyncException
Throws:
SyncException

openFile

protected TwoPhasesFileSyncSource.FileProperties openFile(java.lang.String fileName)
                                                   throws java.io.IOException
This method opens a file and store its input stream and size into a FileProperties object.

Parameters:
fileName - the file name
Returns:
a descriptor of the file (stream to read content and file size)
Throws:
java.io.IOException

closeFileProperties

protected void closeFileProperties(TwoPhasesFileSyncSource.FileProperties fProp)

createUploader

protected HttpUploader createUploader(SyncConfig config,
                                      java.lang.String uploadUrl,
                                      java.lang.String sourceUri,
                                      SyncListener listener)

getItemContent

protected SyncItem getItemContent(SyncItem item)
                           throws SyncException
TODO: is this still needed? This is still kind of strange, we don't really need to get the item content any longer but we just need to create a proper item from which the content can be read

Overrides:
getItemContent in class FileSyncSource
Throws:
SyncException


Copyright © 2001-2009 Funambol.