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 TypeMethodDescriptionintappend(XmlResourceCollection rc, boolean onlyAddIfNotExists) _more_voidThis routine will delete all files in the user's tmp directory but will leave the directoriesvoidThis 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.booleanLookup the given key's value.charLookup the given key's value.doubleLookup the given key's value.floatLookup the given key's value.intLookup the given key's value.longLookup the given key's value.shortLookup 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 XmlEncoderGet 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.intInitialize the store.static voidprotected HashtableprocessTable(Hashtable newTable) Process a HashTablevoidPut the given value.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value into the tabl.voidPut the given value.voidputEncodedFile(String filename, Object o) Encode the given object and write it to the given filename.voidWrite the contents to the filename, which is relative to the user's directory.voidRemove the given value from the table.voidsave()Save the store to disk.voidSave the store to disk if there has been a put since the last saveprotected voidsetEncoder(XmlEncoder encoder) Set theXmlEncoderthat we usevoid_more_booleanCheck 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 theXmlEncoderthat 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:
putin 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:
getin 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:
savein interfacePersistentStore
-
main
- Parameters:
args- Command line args.
-