com.funambol.mail
Class RMSStore

java.lang.Object
  extended by com.funambol.mail.RMSStore
All Implemented Interfaces:
Store

public class RMSStore
extends java.lang.Object
implements Store

Implements the Store using J2ME RecordStore.

A folder is mapped to a RecordStore with name equal to the full path of the folder, and the messages inside the folder are the records inside that RecordStore.

It uses NamedObjectStore to speed up the record access by messageId.


Field Summary
 
Fields inherited from interface com.funambol.mail.Store
DRAFTS, INBOX, OUTBOX, SENT, TRASH
 
Method Summary
 int countMessages(java.lang.String path)
          This method returns the message count in this Store.
 Folder createFolder(java.lang.String path)
          This method creates a folder in the record store.
 Folder[] findFolders(java.lang.String subst)
          This method returns the list of the folders whose path matches subst.
 Folder getFolder(java.lang.String path)
          This method returns the folder whose name is exactly path.
 java.lang.String[] getMessageIDs(java.lang.String path)
          This method returns the messageIDs of all the messages in the folder path.
 Message[] getMsgHeaders(java.lang.String path)
          This method returns the headers of all the messages in the folder path.
 void init(boolean reset)
          Initialize the message store, creating the main folders.
 Folder[] list()
          This method returns the list of the top level folders in this store.
 Folder[] list(java.lang.String path)
          This method returns the list of the folders whose path starts with 'path' and are direct subfolders of it.
 Message readMessage(java.lang.String path, Message msg)
          This method reads the complete message from the Store.
 Message readMessage(java.lang.String path, java.lang.String messageId)
          This method reads a message from the Store, using the message Id.
 boolean removeFolder(java.lang.String path)
          This method removes a folder from the record store.
 void removeMessage(java.lang.String path, java.lang.String messageId)
          This method removes a Message from the Store, using message ID as index.
 void saveMessage(java.lang.String path, Message msg)
          This method saves a message in the Store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public void init(boolean reset)
          throws StoreException
Initialize the message store, creating the main folders.

Specified by:
init in interface Store
Parameters:
reset - if true, erase and re-create all the main folders.
Throws:
StoreException

list

public Folder[] list()
This method returns the list of the top level folders in this store.

Specified by:
list in interface Store
Returns:
an array of folders, or null if the store is empty.

list

public Folder[] list(java.lang.String path)
              throws StoreException
This method returns the list of the folders whose path starts with 'path' and are direct subfolders of it.

Specified by:
list in interface Store
Parameters:
path - the path of the parent folder
Returns:
an array of folders, or null if path has no subfolders.
Throws:
StoreException - If the path is not valid

createFolder

public Folder createFolder(java.lang.String path)
                    throws StoreException
This method creates a folder in the record store. The names of the folder must start with a "/" to distinguish them (they are record stores) from other record stores. The method add the leading slash if not present.

Specified by:
createFolder in interface Store
Parameters:
path - the full path of the folder in the Store.
Throws:
StoreException - If an error occurs on the store (e.g. no space left)

removeFolder

public boolean removeFolder(java.lang.String path)
                     throws StoreException
This method removes a folder from the record store.

Specified by:
removeFolder in interface Store
Parameters:
path - The full pathname in the Store
Returns:
true if the folder has been actually deleted, false if the folder did not exist.
Throws:
StoreException - if an error occurs on the store

getFolder

public Folder getFolder(java.lang.String path)
                 throws StoreException
This method returns the folder whose name is exactly path.

Specified by:
getFolder in interface Store
Parameters:
path - the path of the folder
Returns:
a Folder, or null if not found
Throws:
StoreException - If an error occurs accessing the Store

findFolders

public Folder[] findFolders(java.lang.String subst)
This method returns the list of the folders whose path matches subst.

Specified by:
findFolders in interface Store
Parameters:
subst - the part of name to search for
Returns:
A list of Folder objects whose path matches the provided substring, or null if there are no matches

getMsgHeaders

public Message[] getMsgHeaders(java.lang.String path)
                        throws StoreException
This method returns the headers of all the messages in the folder path.

Specified by:
getMsgHeaders in interface Store
Parameters:
path - the path of the folder
Returns:
An array of Message with all the headers set but without content
Throws:
StoreException - If an error occurs accessing the Store

getMessageIDs

public java.lang.String[] getMessageIDs(java.lang.String path)
                                 throws StoreException
This method returns the messageIDs of all the messages in the folder path.

Specified by:
getMessageIDs in interface Store
Parameters:
path - the complete path of the folder
Returns:
an array of String, or null if the folder is empty.
Throws:
StoreException - If an error occurs accessing the Store

readMessage

public Message readMessage(java.lang.String path,
                           java.lang.String messageId)
                    throws StoreException
This method reads a message from the Store, using the message Id.

Specified by:
readMessage in interface Store
Parameters:
path - The complete path of the Folder containing the Message.
messageId - A string representing the unique message ID
Returns:
The Message corresponding to the passed path and message ID from this Store
Throws:
StoreException - If an error occurs accessing the Store

readMessage

public Message readMessage(java.lang.String path,
                           Message msg)
                    throws StoreException
This method reads the complete message from the Store. TODO: implement the buffered behaviour for Message, so that a light object is returned by the previous method and the complete one from this, but paying attention to the message state before saving it.

Throws:
StoreException

saveMessage

public void saveMessage(java.lang.String path,
                        Message msg)
                 throws StoreException
This method saves a message in the Store. If the storage left is running low, the older message is removed make room for the new ones.

Specified by:
saveMessage in interface Store
Parameters:
path - The complete path of the Folder containing the Message.
msg - The Message to save.
Throws:
StoreException - If an error occurs accessing the Store

removeMessage

public void removeMessage(java.lang.String path,
                          java.lang.String messageId)
                   throws StoreException
This method removes a Message from the Store, using message ID as index.

Specified by:
removeMessage in interface Store
Parameters:
path - The complete path of the Folder containing the Message.
messageId - A string representing the unique message ID
Throws:
StoreException - If an error occurs accessing the Store

countMessages

public int countMessages(java.lang.String path)
                  throws StoreException
This method returns the message count in this Store.

Specified by:
countMessages in interface Store
Parameters:
path - The complete path of the Folder containing the Message.
Throws:
StoreException - If an error occurs accessing the Store


Copyright © 2006 Funambol.