Package ch.kk7.confij
Class ConfijBuilder<T>
- java.lang.Object
-
- ch.kk7.confij.ConfijBuilder<T>
-
public class ConfijBuilder<T> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfijBuilder.ConfijWrapper<T>
-
Constructor Summary
Constructors Modifier Constructor Description protectedConfijBuilder(@NonNull java.lang.reflect.Type forType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <I> ConfijBuilder<T>bindValuesForClassWith(ValueMapperInstance<I> valueMapper, java.lang.Class<I> forClass)Convenience method to register aValueMapperFactorywhich will only handle a single class.ConfijBuilder<T>bindValuesWith(ValueMapperFactory valueMapperFactory)Globally register an additionalValueMapperFactory.Tbuild()Finalize the configuration pipeline and build a single instance of it.ConfijBuilder.ConfijWrapper<T>buildWrapper()Finalize the configuration pipeline and build a single instance holding the most recent configuration.protected voidlazySetDefaults()ConfijBuilder<T>loadFrom(ConfijSource... source)Read configuration values from these ordered sources.ConfijBuilder<T>loadFrom(ConfijResource... resources)Read configuration values from these ordered resources (like from FS, git,...).ConfijBuilder<T>loadFrom(ConfijResource resource, ConfijFormat format)Read configuration values from a well defined source and format.ConfijBuilder<T>loadFrom(java.lang.String... sourceStr)Read configuration values from these orderedAnySources.ConfijBuilder<T>loadFromFirstOf(java.lang.String firstSource, java.lang.String secondSource, java.lang.String... otherSources)Attempt reading configurations from these orderedAnySources.ConfijBuilder<T>loadOptionalFrom(java.lang.String... maybeSourceStr)Attempt reading configurationd from all of these orderedAnySources.protected @NonNull BindingContextnewBindingContext()protected @NonNull NodeBindingContextnewNodeBindingContext()protected @NonNull ConfijPipeline<T>newPipeline()static <X> ConfijBuilder<X>of(GenericType<X> forType)This constructor is used to pass full generics type information, and avoid problems with type erasure (that basically removes most usable type references from runtime Class objects).static <X> ConfijBuilder<X>of(java.lang.Class<X> forClass)The most common constructor to create a new configuration builder of given type.ConfijBuilder<T>reloadPeriodically(@NonNull java.time.Duration duration)APeriodicReloadStrategywith initial delay equal to interval durationConfijBuilder<T>reloadStrategy(@NonNull ConfijReloadStrategy reloadStrategy)define when/how new configurations are loaded.ConfijBuilder<T>templatingDisabled()disables templating (variable substitution), such that your values containing${variables}just stay as they are.ConfijBuilder<T>templatingWith(@NonNull ValueResolver valueResolver)ConfijBuilder<T>validateOnlyWith(@NonNull ConfijValidator<T> validator)replace the default validation/post-processing steps with this new validator.ConfijBuilder<T>validationAllowsNull()ConfijBuilder<T>validationDisabled()Explicitly disable all validation/post-processing steps.
-
-
-
Method Detail
-
lazySetDefaults
protected void lazySetDefaults()
-
of
public static <X> ConfijBuilder<X> of(java.lang.Class<X> forClass)
The most common constructor to create a new configuration builder of given type.- Type Parameters:
X- the configuration instance type- Parameters:
forClass- the configuration instance class- Returns:
- a ConfiJ builder
-
of
public static <X> ConfijBuilder<X> of(GenericType<X> forType)
This constructor is used to pass full generics type information, and avoid problems with type erasure (that basically removes most usable type references from runtime Class objects).- Type Parameters:
X- the configuration instance type- Parameters:
forType- type holder class- Returns:
- a ConfiJ builder
- See Also:
GenericType
-
loadFrom
public ConfijBuilder<T> loadFrom(ConfijSource... source)
Read configuration values from these ordered sources. Intended for more complex scenarios, whereloadFrom(String...)isn't good enough.- Parameters:
source- list of configuration sources- Returns:
- self
-
loadFrom
public ConfijBuilder<T> loadFrom(java.lang.String... sourceStr)
Read configuration values from these orderedAnySources.- Parameters:
sourceStr- list of path's to configuration sources- Returns:
- self
-
loadFrom
public ConfijBuilder<T> loadFrom(ConfijResource... resources)
Read configuration values from these ordered resources (like from FS, git,...). The format of the content is guessed.- Parameters:
resources- list of resources (like files,...) to read configurations from- Returns:
- self
-
loadFrom
public ConfijBuilder<T> loadFrom(ConfijResource resource, ConfijFormat format)
Read configuration values from a well defined source and format. Equivalent toloadFrom(ConfijSource...).- Parameters:
resource- resource (like files,...) to read configurations fromformat- the actual format which understants the content of resource- Returns:
- self
-
loadOptionalFrom
public ConfijBuilder<T> loadOptionalFrom(java.lang.String... maybeSourceStr)
Attempt reading configurationd from all of these orderedAnySources. Read failures are dropped silently. Usefull for optional configuration, like for tests only.- Parameters:
maybeSourceStr- optional sources, reading all of them is attempted- Returns:
- self
- See Also:
MaybeSource
-
loadFromFirstOf
public ConfijBuilder<T> loadFromFirstOf(java.lang.String firstSource, java.lang.String secondSource, java.lang.String... otherSources)
Attempt reading configurations from these orderedAnySources. Ignore all configurations before and after the first successful read. Usefull if a set of configurations should be ignored if another one is present.- Parameters:
firstSource- an optional sourcesecondSource- an optional sourceotherSources- more optional sources, only read if not an earlier one existed- Returns:
- self
- See Also:
OrSource
-
validateOnlyWith
public ConfijBuilder<T> validateOnlyWith(@NonNull @NonNull ConfijValidator<T> validator)
replace the default validation/post-processing steps with this new validator. The default is to load allServiceLoaders implementingConfijValidator. To combine multiple validators use aMultiValidator.- Parameters:
validator- the new validator- Returns:
- self
-
validationAllowsNull
public ConfijBuilder<T> validationAllowsNull()
-
validationDisabled
public ConfijBuilder<T> validationDisabled()
Explicitly disable all validation/post-processing steps.- Returns:
- self
- See Also:
validateOnlyWith(ConfijValidator)
-
templatingWith
public ConfijBuilder<T> templatingWith(@NonNull @NonNull ValueResolver valueResolver)
-
templatingDisabled
public ConfijBuilder<T> templatingDisabled()
disables templating (variable substitution), such that your values containing${variables}just stay as they are.- Returns:
- self
-
bindValuesWith
public ConfijBuilder<T> bindValuesWith(ValueMapperFactory valueMapperFactory)
Globally register an additionalValueMapperFactory. This allows for custom classes in your configuration definition. Same as writing\@ValueMapper(CustomMapper.class) interface MyConfigRoot { ... }- Parameters:
valueMapperFactory- the new mapper with highest preference- Returns:
- self
- See Also:
bindValuesForClassWith(ValueMapperInstance, Class)
-
bindValuesForClassWith
public <I> ConfijBuilder<T> bindValuesForClassWith(ValueMapperInstance<I> valueMapper, java.lang.Class<I> forClass)
Convenience method to register aValueMapperFactorywhich will only handle a single class.- Type Parameters:
I- the target type- Parameters:
valueMapper- functional interface to convert a string toIforClass- the class ofI- Returns:
- self
-
reloadStrategy
public ConfijBuilder<T> reloadStrategy(@NonNull @NonNull ConfijReloadStrategy reloadStrategy)
define when/how new configurations are loaded. default is aNeverReloadStrategy.- Parameters:
reloadStrategy- the new reload strategy to be used- Returns:
- self
-
reloadPeriodically
public ConfijBuilder<T> reloadPeriodically(@NonNull @NonNull java.time.Duration duration)
APeriodicReloadStrategywith initial delay equal to interval duration- Parameters:
duration- time between reload attempts- Returns:
- self
-
newBindingContext
@NonNull protected @NonNull BindingContext newBindingContext()
-
newNodeBindingContext
@NonNull protected @NonNull NodeBindingContext newNodeBindingContext()
-
newPipeline
@NonNull protected @NonNull ConfijPipeline<T> newPipeline()
-
build
public T build()
Finalize the configuration pipeline and build a single instance of it. In cases where you enable periodic configuration reloading, usebuildWrapper()instead.- Returns:
- a fully initialized configuration instance
-
buildWrapper
public ConfijBuilder.ConfijWrapper<T> buildWrapper()
Finalize the configuration pipeline and build a single instance holding the most recent configuration. In cases where no periodic configuration reload strategy is defined,build()is simpler to use instead.- Returns:
- a wrapper with the most up-to-date instance and ways to register reload notification hooks.
-
-