ConfigDataEnvironmentContributorPlaceholdersResolver Class — spring-boot Architecture
Architecture documentation for the ConfigDataEnvironmentContributorPlaceholdersResolver class in ConfigDataEnvironmentContributorPlaceholdersResolver.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorPlaceholdersResolver.java lines 39–109
class ConfigDataEnvironmentContributorPlaceholdersResolver implements PlaceholdersResolver {
private final Iterable<ConfigDataEnvironmentContributor> contributors;
private final @Nullable ConfigDataActivationContext activationContext;
private final boolean failOnResolveFromInactiveContributor;
private final PropertyPlaceholderHelper helper;
private final @Nullable ConfigDataEnvironmentContributor activeContributor;
private final ConversionService conversionService;
ConfigDataEnvironmentContributorPlaceholdersResolver(Iterable<ConfigDataEnvironmentContributor> contributors,
@Nullable ConfigDataActivationContext activationContext,
@Nullable ConfigDataEnvironmentContributor activeContributor, boolean failOnResolveFromInactiveContributor,
ConversionService conversionService) {
this.contributors = contributors;
this.activationContext = activationContext;
this.activeContributor = activeContributor;
this.failOnResolveFromInactiveContributor = failOnResolveFromInactiveContributor;
this.conversionService = conversionService;
this.helper = new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX,
SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR,
SystemPropertyUtils.ESCAPE_CHARACTER, true);
}
@Override
public @Nullable Object resolvePlaceholders(@Nullable Object value) {
if (value instanceof String string) {
return this.helper.replacePlaceholders(string, this::resolvePlaceholder);
}
return value;
}
private @Nullable String resolvePlaceholder(String placeholder) {
Object result = null;
for (ConfigDataEnvironmentContributor contributor : this.contributors) {
PropertySource<?> propertySource = contributor.getPropertySource();
Object value = (propertySource != null) ? propertySource.getProperty(placeholder) : null;
if (value != null && !isActive(contributor)) {
if (this.failOnResolveFromInactiveContributor) {
ConfigDataResource resource = contributor.getResource();
Assert.state(propertySource != null, "'propertySource' can't be null here");
Origin origin = OriginLookup.getOrigin(propertySource, placeholder);
throw new InactiveConfigDataAccessException(propertySource, resource, placeholder, origin);
}
value = null;
}
result = (result != null) ? result : value;
}
return (result != null) ? convertValueIfNecessary(result) : null;
}
private boolean isActive(ConfigDataEnvironmentContributor contributor) {
if (contributor == this.activeContributor) {
return true;
}
if (contributor.getKind() != Kind.UNBOUND_IMPORT) {
return contributor.isActive(this.activationContext);
}
return contributor.withBoundProperties(this.contributors, this.activationContext)
.isActive(this.activationContext);
}
private @Nullable String convertValueIfNecessary(Object value) {
return (value instanceof String string) ? string : this.conversionService.convert(value, String.class);
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free