|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.core.env.PropertySource<T>
public abstract class PropertySource<T>
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 MutablePropertySources
as well as the named(String)
and toString()
methods for details.
Note that when working with @Configuration
classes that
the @PropertySource
annotation provides a convenient and declarative way of adding property sources to the
enclosing Environment
.
PropertySources
,
PropertyResolver
,
PropertySourcesPropertyResolver
,
MutablePropertySources
,
PropertySource
Nested Class Summary | |
---|---|
(package private) static class |
PropertySource.ComparisonPropertySource
|
static class |
PropertySource.StubPropertySource
PropertySource to be used as a placeholder in cases where an actual
property source cannot be eagerly initialized at application context
creation time. |
Field Summary | |
---|---|
protected Log |
logger
|
protected java.lang.String |
name
|
protected T |
source
|
Constructor Summary | |
---|---|
PropertySource(java.lang.String name)
Create a new PropertySource with the given name and with a new Object
instance as the underlying source. |
|
PropertySource(java.lang.String name,
T source)
Create a new PropertySource with the given name and source object. |
Method Summary | |
---|---|
boolean |
containsProperty(java.lang.String name)
Return whether this PropertySource contains the given name. |
boolean |
equals(java.lang.Object obj)
This PropertySource object is equal to the given object if:
they are the same instance
the name properties for both objects are equal
|
java.lang.String |
getName()
Return the name of this PropertySource |
abstract java.lang.Object |
getProperty(java.lang.String name)
Return the value associated with the given name, null if not found. |
T |
getSource()
Return the underlying source object for this PropertySource . |
int |
hashCode()
Return a hashcode derived from the name property of this PropertySource
object. |
static PropertySource<?> |
named(java.lang.String name)
Return a PropertySource implementation intended for collection comparison purposes only. |
java.lang.String |
toString()
Produce concise output (type and name) if the current log level does not include debug. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final Log logger
protected final java.lang.String name
protected final T source
Constructor Detail |
---|
public PropertySource(java.lang.String name, T source)
PropertySource
with the given name and source object.
public PropertySource(java.lang.String name)
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.
Method Detail |
---|
public java.lang.String getName()
PropertySource
public T getSource()
PropertySource
.
public boolean containsProperty(java.lang.String name)
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 findpublic abstract java.lang.Object getProperty(java.lang.String name)
null
if not found.
name
- the property to findPropertyResolver.getRequiredProperty(String)
public int hashCode()
name
property of this PropertySource
object.
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
PropertySource
object is equal to the given object if:
name
properties for both objects are equal
No properties other than name
are evaluated.
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Log#isDebugEnabled()
public static PropertySource<?> named(java.lang.String name)
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |