-
Notifications
You must be signed in to change notification settings - Fork 37.7k
/
EnumerablePropertySource.java
83 lines (74 loc) · 3.04 KB
/
EnumerablePropertySource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.env;
import org.springframework.util.ObjectUtils;
/**
* A {@link PropertySource} implementation capable of interrogating its
* underlying source object to enumerate all possible property name/value
* pairs. Exposes the {@link #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
* {@link #containsProperty(String)}, in that it can call {@link #getPropertyNames()}
* and iterate through the returned array rather than attempting a call to
* {@link #getProperty(String)} which may be more expensive. Implementations may
* consider caching the result of {@link #getPropertyNames()} to fully exploit this
* performance opportunity.
*
* <p>Most framework-provided {@code PropertySource} implementations are enumerable;
* a counter-example would be {@code 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 {@link #getProperty(String)}) in order to evaluate whether it is present
* or not.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @param <T> the source type
*/
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
/**
* Create a new {@code EnumerablePropertySource} with the given name and source object.
* @param name the associated name
* @param source the source object
*/
public EnumerablePropertySource(String name, T source) {
super(name, source);
}
/**
* Create a new {@code EnumerablePropertySource} with the given name and with a new
* {@code Object} instance as the underlying source.
* @param name the associated name
*/
protected EnumerablePropertySource(String name) {
super(name);
}
/**
* Return whether this {@code PropertySource} contains a property with the given name.
* <p>This implementation checks for the presence of the given name within the
* {@link #getPropertyNames()} array.
* @param name the name of the property to find
*/
@Override
public boolean containsProperty(String name) {
return ObjectUtils.containsElement(getPropertyNames(), name);
}
/**
* Return the names of all properties contained by the
* {@linkplain #getSource() source} object (never {@code null}).
*/
public abstract String[] getPropertyNames();
}