001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.core.env;
018
019import org.springframework.core.convert.support.ConfigurableConversionService;
020
021/**
022 * Configuration interface to be implemented by most if not all {@link PropertyResolver}
023 * types. Provides facilities for accessing and customizing the
024 * {@link org.springframework.core.convert.ConversionService ConversionService}
025 * used when converting property values from one type to another.
026 *
027 * @author Chris Beams
028 * @since 3.1
029 */
030public interface ConfigurablePropertyResolver extends PropertyResolver {
031
032        /**
033         * Return the {@link ConfigurableConversionService} used when performing type
034         * conversions on properties.
035         * <p>The configurable nature of the returned conversion service allows for
036         * the convenient addition and removal of individual {@code Converter} instances:
037         * <pre class="code">
038         * ConfigurableConversionService cs = env.getConversionService();
039         * cs.addConverter(new FooConverter());
040         * </pre>
041         * @see PropertyResolver#getProperty(String, Class)
042         * @see org.springframework.core.convert.converter.ConverterRegistry#addConverter
043         */
044        ConfigurableConversionService getConversionService();
045
046        /**
047         * Set the {@link ConfigurableConversionService} to be used when performing type
048         * conversions on properties.
049         * <p><strong>Note:</strong> as an alternative to fully replacing the
050         * {@code ConversionService}, consider adding or removing individual
051         * {@code Converter} instances by drilling into {@link #getConversionService()}
052         * and calling methods such as {@code #addConverter}.
053         * @see PropertyResolver#getProperty(String, Class)
054         * @see #getConversionService()
055         * @see org.springframework.core.convert.converter.ConverterRegistry#addConverter
056         */
057        void setConversionService(ConfigurableConversionService conversionService);
058
059        /**
060         * Set the prefix that placeholders replaced by this resolver must begin with.
061         */
062        void setPlaceholderPrefix(String placeholderPrefix);
063
064        /**
065         * Set the suffix that placeholders replaced by this resolver must end with.
066         */
067        void setPlaceholderSuffix(String placeholderSuffix);
068
069        /**
070         * Specify the separating character between the placeholders replaced by this
071         * resolver and their associated default value, or {@code null} if no such
072         * special character should be processed as a value separator.
073         */
074        void setValueSeparator(String valueSeparator);
075
076        /**
077         * Set whether to throw an exception when encountering an unresolvable placeholder
078         * nested within the value of a given property. A {@code false} value indicates strict
079         * resolution, i.e. that an exception will be thrown. A {@code true} value indicates
080         * that unresolvable nested placeholders should be passed through in their unresolved
081         * ${...} form.
082         * <p>Implementations of {@link #getProperty(String)} and its variants must inspect
083         * the value set here to determine correct behavior when property values contain
084         * unresolvable placeholders.
085         * @since 3.2
086         */
087        void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders);
088
089        /**
090         * Specify which properties must be present, to be verified by
091         * {@link #validateRequiredProperties()}.
092         */
093        void setRequiredProperties(String... requiredProperties);
094
095        /**
096         * Validate that each of the properties specified by
097         * {@link #setRequiredProperties} is present and resolves to a
098         * non-{@code null} value.
099         * @throws MissingRequiredPropertiesException if any of the required
100         * properties are not resolvable.
101         */
102        void validateRequiredProperties() throws MissingRequiredPropertiesException;
103
104}