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.


Field Summary
 
Fields inherited from interface com.funambol.mail.Store
DRAFTS, INBOX, LATEST_VERSION, OUTBOX, SENT, VERSION_101, VERSION_102, VERSION_103
 
Method Summary
 void addMessage(java.lang.String path, Message msg)
          This method add a message to the Store.
 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 a new reference to 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.
 int getVersion()
          This method gets the version of the Store which is currently being used on the device.
 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 readFirstMessage(java.lang.String path)
          Return the first message in the store.
 java.io.DataInputStream readMessage(Message msg)
          This method reads a record from the Store, using its record id.
 Message readMessage(java.lang.String path, java.lang.String recordId)
          This method reads a message from the Store, using the record id.
 Message readNextMessage(java.lang.String path)
          Return the next message in the store.
 boolean removeFolder(java.lang.String path)
          This method removes a folder from the record store.
 void removeMessage(java.lang.String path, java.lang.String recordId)
          This method removes a Message from the Store, using message ID as index.
 void saveMessage(java.lang.String path, Message msg)
          This method saves (NOT ADD) a message in the Store.
 void setVersion(int version)
          This method sets the version of the Store which is currently being used on the device.
 
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 MailException
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:
MailException

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 MailException
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:
MailException - If the path is not valid

createFolder

public Folder createFolder(java.lang.String path)
                    throws MailException
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:
MailException - If an error occurs on the store (e.g. no space left)

removeFolder

public boolean removeFolder(java.lang.String path)
                     throws MailException
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:
MailException - if an error occurs on the store

getFolder

public Folder getFolder(java.lang.String path)
                 throws MailException
This method returns a new reference to the folder whose name is exactly path. IMPORTANT: note that the return statement of this method generates a new reference to the selected folder every time this method is invoked.

Specified by:
getFolder in interface Store
Parameters:
path - the path of the folder
Returns:
a Folder, or null if not found
Throws:
MailException - 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 MailException
This method returns the headers of all the messages in the folder path. IMPORTANT: a folder MUST be set as parent of this message before calling this method, otherwise the headers of this message will be returned as an empty hastable

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:
MailException - If an error occurs accessing the Store

getMessageIDs

public java.lang.String[] getMessageIDs(java.lang.String path)
                                 throws MailException
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:
MailException - If an error occurs accessing the Store

readMessage

public Message readMessage(java.lang.String path,
                           java.lang.String recordId)
                    throws MailException
This method reads a message from the Store, using the record id. IMPORTANT: a folder MUST be set as parent of this message before calling this method, otherwise the headers of this message will be returned as an empty hastable

Specified by:
readMessage in interface Store
Parameters:
path - The complete path of the Folder containing the Message.
recordId - A string representing the record ID of this message (must be a number)
Returns:
The Message corresponding to the passed path and message ID from this Store
Throws:
MailException - If an error occurs accessing the Store

readFirstMessage

public Message readFirstMessage(java.lang.String path)
                         throws MailException
Return the first message in the store.

Specified by:
readFirstMessage in interface Store
Returns:
the first Message if it exists, null otherwise
Throws:
MailException - if the store cannot be accessed

readNextMessage

public Message readNextMessage(java.lang.String path)
                        throws MailException
Return the next message in the store.

Specified by:
readNextMessage in interface Store
Returns:
the next Message if it exists, null otherwise
Throws:
MailException - if the store cannot be accessed

readMessage

public java.io.DataInputStream readMessage(Message msg)
                                    throws MailException
This method reads a record from the Store, using its record id. The message must be in a folder for this method to succeed. If the record is found the method returns a DataInputStream to read its bytes.

Specified by:
readMessage in interface Store
Parameters:
msg - The message whose record must be re-read
Throws:
MailException - If an error occurs accessing the Store

saveMessage

public void saveMessage(java.lang.String path,
                        Message msg)
                 throws MailException
This method saves (NOT ADD) a message in the Store. This is basically and update of an existing message that gets overwritten.

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

addMessage

public void addMessage(java.lang.String path,
                       Message msg)
                throws MailException
This method add a message to the Store. The newly created message is given its record id.

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

removeMessage

public void removeMessage(java.lang.String path,
                          java.lang.String recordId)
                   throws MailException
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:
MailException - If an error occurs accessing the Store

countMessages

public int countMessages(java.lang.String path)
                  throws MailException
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:
MailException - If an error occurs accessing the Store

setVersion

public void setVersion(int version)
This method sets the version of the Store which is currently being used on the device. If no version is specified, the Store defaults to the latest one.

Specified by:
setVersion in interface Store
Parameters:
version - is the store version

getVersion

public int getVersion()
This method gets the version of the Store which is currently being used on the device.

Specified by:
getVersion in interface Store


Copyright © 2006 Funambol.