public abstract class AbstractPropertyResolver extends java.lang.Object implements ConfigurablePropertyResolver
| Constructor and Description |
|---|
AbstractPropertyResolver() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsProperty(java.lang.String key)
Return whether the given property key is available for resolution,
i.e.
|
protected <T> T |
convertValueIfNecessary(java.lang.Object value,
java.lang.Class<T> targetType)
Convert the given value to the specified target type, if necessary.
|
ConfigurableConversionService |
getConversionService()
Return the
ConfigurableConversionService used when performing type
conversions on properties. |
java.lang.String |
getProperty(java.lang.String key)
Return the property value associated with the given key,
or
null if the key cannot be resolved. |
<T> T |
getProperty(java.lang.String key,
java.lang.Class<T> targetType,
T defaultValue)
Return the property value associated with the given key,
or
defaultValue if the key cannot be resolved. |
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
Return the property value associated with the given key, or
defaultValue if the key cannot be resolved. |
<T> java.lang.Class<T> |
getPropertyAsClass(java.lang.String key,
java.lang.Class<T> targetValueType)
Deprecated.
|
protected abstract java.lang.String |
getPropertyAsRawString(java.lang.String key)
Retrieve the specified property as a raw String,
i.e.
|
java.lang.String |
getRequiredProperty(java.lang.String key)
Return the property value associated with the given key (never
null). |
<T> T |
getRequiredProperty(java.lang.String key,
java.lang.Class<T> valueType)
Return the property value associated with the given key, converted to the given
targetType (never
null). |
protected java.lang.String |
resolveNestedPlaceholders(java.lang.String value)
Resolve placeholders within the given string, deferring to the value of
setIgnoreUnresolvableNestedPlaceholders(boolean) to determine whether any
unresolvable placeholders should raise an exception or be ignored. |
java.lang.String |
resolvePlaceholders(java.lang.String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding
property values as resolved by
PropertyResolver.getProperty(java.lang.String). |
java.lang.String |
resolveRequiredPlaceholders(java.lang.String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding
property values as resolved by
PropertyResolver.getProperty(java.lang.String). |
void |
setConversionService(ConfigurableConversionService conversionService)
Set the
ConfigurableConversionService to be used when performing type
conversions on properties. |
void |
setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)
Set whether to throw an exception when encountering an unresolvable placeholder
nested within the value of a given property.
|
void |
setPlaceholderPrefix(java.lang.String placeholderPrefix)
Set the prefix that placeholders replaced by this resolver must begin with.
|
void |
setPlaceholderSuffix(java.lang.String placeholderSuffix)
Set the suffix that placeholders replaced by this resolver must end with.
|
void |
setRequiredProperties(java.lang.String... requiredProperties)
Specify which properties must be present, to be verified by
ConfigurablePropertyResolver.validateRequiredProperties(). |
void |
setValueSeparator(java.lang.String valueSeparator)
Specify the separating character between the placeholders replaced by this
resolver and their associated default value, or
null if no such
special character should be processed as a value separator. |
void |
validateRequiredProperties()
Validate that each of the properties specified by
ConfigurablePropertyResolver.setRequiredProperties(java.lang.String...) is present and resolves to a
non-null value. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPropertyprotected final Log logger
public ConfigurableConversionService getConversionService()
ConfigurablePropertyResolverConfigurableConversionService used when performing type
conversions on properties.
The configurable nature of the returned conversion service allows for
the convenient addition and removal of individual Converter instances:
ConfigurableConversionService cs = env.getConversionService(); cs.addConverter(new FooConverter());
public void setConversionService(ConfigurableConversionService conversionService)
ConfigurablePropertyResolverConfigurableConversionService to be used when performing type
conversions on properties.
Note: as an alternative to fully replacing the
ConversionService, consider adding or removing individual
Converter instances by drilling into ConfigurablePropertyResolver.getConversionService()
and calling methods such as #addConverter.
public void setPlaceholderPrefix(java.lang.String placeholderPrefix)
The default is "${".
setPlaceholderPrefix in interface ConfigurablePropertyResolverSystemPropertyUtils.PLACEHOLDER_PREFIXpublic void setPlaceholderSuffix(java.lang.String placeholderSuffix)
The default is "}".
setPlaceholderSuffix in interface ConfigurablePropertyResolverSystemPropertyUtils.PLACEHOLDER_SUFFIXpublic void setValueSeparator(java.lang.String valueSeparator)
null if no such
special character should be processed as a value separator.
The default is ":".
setValueSeparator in interface ConfigurablePropertyResolverSystemPropertyUtils.VALUE_SEPARATORpublic void setIgnoreUnresolvableNestedPlaceholders(boolean ignoreUnresolvableNestedPlaceholders)
false value indicates strict
resolution, i.e. that an exception will be thrown. A true value indicates
that unresolvable nested placeholders should be passed through in their unresolved
${...} form.
The default is false.
setIgnoreUnresolvableNestedPlaceholders in interface ConfigurablePropertyResolverpublic void setRequiredProperties(java.lang.String... requiredProperties)
ConfigurablePropertyResolverConfigurablePropertyResolver.validateRequiredProperties().setRequiredProperties in interface ConfigurablePropertyResolverpublic void validateRequiredProperties()
ConfigurablePropertyResolverConfigurablePropertyResolver.setRequiredProperties(java.lang.String...) is present and resolves to a
non-null value.validateRequiredProperties in interface ConfigurablePropertyResolverpublic boolean containsProperty(java.lang.String key)
PropertyResolvernull.containsProperty in interface PropertyResolverpublic java.lang.String getProperty(java.lang.String key)
PropertyResolvernull if the key cannot be resolved.getProperty in interface PropertyResolverkey - the property name to resolvePropertyResolver.getProperty(String, String),
PropertyResolver.getProperty(String, Class),
PropertyResolver.getRequiredProperty(String)public java.lang.String getProperty(java.lang.String key,
java.lang.String defaultValue)
PropertyResolverdefaultValue if the key cannot be resolved.getProperty in interface PropertyResolverkey - the property name to resolvedefaultValue - the default value to return if no value is foundPropertyResolver.getRequiredProperty(String),
PropertyResolver.getProperty(String, Class)public <T> T getProperty(java.lang.String key,
java.lang.Class<T> targetType,
T defaultValue)
PropertyResolverdefaultValue if the key cannot be resolved.getProperty in interface PropertyResolverkey - the property name to resolvetargetType - the expected type of the property valuedefaultValue - the default value to return if no value is foundPropertyResolver.getRequiredProperty(String, Class)@Deprecated
public <T> java.lang.Class<T> getPropertyAsClass(java.lang.String key,
java.lang.Class<T> targetValueType)
PropertyResolverClass
of type T or null if the key cannot be resolved.getPropertyAsClass in interface PropertyResolverPropertyResolver.getProperty(String, Class)public java.lang.String getRequiredProperty(java.lang.String key)
throws java.lang.IllegalStateException
PropertyResolvernull).getRequiredProperty in interface PropertyResolverjava.lang.IllegalStateException - if the key cannot be resolvedPropertyResolver.getRequiredProperty(String, Class)public <T> T getRequiredProperty(java.lang.String key,
java.lang.Class<T> valueType)
throws java.lang.IllegalStateException
PropertyResolvernull).getRequiredProperty in interface PropertyResolverjava.lang.IllegalStateException - if the given key cannot be resolvedpublic java.lang.String resolvePlaceholders(java.lang.String text)
PropertyResolverPropertyResolver.getProperty(java.lang.String). Unresolvable placeholders with
no default value are ignored and passed through unchanged.resolvePlaceholders in interface PropertyResolvertext - the String to resolvenull)PropertyResolver.resolveRequiredPlaceholders(java.lang.String),
SystemPropertyUtils.resolvePlaceholders(String)public java.lang.String resolveRequiredPlaceholders(java.lang.String text)
throws java.lang.IllegalArgumentException
PropertyResolverPropertyResolver.getProperty(java.lang.String). Unresolvable placeholders with
no default value will cause an IllegalArgumentException to be thrown.resolveRequiredPlaceholders in interface PropertyResolvernull)java.lang.IllegalArgumentException - if given text is null
or if any placeholders are unresolvableSystemPropertyUtils.resolvePlaceholders(String, boolean)protected java.lang.String resolveNestedPlaceholders(java.lang.String value)
setIgnoreUnresolvableNestedPlaceholders(boolean) to determine whether any
unresolvable placeholders should raise an exception or be ignored.
Invoked from getProperty(java.lang.String) and its variants, implicitly resolving
nested placeholders. In contrast, resolvePlaceholders(java.lang.String) and
resolveRequiredPlaceholders(java.lang.String) do
setIgnoreUnresolvableNestedPlaceholders(boolean)protected <T> T convertValueIfNecessary(java.lang.Object value,
java.lang.Class<T> targetType)
value - the original property valuetargetType - the specified target type for property retrievalprotected abstract java.lang.String getPropertyAsRawString(java.lang.String key)
key - the property name to resolvenull if none found