java.lang.Object
org.miaixz.bus.setting.magic.Profile
- All Implemented Interfaces:
Serializable
Represents a configuration profile, allowing for environment-specific settings. A profile defines a set of
configuration files that are activated under certain conditions. For example, you can define profiles like 'test',
'develop', and 'production', where each profile loads configuration files from a corresponding directory (e.g.,
/test/db.setting, /develop/db.setting).- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear()Clears the cache of all loadedSettinginstances.getSetting(String name) Gets aSettinginstance for a given file name under the current profile.setCharset(Charset charset) Sets the character set to be used for reading configuration files.setProfile(String profile) Sets the active profile.setUseVar(boolean useVar) Sets whether to enable variable substitution in configuration files.
-
Constructor Details
-
Profile
public Profile()Default constructor. Uses the profile name "default", UTF-8 encoding, and disables variable substitution. -
Profile
Constructs a profile with a specific name, UTF-8 encoding, and no variable substitution.- Parameters:
profile- The environment profile name.
-
Profile
Constructs a profile with full configuration.- Parameters:
profile- The environment profile name.charset- The character set for reading files.useVar-trueto enable variable substitution.
-
-
Method Details
-
getSetting
Gets aSettinginstance for a given file name under the current profile. The file is loaded from a path constructed as[profile_name]/[file_name]. Instances are cached to avoid repeated file loading.- Parameters:
name- The name of the settings file. If no extension is provided, ".setting" is assumed.- Returns:
- The
Settinginstance for the current profile.
-
setProfile
Sets the active profile.- Parameters:
profile- The new profile name.- Returns:
- This
Profileinstance for chaining.
-
setCharset
Sets the character set to be used for reading configuration files.- Parameters:
charset- The new character set.- Returns:
- This
Profileinstance for chaining.
-
setUseVar
Sets whether to enable variable substitution in configuration files.- Parameters:
useVar-trueto enable variable substitution.- Returns:
- This
Profileinstance for chaining.
-
clear
Clears the cache of all loadedSettinginstances.- Returns:
- This
Profileinstance for chaining.
-