Class AbstractPropertyResolver
- java.lang.Object
-
- cn.sliew.milky.common.environment.AbstractPropertyResolver
-
- All Implemented Interfaces:
PropertyResolver
- Direct Known Subclasses:
PropertySourcesPropertyResolver
public abstract class AbstractPropertyResolver extends Object implements PropertyResolver
-
-
Constructor Summary
Constructors Constructor Description AbstractPropertyResolver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancontainsProperty(String key)Whether the given property key is available.StringgetProperty(String key, String defaultValue)Find the property value associated with the given key.<R,T>
TgetProperty(String key, Function<R,T> mappingFunction, T defaultValue)Find the property value associated with the given key.protected abstract Optional<String>getPropertyAsRawString(String key)Retrieve the specified property as a raw String, i.e.StringgetRequiredProperty(String key)Find the property value associated with the given key (nevernull).<R,T>
TgetRequiredProperty(String key, Function<R,T> mappingFunction)Find the property value associated with the given key (nevernull).protected StringresolveNestedPlaceholders(String value)Resolve placeholders within the given string.StringresolvePlaceholders(String text)Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String).StringresolveRequiredPlaceholders(String text)Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String).voidsetPlaceholderPrefix(String placeholderPrefix)Set the prefix that placeholders replaced by this resolver must begin with.voidsetPlaceholderSuffix(String placeholderSuffix)Set the suffix that placeholders replaced by this resolver must end with.voidsetValueSeparator(String valueSeparator)Specify the separating character between the placeholders replaced by this resolver and their associated default value, ornullif no such special character should be processed as a value separator.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cn.sliew.milky.common.environment.PropertyResolver
getProperty, getProperty
-
-
-
-
Field Detail
-
log
protected final Logger log
-
-
Method Detail
-
containsProperty
public boolean containsProperty(String key)
Description copied from interface:PropertyResolverWhether the given property key is available.- Specified by:
containsPropertyin interfacePropertyResolver- Returns:
- true if the given property key is available for resolution otherwise false.
-
getProperty
public String getProperty(String key, String defaultValue)
Description copied from interface:PropertyResolverFind the property value associated with the given key. If the associated property value not found, defaultValue will be returned.- Specified by:
getPropertyin interfacePropertyResolver- Parameters:
key- the property name to resolvedefaultValue- the default value to return if no value is found- Returns:
- property value
- See Also:
PropertyResolver.getRequiredProperty(String),PropertyResolver.getProperty(String, Function)
-
getProperty
public <R,T> T getProperty(String key, Function<R,T> mappingFunction, T defaultValue)
Description copied from interface:PropertyResolverFind the property value associated with the given key. If the associated property value not found, defaultValue will be returned.- Specified by:
getPropertyin interfacePropertyResolver- Parameters:
key- the property name to resolvemappingFunction- the mapping function convert original object to target objetdefaultValue- the default value to return if no value is found- Returns:
- property value
- See Also:
PropertyResolver.getRequiredProperty(String, Function)
-
getRequiredProperty
public String getRequiredProperty(String key) throws IllegalStateException
Description copied from interface:PropertyResolverFind the property value associated with the given key (nevernull).- Specified by:
getRequiredPropertyin interfacePropertyResolver- Parameters:
key- the property name to resolve- Returns:
- property value
- Throws:
IllegalStateException- if the key cannot be resolved- See Also:
PropertyResolver.getRequiredProperty(String, Function)
-
getRequiredProperty
public <R,T> T getRequiredProperty(String key, Function<R,T> mappingFunction) throws IllegalStateException
Description copied from interface:PropertyResolverFind the property value associated with the given key (nevernull).- Specified by:
getRequiredPropertyin interfacePropertyResolver- Parameters:
key- the property name to resolvemappingFunction- the mapping function convert original object to target objet- Returns:
- property value
- Throws:
IllegalStateException- if the given key cannot be resolved
-
resolvePlaceholders
public String resolvePlaceholders(String text)
Description copied from interface:PropertyResolverResolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String). Unresolvable placeholders with no default value are ignored and passed through unchanged.- Specified by:
resolvePlaceholdersin interfacePropertyResolver- Parameters:
text- the String to resolve- Returns:
- the resolved String (never
null) - See Also:
PropertyResolver.resolveRequiredPlaceholders(java.lang.String)
-
resolveRequiredPlaceholders
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException
Description copied from interface:PropertyResolverResolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved byPropertyResolver.getProperty(java.lang.String). Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.- Specified by:
resolveRequiredPlaceholdersin interfacePropertyResolver- Returns:
- the resolved String (never
null) - Throws:
IllegalArgumentException- if given text isnullor if any placeholders are unresolvable
-
resolveNestedPlaceholders
protected String resolveNestedPlaceholders(String value)
Resolve placeholders within the given string.
-
setPlaceholderPrefix
public void setPlaceholderPrefix(String placeholderPrefix)
Description copied from interface:PropertyResolverSet the prefix that placeholders replaced by this resolver must begin with.- Specified by:
setPlaceholderPrefixin interfacePropertyResolver
-
setPlaceholderSuffix
public void setPlaceholderSuffix(String placeholderSuffix)
Description copied from interface:PropertyResolverSet the suffix that placeholders replaced by this resolver must end with.- Specified by:
setPlaceholderSuffixin interfacePropertyResolver
-
setValueSeparator
public void setValueSeparator(String valueSeparator)
Description copied from interface:PropertyResolverSpecify the separating character between the placeholders replaced by this resolver and their associated default value, ornullif no such special character should be processed as a value separator.- Specified by:
setValueSeparatorin interfacePropertyResolver
-
getPropertyAsRawString
protected abstract Optional<String> getPropertyAsRawString(String key)
Retrieve the specified property as a raw String, i.e. without resolution of nested placeholders.- Parameters:
key- the property name to resolve- Returns:
- the property value or
Optional.empty()if none found
-
-