- java.lang.Object
-
- io.helidon.config.AbstractSource
-
- io.helidon.config.AbstractConfigSource
-
- io.helidon.config.ClasspathConfigSource
-
- All Implemented Interfaces:
ConfigSource
,ParsableSource
,Source
,Supplier<ConfigSource>
public class ClasspathConfigSource extends AbstractConfigSource implements ConfigSource, ParsableSource
ConfigSource
implementation that loads configuration content from a resource on a classpath. Classpath config source does not support changes (neither through polling nor through change notifications).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClasspathConfigSource.Builder
Classpath ConfigSource Builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClasspathConfigSource.Builder
builder()
Create a new fluent API builder for classpath config source.static ClasspathConfigSource
create(Config metaConfig)
Initializes config source instance from configuration properties.static ClasspathConfigSource
create(String resource)
Create a config source for the first resource on the classpath.static List<ConfigSource>
createAll(Config metaConfig)
Create config source for each resource on the classpath.static Collection<? super ClasspathConfigSource>
createAll(String resource)
Create config source for each resource on the classpath.Optional<ConfigParser.Content>
load()
Loads the underlying source data.Optional<String>
mediaType()
Media type if on eis configured for parsing content ofParsableSource
.Optional<ConfigParser>
parser()
Config parser if one is configured to use for parsing content ofParsableSource
.Function<String,Optional<InputStream>>
relativeResolver()
Resolve relative resource to the current resource.String
toString()
protected String
uid()
Returns universal id of source to be used to constructAbstractSource.description()
.-
Methods inherited from class io.helidon.config.AbstractSource
changeWatcher, description, optional, pollingStrategy, retryPolicy
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.helidon.config.spi.ConfigSource
get, init
-
Methods inherited from interface io.helidon.config.spi.Source
description, exists, optional, retryPolicy
-
-
-
-
Method Detail
-
create
public static ClasspathConfigSource create(Config metaConfig) throws ConfigMappingException, MissingValueException
Initializes config source instance from configuration properties.Mandatory
properties
, seeConfigSources.classpath(String)
:resource
- typeString
properties
: seeAbstractConfigSourceBuilder.config(io.helidon.config.Config)
.- Parameters:
metaConfig
- meta-configuration used to initialize returned config source instance from.- Returns:
- new instance of config source described by
metaConfig
- Throws:
MissingValueException
- in case the configuration tree does not contain all expected sub-nodes required by the mapper implementation to provide instance of Java type.ConfigMappingException
- in case the mapper fails to map the (existing) configuration tree represented by the supplied configuration node to an instance of a given Java type.- See Also:
ConfigSources.classpath(String)
,AbstractConfigSourceBuilder.config(Config)
-
create
public static ClasspathConfigSource create(String resource)
Create a config source for the first resource on the classpath.- Parameters:
resource
- resource to find- Returns:
- a config source based on the classpath resource
-
createAll
public static Collection<? super ClasspathConfigSource> createAll(String resource)
Create config source for each resource on the classpath.- Parameters:
resource
- resource to find- Returns:
- a collection of sources for each resource present on the classpath, always at least one
-
createAll
public static List<ConfigSource> createAll(Config metaConfig)
Create config source for each resource on the classpath.- Parameters:
metaConfig
- meta configuration of the config source- Returns:
- a collection of sources for each resource present on the classpath
-
builder
public static ClasspathConfigSource.Builder builder()
Create a new fluent API builder for classpath config source.- Returns:
- a new builder instance
-
uid
protected String uid()
Description copied from class:AbstractSource
Returns universal id of source to be used to constructAbstractSource.description()
.- Overrides:
uid
in classAbstractSource
- Returns:
- universal id of source
-
load
public Optional<ConfigParser.Content> load() throws ConfigException
Description copied from interface:ParsableSource
Loads the underlying source data. This method is only called when the sourceSource.exists()
.The method can be invoked repeatedly, for example during retries. In case the underlying data is gone or does not exist, return an empty optional.
- Specified by:
load
in interfaceParsableSource
- Returns:
- An instance of
T
as read from the underlying origin of the data (if it exists) - Throws:
ConfigException
- in case of errors loading from the underlying origin
-
relativeResolver
public Function<String,Optional<InputStream>> relativeResolver()
Description copied from interface:ParsableSource
Resolve relative resource to the current resource.- Specified by:
relativeResolver
in interfaceParsableSource
- Returns:
- a function to resolve resource name into an input stream
-
toString
public String toString()
- Overrides:
toString
in classAbstractConfigSource
-
mediaType
public Optional<String> mediaType()
Description copied from class:AbstractConfigSource
Media type if on eis configured for parsing content ofParsableSource
. If there is none configured (default), a parser is chosen based onConfigParser.Content.mediaType()
- media type detected during load of data.- Specified by:
mediaType
in interfaceParsableSource
- Overrides:
mediaType
in classAbstractConfigSource
- Returns:
- configured media type or empty if none configured
-
parser
public Optional<ConfigParser> parser()
Description copied from class:AbstractConfigSource
Config parser if one is configured to use for parsing content ofParsableSource
. If one is not configured on a source (default), a parser is chosen based onAbstractConfigSource.mediaType()
.- Specified by:
parser
in interfaceParsableSource
- Overrides:
parser
in classAbstractConfigSource
- Returns:
- a configured parser, or empty if one should be chosen from media type (or if this is not a parsable source)
-
-