Class AbstractFileConfigurationManager

  • All Implemented Interfaces:
    io.confound.config.ConfigurationManager
    Direct Known Subclasses:
    FileSystemConfigurationManager, ResourcesConfigurationManager

    public abstract class AbstractFileConfigurationManager
    extends io.confound.config.AbstractConfigurationManager
    A configuration manager that knows how to load a configuration by parsing some document from an input stream.
    Author:
    Garret Wilson
    • Constructor Detail

      • AbstractFileConfigurationManager

        public AbstractFileConfigurationManager​(@Nonnull
                                                java.lang.Iterable<ConfigurationFileFormat> fileFormats,
                                                boolean required)
        Configuration file formats constructor. The provided file formats will be registered with this configuration manager.

        The value returned by each ConfigurationFileFormat.getFilenameExtensions() will be used as format identifiers. If multiple file file formats indicate the same filename extension suffix, the last file format will replace the others for that format. Otherwise the formats will be attempted in the order given.

        Parameters:
        fileFormats - The specific file formats to support.
        required - Whether the manager requires a configuration to be determined when loading.
    • Method Detail

      • defaultFileFormats

        protected static java.lang.Iterable<ConfigurationFileFormat> defaultFileFormats()
        Determines the default configuration file formats. This method returns those formats that have been configured as service providers for the ConfigurationFileFormat class using the ServiceLoader mechanism.
        Returns:
        The default configured configuration file formats.
      • getFileFormatsByExtension

        public java.util.Set<java.util.Map.Entry<java.lang.String,​ConfigurationFileFormat>> getFileFormatsByExtension()
        Returns:
        The available file extensions, in no particular order, paired with the supporting file format.
      • getFileFormatForExtension

        public java.util.Optional<ConfigurationFileFormat> getFileFormatForExtension​(@Nonnull
                                                                                     java.lang.String id)
        Determines the file format to use for the given filename extension.
        Parameters:
        id - The filename extension suffix.
        Returns:
        The configured file format for the extension, if any.
      • getFileFormatForFilename

        public java.util.Optional<ConfigurationFileFormat> getFileFormatForFilename​(@Nonnull
                                                                                    java.lang.CharSequence filename)
        Determines the file format to use for the given filename based on the registered formats and the filename extension(s). If the file has multiple extensions, the registered file format for the longest extension will be used.
        Parameters:
        filename - The filename for which the file format should be determined.
        Returns:
        The configured file format for the filename, if any.
      • createConfigurationNotFoundException

        public static io.confound.config.ConfigurationException createConfigurationNotFoundException()
        Utility factory method for creating a configuration exception indicating that no supported configuration file could be found.
        Returns:
        A new configuration exception indicating no configuration file found.