Package net.morimekta.providence.config
Class ConfigLoader
- java.lang.Object
-
- net.morimekta.providence.config.ConfigLoader
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ConfigLoader extends java.lang.Object implements java.lang.AutoCloseable
Providence config loader. This loads providence configs.
-
-
Constructor Summary
Constructors Constructor Description ConfigLoader(TypeRegistry registry)
Make a non-strict config instance.ConfigLoader(TypeRegistry registry, java.util.function.Consumer<ConfigWarning> warningHandler)
Make a non-strict config instance.ConfigLoader(TypeRegistry registry, net.morimekta.util.FileWatcher watcher, java.util.function.Consumer<ConfigWarning> warningHandler, boolean strict)
Make a config instance.ConfigLoader(TypeRegistry registry, net.morimekta.util.FileWatcher watcher, java.util.function.Consumer<ConfigWarning> warningHandler, boolean strict, java.time.Clock clock)
Make a config instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
<M extends PMessage<M>>
MgetConfig(java.nio.file.Path configFile)
Get config for the given file.<M extends PMessage<M>>
MgetConfig(java.nio.file.Path configFile, M parent)
Get config for the given with parent.<M extends PMessage<M>>
ConfigSupplier<M>loadFile(java.nio.file.Path configFile)
Load a config file without parent config like on config file includes.<M extends PMessage<M>>
ConfigSupplier<M>loadFile(java.nio.file.Path configFile, ConfigSupplier<M> parentConfig)
Load a config file overlaying another config.<M extends PMessage<M>>
ConfigSupplier<M>loadResource(java.lang.String resourcePath)
Load a config resource without parent config like on config file includes.
-
-
-
Constructor Detail
-
ConfigLoader
public ConfigLoader(@Nonnull TypeRegistry registry)
Make a non-strict config instance.- Parameters:
registry
- The type registry used to find message and enum types.
-
ConfigLoader
public ConfigLoader(@Nonnull TypeRegistry registry, @Nonnull java.util.function.Consumer<ConfigWarning> warningHandler)
Make a non-strict config instance.- Parameters:
registry
- The type registry used to find message and enum types.warningHandler
- Handle parse warnings.
-
ConfigLoader
public ConfigLoader(@Nonnull TypeRegistry registry, @Nonnull net.morimekta.util.FileWatcher watcher, @Nonnull java.util.function.Consumer<ConfigWarning> warningHandler, boolean strict)
Make a config instance.- Parameters:
registry
- The type registry used to find message and enum types.watcher
- File watcher used to detect config file updates.warningHandler
- Handle parse warnings.strict
- If the config should be parsed and verified strictly.
-
ConfigLoader
public ConfigLoader(@Nonnull TypeRegistry registry, @Nonnull net.morimekta.util.FileWatcher watcher, @Nonnull java.util.function.Consumer<ConfigWarning> warningHandler, boolean strict, @Nonnull java.time.Clock clock)
Make a config instance.- Parameters:
registry
- The type registry used to find message and enum types.watcher
- File watcher used to detect config file updates.warningHandler
- Handle parse warnings.strict
- If the config should be parsed strictly.clock
- The clock to use in timing config loads.
-
-
Method Detail
-
loadFile
@Nonnull public <M extends PMessage<M>> ConfigSupplier<M> loadFile(@Nonnull java.nio.file.Path configFile, @Nonnull ConfigSupplier<M> parentConfig) throws ConfigException
Load a config file overlaying another config.- Type Parameters:
M
- The message type.- Parameters:
configFile
- The file to resolve.parentConfig
- The parent config supplier if any.- Returns:
- The resolved config.
- Throws:
ConfigException
- If parsing of config failed.
-
loadFile
@Nonnull public <M extends PMessage<M>> ConfigSupplier<M> loadFile(@Nonnull java.nio.file.Path configFile) throws ConfigException
Load a config file without parent config like on config file includes.- Type Parameters:
M
- The message type.- Parameters:
configFile
- The file to resolve.- Returns:
- The resolved config.
- Throws:
ConfigException
- If parsing of config failed.
-
loadResource
public <M extends PMessage<M>> ConfigSupplier<M> loadResource(@Nonnull java.lang.String resourcePath) throws ConfigException
Load a config resource without parent config like on config file includes.- Type Parameters:
M
- The message type.- Parameters:
resourcePath
- The file to resolve.- Returns:
- The resolved config.
- Throws:
ConfigException
- If parsing of config failed.
-
getConfig
@Nonnull public <M extends PMessage<M>> M getConfig(@Nonnull java.nio.file.Path configFile) throws ConfigException
Get config for the given file.- Type Parameters:
M
- The config message type.- Parameters:
configFile
- The file to read config for.- Returns:
- The config message.
- Throws:
ConfigException
- On config load failure.
-
getConfig
@Nonnull public <M extends PMessage<M>> M getConfig(@Nonnull java.nio.file.Path configFile, @Nonnull M parent) throws ConfigException
Get config for the given with parent.- Type Parameters:
M
- The config message type.- Parameters:
configFile
- The file to read config for.parent
- The designated parent config.- Returns:
- The config message.
- Throws:
ConfigException
- On config load failure.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-