public class Vault extends Object
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.
Modifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
static DataSource |
getDataSource()
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)
setDataSource
|
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.
|
protected static Properties properties
protected static String homeDir
public static void setDataSource(DataSource dataSource)
setDataSource
dataSource
- a DataSource
object.public static DataSource getDataSource()
getDataSource
DataSource
object.public static Connection getDbConnection() throws SQLException
Connection
object.SQLException
- if any.public static void releaseDbConnection(Connection connection) throws SQLException
connection
- the connection to releaseSQLException
- If a SQL error occurs while calling connection.close() on the
connection.public static void setProperties(Properties properties)
properties
- a Properties
object.public static Properties getProperties()
Properties
object.public static String getProperty(String key)
public static void setHomeDir(String homeDir)
homeDir
- a String
object.public static String getHomeDir()
String
object.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.
key
- The key name used to lookup the property path values.Copyright © 2015. All Rights Reserved.