gov.sns.tools.database
Class ConnectionDictionary

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--gov.sns.tools.database.ConnectionDictionary
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class ConnectionDictionary
extends java.util.Properties

ConnectionDictionary contains properties that can be used to establish a database connection. It should contain at least the database URL, user name and password. A default connection dictionary can be fetched from a file specified in the user's preferences.

See Also:
Serialized Form

Field Summary
static java.lang.String DATABASE_ADAPTOR_KEY
           
protected static java.lang.String DICTIONARY_URL_KEY
           
static java.lang.String PASSWORD_KEY
           
static java.lang.String URL_KEY
           
static java.lang.String USER_KEY
           
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
ConnectionDictionary()
          Constructor
ConnectionDictionary(java.io.File file)
          Constructor
ConnectionDictionary(java.net.URL url)
          Constructor
 
Method Summary
static ConnectionDictionary defaultDictionary()
          Get the connection dictionary from the file specified in the user's preferences.
 DatabaseAdaptor getDatabaseAdaptor()
          Get the database adaptor to use
static java.net.URL getDefaultDictionaryURL()
          Get the URL of the default connection dictionary properties file
static java.lang.String getDefaultDictionaryURLSpec()
          Get the URL Spec of the default connection dictionary's properties file
protected static java.util.prefs.Preferences getDefaults()
          Get the user preferences for this class
 java.lang.String getPassword()
          Get the user password for connecting
 java.lang.String getURLSpec()
          Get the connection URL
 java.lang.String getUser()
          Get the user name for connecting
 void loadFrom(java.net.URL url)
          Load the connection dictionary from the dictionary file.
 void saveTo(java.net.URL url)
          Save the connection dictionary to the dictionary file.
 void setDatabaseAdaptorClass(java.lang.Class databaseAdaptorClass)
          Set the database adaptor class
 void setDatabaseAdaptorClass(java.lang.String className)
          Set the database adaptor class
static void setDefaultDictionaryFile(java.io.File file)
          Set the connection dictionary's default properties file.
static void setDefaultDictionaryPath(java.lang.String filePath)
          Set the file path of the connection dictionary's default properties file.
static void setDefaultDictionaryURL(java.net.URL url)
          Set the URL of the connection dictionary's default properties file.
static void setDefaultDictionaryURLSpec(java.lang.String urlSpec)
          Set the URL spec of the connection dictionary's default properties file.
 void setPassword(java.lang.String password)
          Set the password
 void setURLSpec(java.lang.String urlSpec)
          Set the URL spec
 void setUser(java.lang.String userID)
          Set the user ID
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

USER_KEY

public static final java.lang.String USER_KEY
See Also:
Constant Field Values

PASSWORD_KEY

public static final java.lang.String PASSWORD_KEY
See Also:
Constant Field Values

URL_KEY

public static final java.lang.String URL_KEY
See Also:
Constant Field Values

DATABASE_ADAPTOR_KEY

public static final java.lang.String DATABASE_ADAPTOR_KEY
See Also:
Constant Field Values

DICTIONARY_URL_KEY

protected static final java.lang.String DICTIONARY_URL_KEY
See Also:
Constant Field Values
Constructor Detail

ConnectionDictionary

public ConnectionDictionary()
Constructor


ConnectionDictionary

public ConnectionDictionary(java.net.URL url)
                     throws java.io.IOException
Constructor

Parameters:
url - The URL of the connection dictionary properties
Throws:
java.io.IOException - if the properties file can't be loaded

ConnectionDictionary

public ConnectionDictionary(java.io.File file)
                     throws java.io.IOException,
                            java.net.MalformedURLException
Constructor

Parameters:
file - The file of the connection dictionary properties
Throws:
java.io.IOException - if the properties file can't be loaded
java.net.MalformedURLException - if the file cannot be converted to a URL
Method Detail

defaultDictionary

public static ConnectionDictionary defaultDictionary()
Get the connection dictionary from the file specified in the user's preferences.

Returns:
the user's default connection dictionary

getUser

public java.lang.String getUser()
Get the user name for connecting

Returns:
the user name

setUser

public void setUser(java.lang.String userID)
Set the user ID

Parameters:
userID - The user ID

getPassword

public java.lang.String getPassword()
Get the user password for connecting

Returns:
the user password

setPassword

public void setPassword(java.lang.String password)
Set the password

Parameters:
password - the password

getURLSpec

public java.lang.String getURLSpec()
Get the connection URL

Returns:
the connection URL

setURLSpec

public void setURLSpec(java.lang.String urlSpec)
Set the URL spec

Parameters:
urlSpec - The URL spec

getDatabaseAdaptor

public DatabaseAdaptor getDatabaseAdaptor()
Get the database adaptor to use

Returns:
the database adaptor

setDatabaseAdaptorClass

public void setDatabaseAdaptorClass(java.lang.Class databaseAdaptorClass)
Set the database adaptor class

Parameters:
databaseAdaptorClass - the database adaptor class to use

setDatabaseAdaptorClass

public void setDatabaseAdaptorClass(java.lang.String className)
Set the database adaptor class

Parameters:
className - the database adaptor class name to use

saveTo

public void saveTo(java.net.URL url)
            throws java.io.IOException
Save the connection dictionary to the dictionary file.

Parameters:
url - The url of the dictionary properties file.
Throws:
java.io.IOException - if the connection dictionary cannot be saved to its properties file

loadFrom

public void loadFrom(java.net.URL url)
              throws java.io.IOException
Load the connection dictionary from the dictionary file.

Parameters:
url - The url of the dictionary properties file.
Throws:
java.io.IOException - if the connection dictionary cannot be loaded from its properties file

getDefaults

protected static java.util.prefs.Preferences getDefaults()
Get the user preferences for this class

Returns:
the user preferences for this class

getDefaultDictionaryURL

public static java.net.URL getDefaultDictionaryURL()
                                            throws java.net.MalformedURLException
Get the URL of the default connection dictionary properties file

Returns:
the URL of the default connection dictionary properties file
Throws:
java.net.MalformedURLException - if the default URL spec cannot form a valid URL

getDefaultDictionaryURLSpec

public static java.lang.String getDefaultDictionaryURLSpec()
Get the URL Spec of the default connection dictionary's properties file

Returns:
the URL Spec of the connection dictionary properties file

setDefaultDictionaryPath

public static void setDefaultDictionaryPath(java.lang.String filePath)
                                     throws java.net.MalformedURLException,
                                            java.util.prefs.BackingStoreException
Set the file path of the connection dictionary's default properties file.

Parameters:
filePath - The file path of the connection dictionary properties file.
Throws:
java.net.MalformedURLException - if the file path cannot form a valid URL
java.util.prefs.BackingStoreException - if the path failed to be saved as a default

setDefaultDictionaryFile

public static void setDefaultDictionaryFile(java.io.File file)
                                     throws java.net.MalformedURLException,
                                            java.util.prefs.BackingStoreException
Set the connection dictionary's default properties file.

Parameters:
file - The connection dictionary properties file.
Throws:
java.net.MalformedURLException - if the file cannot form a valid URL
java.util.prefs.BackingStoreException - if the file failed to be saved as a default

setDefaultDictionaryURL

public static void setDefaultDictionaryURL(java.net.URL url)
                                    throws java.util.prefs.BackingStoreException
Set the URL of the connection dictionary's default properties file.

Parameters:
url - The URL of the connection dictionary properties file.
Throws:
java.util.prefs.BackingStoreException - if the url failed to be saved as a default

setDefaultDictionaryURLSpec

public static void setDefaultDictionaryURLSpec(java.lang.String urlSpec)
                                        throws java.util.prefs.BackingStoreException
Set the URL spec of the connection dictionary's default properties file.

Parameters:
urlSpec - The URL spec of the connection dictionary properties file.
Throws:
java.util.prefs.BackingStoreException - if the url spec failed to be saved as a default