org.springframework.core.env

## Class EnumerablePropertySource<T>

- java.lang.Object
- - org.springframework.core.env.PropertySource<T>
  - - org.springframework.core.env.EnumerablePropertySource<T>

- Direct Known Subclasses:
    CommandLinePropertySource, MapPropertySource, PortletConfigPropertySource, PortletContextPropertySource, ServletConfigPropertySource, ServletContextPropertySource

      public abstract class EnumerablePropertySource<T>
      extends PropertySource<T>

  A `PropertySource` implementation capable of interrogating its underlying source object to enumerate all possible property name/value pairs. Exposes the `getPropertyNames()` method to allow callers to introspect available properties without having to access the underlying source object. This also facilitates a more efficient implementation of `containsProperty(String)`, in that it can call `getPropertyNames()` and iterate through the returned array rather than attempting a call to `PropertySource.getProperty(String)` which may be more expensive. Implementations may consider caching the result of `getPropertyNames()` to fully exploit this performance opportunity. Most framework-provided `PropertySource` implementations are enumerable; a counter-example would be `JndiPropertySource` where, due to the nature of JNDI it is not possible to determine all possible property names at any given time; rather it is only possible to try to access a property (via `PropertySource.getProperty(String)`) in order to evaluate whether it is present or not.
  Since:
    3.1
  Author:
    Chris Beams

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource

      `PropertySource.StubPropertySource`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String[]` | `EMPTY_NAMES_ARRAY`
    `protected Log` | `logger`

    - ### Fields inherited from class org.springframework.core.env.PropertySource

      `name, source`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EnumerablePropertySource(String name, T source)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsProperty(String name)` Return whether this `PropertySource` contains a property with the given name.
    `abstract String[]` | `getPropertyNames()` Return the names of all properties contained by the source object (never `null`).

    - ### Methods inherited from class org.springframework.core.env.PropertySource

      `equals, getName, getProperty, getSource, hashCode, named, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### EMPTY_NAMES_ARRAY

          protected static final String[] EMPTY_NAMES_ARRAY

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### EnumerablePropertySource

          public EnumerablePropertySource(String name,
                                          T source)

  - ### Method Detail

    - #### getPropertyNames

          public abstract String[] getPropertyNames()

      Return the names of all properties contained by the source object (never `null`).

    - #### containsProperty

          public boolean containsProperty(String name)

      Return whether this `PropertySource` contains a property with the given name.

      This implementation checks for the presence of the given name within the `getPropertyNames()` array.

      Overrides:
        `containsProperty` in class `PropertySource<T>`
      Parameters:
        `name` - the property to find