org.springframework.core.env
Class AbstractEnvironment

java.lang.Object
  extended by org.springframework.core.env.AbstractEnvironment
All Implemented Interfaces:
ConfigurableEnvironment, ConfigurablePropertyResolver, Environment, PropertyResolver
Direct Known Subclasses:
DefaultEnvironment

public abstract class AbstractEnvironment
extends Object
implements ConfigurableEnvironment

Abstract base class for Environment implementations.

Since:
3.1
Author:
Chris Beams
See Also:
DefaultEnvironment

Field Summary
static String ACTIVE_PROFILES_PROPERTY_NAME
          Name of property to set to specify active profiles: "spring.profiles.active".
static String DEFAULT_PROFILES_PROPERTY_NAME
          Name of property to set to specify default profiles: "spring.profiles.default".
protected  Log logger
           
 
Constructor Summary
AbstractEnvironment()
           
 
Method Summary
 boolean acceptsProfiles(String... profiles)
           
 boolean containsProperty(String key)
          Return whether the given property key is available for resolution.
protected  Set<String> doGetActiveProfiles()
           
protected  Set<String> doGetDefaultProfiles()
           
 String[] getActiveProfiles()
          Return the set of profiles explicitly made active for this environment.
 ConversionService getConversionService()
           
 String[] getDefaultProfiles()
          Return the set of profiles to be active by default when no active profiles have been set explicitly.
 String getProperty(String key)
          Return the property value associated with the given key.
<T> T
getProperty(String key, Class<T> targetType)
          Return the property value associated with the given key, or null if the key cannot be resolved.
 ConfigurablePropertyResolver getPropertyResolver()
           
 MutablePropertySources getPropertySources()
          Return the PropertySources for this environment in mutable form
 String getRequiredProperty(String key)
          Return the property value associated with the given key, converted to the given targetType (never null).
<T> T
getRequiredProperty(String key, Class<T> targetType)
          Return the property value associated with the given key, converted to the given targetType (never null).
 Map<String,Object> getSystemEnvironment()
          Return the value of System.getenv() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to System.getenv(String).
 Map<String,Object> getSystemProperties()
          Return the value of System.getProperties() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to System.getProperty(String).
 String resolvePlaceholders(String text)
          Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by PropertyResolver.getProperty(java.lang.String).
 String resolveRequiredPlaceholders(String text)
          Resolve ${...} placeholders in the given text, replacing them with corresponding property values as resolved by PropertyResolver.getProperty(java.lang.String).
 void setActiveProfiles(String... profiles)
          Specify the set of profiles active for this Environment.
 void setConversionService(ConversionService conversionService)
          Set the ConversionService to be used when performing type conversions on properties.
 void setDefaultProfiles(String... profiles)
          Specify the set of profiles to be made active by default if no other profiles are explicitly made active through ConfigurableEnvironment.setActiveProfiles(java.lang.String...).
 void setPlaceholderPrefix(String placeholderPrefix)
           
 void setPlaceholderSuffix(String placeholderSuffix)
           
 void setValueSeparator(String valueSeparator)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTIVE_PROFILES_PROPERTY_NAME

public static final String ACTIVE_PROFILES_PROPERTY_NAME
Name of property to set to specify active profiles: "spring.profiles.active". May be comma delimited.

See Also:
ConfigurableEnvironment.setActiveProfiles(java.lang.String...), Constant Field Values

DEFAULT_PROFILES_PROPERTY_NAME

public static final String DEFAULT_PROFILES_PROPERTY_NAME
Name of property to set to specify default profiles: "spring.profiles.default". May be comma delimited.

See Also:
ConfigurableEnvironment.setDefaultProfiles(java.lang.String...), Constant Field Values

logger

protected final Log logger
Constructor Detail

AbstractEnvironment

public AbstractEnvironment()
Method Detail

getActiveProfiles

public String[] getActiveProfiles()
Description copied from interface: Environment
Return the set of profiles explicitly made active for this environment. Profiles are used for creating logical groupings of bean definitions to be registered conditionally, often based on deployment environment. Profiles can be activated by setting "spring.profiles.active" as a system property or by calling ConfigurableEnvironment.setActiveProfiles(String...).

If no profiles have explicitly been specified as active, then any 'default' profiles will implicitly be considered active.

Specified by:
getActiveProfiles in interface Environment
See Also:
Environment.getDefaultProfiles(), ConfigurableEnvironment.setActiveProfiles(java.lang.String...), ACTIVE_PROFILES_PROPERTY_NAME

doGetActiveProfiles

protected Set<String> doGetActiveProfiles()

setActiveProfiles

public void setActiveProfiles(String... profiles)
Description copied from interface: ConfigurableEnvironment
Specify the set of profiles active for this Environment. Profiles are evaluated during container bootstrap to determine whether bean definitions should be registered with the container.

Specified by:
setActiveProfiles in interface ConfigurableEnvironment
See Also:
ConfigurableEnvironment.setDefaultProfiles(java.lang.String...), Profile, ACTIVE_PROFILES_PROPERTY_NAME

getDefaultProfiles

public String[] getDefaultProfiles()
Description copied from interface: Environment
Return the set of profiles to be active by default when no active profiles have been set explicitly.

Specified by:
getDefaultProfiles in interface Environment
See Also:
Environment.getActiveProfiles(), ConfigurableEnvironment.setDefaultProfiles(java.lang.String...)

doGetDefaultProfiles

protected Set<String> doGetDefaultProfiles()

setDefaultProfiles

public void setDefaultProfiles(String... profiles)
Description copied from interface: ConfigurableEnvironment
Specify the set of profiles to be made active by default if no other profiles are explicitly made active through ConfigurableEnvironment.setActiveProfiles(java.lang.String...).

Specified by:
setDefaultProfiles in interface ConfigurableEnvironment
See Also:
DEFAULT_PROFILES_PROPERTY_NAME

acceptsProfiles

public boolean acceptsProfiles(String... profiles)
Specified by:
acceptsProfiles in interface Environment
Returns:
whether one or more of the given profiles is active, or in the case of no explicit active profiles, whether one or more of the given profiles is included in the set of default profiles
See Also:
Environment.getActiveProfiles(), Environment.getDefaultProfiles()

getPropertySources

public MutablePropertySources getPropertySources()
Description copied from interface: ConfigurableEnvironment
Return the PropertySources for this environment in mutable form

Specified by:
getPropertySources in interface ConfigurableEnvironment

getPropertyResolver

public ConfigurablePropertyResolver getPropertyResolver()

getSystemEnvironment

public Map<String,Object> getSystemEnvironment()
Description copied from interface: ConfigurableEnvironment
Return the value of System.getenv() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to System.getenv(String).

Note that most Environment implementations will include this system environment map as a default PropertySource to be searched. Therefore, it is recommended that this method not be used directly unless bypassing other property sources is expressly intended.

Calls to Map.get(Object) on the Map returned will never throw IllegalAccessException; in cases where the SecurityManager forbids access to a property, null will be returned and an INFO-level log message will be issued noting the exception.

Specified by:
getSystemEnvironment in interface ConfigurableEnvironment

getSystemProperties

public Map<String,Object> getSystemProperties()
Description copied from interface: ConfigurableEnvironment
Return the value of System.getProperties() if allowed by the current SecurityManager, otherwise return a map implementation that will attempt to access individual keys using calls to System.getProperty(String).

Note that most Environment implementations will include this system properties map as a default PropertySource to be searched. Therefore, it is recommended that this method not be used directly unless bypassing other property sources is expressly intended.

Calls to Map.get(Object) on the Map returned will never throw IllegalAccessException; in cases where the SecurityManager forbids access to a property, null will be returned and an INFO-level log message will be issued noting the exception.

Specified by:
getSystemProperties in interface ConfigurableEnvironment

containsProperty

public boolean containsProperty(String key)
Description copied from interface: PropertyResolver
Return whether the given property key is available for resolution.

Specified by:
containsProperty in interface PropertyResolver

getProperty

public String getProperty(String key)
Description copied from interface: PropertyResolver
Return the property value associated with the given key.

Specified by:
getProperty in interface PropertyResolver
See Also:
PropertyResolver.getProperty(String, Class)

getProperty

public <T> T getProperty(String key,
                         Class<T> targetType)
Description copied from interface: PropertyResolver
Return the property value associated with the given key, or null if the key cannot be resolved.

Specified by:
getProperty in interface PropertyResolver

getRequiredProperty

public String getRequiredProperty(String key)
                           throws IllegalStateException
Description copied from interface: PropertyResolver
Return the property value associated with the given key, converted to the given targetType (never null).

Specified by:
getRequiredProperty in interface PropertyResolver
Throws:
IllegalStateException - if the key cannot be resolved
See Also:
PropertyResolver.getRequiredProperty(String, Class)

getRequiredProperty

public <T> T getRequiredProperty(String key,
                                 Class<T> targetType)
                      throws IllegalStateException
Description copied from interface: PropertyResolver
Return the property value associated with the given key, converted to the given targetType (never null).

Specified by:
getRequiredProperty in interface PropertyResolver
Throws:
IllegalStateException - if the given key cannot be resolved

resolvePlaceholders

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

Specified by:
resolvePlaceholders in interface PropertyResolver
Parameters:
text - the String to resolve
Returns:
the resolved String (never null)
See Also:
PropertyResolver.resolveRequiredPlaceholders(java.lang.String), SystemPropertyUtils.resolvePlaceholders(String)

resolveRequiredPlaceholders

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

Specified by:
resolveRequiredPlaceholders in interface PropertyResolver
Returns:
the resolved String (never null)
Throws:
IllegalArgumentException - if given text is null
See Also:
SystemPropertyUtils.resolvePlaceholders(String, boolean)

setConversionService

public void setConversionService(ConversionService conversionService)
Description copied from interface: ConfigurablePropertyResolver
Set the ConversionService to be used when performing type conversions on properties.

Specified by:
setConversionService in interface ConfigurablePropertyResolver
See Also:
PropertyResolver.getProperty(String, Class)

getConversionService

public ConversionService getConversionService()
Specified by:
getConversionService in interface ConfigurablePropertyResolver
Returns:
the ConversionService used when performing type conversions on properties.
See Also:
PropertyResolver.getProperty(String, Class)

setPlaceholderPrefix

public void setPlaceholderPrefix(String placeholderPrefix)
Specified by:
setPlaceholderPrefix in interface ConfigurablePropertyResolver

setPlaceholderSuffix

public void setPlaceholderSuffix(String placeholderSuffix)
Specified by:
setPlaceholderSuffix in interface ConfigurablePropertyResolver

setValueSeparator

public void setValueSeparator(String valueSeparator)
Specified by:
setValueSeparator in interface ConfigurablePropertyResolver

toString

public String toString()
Overrides:
toString in class Object