public class ConfigurationBuilder extends Object
Builder class used for building a configuration manually without relying only on the Service Provider Interface API.
Features of the builder
Example
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.disableProvidedPropertySources() // Do not load provided property
.disableProvidedPropertySourceProviders() // sources and providers automatically
.addPropertySource("file:/etc/conf.properties"); // Load properties from conf.properties
Configuration config = builder.build();
Support for configuration formats
The configuration builder allows you to put property resources via a URL, as shown in the code example above, without implementing aPropertySource
or providing an
instance of a PropertySource
.
If a property resource in
a specific format can be added to configuration builder or not depends
on the available implementations of
ConfigurationFormat
in the classpath.
Which formats are available can be checked via
ConfigurationFormats.getFormats()
.Constructor and Description |
---|
ConfigurationBuilder()
Creates a new builder instance.
|
Modifier and Type | Method and Description |
---|---|
<T> ConfigurationBuilder |
addPropertyConverter(Class<T> type,
org.apache.tamaya.spi.PropertyConverter<T> converter)
Adds a property converter for the a given type to the configuration to
be build.
|
<T> ConfigurationBuilder |
addPropertyConverter(org.apache.tamaya.TypeLiteral<T> type,
org.apache.tamaya.spi.PropertyConverter<T> propertyConverter)
Adds a propertyConverter of a given type.
|
ConfigurationBuilder |
addPropertyFilters(org.apache.tamaya.spi.PropertyFilter... filters)
Adds one or more property filter instances to the configuration to be build.
|
ConfigurationBuilder |
addPropertySource(URL url)
Adds one resources with properties in an arbitrary format
to the configuration to be build.
|
ConfigurationBuilder |
addPropertySourceProviders(org.apache.tamaya.spi.PropertySourceProvider... providers)
Adds one or more property source provider instances to the configuration to be build.
|
ConfigurationBuilder |
addPropertySources(Collection<URL> urls)
Adds one or more resources with properties in an arbitrary format
to the configuration to be build.
|
ConfigurationBuilder |
addPropertySources(org.apache.tamaya.spi.PropertySource... sources)
Adds one or more property source instances to the configuration to be build.
|
ConfigurationBuilder |
addPropertySources(String... urls)
Adds one or more resources with properties in an arbitrary format
to the configuration to be build.
|
ConfigurationBuilder |
addPropertySources(URL... urls)
Adds one or more resources with properties in an arbitrary format
to the configuration to be build.
|
org.apache.tamaya.Configuration |
build()
Builds a new configuration based on the configuration of this builder instance.
|
ConfigurationBuilder |
disableProvidedPropertyConverters()
Disables the automatic loading of all
PropertyConverter
service providers. |
ConfigurationBuilder |
disableProvidedPropertyFilters()
Disables the automatic loading of all
PropertyFilter
service providers. |
ConfigurationBuilder |
disableProvidedPropertySourceProviders()
Disables the automatic loading of
property source providers provided via the SPI API. |
ConfigurationBuilder |
disableProvidedPropertySources()
Disables the automatic loading of all
PropertySource
service providers. |
ConfigurationBuilder |
enabledProvidedPropertyFilters()
Enables the automatic loading of all
PropertyFilter
service providers. |
ConfigurationBuilder |
enableProvidedPropertyConverters()
Enables the loading of all
PropertyConverter
service providers. |
ConfigurationBuilder |
enableProvidedPropertySourceProviders()
Enables the automatic loading of
property source providers provided via the SPI API. |
ConfigurationBuilder |
enableProvidedPropertySources()
Enables the automatic loading of all
PropertySource
service providers. |
protected org.apache.tamaya.format.ConfigurationData |
getConfigurationDataFromURL(URL url) |
boolean |
isPropertyConverterLoadingEnabled()
Checks if the automatic loading of all
PropertyConverter service providers is enabled or disabled. |
boolean |
isPropertyFilterLoadingEnabled()
Checks if the automatic loading of all
PropertyFilter service providers is enabled or disabled. |
boolean |
isPropertySourceProvidersLoadingEnabled()
Checks if the automatic loading of
PropertySourceProviders is enabled or disabled. |
boolean |
isPropertySourcesLoadingEnabled()
Checks if the automatic loading of all
PropertySource service providers is enabled or disabled. |
ConfigurationBuilder |
setPropertyValueCombinationPolicy(org.apache.tamaya.spi.PropertyValueCombinationPolicy propertyValueCombinationPolicy) |
public ConfigurationBuilder()
public ConfigurationBuilder addPropertySource(URL url)
If a specific format is supported depends on the available
ConfigurationFormat
implementations.
URL resource = new URL("file:/etc/service/config.json");
builder.addPropertySources(resource);
url
- resource with properties for the the configuration to be build.ConfigurationFormat
,
ConfigurationFormats.getFormats()
protected org.apache.tamaya.format.ConfigurationData getConfigurationDataFromURL(URL url) throws IOException
IOException
public ConfigurationBuilder addPropertySources(URL... urls)
If a specific format is supported depends on the available
ConfigurationFormat
implementations.
URL first = new URL("file:/etc/service/config.json");
URL second = new URL("file:/etc/defaults/values.properties");
builder.addPropertySources(first, second);
urls
- list of resources with properties for the configuration to be
build.ConfigurationFormat
,
ConfigurationFormats.getFormats()
public ConfigurationBuilder addPropertySources(Collection<URL> urls)
If a specific format is supported depends on the available
ConfigurationFormat
implementations.
URL first = new URL("file:/etc/service/config.json");
URL second = new URL("file:/etc/defaults/values.properties");
builder.addPropertySources(first, second);
urls
- list of resources with properties for the configuration to be
build.ConfigurationFormat
,
ConfigurationFormats.getFormats()
public ConfigurationBuilder addPropertySources(String... urls)
If a specific format is supported depends on the available
ConfigurationFormat
implementations.
builder.addPropertySources("file:/etc/service/config.json",
"file:/etc/defaults/values.properties");
urls
- list of resources with properties for the configuration to be
build.ConfigurationFormat
,
ConfigurationFormats.getFormats()
public ConfigurationBuilder addPropertySources(org.apache.tamaya.spi.PropertySource... sources)
PropertySource first = new CustomPropertySource();
PropertySource second = new YetAnotherPropertySource();
builder.addPropertySources(first, second)
;
sources
- list of property source instances with properties for the
configuration to be build.PropertySource
public ConfigurationBuilder addPropertySourceProviders(org.apache.tamaya.spi.PropertySourceProvider... providers)
PropertySourceProvider jc = new JavaConfigurationProvider();
builder.addPropertySources(jc)
;
providers
- list of property source provider instances each providing a set
of property source instances for the configuration to be build.PropertySourceProvider
public ConfigurationBuilder addPropertyFilters(org.apache.tamaya.spi.PropertyFilter... filters)
PropertyFilter quoteReplacingFilter = new QuoteFilter();
PropertyFilter commaRemovingFilter = new CommaFilter();
builder.addPropertyFilters(commaRemovingFilter, quoteReplacingFilter)
;
filters
- list of property filter instances which should be applied
to the properties of the configuration to be build.PropertyFilter
,
disableProvidedPropertyFilters()
,
enabledProvidedPropertyFilters()
public ConfigurationBuilder setPropertyValueCombinationPolicy(org.apache.tamaya.spi.PropertyValueCombinationPolicy propertyValueCombinationPolicy)
propertyValueCombinationPolicy
- combination policy to use for this builder.public <T> ConfigurationBuilder addPropertyConverter(Class<T> type, org.apache.tamaya.spi.PropertyConverter<T> converter)
PropertyConverter<MyType> converter = value -> new MyType(value, 42);
builder.addPropertyConverter(MyType.class, converter
T
- the type of the configurationtype
- the required target type the converter should be applied toconverter
- the converter to be used to convert the string property
to the given target type.PropertyConverter
,
enableProvidedPropertyConverters()
,
disableProvidedPropertyConverters()
public <T> ConfigurationBuilder addPropertyConverter(org.apache.tamaya.TypeLiteral<T> type, org.apache.tamaya.spi.PropertyConverter<T> propertyConverter)
T
- the type of the configurationtype
- type literal of this converter.propertyConverter
- property converter.public boolean isPropertyConverterLoadingEnabled()
PropertyConverter
service providers is enabled or disabled.true
if the automatic loading is enabled,
otherwise false
.enableProvidedPropertyConverters()
,
disableProvidedPropertyConverters()
,
addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
,
addPropertyConverter(org.apache.tamaya.TypeLiteral, org.apache.tamaya.spi.PropertyConverter)
public ConfigurationBuilder enableProvidedPropertyConverters()
PropertyConverter
service providers.PropertyConverter
,
disableProvidedPropertyConverters()
,
enableProvidedPropertyConverters()
public ConfigurationBuilder disableProvidedPropertyConverters()
PropertyConverter
service providers.PropertyConverter
,
enableProvidedPropertyConverters()
,
addPropertyConverter(Class, org.apache.tamaya.spi.PropertyConverter)
public ConfigurationBuilder enableProvidedPropertySources()
PropertySource
service providers.PropertySource
,
disableProvidedPropertySources()
public boolean isPropertySourcesLoadingEnabled()
PropertySource
service providers is enabled or disabled.true
if the automatic loading is enabled,
otherwise false
.public boolean isPropertyFilterLoadingEnabled()
PropertyFilter
service providers is enabled or disabled.true
if the automatic loading is enabled,
otherwise false
.public ConfigurationBuilder enabledProvidedPropertyFilters()
PropertyFilter
service providers.PropertyFilter
,
disableProvidedPropertyFilters()
,
addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
public ConfigurationBuilder disableProvidedPropertyFilters()
PropertyFilter
service providers.PropertyFilter
,
enabledProvidedPropertyFilters()
,
addPropertyFilters(org.apache.tamaya.spi.PropertyFilter...)
public ConfigurationBuilder disableProvidedPropertySources()
PropertySource
service providers.PropertySource
,
enableProvidedPropertySources()
public ConfigurationBuilder enableProvidedPropertySourceProviders()
property source providers
provided via the SPI API.PropertySourceProvider
public ConfigurationBuilder disableProvidedPropertySourceProviders()
property source providers
provided via the SPI API.public boolean isPropertySourceProvidersLoadingEnabled()
PropertySourceProviders
is enabled or disabled.true
if the automatic loading is enabled,
otherwise false
.public org.apache.tamaya.Configuration build()
configuration instance
,
never null
.Copyright © 2015–2016 Apache Software Foundation. All rights reserved.