com.funambol.syncml.client
Class FileSyncSource

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

public class FileSyncSource
extends TrackableSyncSource

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 FileSyncSource.FileSyncItem
           
 
Field Summary
protected  java.lang.String directory
           
protected  java.lang.String[] 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
FileSyncSource(SourceConfig config, ChangesTracker tracker, java.lang.String directory)
          FileSyncSource constructor: initialize source config
 
Method Summary
 int addItem(SyncItem item)
          Add an item to the local store.
protected  void applyFileObjectProperties(FileSyncSource.FileSyncItem fsi, FileObjectOutputStream foos)
           
 void beginSync(int syncMode)
          Called after SyncManager preparation and initialization just before start the synchronization of the SyncSource.
 SyncItem createSyncItem(java.lang.String key, java.lang.String type, char state, java.lang.String parent, long size)
          Creates a new SyncItem for the engine to store incoming items
protected  void deleteAllItems()
          Physically delete all items
 int deleteItem(java.lang.String key)
          Delete an item from the local store.
 boolean filterFile(java.lang.String name)
          Return whether a given filename is filtered by the SyncSource.
protected  java.util.Enumeration getAllItemsKeys()
           
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
 void setSupportedExtensions(java.lang.String[] extensions)
           
 int updateItem(SyncItem item)
          Update an item in the local store.
 
Methods inherited from class com.funambol.syncml.client.TrackableSyncSource
dataReceived, endSync, getClientAddNumber, getClientDeleteNumber, getClientItemsNumber, getClientReplaceNumber, getConfig, getEncoding, getFilter, getLastAnchor, getListener, getName, getNextAnchor, getNextDeletedItem, getNextItem, getNextNewItem, getNextUpdatedItem, getServerItemsNumber, getSourceUri, getStatus, getSyncMode, getTracker, getType, setConfig, setFilter, setItemStatus, 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

directory

protected java.lang.String directory

extensions

protected java.lang.String[] extensions
Constructor Detail

FileSyncSource

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

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 TrackableSyncSource
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

getAllItemsKeys

protected java.util.Enumeration getAllItemsKeys()
                                         throws SyncException
Specified by:
getAllItemsKeys in class TrackableSyncSource
Throws:
SyncException

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 TrackableSyncSource
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 TrackableSyncSource
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

deleteItem

public int deleteItem(java.lang.String key)
               throws SyncException
Delete an item from the local store.

Specified by:
deleteItem in interface SyncSource
Overrides:
deleteItem in class TrackableSyncSource
Parameters:
key - the item key
Returns:
SUCCESS if the tracker was successfully updated, GENERIC_ERROR otherwise
Throws:
SyncException - if the operation fails for any reason

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

Specified by:
getItemContent in class TrackableSyncSource
Throws:
SyncException

createSyncItem

public SyncItem createSyncItem(java.lang.String key,
                               java.lang.String type,
                               char state,
                               java.lang.String parent,
                               long size)
                        throws SyncException
Description copied from class: TrackableSyncSource
Creates a new SyncItem for the engine to store incoming items

Specified by:
createSyncItem in interface SyncSource
Overrides:
createSyncItem in class TrackableSyncSource
Parameters:
key - is the item key
type - is the item type
state - this item's state
parent - is the item's parent
size - is the item size
Throws:
SyncException

applyFileObjectProperties

protected void applyFileObjectProperties(FileSyncSource.FileSyncItem fsi,
                                         FileObjectOutputStream foos)
                                  throws java.io.IOException
Throws:
java.io.IOException

deleteAllItems

protected void deleteAllItems()
Description copied from class: TrackableSyncSource
Physically delete all items

Specified by:
deleteAllItems in class TrackableSyncSource

setSupportedExtensions

public void setSupportedExtensions(java.lang.String[] extensions)

filterFile

public boolean filterFile(java.lang.String name)
Return whether a given filename is filtered by the SyncSource.

Parameters:
filename -
Returns:
true if the given filename is actually filtered by the SyncSource.


Copyright © 2001-2009 Funambol.