/** * Loads the configuration from a set of files. * * @param subFiles the files to load from. */ private void load(final String[] subFiles) { for (int i = 0; i < subFiles.length; i++) { load(subFiles[i]); } }
/** * Loading of "top level" resources is different to the general recursive case, since it is only at the top level * that we check for the includeAfter parameter. * * @param resourceName the path of the resource to load from. */ @SuppressWarnings("checkstyle:emptyblock") private void loadTop(final String resourceName) { try { resources.push(resourceName); load(resourceName); // Now check for INCLUDE_AFTER resources String includes = get(INCLUDE_AFTER); if (includes != null) { // First, do substitution on the INCLUDE_AFTER do { } while (substitute(INCLUDE_AFTER)); // Now split and process String[] includeAfter = getString(INCLUDE_AFTER).split(","); backing.remove(INCLUDE_AFTER); for (String after : includeAfter) { loadTop(after); } } } finally { resources.pop(); } }
load(System.getProperties(), "System Properties", true);
/** * Creates a DefaultInternalConfiguration. The constructor is package protected as it is called from * {@link Config#getInstance()}; */ protected DefaultInternalConfiguration() { initialiseInstanceVariables(); load(); }
/** * Load the properties from the given Properties object, recording the origin on those properties as being from the * given location. * * @param properties the properties to load from * @param location the location where the parameter was defined. * @param overwriteOnly if true, only properties that are already defined will be loaded */ private void load(final Properties properties, final String location, final boolean overwriteOnly) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); String already = get(key); if (overwriteOnly && already == null && !INCLUDE.equals(key)) { continue; } String value = (String) entry.getValue(); load(key, value, location); } }
/** * Loads a single parameter into the configuration. This handles the special directives such as "include". * * @param key the parameter key. * @param value the parameter value. * @param location the location where the parameter was defined. */ private void load(final String key, final String value, final String location) { // Recursive bit if (INCLUDE.equals(key)) { load(parseStringArray(value)); } else { backing.put(key, value); if ("yes".equals(value) || "true".equals(value)) { booleanBacking.add(key); } else { booleanBacking.remove(key); } String history = locations.get(key); if (history == null) { history = location; } else { history = location + "; " + history; } locations.put(key, history); } }
/** * {@inheritDoc} */ public void refresh() { synchronized (lockObject) { // Now reset this object back to its initial state. initialiseInstanceVariables(); // Load all the parameters from scratch. load(); // Finally, notify all the listeners that have registered with this object that a change in properties has // occurred. Config.notifyListeners(); } }