Package io.micronaut.context.env
Class DefaultPropertyPlaceholderResolver
- java.lang.Object
-
- io.micronaut.context.env.DefaultPropertyPlaceholderResolver
-
- All Implemented Interfaces:
PropertyPlaceholderResolver,java.lang.AutoCloseable
public class DefaultPropertyPlaceholderResolver extends java.lang.Object implements PropertyPlaceholderResolver, java.lang.AutoCloseable
The defaultPropertyPlaceholderResolver.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDefaultPropertyPlaceholderResolver.PlaceholderSegmentA segment that represents one or more expressions that should be searched for in the environment.classDefaultPropertyPlaceholderResolver.RawSegmentA segment that represents static text.static interfaceDefaultPropertyPlaceholderResolver.SegmentA segment of placeholder resolution.
-
Constructor Summary
Constructors Constructor Description DefaultPropertyPlaceholderResolver(io.micronaut.core.value.PropertyResolver environment, io.micronaut.core.convert.ConversionService conversionService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<DefaultPropertyPlaceholderResolver.Segment>buildSegments(java.lang.String str)Split a placeholder value into logic segments.voidclose()java.lang.StringgetPrefix()protected <T> TresolveExpression(java.lang.String context, java.lang.String expression, java.lang.Class<T> type)Resolves a single expression.java.util.Optional<java.lang.String>resolvePlaceholders(java.lang.String str)Resolve the placeholders and return an Optional String if it was possible to resolve them.<T> TresolveRequiredPlaceholder(java.lang.String str, java.lang.Class<T> type)Resolves the value of a single placeholder.java.lang.StringresolveRequiredPlaceholders(java.lang.String str)Resolve the placeholders and return an Optional String if it was possible to resolve them.
-
-
-
Field Detail
-
PREFIX
public static final java.lang.String PREFIX
Prefix for placeholder in properties.- See Also:
- Constant Field Values
-
SUFFIX
public static final java.lang.String SUFFIX
Suffix for placeholder in properties.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultPropertyPlaceholderResolver
public DefaultPropertyPlaceholderResolver(io.micronaut.core.value.PropertyResolver environment, io.micronaut.core.convert.ConversionService conversionService)- Parameters:
environment- The property resolver for the environmentconversionService- The conversion service
-
-
Method Detail
-
getPrefix
public java.lang.String getPrefix()
- Specified by:
getPrefixin interfacePropertyPlaceholderResolver- Returns:
- The prefix used
-
resolvePlaceholders
public java.util.Optional<java.lang.String> resolvePlaceholders(java.lang.String str)
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
public java.lang.String resolveRequiredPlaceholders(java.lang.String str) throws ConfigurationExceptionDescription copied from interface:PropertyPlaceholderResolverResolve the placeholders and return an Optional String if it was possible to resolve them.- Specified by:
resolveRequiredPlaceholdersin interfacePropertyPlaceholderResolver- Parameters:
str- The placeholder to resolve- Returns:
- The optional string or
Optional.empty()if resolution was not possible - Throws:
ConfigurationException- If the placeholders could not be resolved
-
resolveRequiredPlaceholder
public <T> T resolveRequiredPlaceholder(java.lang.String str, java.lang.Class<T> type) throws ConfigurationExceptionDescription 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
-
buildSegments
public java.util.List<DefaultPropertyPlaceholderResolver.Segment> buildSegments(java.lang.String str)
Split a placeholder value into logic segments.- Parameters:
str- The placeholder- Returns:
- The list of segments
-
resolveExpression
@Nullable protected <T> T resolveExpression(java.lang.String context, java.lang.String expression, java.lang.Class<T> type)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
public void close() throws java.lang.Exception- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
-