Class PropertyLoader
- java.lang.Object
-
- org.apache.webbeans.config.PropertyLoader
-
public final class PropertyLoader extends Object
Utility class to load configuration properties via a list of artibrary property files by a well defined order.
User configurations should start with 'configuration.ordinal' greather than 100.
-
-
Field Summary
Fields Modifier and Type Field Description static intCONFIGURATION_ORDINAL_DEFAULT_VALUEstatic StringCONFIGURATION_ORDINAL_PROPERTY_NAME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PropertiesgetProperties(String propertyFileName)static PropertiesgetProperties(String propertyFileName, Function<List<Properties>,Properties> merger, Runnable onMissing)Look for all property files with the given name (e.g.static List<Properties>loadAllProperties(String propertyFileName)static List<Properties>loadAllProperties(String propertyFileName, Runnable onMissing)static PropertiesmergeProperties(List<Properties> sortedProperties)Merge the given Properties in order of appearance.
-
-
-
Field Detail
-
CONFIGURATION_ORDINAL_DEFAULT_VALUE
public static final int CONFIGURATION_ORDINAL_DEFAULT_VALUE
- See Also:
- Constant Field Values
-
CONFIGURATION_ORDINAL_PROPERTY_NAME
public static final String CONFIGURATION_ORDINAL_PROPERTY_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProperties
public static Properties getProperties(String propertyFileName, Function<List<Properties>,Properties> merger, Runnable onMissing)
Look for all property files with the given name (e.g. 'myconfig.properties') in the classpath. Then load all properties files and sort them by their ascending configuration order and apply them in this order.
The idea is to be able to 'override' properties by just providing a new properties file with the same name but a higher 'configuration.ordinal' than the old one.
If a property file defines no 'configuration.ordinal' property than a default value of
CONFIGURATION_ORDINAL_DEFAULT_VALUEis assumed. Any sensitive default which is provided by the system parsing for the configuration should have a 'configuration.ordinal' value lower than 10. In most cases a value of 1If 2 property files have the same ordinal 'configuraiton.order' the outcome is not really defined. The Properties file which got found first will be processed first and thus get overwritten by the one found later.
- Parameters:
propertyFileName- the name of the properties file.merger- how to merge conflicting properties sets.onMissing- executed when no file is found.- Returns:
- the final property values
-
getProperties
public static Properties getProperties(String propertyFileName)
-
loadAllProperties
public static List<Properties> loadAllProperties(String propertyFileName) throws IOException
- Throws:
IOException
-
loadAllProperties
public static List<Properties> loadAllProperties(String propertyFileName, Runnable onMissing) throws IOException
- Throws:
IOException
-
mergeProperties
public static Properties mergeProperties(List<Properties> sortedProperties)
Merge the given Properties in order of appearance.- Parameters:
sortedProperties-- Returns:
- the merged Properties
-
-