Package org.confng.sources
Class PropertiesSource
- java.lang.Object
-
- org.confng.sources.PropertiesSource
-
- All Implemented Interfaces:
ConfigSource
public class PropertiesSource extends Object implements ConfigSource
Configuration source that reads from Java properties files.This source loads configuration from standard Java properties files using the Properties class for parsing.
- Since:
- 1.0
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
- See Also:
ConfigSource
-
-
Constructor Summary
Constructors Constructor Description PropertiesSource(String filePath)Creates a new PropertiesSource from the given file path (supports both filesystem and classpath).PropertiesSource(Path file)Creates a new PropertiesSource from the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<String>get(String key)Retrieves a configuration value for the given key.StringgetName()Returns the name of this configuration source.intgetPriority()Returns the priority of this configuration source.
-
-
-
Constructor Detail
-
PropertiesSource
public PropertiesSource(String filePath)
Creates a new PropertiesSource from the given file path (supports both filesystem and classpath).- Parameters:
filePath- path to the properties file (filesystem or classpath)- Throws:
IllegalStateException- if the file cannot be loaded
-
PropertiesSource
public PropertiesSource(Path file)
Creates a new PropertiesSource from the given file.- Parameters:
file- path to the properties file- Throws:
IllegalStateException- if the file cannot be loaded
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:ConfigSourceReturns the name of this configuration source.- Specified by:
getNamein interfaceConfigSource- Returns:
- the source name, never null
-
get
public Optional<String> get(String key)
Description copied from interface:ConfigSourceRetrieves a configuration value for the given key.If the key is not found in this source, an empty Optional should be returned. This allows the ConfNG system to try other sources in the resolution chain.
- Specified by:
getin interfaceConfigSource- Parameters:
key- the configuration key to look up- Returns:
- an Optional containing the value if found, empty otherwise
-
getPriority
public int getPriority()
Description copied from interface:ConfigSourceReturns the priority of this configuration source.Sources with higher priority values are consulted first in the resolution chain. Default priorities:
- 100+ - Secret managers and secure sources
- 80-99 - TestNG parameters and test-specific sources
- 60-79 - Environment variables
- 40-59 - System properties
- 20-39 - Configuration files (JSON, Properties)
- 0-19 - Default and fallback sources
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- the priority value, higher values have higher priority
-
-