- java.lang.Object
-
- org.github.gestalt.config.builder.GestaltBuilder
-
public class GestaltBuilder extends java.lang.ObjectBuilder to setup and create the Gestalt config class.The minimum requirements for building a config is to provide a source. Gestalt gestalt = new GestaltBuilder() .addSource(new FileConfigSource(defaultFile)) .build();
The builder will automatically add the default config loaders and decoders. You can customise and replace functionality as needed using the appropriate builder methods.
If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed. If there are any config loaders set, it will not add the default config loaders. So you will need to add the defaults manually if needed.
The builder can be used to customize and replace any of the functionality of Gestalt.
-
-
Constructor Summary
Constructors Constructor Description GestaltBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description GestaltBuilderaddConfigLoader(ConfigLoader configLoader)Add a config loader.GestaltBuilderaddConfigLoaders(java.util.List<ConfigLoader> configLoaders)Adds a list of config loader to the builder.GestaltBuilderaddCoreReloadListener(java.util.List<CoreReloadListener> coreCoreReloadListeners)Add a list of Core reload listener.GestaltBuilderaddCoreReloadListener(CoreReloadListener coreReloadListener)Add a Core reload listener to the builder.GestaltBuilderaddDecoder(Decoder decoder)Add a decoder.GestaltBuilderaddDecoders(java.util.List<Decoder<?>> decoders)Add a list of decoders.GestaltBuilderaddDefaultConfigLoaders()Add default config loaders to the builder.GestaltBuilderaddDefaultDecoders()Adds all default decoders to the builder.GestaltBuilderaddDefaultPathMappers()Add default post processors to the builder.GestaltBuilderaddDefaultPostProcessors()Add default post processors to the builder.GestaltBuilderaddModuleConfig(GestaltModuleConfig extension)GestaltBuilderaddPathMapper(java.util.List<PathMapper> pathMappers)List of PostProcessor to add to the builder.GestaltBuilderaddPathMapper(PathMapper pathMapper)Add a single PathMapper to the builder.GestaltBuilderaddPostProcessor(PostProcessor postProcessor)Add a single PostProcessor to the builder.GestaltBuilderaddPostProcessors(java.util.List<PostProcessor> postProcessors)List of PostProcessor to add to the builder.GestaltBuilderaddReloadStrategies(java.util.List<ConfigReloadStrategy> reloadStrategies)Deprecated, for removal: This API element is subject to removal in a future version.GestaltBuilderaddReloadStrategy(ConfigReloadStrategy configReloadStrategy)Deprecated, for removal: This API element is subject to removal in a future version.GestaltBuilderaddSource(ConfigSource source)Deprecated.GestaltBuilderaddSource(ConfigSourcePackage configSourcePackage)Add a single ConfigSourcePackage built with a builder, to gestalt the builder.GestaltBuilderaddSources(java.util.List<ConfigSourcePackage> configSourcePackage)Add a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.Gestaltbuild()Build Gestalt.protected java.util.List<ConfigLoader>dedupeConfigLoaders()Dedupe the list of config loaders and return the deduped list.protected java.util.List<Decoder<?>>dedupeDecoders()dedupe decoders and return the deduped list.TagsgetDefaultTags()Get default tags to apply to all calls to get a configuration when tags are not provided.java.lang.System.Logger.LevelgetLogLevelForMissingValuesWhenDefaultOrOptional()Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.java.lang.IntegergetMaxSubstitutionNestedDepth()Get the maximum string substitution nested depth.ProxyDecoderModegetProxyDecoderMode()Get the mode the for proxy decoder.java.lang.StringgetSubstitutionRegex()the regex used to parse string substitutions.java.lang.BooleanisTreatWarningsAsErrors()Get Treat warnings as errors.GestaltBuildersetConfigLoaders(java.util.List<ConfigLoader> configLoaders)Sets a list of config loader to the builder.GestaltBuildersetConfigLoaderService(ConfigLoaderService configLoaderService)Add a config loader service to the builder.GestaltBuildersetConfigNodeService(ConfigNodeService configNodeService)Set the config node service if you want to provide your own.GestaltBuildersetDateDecoderFormat(java.time.format.DateTimeFormatter dateDecoderFormat)Set a date decoder format.GestaltBuildersetDecoders(java.util.List<Decoder<?>> decoders)Set a list of decoders, replaces the existing decoders.GestaltBuildersetDecoderService(DecoderService decoderService)Set the decoder service if you want to provide your own.GestaltBuildersetDefaultTags(Tags defaultTags)Set default tags to apply to all calls to get a configuration when tags are not provided.GestaltBuildersetGestaltConfig(GestaltConfig gestaltConfig)Set the configuration for Gestalt.GestaltBuildersetLocalDateFormat(java.time.format.DateTimeFormatter localDateFormat)Set a local date format.GestaltBuildersetLocalDateTimeFormat(java.time.format.DateTimeFormatter localDateTimeFormat)Set a local date time format.GestaltBuildersetLogLevelForMissingValuesWhenDefaultOrOptional(java.lang.System.Logger.Level logLevelForMissingValuesWhenDefaultOrOptional)Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.GestaltBuildersetMaxSubstitutionNestedDepth(java.lang.Integer maxSubstitutionNestedDepth)Set the maximum string substitution nested depth.GestaltBuildersetPathMappers(java.util.List<PathMapper> pathMappers)Sets the list of PathMappers.GestaltBuildersetPostProcessors(java.util.List<PostProcessor> postProcessors)Sets the list of PostProcessors.GestaltBuildersetProxyDecoderMode(ProxyDecoderMode proxyDecoderMode)Set the mode the for proxy decoder.GestaltBuildersetSentenceLexer(SentenceLexer sentenceLexer)Set the sentence lexer that will be passed through to the DecoderRegistry.GestaltBuildersetSources(java.util.List<ConfigSourcePackage> configSourcePackage)Set a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.GestaltBuildersetSubstitutionClosingToken(java.lang.String substitutionClosingToken)Token that represents the closing of a string substitution.GestaltBuildersetSubstitutionOpeningToken(java.lang.String substitutionOpeningToken)Set a Token that represents the opening of a string substitution.GestaltBuildersetSubstitutionRegex(java.lang.String substitutionRegex)the regex used to parse string substitutions.GestaltBuildersetTreatMissingArrayIndexAsError(java.lang.Boolean treatMissingArrayIndexAsError)Treat missing array indexes as errors.GestaltBuildersetTreatMissingValuesAsErrors(java.lang.Boolean treatMissingValuesAsErrors)treat missing object values as errors.GestaltBuildersetTreatNullValuesInClassAsErrors(java.lang.Boolean treatNullValuesInClassAsErrors)Treat null values in classes after decoding as errors.GestaltBuildersetTreatWarningsAsErrors(boolean warningsAsErrors)Treat warnings as errors.GestaltBuilderuseCacheDecorator(boolean useCacheDecorator)Add a cache layer to gestalt.
-
-
-
Method Detail
-
addDefaultDecoders
public GestaltBuilder addDefaultDecoders()
Adds all default decoders to the builder. Uses the ServiceLoader to find all registered Decoders and adds them- Returns:
- GestaltBuilder builder
-
addDefaultConfigLoaders
public GestaltBuilder addDefaultConfigLoaders()
Add default config loaders to the builder. Uses the ServiceLoader to find all registered Config Loaders and adds them- Returns:
- GestaltBuilder builder
-
addDefaultPostProcessors
public GestaltBuilder addDefaultPostProcessors()
Add default post processors to the builder. Uses the ServiceLoader to find all registered post processors and adds them- Returns:
- GestaltBuilder builder
-
addDefaultPathMappers
public GestaltBuilder addDefaultPathMappers()
Add default post processors to the builder. Uses the ServiceLoader to find all registered post processors and adds them- Returns:
- GestaltBuilder builder
-
addSource
@Deprecated(since="0.23.4") public GestaltBuilder addSource(ConfigSource source)
Deprecated.Add a single source to the builder.Deprecated prefer the use of
addSourcewith a source builder- Parameters:
source- add a single sources- Returns:
- GestaltBuilder builder
-
addSource
public GestaltBuilder addSource(ConfigSourcePackage configSourcePackage)
Add a single ConfigSourcePackage built with a builder, to gestalt the builder.- Parameters:
configSourcePackage- add a single Config source Package- Returns:
- GestaltBuilder builder
-
setSources
public GestaltBuilder setSources(java.util.List<ConfigSourcePackage> configSourcePackage)
Set a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.- Parameters:
configSourcePackage- set a list of ConfigSourcePackage- Returns:
- GestaltBuilder builder
-
addSources
public GestaltBuilder addSources(java.util.List<ConfigSourcePackage> configSourcePackage)
Add a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.- Parameters:
configSourcePackage- add list of Config source Package- Returns:
- GestaltBuilder builder
-
addReloadStrategy
@Deprecated(since="0.23.4", forRemoval=true) public GestaltBuilder addReloadStrategy(ConfigReloadStrategy configReloadStrategy)Deprecated, for removal: This API element is subject to removal in a future version.Add a config reload strategy to the builder.Deprecated prefer the use of
addSourcewith a source builder. Use the source builder to add a reload strategy- Parameters:
configReloadStrategy- add a config reload strategy.- Returns:
- GestaltBuilder builder
-
addReloadStrategies
@Deprecated(since="0.23.4", forRemoval=true) public GestaltBuilder addReloadStrategies(java.util.List<ConfigReloadStrategy> reloadStrategies)Deprecated, for removal: This API element is subject to removal in a future version.Add a list of config reload strategies to the builder. Deprecated prefer the use ofaddSourcewith a source builder. Use the source builder to add a reload strategy- Parameters:
reloadStrategies- list of config reload strategies.- Returns:
- GestaltBuilder builder
-
addCoreReloadListener
public GestaltBuilder addCoreReloadListener(CoreReloadListener coreReloadListener)
Add a Core reload listener to the builder.- Parameters:
coreReloadListener- a Core reload listener- Returns:
- GestaltBuilder builder
-
addCoreReloadListener
public GestaltBuilder addCoreReloadListener(java.util.List<CoreReloadListener> coreCoreReloadListeners)
Add a list of Core reload listener.- Parameters:
coreCoreReloadListeners- a list of Core reload listener- Returns:
- GestaltBuilder builder
-
setConfigLoaderService
public GestaltBuilder setConfigLoaderService(ConfigLoaderService configLoaderService)
Add a config loader service to the builder.- Parameters:
configLoaderService- a config loader service- Returns:
- GestaltBuilder builder
-
setConfigLoaders
public GestaltBuilder setConfigLoaders(java.util.List<ConfigLoader> configLoaders) throws GestaltConfigurationException
Sets a list of config loader to the builder. Replaces any currently set. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.- Parameters:
configLoaders- a list of config loader- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- if there are no config loaders.
-
addConfigLoaders
public GestaltBuilder addConfigLoaders(java.util.List<ConfigLoader> configLoaders) throws GestaltConfigurationException
Adds a list of config loader to the builder. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.- Parameters:
configLoaders- a list of config loader- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- if the config loaders are empty
-
addConfigLoader
public GestaltBuilder addConfigLoader(ConfigLoader configLoader)
Add a config loader. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.- Parameters:
configLoader- a config loader- Returns:
- GestaltBuilder builder
-
setPostProcessors
public GestaltBuilder setPostProcessors(java.util.List<PostProcessor> postProcessors) throws GestaltConfigurationException
Sets the list of PostProcessors. Replaces any PostProcessors already set.- Parameters:
postProcessors- list of postProcessors to run.- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- exception if there are no postProcessors
-
addPostProcessors
public GestaltBuilder addPostProcessors(java.util.List<PostProcessor> postProcessors) throws GestaltConfigurationException
List of PostProcessor to add to the builder.- Parameters:
postProcessors- list of PostProcessor to add.- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- no PostProcessor provided
-
addPostProcessor
public GestaltBuilder addPostProcessor(PostProcessor postProcessor)
Add a single PostProcessor to the builder.- Parameters:
postProcessor- add a single PostProcessor- Returns:
- GestaltBuilder builder
-
setPathMappers
public GestaltBuilder setPathMappers(java.util.List<PathMapper> pathMappers) throws GestaltConfigurationException
Sets the list of PathMappers. Replaces any PathMappers already set.- Parameters:
pathMappers- list of pathMappers to run.- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- exception if there are no pathMappers
-
addPathMapper
public GestaltBuilder addPathMapper(java.util.List<PathMapper> pathMappers) throws GestaltConfigurationException
List of PostProcessor to add to the builder.- Parameters:
pathMappers- list of PathMapper to add.- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- no PathMapper provided
-
addPathMapper
public GestaltBuilder addPathMapper(PathMapper pathMapper)
Add a single PathMapper to the builder.- Parameters:
pathMapper- add a single PathMapper- Returns:
- GestaltBuilder builder
-
setSentenceLexer
public GestaltBuilder setSentenceLexer(SentenceLexer sentenceLexer)
Set the sentence lexer that will be passed through to the DecoderRegistry.- Parameters:
sentenceLexer- for the DecoderRegistry- Returns:
- GestaltBuilder builder
-
setGestaltConfig
public GestaltBuilder setGestaltConfig(GestaltConfig gestaltConfig)
Set the configuration for Gestalt. Will be overridden by any settings specified in the builder- Parameters:
gestaltConfig- configuration for the Gestalt- Returns:
- GestaltBuilder builder
-
setConfigNodeService
public GestaltBuilder setConfigNodeService(ConfigNodeService configNodeService)
Set the config node service if you want to provide your own. Otherwise a default is provided.- Parameters:
configNodeService- a config node service- Returns:
- GestaltBuilder builder
-
setDecoderService
public GestaltBuilder setDecoderService(DecoderService decoderService)
Set the decoder service if you want to provide your own. Otherwise a default is provided. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.- Parameters:
decoderService- decoder service- Returns:
- GestaltBuilder builder
-
setDecoders
public GestaltBuilder setDecoders(java.util.List<Decoder<?>> decoders) throws GestaltConfigurationException
Set a list of decoders, replaces the existing decoders. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.- Parameters:
decoders- list of decoders- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- no decoders provided
-
addDecoders
public GestaltBuilder addDecoders(java.util.List<Decoder<?>> decoders) throws GestaltConfigurationException
Add a list of decoders. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.- Parameters:
decoders- list of decoders- Returns:
- GestaltBuilder builder
- Throws:
GestaltConfigurationException- no decoders provided
-
addDecoder
public GestaltBuilder addDecoder(Decoder decoder)
Add a decoder. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.- Parameters:
decoder- add a decoder- Returns:
- GestaltBuilder builder
-
addModuleConfig
public GestaltBuilder addModuleConfig(GestaltModuleConfig extension)
-
setTreatWarningsAsErrors
public GestaltBuilder setTreatWarningsAsErrors(boolean warningsAsErrors)
Treat warnings as errors.- Parameters:
warningsAsErrors- treat warnings as errors.- Returns:
- GestaltBuilder builder
-
isTreatWarningsAsErrors
public java.lang.Boolean isTreatWarningsAsErrors()
Get Treat warnings as errors.- Returns:
- warningsAsErrors
-
setTreatMissingArrayIndexAsError
public GestaltBuilder setTreatMissingArrayIndexAsError(java.lang.Boolean treatMissingArrayIndexAsError)
Treat missing array indexes as errors.- Parameters:
treatMissingArrayIndexAsError- treat missing array indexes as errors.- Returns:
- GestaltBuilder builder
-
setTreatMissingValuesAsErrors
public GestaltBuilder setTreatMissingValuesAsErrors(java.lang.Boolean treatMissingValuesAsErrors)
treat missing object values as errors.- Parameters:
treatMissingValuesAsErrors- treat missing object values as errors- Returns:
- GestaltBuilder builder
-
setTreatNullValuesInClassAsErrors
public GestaltBuilder setTreatNullValuesInClassAsErrors(java.lang.Boolean treatNullValuesInClassAsErrors)
Treat null values in classes after decoding as errors.- Parameters:
treatNullValuesInClassAsErrors- treat null values in classes after decoding as errors- Returns:
- GestaltBuilder builder
-
useCacheDecorator
public GestaltBuilder useCacheDecorator(boolean useCacheDecorator)
Add a cache layer to gestalt.- Parameters:
useCacheDecorator- use a cache decorator.- Returns:
- GestaltBuilder builder
-
setDateDecoderFormat
public GestaltBuilder setDateDecoderFormat(java.time.format.DateTimeFormatter dateDecoderFormat)
Set a date decoder format. Used to decode date times.- Parameters:
dateDecoderFormat- a date decoder format- Returns:
- GestaltBuilder builder
-
getLogLevelForMissingValuesWhenDefaultOrOptional
public java.lang.System.Logger.Level getLogLevelForMissingValuesWhenDefaultOrOptional()
Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.- Returns:
- Log level
-
setLogLevelForMissingValuesWhenDefaultOrOptional
public GestaltBuilder setLogLevelForMissingValuesWhenDefaultOrOptional(java.lang.System.Logger.Level logLevelForMissingValuesWhenDefaultOrOptional)
Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.- Parameters:
logLevelForMissingValuesWhenDefaultOrOptional- log level- Returns:
- GestaltBuilder builder
-
setLocalDateTimeFormat
public GestaltBuilder setLocalDateTimeFormat(java.time.format.DateTimeFormatter localDateTimeFormat)
Set a local date time format. Used to decode local date times.- Parameters:
localDateTimeFormat- a date decoder format- Returns:
- GestaltBuilder builder
-
setLocalDateFormat
public GestaltBuilder setLocalDateFormat(java.time.format.DateTimeFormatter localDateFormat)
Set a local date format. Used to decode local date.- Parameters:
localDateFormat- a local date decoder format- Returns:
- GestaltBuilder builder
-
setSubstitutionOpeningToken
public GestaltBuilder setSubstitutionOpeningToken(java.lang.String substitutionOpeningToken)
Set a Token that represents the opening of a string substitution.- Parameters:
substitutionOpeningToken- Token that represents the opening of a string substitution.- Returns:
- GestaltBuilder builder
-
setSubstitutionClosingToken
public GestaltBuilder setSubstitutionClosingToken(java.lang.String substitutionClosingToken)
Token that represents the closing of a string substitution.- Parameters:
substitutionClosingToken- a token that represents the closing of a string substitution.- Returns:
- GestaltBuilder builder
-
getMaxSubstitutionNestedDepth
public java.lang.Integer getMaxSubstitutionNestedDepth()
Get the maximum string substitution nested depth. If you have nested or recursive substitutions that go deeper than this it will fail.- Returns:
- the maximum string substitution nested depth.
-
setMaxSubstitutionNestedDepth
public GestaltBuilder setMaxSubstitutionNestedDepth(java.lang.Integer maxSubstitutionNestedDepth)
Set the maximum string substitution nested depth. If you have nested or recursive substitutions that go deeper than this it will fail.- Parameters:
maxSubstitutionNestedDepth- the maximum string substitution nested depth.- Returns:
- GestaltBuilder builder
-
getSubstitutionRegex
public java.lang.String getSubstitutionRegex()
the regex used to parse string substitutions. Must have a named capture group transform, key, and default, where the key is required and the transform and default are optional.- Returns:
- the string substitution regex
-
setSubstitutionRegex
public GestaltBuilder setSubstitutionRegex(java.lang.String substitutionRegex)
the regex used to parse string substitutions. Must have a named capture group transform, key, and default, where the key is required and the transform and default are optional.- Parameters:
substitutionRegex- the string substitution regex- Returns:
- GestaltBuilder builder
-
getProxyDecoderMode
public ProxyDecoderMode getProxyDecoderMode()
Get the mode the for proxy decoder.- Returns:
- the mode the for proxy decoder
-
setProxyDecoderMode
public GestaltBuilder setProxyDecoderMode(ProxyDecoderMode proxyDecoderMode)
Set the mode the for proxy decoder.- Parameters:
proxyDecoderMode- the mode the for proxy decoder- Returns:
- GestaltBuilder builder
-
getDefaultTags
public Tags getDefaultTags()
Get default tags to apply to all calls to get a configuration when tags are not provided.- Returns:
- default tags
-
setDefaultTags
public GestaltBuilder setDefaultTags(Tags defaultTags)
Set default tags to apply to all calls to get a configuration when tags are not provided.- Parameters:
defaultTags- Set of default tags to apply to all calls to get a configuration when tags are not provided.- Returns:
- GestaltBuilder builder
-
dedupeDecoders
protected java.util.List<Decoder<?>> dedupeDecoders()
dedupe decoders and return the deduped list.- Returns:
- deduped list of decoders.
-
dedupeConfigLoaders
protected java.util.List<ConfigLoader> dedupeConfigLoaders()
Dedupe the list of config loaders and return the deduped list.- Returns:
- a list of deduped config loaders.
-
build
public Gestalt build() throws GestaltConfigurationException
Build Gestalt.- Returns:
- Gestalt
- Throws:
GestaltConfigurationException- multiple validations can throw exceptions
-
-