Spring Framework

org.springframework.core.env
Interface PropertyResolver

All Known Subinterfaces:
ConfigurableEnvironment, ConfigurablePropertyResolver, ConfigurableWebEnvironment, Environment
All Known Implementing Classes:
AbstractEnvironment, AbstractPropertyResolver, PropertySourcesPropertyResolver, StandardEnvironment, StandardPortletEnvironment, StandardServletEnvironment

public interface PropertyResolver

Interface for resolving properties against any underlying source.

Since:
3.1
Author:
Chris Beams
See Also:
Environment, PropertySourcesPropertyResolver

Method Summary
 boolean containsProperty(java.lang.String key)
          Return whether the given property key is available for resolution, i.e., the value for the given key is not null.
 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)
          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> targetType)
          Convert the property value associated with the given key to a Class of type T or null if the key cannot be resolved.
 java.lang.String getRequiredProperty(java.lang.String key)
          Return the property value associated with the given key, converted to the given targetType (never null).
<T> T
getRequiredProperty(java.lang.String key, java.lang.Class<T> targetType)
          Return the property value associated with the given key, converted to the given targetType (never null).
 java.lang.String resolvePlaceholders(java.lang.String text)
          Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by 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 getProperty(java.lang.String).
 

Method Detail

containsProperty

boolean containsProperty(java.lang.String key)
Return whether the given property key is available for resolution, i.e., the value for the given key is not null.


getProperty

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.

Parameters:
key - the property name to resolve
See Also:
getProperty(String, String), getProperty(String, Class), getRequiredProperty(String)

getProperty

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.

Parameters:
key - the property name to resolve
defaultValue - the default value to return if no value is found
See Also:
getRequiredProperty(String), getProperty(String, Class)

getProperty

<T> T getProperty(java.lang.String key,
                  java.lang.Class<T> targetType)
Return the property value associated with the given key, or null if the key cannot be resolved.

Parameters:
key - the property name to resolve
targetType - the expected type of the property value
See Also:
getRequiredProperty(String, Class)

getProperty

<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.

Parameters:
key - the property name to resolve
targetType - the expected type of the property value
defaultValue - the default value to return if no value is found
See Also:
getRequiredProperty(String, Class)

getPropertyAsClass

<T> java.lang.Class<T> getPropertyAsClass(java.lang.String key,
                                          java.lang.Class<T> targetType)
Convert the property value associated with the given key to a Class of type T or null if the key cannot be resolved.

Throws:
ConversionException - if class specified by property value cannot be found or loaded or if targetType is not assignable from class specified by property value
See Also:
getProperty(String, Class)

getRequiredProperty

java.lang.String getRequiredProperty(java.lang.String key)
                                     throws java.lang.IllegalStateException
Return the property value associated with the given key, converted to the given targetType (never null).

Throws:
java.lang.IllegalStateException - if the key cannot be resolved
See Also:
getRequiredProperty(String, Class)

getRequiredProperty

<T> T getRequiredProperty(java.lang.String key,
                          java.lang.Class<T> targetType)
                      throws java.lang.IllegalStateException
Return the property value associated with the given key, converted to the given targetType (never null).

Throws:
java.lang.IllegalStateException - if the given key cannot be resolved

resolvePlaceholders

java.lang.String resolvePlaceholders(java.lang.String text)
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty(java.lang.String). Unresolvable placeholders with no default value are ignored and passed through unchanged.

Parameters:
text - the String to resolve
Returns:
the resolved String (never null)
Throws:
java.lang.IllegalArgumentException - if given text is null
See Also:
resolveRequiredPlaceholders(java.lang.String), SystemPropertyUtils.resolvePlaceholders(String)

resolveRequiredPlaceholders

java.lang.String resolveRequiredPlaceholders(java.lang.String text)
                                             throws java.lang.IllegalArgumentException
Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by getProperty(java.lang.String). Unresolvable placeholders with no default value will cause an IllegalArgumentException to be thrown.

Returns:
the resolved String (never null)
Throws:
java.lang.IllegalArgumentException - if given text is null
java.lang.IllegalArgumentException - if any placeholders are unresolvable
See Also:
SystemPropertyUtils.resolvePlaceholders(String, boolean)

Spring Framework