类 PropertySource<T>

java.lang.Object
cn.taketoday.core.env.PropertySource<T>
类型参数:
T - the source type
直接已知子类:
EnumerablePropertySource, PropertySource.StubPropertySource

public abstract class PropertySource<T> extends Object
Abstract base class representing a source of name/value property pairs. The underlying source object may be of any type T that encapsulates properties. Examples include Properties objects, Map objects, ServletContext and ServletConfig objects (for access to init parameters). Explore the PropertySource type hierarchy to see provided implementations.

PropertySource objects are not typically used in isolation, but rather through a PropertySources object, which aggregates property sources and in conjunction with a PropertyResolver implementation that can perform precedence-based searches across the set of PropertySources.

PropertySource identity is determined not based on the content of encapsulated properties, but rather based on the name of the PropertySource alone. This is useful for manipulating PropertySource objects when in collection contexts. See operations in PropertySources as well as the named(String) and toString() methods for details.

从以下版本开始:
4.0
作者:
Chris Beams
另请参阅:
  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    static class 
    PropertySource to be used as a placeholder in cases where an actual property source cannot be eagerly initialized at application context creation time.
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    protected final String
     
    protected final T
     
  • 构造器概要

    构造器
    构造器
    说明
    Create a new PropertySource with the given name and with a new Object instance as the underlying source.
    PropertySource(String name, T source)
    Create a new PropertySource with the given name and source object.
  • 方法概要

    修饰符和类型
    方法
    说明
    boolean
    Return whether this PropertySource contains the given name.
    boolean
    equals(Object other)
    This PropertySource object is equal to the given object if: they are the same instance the name properties for both objects are equal
    Return the name of this PropertySource.
    abstract Object
    Return the value associated with the given name, or null if not found.
    Return the underlying source object for this PropertySource.
    int
    Return a hash code derived from the name property of this PropertySource object.
    static PropertySource<?>
    named(String name)
    Return a PropertySource implementation intended for collection comparison purposes only.
    Produce concise output (type and name) if the current log level does not include debug.

    从类继承的方法 java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 字段详细资料

    • name

      protected final String name
    • source

      protected final T source
  • 构造器详细资料

    • PropertySource

      public PropertySource(String name, T source)
      Create a new PropertySource with the given name and source object.
      参数:
      name - the associated name
      source - the source object
    • PropertySource

      public PropertySource(String name)
      Create a new PropertySource with the given name and with a new Object instance as the underlying source.

      Often useful in testing scenarios when creating anonymous implementations that never query an actual source but rather return hard-coded values.

  • 方法详细资料

    • getName

      public String getName()
      Return the name of this PropertySource.
    • getSource

      public T getSource()
      Return the underlying source object for this PropertySource.
    • containsProperty

      public boolean containsProperty(String name)
      Return whether this PropertySource contains the given name.

      This implementation simply checks for a null return value from getProperty(String). Subclasses may wish to implement a more efficient algorithm if possible.

      参数:
      name - the property name to find
    • getProperty

      @Nullable public abstract Object getProperty(String name)
      Return the value associated with the given name, or null if not found.
      参数:
      name - the property to find
      另请参阅:
    • equals

      public boolean equals(@Nullable Object other)
      This PropertySource object is equal to the given object if:
      • they are the same instance
      • the name properties for both objects are equal

      No properties other than name are evaluated.

      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      Return a hash code derived from the name property of this PropertySource object.
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      Produce concise output (type and name) if the current log level does not include debug. If debug is enabled, produce verbose output including the hash code of the PropertySource instance and every name/value property pair.

      This variable verbosity is useful as a property source such as system properties or environment variables may contain an arbitrary number of property pairs, potentially leading too difficult to read exception and log messages.

      覆盖:
      toString 在类中 Object
      另请参阅:
    • named

      public static PropertySource<?> named(String name)
      Return a PropertySource implementation intended for collection comparison purposes only.

      Primarily for internal use, but given a collection of PropertySource objects, may be used as follows:

       List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
       sources.add(new MapPropertySource("sourceA", mapA));
       sources.add(new MapPropertySource("sourceB", mapB));
       assert sources.contains(PropertySource.named("sourceA"));
       assert sources.contains(PropertySource.named("sourceB"));
       assert !sources.contains(PropertySource.named("sourceC"));
       
      The returned PropertySource will throw UnsupportedOperationException if any methods other than equals(Object), hashCode(), and toString() are called.
      参数:
      name - the name of the comparison PropertySource to be created and returned.