Package io.micronaut.context.env
Class DefaultPropertyPlaceholderResolver
java.lang.Object
io.micronaut.context.env.DefaultPropertyPlaceholderResolver
- All Implemented Interfaces:
PropertyPlaceholderResolver
,AutoCloseable
public class DefaultPropertyPlaceholderResolver
extends Object
implements PropertyPlaceholderResolver, AutoCloseable
The default
PropertyPlaceholderResolver
.- Since:
- 1.0
- Author:
- graemerocher
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
A segment that represents one or more expressions that should be searched for in the environment.class
A segment that represents static text.static interface
A segment of placeholder resolution. -
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultPropertyPlaceholderResolver
(PropertyResolver environment, ConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescriptionbuildSegments
(String str) Split a placeholder value into logic segments.void
close()
protected <T> T
resolveExpression
(String context, String expression, Class<T> type) Resolves a single expression.Resolve the placeholders and return an Optional String if it was possible to resolve them.<T> T
resolveRequiredPlaceholder
(String str, Class<T> type) Resolves the value of a single placeholder.Resolve the placeholders and return a string if it was possible to resolve them.Resolve the placeholders in the given string.
-
Field Details
-
PREFIX
Prefix for placeholder in properties.- See Also:
-
SUFFIX
Suffix for placeholder in properties.- See Also:
-
-
Constructor Details
-
DefaultPropertyPlaceholderResolver
public DefaultPropertyPlaceholderResolver(PropertyResolver environment, ConversionService conversionService) - Parameters:
environment
- The property resolver for the environmentconversionService
- The conversion service
-
-
Method Details
-
getPrefix
- Specified by:
getPrefix
in interfacePropertyPlaceholderResolver
- Returns:
- The prefix used
-
resolvePlaceholders
Description copied from interface:PropertyPlaceholderResolver
Resolve the placeholders and return an Optional String if it was possible to resolve them.- Specified by:
resolvePlaceholders
in interfacePropertyPlaceholderResolver
- Parameters:
str
- The placeholder to resolve- Returns:
- The optional string or
Optional.empty()
if resolution was not possible
-
resolveRequiredPlaceholders
Description copied from interface:PropertyPlaceholderResolver
Resolve the placeholders and return a string if it was possible to resolve them.- Specified by:
resolveRequiredPlaceholders
in interfacePropertyPlaceholderResolver
- Parameters:
str
- The placeholder to resolve- Returns:
- The resolved string
- Throws:
ConfigurationException
- If the placeholders could not be resolved
-
resolveRequiredPlaceholdersObject
Description copied from interface:PropertyPlaceholderResolver
Resolve the placeholders in the given string. This behaves likePropertyPlaceholderResolver.resolveRequiredPlaceholders(String)
, except that when the whole input is a placeholder, the value is not converted to String but returned as-is.- Specified by:
resolveRequiredPlaceholdersObject
in interfacePropertyPlaceholderResolver
- Parameters:
str
- The placeholder to resolve- Returns:
- The resolved object or string
- Throws:
ConfigurationException
- If the placeholders could not be resolved
-
resolveRequiredPlaceholder
Description copied from interface:PropertyPlaceholderResolver
Resolves the value of a single placeholder.- Specified by:
resolveRequiredPlaceholder
in interfacePropertyPlaceholderResolver
- Type Parameters:
T
- The type the value should be converted to- Parameters:
str
- The string containing the placeholdertype
- The class of the type- Returns:
- The resolved value
- Throws:
ConfigurationException
- If multiple placeholders are found or if the placeholder could not be converted to the requested type
-
buildSegments
Split a placeholder value into logic segments.- Parameters:
str
- The placeholder- Returns:
- The list of segments
-
resolveExpression
Resolves a single expression.- Type Parameters:
T
- The type the expression should be converted to- Parameters:
context
- The context of the expressionexpression
- The expressiontype
- The class- Returns:
- The resolved and converted expression
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-