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 class
DefaultPropertyPlaceholderResolver.PlaceholderSegment
A segment that represents one or more expressions that should be searched for in the environment.class
DefaultPropertyPlaceholderResolver.RawSegment
A segment that represents static text.static interface
DefaultPropertyPlaceholderResolver.Segment
A 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.void
close()
java.lang.String
getPrefix()
protected <T> T
resolveExpression(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> T
resolveRequiredPlaceholder(java.lang.String str, java.lang.Class<T> type)
Resolves the value of a single placeholder.java.lang.String
resolveRequiredPlaceholders(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:
getPrefix
in interfacePropertyPlaceholderResolver
- Returns:
- The prefix used
-
resolvePlaceholders
public java.util.Optional<java.lang.String> resolvePlaceholders(java.lang.String str)
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
public java.lang.String resolveRequiredPlaceholders(java.lang.String str) throws ConfigurationException
Description copied from interface:PropertyPlaceholderResolver
Resolve the placeholders and return an Optional String if it was possible to resolve them.- Specified by:
resolveRequiredPlaceholders
in 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 ConfigurationException
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
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:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
-