ucar.unidata.xml
Class XmlObjectStore

java.lang.Object
  extended by ucar.unidata.xml.XmlObjectStore
All Implemented Interfaces:
PersistentStore
Direct Known Subclasses:
IdvObjectStore

public class XmlObjectStore
extends Object
implements PersistentStore

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
protected  List tmpFiles
          Keep track of the tmp files that have been created
 
Constructor Summary
XmlObjectStore(XmlEncoder encoder)
          Create a new store.
 
Method Summary
 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.
 Object get(Object key)
          Lookup the given key's value.
 Object get(String key)
          Return the object held in the table identified by the given key.
 boolean get(String key, boolean dflt)
          Lookup the given key's value.
 char get(String key, char dflt)
          Lookup the given key's value.
 Color get(String key, Color dflt)
          Lookup the given key's value.
 double get(String key, double dflt)
          Lookup the given key's value.
 float get(String key, float dflt)
          Lookup the given key's value.
 Font get(String key, Font dflt)
          Lookup the given key's value.
 int get(String key, int dflt)
          Lookup the given key's value.
 long get(String key, long dflt)
          Lookup the given key's value.
 short get(String key, short dflt)
          Lookup the given key's value.
 String get(String key, String dflt)
          Lookup the given key's value.
 Object getEncodedFile(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
 String getFileContents(String filename)
          Read the contents of the filename, which is relative to the user's directory.
 String getTmpFile(String tail)
          Return the full path to a temporary file with the given file tail.
 File getUniqueTmpDirectory()
          _more_
 String getUniqueTmpFile(String prefix, String suffix)
          _more_
 File getUserDirectory()
          We will assume that the first file in the list of store files is held within the user's directory.
 String getUserTmpDirectory()
          Create (if not there) a "tmp" directory under the user's directory.
 int init(XmlResourceCollection rc)
          Initialize the store.
static void main(String[] args)
           
protected  Hashtable processTable(Hashtable newTable)
          Process a HashTable
 void put(Object key, Object value)
          Put the given value.
 void put(String key, boolean value)
          Put the given value into the tabl.
 void put(String key, char value)
          Put the given value into the tabl.
 void put(String key, double value)
          Put the given value into the tabl.
 void put(String key, float value)
          Put the given value into the tabl.
 void put(String key, int value)
          Put the given value into the tabl.
 void put(String key, long value)
          Put the given value into the tabl.
 void put(String key, Object value)
          Put the given value.
 void put(String key, short value)
          Put the given value into the tabl.
 void putEncodedFile(String filename, Object o)
          Encode the given object and write it to the given filename.
 void putFile(String filename, String contents)
          Write the contents to the filename, which is relative to the user's directory.
 void remove(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(String dir)
          _more_
 boolean userDirectoryOk()
          Check if the userDirectory is okay to write to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tmpFiles

protected List tmpFiles
Keep track of the tmp files that have been created

Constructor Detail

XmlObjectStore

public XmlObjectStore(XmlEncoder encoder)
Create a new store.

Parameters:
encoder -
Method Detail

setEncoder

protected void setEncoder(XmlEncoder encoder)
Set the XmlEncoder that we use

Parameters:
encoder - The encoder we use to write out the store

getEncoder

protected XmlEncoder getEncoder()
Get the encoder we use

Returns:
The encoder we use to write out the store

getUserDirectory

public File 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

public void setTmpDir(String dir)
_more_

Parameters:
dir - _more_

getUserTmpDirectory

public String getUserTmpDirectory()
Create (if not there) a "tmp" directory under the user's directory.

Returns:
The path to the new tmp directory.

getTmpFile

public String getTmpFile(String tail)
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

public File getUniqueTmpDirectory()
_more_

Returns:
_more_

getUniqueTmpFile

public String getUniqueTmpFile(String prefix,
                               String suffix)
_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

public int init(XmlResourceCollection rc)
Initialize the store.

Parameters:
rc - The resource collection to read from
Returns:
_more_

append

public int append(XmlResourceCollection rc,
                  boolean onlyAddIfNotExists)
_more_

Parameters:
rc - _more_
onlyAddIfNotExists - _more_
Returns:
_more_

processTable

protected Hashtable processTable(Hashtable newTable)
Process a HashTable

Parameters:
newTable - table to process
Returns:
a processed table

getEncodedFile

public Object getEncodedFile(String filename)
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

public void putEncodedFile(String filename,
                           Object o)
Encode the given object and write it to the given filename.

Parameters:
filename - The filename to write to.
o - The object to encode.

getFileContents

public String getFileContents(String filename)
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

public void putFile(String filename,
                    String contents)
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

public Object get(String key)
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

public void put(String key,
                boolean value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                char value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                short value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                int value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                float value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                long value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(String key,
                double value)
Put the given value into the tabl.

Parameters:
key - The object's key.
value - The value to store.

put

public void put(Object key,
                Object value)
Put the given value.

Specified by:
put in interface PersistentStore
Parameters:
key - Convert to toString to get the actual key.
value - The value to store.

put

public void put(String key,
                Object value)
Put the given value.

Parameters:
key - The object's key.
value - The value to store.

get

public String get(String key,
                  String dflt)
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

public Color get(String key,
                 Color dflt)
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

public Font get(String key,
                Font dflt)
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

public boolean get(String key,
                   boolean dflt)
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

public char get(String key,
                char dflt)
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

public short get(String key,
                 short dflt)
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

public int get(String key,
               int dflt)
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

public float get(String key,
                 float dflt)
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

public long get(String key,
                long dflt)
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

public double get(String key,
                  double dflt)
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

public Object get(Object key)
Lookup the given key's value. If not found return null.

Specified by:
get in interface PersistentStore
Parameters:
key - The object's key.
Returns:
The value of the given key.

remove

public void remove(String key)
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 interface PersistentStore

main

public static void main(String[] args)
Parameters:
args - Command line args.