public class XmlObjectStore extends java.lang.Object implements PersistentStore
XmlEncoder
to read/write a Hashtable that holds a collection
of persistent objects.Modifier and Type | Field and Description |
---|---|
protected java.util.List |
tmpFiles
Keep track of the tmp files that have been created
|
Constructor and Description |
---|
XmlObjectStore(XmlEncoder encoder)
Create a new store.
|
Modifier and Type | Method and Description |
---|---|
int |
append(XmlResourceCollection rc,
boolean onlyAddIfNotExists)
_more_
|
void |
cleanupTmpDirectory()
This routine will delete all files in the user's tmp directory but
will leave the directories
|
void |
cleanupTmpFiles()
This method will remove all temp files that have been created during the
current run of the program and clear out the list of tmp files.
|
java.lang.Object |
get(java.lang.Object key)
Lookup the given key's value.
|
java.lang.Object |
get(java.lang.String key)
Return the object held in the table identified by the given key.
|
boolean |
get(java.lang.String key,
boolean dflt)
Lookup the given key's value.
|
char |
get(java.lang.String key,
char dflt)
Lookup the given key's value.
|
java.awt.Color |
get(java.lang.String key,
java.awt.Color dflt)
Lookup the given key's value.
|
double |
get(java.lang.String key,
double dflt)
Lookup the given key's value.
|
float |
get(java.lang.String key,
float dflt)
Lookup the given key's value.
|
java.awt.Font |
get(java.lang.String key,
java.awt.Font dflt)
Lookup the given key's value.
|
int |
get(java.lang.String key,
int dflt)
Lookup the given key's value.
|
long |
get(java.lang.String key,
long dflt)
Lookup the given key's value.
|
short |
get(java.lang.String key,
short dflt)
Lookup the given key's value.
|
java.lang.String |
get(java.lang.String key,
java.lang.String dflt)
Lookup the given key's value.
|
java.lang.Object |
getEncodedFile(java.lang.String filename)
The given filename is a file which (should) hold the xml
encoded (
XmlEncoder ) version of some Object. |
protected XmlEncoder |
getEncoder()
Get the encoder we use
|
java.lang.String |
getFileContents(java.lang.String filename)
Read the contents of the filename, which is relative to the user's directory.
|
java.lang.String |
getTmpFile(java.lang.String tail)
Return the full path to a temporary file with the given file tail.
|
java.io.File |
getUniqueTmpDirectory()
_more_
|
java.lang.String |
getUniqueTmpFile(java.lang.String prefix,
java.lang.String suffix)
_more_
|
java.io.File |
getUserDirectory()
We will assume that the first file in the list of store files
is held within the user's directory.
|
java.lang.String |
getUserTmpDirectory()
Create (if not there) a "tmp" directory under the user's directory.
|
int |
init(XmlResourceCollection rc)
Initialize the store.
|
static void |
main(java.lang.String[] args) |
protected java.util.Hashtable |
processTable(java.util.Hashtable newTable)
Process a HashTable
|
void |
put(java.lang.Object key,
java.lang.Object value)
Put the given value.
|
void |
put(java.lang.String key,
boolean value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
char value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
double value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
float value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
int value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
long value)
Put the given value into the tabl.
|
void |
put(java.lang.String key,
java.lang.Object value)
Put the given value.
|
void |
put(java.lang.String key,
short value)
Put the given value into the tabl.
|
void |
putEncodedFile(java.lang.String filename,
java.lang.Object o)
Encode the given object and write it to the given filename.
|
void |
putFile(java.lang.String filename,
java.lang.String contents)
Write the contents to the filename, which is relative to the user's directory.
|
void |
remove(java.lang.String key)
Remove the given value from the table.
|
void |
save()
Save the store to disk.
|
void |
saveIfNeeded()
Save the store to disk if there has been a put since the last save
|
protected void |
setEncoder(XmlEncoder encoder)
Set the
XmlEncoder that we use |
void |
setTmpDir(java.lang.String dir)
_more_
|
boolean |
userDirectoryOk()
Check if the userDirectory is okay to write to.
|
protected java.util.List tmpFiles
public XmlObjectStore(XmlEncoder encoder)
encoder
- protected void setEncoder(XmlEncoder encoder)
XmlEncoder
that we useencoder
- The encoder we use to write out the storeprotected XmlEncoder getEncoder()
public java.io.File getUserDirectory()
public boolean userDirectoryOk()
public void setTmpDir(java.lang.String dir)
dir
- _more_public java.lang.String getUserTmpDirectory()
public java.lang.String getTmpFile(java.lang.String tail)
tail
- The file tail (e.g., temp.txt)public void cleanupTmpDirectory()
public java.io.File getUniqueTmpDirectory()
public java.lang.String getUniqueTmpFile(java.lang.String prefix, java.lang.String suffix)
prefix
- _more_suffix
- _more_public void cleanupTmpFiles()
public int init(XmlResourceCollection rc)
rc
- The resource collection to read frompublic int append(XmlResourceCollection rc, boolean onlyAddIfNotExists)
rc
- _more_onlyAddIfNotExists
- _more_protected java.util.Hashtable processTable(java.util.Hashtable newTable)
newTable
- table to processpublic java.lang.Object getEncodedFile(java.lang.String filename)
XmlEncoder
) version of some Object.filename
- The file that contains the encoded object.public void putEncodedFile(java.lang.String filename, java.lang.Object o)
filename
- The filename to write to.o
- The object to encode.public java.lang.String getFileContents(java.lang.String filename)
filename
- The file to read.public void putFile(java.lang.String filename, java.lang.String contents)
filename
- The file to read.contents
- The contents of the file.public java.lang.Object get(java.lang.String key)
key
- The object's key.public void put(java.lang.String key, boolean value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, char value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, short value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, int value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, float value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, long value)
key
- The object's key.value
- The value to store.public void put(java.lang.String key, double value)
key
- The object's key.value
- The value to store.public void put(java.lang.Object key, java.lang.Object value)
put
in interface PersistentStore
key
- Convert to toString to get the actual key.value
- The value to store.public void put(java.lang.String key, java.lang.Object value)
key
- The object's key.value
- The value to store.public java.lang.String get(java.lang.String key, java.lang.String dflt)
key
- The object's key.dflt
- The default value to return if not found.public java.awt.Color get(java.lang.String key, java.awt.Color dflt)
key
- The object's key.dflt
- The default value to return if not found.public java.awt.Font get(java.lang.String key, java.awt.Font dflt)
key
- The object's key.dflt
- The default value to return if not found.public boolean get(java.lang.String key, boolean dflt)
key
- The object's key.dflt
- The default value to return if not found.public char get(java.lang.String key, char dflt)
key
- The object's key.dflt
- The default value to return if not found.public short get(java.lang.String key, short dflt)
key
- The object's key.dflt
- The default value to return if not found.public int get(java.lang.String key, int dflt)
key
- The object's key.dflt
- The default value to return if not found.public float get(java.lang.String key, float dflt)
key
- The object's key.dflt
- The default value to return if not found.public long get(java.lang.String key, long dflt)
key
- The object's key.dflt
- The default value to return if not found.public double get(java.lang.String key, double dflt)
key
- The object's key.dflt
- The default value to return if not found.public java.lang.Object get(java.lang.Object key)
get
in interface PersistentStore
key
- The object's key.public void remove(java.lang.String key)
key
- The object's key.public void saveIfNeeded()
public void save()
save
in interface PersistentStore
public static void main(java.lang.String[] args)
args
- Command line args.