org.opennms.core.resource
Class Vault

java.lang.Object
  extended by org.opennms.core.resource.Vault

public class Vault
extends Object

The Vault handles policies for allocating/deallocating scarce resources and stores application configuration properties.

Since our code might be deployed in different environments, this class provides a deployment-neutral way of retrieving scarce resources and configuration properties. Our application code may be deployed as a daemon, command-line interface, graphical user interface, applet, or servlet. Some of the scarce resources we might like to have allocation policies for are database connections, socket connections, RMI connections, CORBA connections, or open temporary files.

Author:
Lawrence Karnowski , Brian Weaver , OpenNMS

Field Summary
protected static String homeDir
          Stores the directory where the OpenNMS configuration files can be found.
protected static Properties properties
          Holds all the application configuration properties.
 
Method Summary
static DataSource getDataSource()
           
static Connection getDbConnection()
          Retrieve a database connection from the datasource.
static String getHomeDir()
          Get the directory that holds the OpenNMS configuration files.
static Properties getProperties()
          Return the entire set of application configuration properties.
static String getProperty(String key)
          Return property from the configuration parameter list.
static void releaseDbConnection(Connection connection)
          Release a database connection.
static void setDataSource(DataSource dataSource)
           
static void setHomeDir(String homeDir)
          Set the directory so we will know where we can get the OpenNMS configuration files.
static void setProperties(Properties properties)
          Set the application configuration properties.
static boolean supplementSystemPropertiesFromKey(String key)
           Adds new keys to the system properties using the passed key name a the properties location instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected static Properties properties
Holds all the application configuration properties.


homeDir

protected static String homeDir
Stores the directory where the OpenNMS configuration files can be found. The default is /opt/OpenNMS.

Method Detail

setDataSource

public static void setDataSource(DataSource dataSource)

getDataSource

public static DataSource getDataSource()

getDbConnection

public static Connection getDbConnection()
                                  throws SQLException
Retrieve a database connection from the datasource.

Throws:
SQLException

releaseDbConnection

public static void releaseDbConnection(Connection connection)
                                throws SQLException
Release a database connection.

Parameters:
connection - the connection to release
Throws:
SQLException - If a SQL error occurs while calling connection.close() on the connection.

setProperties

public static void setProperties(Properties properties)
Set the application configuration properties.


getProperties

public static Properties getProperties()
Return the entire set of application configuration properties.


getProperty

public static String getProperty(String key)
Return property from the configuration parameter list.


setHomeDir

public static void setHomeDir(String homeDir)
Set the directory so we will know where we can get the OpenNMS configuration files.


getHomeDir

public static String getHomeDir()
Get the directory that holds the OpenNMS configuration files.


supplementSystemPropertiesFromKey

public static boolean supplementSystemPropertiesFromKey(String key)

Adds new keys to the system properties using the passed key name a the properties location instance. The passed key is used as a key to the system property to find the supplementary property information. The returned value should be in the form of a list of file names, each separated by the system separator character.

Once the list of files is recovered, each file is visited and loaded into the system properties. If any file cannot be loaded due to an I/O error then it is skipped as a whole. No partial key sets are loaded into the system properties. Also, this method will not overwrite an existing key in the currently loaded properties.

Parameters:
key - The key name used to lookup the property path values.
Returns:
True if all properties loaded correctly, false if any property file failed to load.


Copyright © 2009. All Rights Reserved.