org.LexGrid.util.config
Class PropertiesUtility

java.lang.Object
  extended by org.LexGrid.util.config.PropertiesUtility

public class PropertiesUtility
extends java.lang.Object

Class to aid in finding and loading properties files.

Author:
Dan Armbrust

Field Summary
static LgMessageDirectorIF logger
           
static java.lang.String propertiesLocationKey
           
static java.lang.String propertiesParentFolderKey
           
static java.lang.String systemVariable
           
 
Constructor Summary
PropertiesUtility()
           
 
Method Summary
static java.util.Properties loadPropertiesFromClasspath(java.lang.String absolutePath)
          Load a properties file from the classpath.
static java.util.Properties loadPropertiesFromFileOrURL(java.lang.String propertiesFile)
          Create a java properties object from a location.
static java.util.Properties locateAndLoadPropFile(java.lang.String fileName)
          Convenience method that combines locatePropFile(fileName) and loadPropertiesFromFileOrURL(String)
static java.util.Properties locateAndLoadPropFile(java.lang.String fileName, java.lang.String classToSearchFor)
          Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String)
static java.util.Properties locateAndLoadPropFileConfigureLog4J(java.lang.String fileName, java.lang.String log4JConfigFilePropertyName)
          Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String) and Log4JUtility.configureLog4JFromPathSpecifiedInProperties
static java.util.Properties locateAndLoadPropFileConfigureLog4J(java.lang.String fileName, java.lang.String log4JConfigFilePropertyName, java.lang.String classToSearchFor)
          Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String) and Log4JUtility.configureLog4JFromPathSpecifiedInProperties
static java.lang.String locatePropFile(java.lang.String fileName)
          Located the named file on the file system.
static java.lang.String locatePropFile(java.lang.String fileName, java.lang.String classToSearchFor)
          Located the named file on the file system.
static java.lang.String locatePropFile(java.lang.String fileName, java.lang.String classToSearchFor, LgLoggerIF logger)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertiesLocationKey

public static java.lang.String propertiesLocationKey

propertiesParentFolderKey

public static java.lang.String propertiesParentFolderKey

logger

public static LgMessageDirectorIF logger

systemVariable

public static java.lang.String systemVariable
Constructor Detail

PropertiesUtility

public PropertiesUtility()
Method Detail

loadPropertiesFromFileOrURL

public static java.util.Properties loadPropertiesFromFileOrURL(java.lang.String propertiesFile)
                                                        throws java.io.IOException
Create a java properties object from a location. Adds a "propertiesFileParentFolder" value to the properties object. The value is set to the file path of the folder containing the properties file. This is useful for the method Log4JUtility.configureLog4JFromPathSpecifiedInProperties

Parameters:
propertiesFile - can be a file path or a url.
Returns:
The loaded properties file.
Throws:
java.io.IOException

loadPropertiesFromClasspath

public static java.util.Properties loadPropertiesFromClasspath(java.lang.String absolutePath)
                                                        throws java.io.IOException
Load a properties file from the classpath.

Parameters:
absolutePath - absolute path to the properties file in the classpath. Should start with '/'
Returns:
the properties object.
Throws:
java.io.IOException

locatePropFile

public static java.lang.String locatePropFile(java.lang.String fileName)
Located the named file on the file system. Does the best it can to find it. Returns null if it could not be found. If you pass in the VM parameter 'PropFileLocation' - this will override everything - example: -DPropFileLocation=c:/temp/HL7TestProperties.prps However, if the named file doesn't exist, then it will attempt to locate the file. This is not a drive search, it will always return very quickly.

Parameters:
fileName - Name of the file to locate
Returns:
file location (or null if file could not be found) - the may be a URL.

locatePropFile

public static java.lang.String locatePropFile(java.lang.String fileName,
                                              java.lang.String classToSearchFor)
Located the named file on the file system. Does the best it can to find it. Returns null if it could not be found. If you pass in the VM parameter 'PropFileLocation' - this will override everything - example: -DPropFileLocation=c:/temp/HL7TestProperties.prps However, if the named file doesn't exist, then it will attempt to locate the file. This is not a drive search, it will always return very quickly.

Parameters:
fileName - Name of the file to locate
classToSearchFor - A class that exists in your classpath to use as a starting point for the search. The recommended value for most use cases is "this.getClass().getName()".
Returns:
file location (or null if file could not be found) - this may be a URL.

locatePropFile

public static java.lang.String locatePropFile(java.lang.String fileName,
                                              java.lang.String classToSearchFor,
                                              LgLoggerIF logger)

locateAndLoadPropFile

public static java.util.Properties locateAndLoadPropFile(java.lang.String fileName)
                                                  throws java.io.IOException
Convenience method that combines locatePropFile(fileName) and loadPropertiesFromFileOrURL(String)

Parameters:
fileName -
Returns:
Throws:
java.io.IOException

locateAndLoadPropFile

public static java.util.Properties locateAndLoadPropFile(java.lang.String fileName,
                                                         java.lang.String classToSearchFor)
                                                  throws java.io.IOException
Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String)

Parameters:
fileName -
Returns:
Throws:
java.io.IOException

locateAndLoadPropFileConfigureLog4J

public static java.util.Properties locateAndLoadPropFileConfigureLog4J(java.lang.String fileName,
                                                                       java.lang.String log4JConfigFilePropertyName,
                                                                       java.lang.String classToSearchFor)
                                                                throws java.lang.Exception
Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String) and Log4JUtility.configureLog4JFromPathSpecifiedInProperties

Parameters:
fileName -
Returns:
Throws:
java.lang.Exception

locateAndLoadPropFileConfigureLog4J

public static java.util.Properties locateAndLoadPropFileConfigureLog4J(java.lang.String fileName,
                                                                       java.lang.String log4JConfigFilePropertyName)
                                                                throws java.lang.Exception
Convenience method that combines locatePropFile(fileName, classToSearchFor) and loadPropertiesFromFileOrURL(String) and Log4JUtility.configureLog4JFromPathSpecifiedInProperties

Parameters:
fileName -
Returns:
Throws:
java.lang.Exception

Copyright: (c) 2004-2006 Mayo Foundation for Medical Education and Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the triple-shield Mayo logo are trademarks and service marks of MFMER.