io.micronaut.context.env.PropertyPlaceholderResolver Maven / Gradle / Ivy
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.context.env;
import io.micronaut.context.exceptions.ConfigurationException;
import io.micronaut.core.annotation.NonNull;
import java.util.Optional;
/**
* Interface for implementations that resolve placeholders in configuration and annotations.
*
* @author Graeme Rocher
* @since 1.0
*/
public interface PropertyPlaceholderResolver {
/**
* Resolve the placeholders and return an Optional String if it was possible to resolve them.
*
* @param str The placeholder to resolve
* @return The optional string or {@link Optional#empty()} if resolution was not possible
*/
Optional resolvePlaceholders(String str);
/**
* @return The prefix used
*/
default @NonNull String getPrefix() {
return DefaultPropertyPlaceholderResolver.PREFIX;
}
/**
* Resolve the placeholders and return an Optional String if it was possible to resolve them.
*
* @param str The placeholder to resolve
* @return The optional string or {@link Optional#empty()} if resolution was not possible
* @throws ConfigurationException If the placeholders could not be resolved
*/
default @NonNull String resolveRequiredPlaceholders(String str) throws ConfigurationException {
return resolvePlaceholders(str).orElseThrow(() -> new ConfigurationException("Unable to resolve placeholders for property: " + str));
}
/**
* Resolves the value of a single placeholder.
*
* @param str The string containing the placeholder
* @param type The class of the type
* @param The type the value should be converted to
* @return The resolved value
* @throws ConfigurationException If multiple placeholders are found or
* if the placeholder could not be converted to the requested type
*/
default @NonNull T resolveRequiredPlaceholder(String str, Class type) throws ConfigurationException {
throw new ConfigurationException("Unsupported operation");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy