Class ResourceConfig
- java.lang.Object
-
- com.opengamma.strata.collect.io.ResourceConfig
-
public final class ResourceConfig extends Object
Provides access to configuration files.A standard approach to configuration is provided by this class. Any configuration information provided by this library can be overridden or added to by applications.
By default, there are three groups of recognized configuration directories:
- base
- library
- application
Each group consists of ten directories using a numeric suffix:
com/opengamma/strata/config/base
com/opengamma/strata/config/base1
com/opengamma/strata/config/base2
- ...
com/opengamma/strata/config/base9
com/opengamma/strata/config/library
com/opengamma/strata/config/library1
- ...
com/opengamma/strata/config/library9
com/opengamma/strata/config/application
com/opengamma/strata/config/application1
- ...
com/opengamma/strata/config/application9
The search strategy looks for the same file name in each of the thirty directories. All the files that are found are then merged, with directories lower down the list taking priorty. Thus, any configuration file in the 'application9' directory will override the same file in the 'appication1' directory, which will override the same file in the 'library' group, which will further override the same file in the 'base' group.
The 'base' group is reserved for Strata. The 'library' group is reserved for libraries built directly on Strata.
The set of configuration directories can be changed using the system property 'com.opengamma.strata.config.directories'. This must be a comma separated list, such as 'base,base1,base2,override,application'.
In general, the configuration managed by this class will be in INI format. The
combinedIniFile(String)
method is the main entry point, returning a single INI file merged from all available configuration files.
-
-
Field Summary
Fields Modifier and Type Field Description static String
RESOURCE_DIRS_PROPERTY
The system property defining the comma separated list of groups.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IniFile
combinedIniFile(String resourceName)
Returns a combined INI file formed by merging INI files with the specified name.static IniFile
combinedIniFile(List<ResourceLocator> resources)
Returns a combined INI file formed by merging the specified INI files.static List<ResourceLocator>
orderedResources(String resourceName)
Obtains an ordered list of resource locators.
-
-
-
Field Detail
-
RESOURCE_DIRS_PROPERTY
public static final String RESOURCE_DIRS_PROPERTY
The system property defining the comma separated list of groups.- See Also:
- Constant Field Values
-
-
Method Detail
-
combinedIniFile
public static IniFile combinedIniFile(String resourceName)
Returns a combined INI file formed by merging INI files with the specified name.This finds the all files with the specified name in the configuration directories. Each file is loaded, with the result being formed by merging the files into one. See
combinedIniFile(List)
for more details on the merge process.- Parameters:
resourceName
- the resource name- Returns:
- the resource locators
- Throws:
UncheckedIOException
- if an IO exception occursIllegalStateException
- if there is a configuration error
-
combinedIniFile
public static IniFile combinedIniFile(List<ResourceLocator> resources)
Returns a combined INI file formed by merging the specified INI files.The result of this method is formed by merging the specified files together. The files are combined in order forming a chain. The first file in the list has the lowest priority. The last file in the list has the highest priority.
The algorithm starts with all the sections and properties from the highest priority file. It then adds any sections or properties from subsequent files that are not already present.
The algorithm can be controlled by providing a '[chain]' section. Within the 'chain' section, if 'chainNextFile' is 'false', then processing stops, and lower priority files are ignored. If the 'chainRemoveSections' property is specified, the listed sections are ignored from the files lower in the chain.
- Parameters:
resources
- the INI file resources to read- Returns:
- the combined chained INI file
- Throws:
UncheckedIOException
- if an IO error occursIllegalArgumentException
- if the configuration is invalid
-
orderedResources
public static List<ResourceLocator> orderedResources(String resourceName)
Obtains an ordered list of resource locators.This finds the all files with the specified name in the configuration directories. The result is ordered from the lowest priority (base) file to the highest priority (application) file. The result will always contain at least one file, but it may contain more than one.
- Parameters:
resourceName
- the resource name- Returns:
- the resource locators
- Throws:
UncheckedIOException
- if an IO exception occursIllegalStateException
- if there is a configuration error
-
-