Package ucar.unidata.xml
Class XmlObjectStore
java.lang.Object
ucar.unidata.xml.XmlObjectStore
- All Implemented Interfaces:
PersistentStore
- Direct Known Subclasses:
IdvObjectStore
This allows us to use the
XmlEncoder
to read/write a Hashtable that holds a collection
of persistent objects.- Version:
- $Revision: 1.51 $
- Author:
- Metapps development team
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
append
(XmlResourceCollection rc, boolean onlyAddIfNotExists) _more_void
This routine will delete all files in the user's tmp directory but will leave the directoriesvoid
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.Lookup the given key's value.Return the object held in the table identified by the given key.boolean
Lookup the given key's value.char
Lookup the given key's value.double
Lookup the given key's value.float
Lookup the given key's value.int
Lookup the given key's value.long
Lookup the given key's value.short
Lookup the given key's value.Lookup the given key's value.Lookup the given key's value.Lookup the given key's value.getEncodedFile
(String filename) The given filename is a file which (should) hold the xml encoded (XmlEncoder
) version of some Object.protected XmlEncoder
Get the encoder we usegetFileContents
(String filename) Read the contents of the filename, which is relative to the user's directory.getTmpFile
(String tail) Return the full path to a temporary file with the given file tail._more_getUniqueTmpFile
(String prefix, String suffix) _more_We will assume that the first file in the list of store files is held within the user's directory.Create (if not there) a "tmp" directory under the user's directory.int
Initialize the store.static void
protected Hashtable
processTable
(Hashtable newTable) Process a HashTablevoid
Put the given value.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value into the tabl.void
Put the given value.void
putEncodedFile
(String filename, Object o) Encode the given object and write it to the given filename.void
Write the contents to the filename, which is relative to the user's directory.void
Remove the given value from the table.void
save()
Save the store to disk.void
Save the store to disk if there has been a put since the last saveprotected void
setEncoder
(XmlEncoder encoder) Set theXmlEncoder
that we usevoid
_more_boolean
Check if the userDirectory is okay to write to.
-
Field Details
-
tmpFiles
Keep track of the tmp files that have been created
-
-
Constructor Details
-
XmlObjectStore
Create a new store.- Parameters:
encoder
-
-
-
Method Details
-
setEncoder
Set theXmlEncoder
that we use- Parameters:
encoder
- The encoder we use to write out the store
-
getEncoder
Get the encoder we use- Returns:
- The encoder we use to write out the store
-
getUserDirectory
We will assume that the first file in the list of store files is held within the user's directory.- Returns:
- The user's directory.
-
userDirectoryOk
public boolean userDirectoryOk()Check if the userDirectory is okay to write to.- Returns:
- true if the directory exists and is writable
-
setTmpDir
_more_- Parameters:
dir
- _more_
-
getUserTmpDirectory
Create (if not there) a "tmp" directory under the user's directory.- Returns:
- The path to the new tmp directory.
-
getTmpFile
Return the full path to a temporary file with the given file tail. The filename will be added to a list of tmpFiles that can then be removed when an application exits.- Parameters:
tail
- The file tail (e.g., temp.txt)- Returns:
- The full path (e.g., ~/.metapps/tmp/temp.txt)
-
cleanupTmpDirectory
public void cleanupTmpDirectory()This routine will delete all files in the user's tmp directory but will leave the directories -
getUniqueTmpDirectory
_more_- Returns:
- _more_
-
getUniqueTmpFile
_more_- Parameters:
prefix
- _more_suffix
- _more_- Returns:
- _more_
-
cleanupTmpFiles
public 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. -
init
Initialize the store.- Parameters:
rc
- The resource collection to read from- Returns:
- _more_
-
append
_more_- Parameters:
rc
- _more_onlyAddIfNotExists
- _more_- Returns:
- _more_
-
processTable
Process a HashTable- Parameters:
newTable
- table to process- Returns:
- a processed table
-
getEncodedFile
The given filename is a file which (should) hold the xml encoded (XmlEncoder
) version of some Object.- Parameters:
filename
- The file that contains the encoded object.- Returns:
- The decoded object.
-
putEncodedFile
Encode the given object and write it to the given filename.- Parameters:
filename
- The filename to write to.o
- The object to encode.
-
getFileContents
Read the contents of the filename, which is relative to the user's directory.- Parameters:
filename
- The file to read.- Returns:
- The contents of the file.
-
putFile
Write the contents to the filename, which is relative to the user's directory.- Parameters:
filename
- The file to read.contents
- The contents of the file.
-
get
Return the object held in the table identified by the given key.- Parameters:
key
- The object's key.- Returns:
- The Object identified by the given key or null if not found.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value into the tabl.- Parameters:
key
- The object's key.value
- The value to store.
-
put
Put the given value.- Specified by:
put
in interfacePersistentStore
- Parameters:
key
- Convert to toString to get the actual key.value
- The value to store.
-
put
Put the given value.- Parameters:
key
- The object's key.value
- The value to store.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return the dflt.- Parameters:
key
- The object's key.dflt
- The default value to return if not found.- Returns:
- The value of the given key or the dflt if not found.
-
get
Lookup the given key's value. If not found return null.- Specified by:
get
in interfacePersistentStore
- Parameters:
key
- The object's key.- Returns:
- The value of the given key.
-
remove
Remove the given value from the table.- Parameters:
key
- The object's key.
-
saveIfNeeded
public void saveIfNeeded()Save the store to disk if there has been a put since the last save -
save
public void save()Save the store to disk.- Specified by:
save
in interfacePersistentStore
-
main
- Parameters:
args
- Command line args.
-