org.springframework.beans.factory.config
public class: PreferencesPlaceholderConfigurer [javadoc |
source]
java.lang.Object
org.springframework.core.io.support.PropertiesLoaderSupport
org.springframework.beans.factory.config.PropertyResourceConfigurer
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer
All Implemented Interfaces:
InitializingBean, BeanFactoryAware, BeanNameAware, PriorityOrdered, BeanFactoryPostProcessor
Subclass of PropertyPlaceholderConfigurer that supports JDK 1.4's
Preferences API (
java.util.prefs).
Tries to resolve placeholders as keys first in the user preferences,
then in the system preferences, then in this configurer's properties.
Thus, behaves like PropertyPlaceholderConfigurer if no corresponding
preferences defined.
Supports custom paths for the system and user preferences trees. Also
supports custom paths specified in placeholders ("myPath/myPlaceholderKey").
Uses the respective root node if not specified.
| Methods from org.springframework.beans.factory.config.PropertyPlaceholderConfigurer: |
|---|
|
parseStringValue, processProperties, resolvePlaceholder, resolvePlaceholder, resolveSystemProperty, setBeanFactory, setBeanName, setIgnoreUnresolvablePlaceholders, setNullValue, setPlaceholderPrefix, setPlaceholderSuffix, setSearchSystemEnvironment, setSystemPropertiesMode, setSystemPropertiesModeName |
| Method from org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer Detail: |
public void afterPropertiesSet() {
this.systemPrefs = (this.systemTreePath != null) ?
Preferences.systemRoot().node(this.systemTreePath) : Preferences.systemRoot();
this.userPrefs = (this.userTreePath != null) ?
Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot();
}
This implementation eagerly fetches the Preferences instances
for the required system and user tree nodes. |
protected String resolvePlaceholder(String placeholder,
Properties props) {
String path = null;
String key = placeholder;
int endOfPath = placeholder.lastIndexOf('/");
if (endOfPath != -1) {
path = placeholder.substring(0, endOfPath);
key = placeholder.substring(endOfPath + 1);
}
String value = resolvePlaceholder(path, key, this.userPrefs);
if (value == null) {
value = resolvePlaceholder(path, key, this.systemPrefs);
if (value == null) {
value = props.getProperty(placeholder);
}
}
return value;
}
This implementation tries to resolve placeholders as keys first
in the user preferences, then in the system preferences, then in
the passed-in properties. |
protected String resolvePlaceholder(String path,
String key,
Preferences preferences) {
if (path != null) {
// Do not create the node if it does not exist...
try {
if (preferences.nodeExists(path)) {
return preferences.node(path).get(key, null);
}
else {
return null;
}
}
catch (BackingStoreException ex) {
throw new BeanDefinitionStoreException("Cannot access specified node path [" + path + "]", ex);
}
}
else {
return preferences.get(key, null);
}
}
Resolve the given path and key against the given Preferences. |
public void setSystemTreePath(String systemTreePath) {
this.systemTreePath = systemTreePath;
}
Set the path in the system preferences tree to use for resolving
placeholders. Default is the root node. |
public void setUserTreePath(String userTreePath) {
this.userTreePath = userTreePath;
}
Set the path in the system preferences tree to use for resolving
placeholders. Default is the root node. |