siuying.gm.app.gmailer4j
Class XMLStorage

java.lang.Object
  extended by siuying.gm.app.gmailer4j.XMLStorage
All Implemented Interfaces:
GMStorage

public class XMLStorage
extends java.lang.Object
implements GMStorage

Open a directory, use files under this directorys as data store

Version:
0.1
To do:
use some caching technique to improve performance

Field Summary
protected  java.util.HashSet items
          list of all items in storage
protected static java.util.logging.Logger logger
           
 
Method Summary
 void close()
          close a storage
 boolean containsId(java.lang.String id)
          check if the thread with id specified existed in the store
 void flush()
          do nothing in this implementation as we save every time we access file
 java.lang.Object get(java.lang.String id)
          get thread from xml store by id
 java.lang.String getPostfix()
           
 java.lang.String getUrl()
           
static XMLStorage getXMLStorage(java.lang.String path)
          Open a XMLThreadStorage by url
static XMLStorage getXMLStorage(java.lang.String path, java.lang.String postfix)
          Open a XMLThreadStorage by url
 java.util.Iterator iterator()
          iterate through the threads in storage
 void open()
          open a storage
 void put(java.lang.String id, java.lang.Object thread)
          save thread as xml
 void remove(java.lang.String id)
          remove thread xml file
 void setPostfix(java.lang.String postfix)
           
 void setUrl(java.lang.String url)
          set the url/identifer of the storage depends on implementation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

protected java.util.HashSet items
list of all items in storage


logger

protected static java.util.logging.Logger logger
Method Detail

getPostfix

public java.lang.String getPostfix()

setPostfix

public void setPostfix(java.lang.String postfix)

getXMLStorage

public static XMLStorage getXMLStorage(java.lang.String path)
                                throws java.io.IOException
Open a XMLThreadStorage by url

Parameters:
String - pathname directory to store the XML files
Throws:
java.io.IOException - when open directory failed

getXMLStorage

public static XMLStorage getXMLStorage(java.lang.String path,
                                       java.lang.String postfix)
                                throws java.io.IOException
Open a XMLThreadStorage by url

Parameters:
String - pathname directory to store the XML files
String - postfix the files type treated as xml files, e.g. ".xml"
Throws:
java.io.IOException - when open directory failed

setUrl

public void setUrl(java.lang.String url)
            throws java.lang.NullPointerException
Description copied from interface: GMStorage
set the url/identifer of the storage depends on implementation

Specified by:
setUrl in interface GMStorage
Throws:
java.lang.NullPointerException

getUrl

public java.lang.String getUrl()

open

public void open()
          throws java.io.IOException
Description copied from interface: GMStorage
open a storage

Specified by:
open in interface GMStorage
Throws:
java.io.IOException

close

public void close()
Description copied from interface: GMStorage
close a storage

Specified by:
close in interface GMStorage

containsId

public boolean containsId(java.lang.String id)
check if the thread with id specified existed in the store

Specified by:
containsId in interface GMStorage
Parameters:
id - the id of the thread

put

public void put(java.lang.String id,
                java.lang.Object thread)
         throws java.io.IOException,
                java.lang.NullPointerException
save thread as xml

Specified by:
put in interface GMStorage
Throws:
java.lang.NullPointerException - when id or thread is null
java.lang.IllegalArgumentException - when id is empty string
java.io.IOException

get

public java.lang.Object get(java.lang.String id)
                     throws java.io.IOException,
                            java.lang.NullPointerException
get thread from xml store by id

Specified by:
get in interface GMStorage
Throws:
java.lang.NullPointerException - when id or thread is null
java.lang.IllegalArgumentException - when id is empty string
java.io.IOException

remove

public void remove(java.lang.String id)
            throws java.lang.NullPointerException,
                   java.lang.SecurityException
remove thread xml file

Specified by:
remove in interface GMStorage
Throws:
java.lang.NullPointerException - when id is null
java.lang.SecurityException

flush

public void flush()
           throws java.io.IOException
do nothing in this implementation as we save every time we access file

Specified by:
flush in interface GMStorage
Throws:
java.io.IOException

iterator

public java.util.Iterator iterator()
Description copied from interface: GMStorage
iterate through the threads in storage

Specified by:
iterator in interface GMStorage