public interface ConfigPropertyProvider
Modifier and Type | Method and Description |
---|---|
boolean |
containsProperty(String key)
Return whether the given property key is available, i.e. the property key is present and the value for the given
key is not
null . |
<T> T |
getProperty(String key,
Class<T> targetType)
Return the property value associated with the given key and try to convert property value to given target type.
|
Stream<String> |
getPropertyNames()
Returns a Stream of all available property names
|
static ConfigPropertyProvider |
prefixed(ConfigPropertyProvider provider,
String prefix)
Create a ConfigPropertyProvider that filters property names from given concrete
provider , returning
only property names which starts with given prefix . |
static ConfigPropertyProvider |
using(InputStream propertySource)
|
static ConfigPropertyProvider |
using(Map<String,Object> propertyMap)
Build a
ConfigPropertyProvider using given Map as property source. |
static ConfigPropertyProvider |
using(Properties properties)
Build a
ConfigPropertyProvider using given Properties as property source. |
static ConfigPropertyProvider |
using(String sourceFileName,
ClassLoader classLoader)
Build a
ConfigPropertyProvider using given sourceFileName as property source. |
static ConfigPropertyProvider |
using(String sourceFileName,
ClassLoader classLoader,
boolean lenient)
Build a
ConfigPropertyProvider using given sourceFileName as property source. |
static ConfigPropertyProvider |
usingSystemProperties()
Build a
ConfigPropertyProvider using System properties as property source. |
boolean containsProperty(String key)
null
.key
- Property key (not null)true
if property exists and has not null
value<T> T getProperty(String key, Class<T> targetType) throws IllegalArgumentException
T
- Expected property and result typekey
- the property name to resolve (not null)targetType
- the expected type of the property valuenull
if the key cannot be resolvedIllegalArgumentException
- If property value cannot be converted to target typeStream<String> getPropertyNames() throws UnsupportedOperationException
UnsupportedOperationException
- If this operation is not supported by concrete implementationstatic ConfigPropertyProvider usingSystemProperties()
ConfigPropertyProvider
using System
properties as property source.static ConfigPropertyProvider using(Map<String,Object> propertyMap)
ConfigPropertyProvider
using given Map as property source.propertyMap
- Property key-value mappropertyMap
as property source.static ConfigPropertyProvider using(Properties properties)
ConfigPropertyProvider
using given Properties
as property source.properties
- Source Propertiesproperties
as property source.static ConfigPropertyProvider using(InputStream propertySource) throws IOException
propertySource
- Source properties input streampropertySource
as property source.IOException
- Inout stream read errorstatic ConfigPropertyProvider using(String sourceFileName, ClassLoader classLoader, boolean lenient) throws IOException
ConfigPropertyProvider
using given sourceFileName
as property source.
This method uses ClassLoader.getResourceAsStream(String)
method to load the property stream, using the
same conventions to locate the resource to load.
sourceFileName
- Property file nameclassLoader
- ClassLoader to use. If null
, the default current classloader is usedlenient
- true
to ignore source loading errors and return a provider with an empty set of
propertiessourceFileName
as property source.IOException
- File not found or read errorstatic ConfigPropertyProvider using(String sourceFileName, ClassLoader classLoader) throws IOException
ConfigPropertyProvider
using given sourceFileName
as property source.
This method uses ClassLoader.getResourceAsStream(String)
method to load the property stream, using the
same conventions to locate the resource to load.
sourceFileName
- Property file nameclassLoader
- ClassLoader to use. If null
, the default current classloader is usedsourceFileName
as property source.IOException
- File not found or read errorstatic ConfigPropertyProvider prefixed(ConfigPropertyProvider provider, String prefix)
provider
, returning
only property names which starts with given prefix
.provider
- Concrete provider (not null)prefix
- Prefix to use (not null)Copyright © 2019 The Holon Platform. All rights reserved.