* @return A new Settings object
*/
protected MutableSettings createSettings() {
final String mode = getRunningMode();
// create an empty settings objects
final MutableSettings s = createMutableSettingsInstance();
// create the initial properties
final Properties properties = new Properties();
// invoke pre initialization hook
preInit(s, properties);
// check for property providers
if (this.beanFactory != null && this.beanFactory.containsBean(PropertyProvider.ROLE) ) {
try {
final PropertyProvider provider = (PropertyProvider) this.beanFactory.getBean(PropertyProvider.ROLE);
final Properties providedProperties = provider.getProperties(s, mode, this.getNameForPropertyProvider());
if (providedProperties != null) {
properties.putAll(providedProperties);
}
} catch (Exception ignore) {
this.logger.warn("Unable to get properties from provider.", ignore);
this.logger.warn("Continuing initialization.");
}
}
// add aditional directories
if (this.directories != null) {
final Iterator i = directories.iterator();
while (i.hasNext()) {
final String directory = (String) i.next();
// now read all properties from the properties directory
ResourceUtils.readProperties(directory, properties, getResourceLoader(), this.resourceFilter, this.logger);
// read all properties from the mode dependent directory
ResourceUtils.readProperties(directory + '/' + mode, properties, getResourceLoader(), this.resourceFilter, this.logger);
}
}
// add additional properties
if (this.additionalProperties != null) {
PropertyHelper.replaceAll(this.additionalProperties, s);
properties.putAll(this.additionalProperties);
}
// now overwrite with system properties
try {
properties.putAll(System.getProperties());
} catch (SecurityException se) {
// we ignore this
}
// invoke post initialization hook
postInit(s, properties);
PropertyHelper.replaceAll(properties, getParentSettings());
// configure settings
s.configure(properties);
s.makeReadOnly();
return s;
}