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; 020import org.springframework.lang.Nullable; 021 022/** 023 * Configuration interface to be implemented by most if not all {@link PropertyResolver} 024 * types. Provides facilities for accessing and customizing the 025 * {@link org.springframework.core.convert.ConversionService ConversionService} 026 * used when converting property values from one type to another. 027 * 028 * @author Chris Beams 029 * @since 3.1 030 */ 031public interface ConfigurablePropertyResolver extends PropertyResolver { 032 033 /** 034 * Return the {@link ConfigurableConversionService} used when performing type 035 * conversions on properties. 036 * <p>The configurable nature of the returned conversion service allows for 037 * the convenient addition and removal of individual {@code Converter} instances: 038 * <pre class="code"> 039 * ConfigurableConversionService cs = env.getConversionService(); 040 * cs.addConverter(new FooConverter()); 041 * </pre> 042 * @see PropertyResolver#getProperty(String, Class) 043 * @see org.springframework.core.convert.converter.ConverterRegistry#addConverter 044 */ 045 ConfigurableConversionService getConversionService(); 046 047 /** 048 * Set the {@link ConfigurableConversionService} to be used when performing type 049 * conversions on properties. 050 * <p><strong>Note:</strong> as an alternative to fully replacing the 051 * {@code ConversionService}, consider adding or removing individual 052 * {@code Converter} instances by drilling into {@link #getConversionService()} 053 * and calling methods such as {@code #addConverter}. 054 * @see PropertyResolver#getProperty(String, Class) 055 * @see #getConversionService() 056 * @see org.springframework.core.convert.converter.ConverterRegistry#addConverter 057 */ 058 void setConversionService(ConfigurableConversionService conversionService); 059 060 /** 061 * Set the prefix that placeholders replaced by this resolver must begin with. 062 */ 063 void setPlaceholderPrefix(String placeholderPrefix); 064 065 /** 066 * Set the suffix that placeholders replaced by this resolver must end with. 067 */ 068 void setPlaceholderSuffix(String placeholderSuffix); 069 070 /** 071 * Specify the separating character between the placeholders replaced by this 072 * resolver and their associated default value, or {@code null} if no such 073 * special character should be processed as a value separator. 074 */ 075 void setValueSeparator(@Nullable String valueSeparator); 076 077 /** 078 * Set whether to throw an exception when encountering an unresolvable placeholder 079 * nested within the value of a given property. A {@code false} value indicates strict 080 * resolution, i.e. that an exception will be thrown. A {@code true} value indicates 081 * that unresolvable nested placeholders should be passed through in their unresolved 082 * ${...} form. 083 * <p>Implementations of {@link #getProperty(String)} and its variants must inspect 084 * the value set here to determine correct behavior when property values contain 085 * unresolvable placeholders. 086 * @since 3.2 087 */ 088 void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders); 089 090 /** 091 * Specify which properties must be present, to be verified by 092 * {@link #validateRequiredProperties()}. 093 */ 094 void setRequiredProperties(String... requiredProperties); 095 096 /** 097 * Validate that each of the properties specified by 098 * {@link #setRequiredProperties} is present and resolves to a 099 * non-{@code null} value. 100 * @throws MissingRequiredPropertiesException if any of the required 101 * properties are not resolvable. 102 */ 103 void validateRequiredProperties() throws MissingRequiredPropertiesException; 104 105}