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
Nested ClassesModifier and TypeClassDescriptionclassA segment that represents one or more expressions that should be searched for in the environment.classA segment that represents static text.static interfaceA segment of placeholder resolution. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultPropertyPlaceholderResolver(PropertyResolver environment, ConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescriptionbuildSegments(String str) Split a placeholder value into logic segments.voidclose()protected <T> TresolveExpression(String context, String expression, Class<T> type) Resolves a single expression.<T> Optional<T>resolveOptionalPlaceholder(String str, Class<T> type) Resolves the optional value of a single placeholder.Resolve the placeholders and return an Optional String if it was possible to resolve them.<T> TresolveRequiredPlaceholder(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:
getPrefixin interfacePropertyPlaceholderResolver- Returns:
- The prefix used
-
resolvePlaceholders
Description copied from interface:PropertyPlaceholderResolverResolve the placeholders and return an Optional String if it was possible to resolve them.- Specified by:
resolvePlaceholdersin interfacePropertyPlaceholderResolver- Parameters:
str- The placeholder to resolve- Returns:
- The optional string or
Optional.empty()if resolution was not possible
-
resolveRequiredPlaceholders
Description copied from interface:PropertyPlaceholderResolverResolve the placeholders and return a string if it was possible to resolve them.- Specified by:
resolveRequiredPlaceholdersin 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:PropertyPlaceholderResolverResolve 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:
resolveRequiredPlaceholdersObjectin 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:PropertyPlaceholderResolverResolves the value of a single placeholder.- Specified by:
resolveRequiredPlaceholderin 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
-
resolveOptionalPlaceholder
public <T> Optional<T> resolveOptionalPlaceholder(String str, Class<T> type) throws ConfigurationException Description copied from interface:PropertyPlaceholderResolverResolves the optional value of a single placeholder.- Specified by:
resolveOptionalPlaceholderin 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 optional value
- Throws:
ConfigurationException
-
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:
closein interfaceAutoCloseable- Throws:
Exception
-