Module bus.setting

Class Profile

java.lang.Object
org.miaixz.bus.setting.magic.Profile
All Implemented Interfaces:
Serializable

public class Profile extends Object implements 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 Details

    • Profile

      public Profile()
      Default constructor. Uses the profile name "default", UTF-8 encoding, and disables variable substitution.
    • Profile

      public Profile(String profile)
      Constructs a profile with a specific name, UTF-8 encoding, and no variable substitution.
      Parameters:
      profile - The environment profile name.
    • Profile

      public Profile(String profile, Charset charset, boolean useVar)
      Constructs a profile with full configuration.
      Parameters:
      profile - The environment profile name.
      charset - The character set for reading files.
      useVar - true to enable variable substitution.
  • Method Details

    • getSetting

      public Setting getSetting(String name)
      Gets a Setting instance 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 Setting instance for the current profile.
    • setProfile

      public Profile setProfile(String profile)
      Sets the active profile.
      Parameters:
      profile - The new profile name.
      Returns:
      This Profile instance for chaining.
    • setCharset

      public Profile setCharset(Charset charset)
      Sets the character set to be used for reading configuration files.
      Parameters:
      charset - The new character set.
      Returns:
      This Profile instance for chaining.
    • setUseVar

      public Profile setUseVar(boolean useVar)
      Sets whether to enable variable substitution in configuration files.
      Parameters:
      useVar - true to enable variable substitution.
      Returns:
      This Profile instance for chaining.
    • clear

      public Profile clear()
      Clears the cache of all loaded Setting instances.
      Returns:
      This Profile instance for chaining.