/** * Returns a configuration explorer on the test section. * @return a configuration explorer on the test section. */ protected ConfigurationExplorer getExplorer() { return new ConfigurationExplorer(conf.getRoot()); }
/** * Returns the value of the specified variable. * @param name fully qualified name of the variable whose value should be retrieved. * @return the variable's value if set, <code>null</code> otherwise. * @see #setVariable(String,String) * @see #getVariable(String,String) */ public synchronized String getVariable(String name) { ConfigurationExplorer explorer; // Used to navigate to the variable's parent section. // If the variable's 'path' doesn't exist, return null. if((name = moveToParent(explorer = new ConfigurationExplorer(root), name, false)) == null) return null; return explorer.getSection().getVariable(name); }
/** * Sets the value of the specified variable. * <p> * This method will return <code>false</code> if it didn't modify <code>name</code>'s value. Note that this doesn't * mean the call failed, but that <code>name</code>'s value was already equal to <code>value</code>. * </p> * <p> * If the value of the specified variable is actually modified, an {@link ConfigurationEvent event} will be passed * to all LISTENERS. * </p> * @param name fully qualified name of the variable to set. * @param value new value for the variable. * @return <code>true</code> if this call resulted in a modification of the variable's value, * <code>false</code> otherwise. * @see #getVariable(String) * @see #getVariable(String,String) */ public synchronized boolean setVariable(String name, String value) { ConfigurationExplorer explorer; // Used to navigate to the variable's parent section. String buffer; // Buffer for the variable's name trimmed of section information. // Moves to the parent section. buffer = moveToParent(explorer = new ConfigurationExplorer(root), name, true); // If the variable's value was actually modified, triggers an event. if(explorer.getSection().setVariable(buffer, value)) { triggerEvent(new ConfigurationEvent(this, name, value)); return true; } return false; }
/** * Retrieves the value of the specified variable. * <p> * If the variable isn't set, this method will set it to <code>defaultValue</code> before * returning it. If this happens, a configuration {@link ConfigurationEvent event} will * be sent to all registered LISTENERS. * </p> * @param name name of the variable to retrieve. * @param defaultValue value to use if <code>name</code> is not set. * @return the specified variable's value. * @see #setVariable(String,String) * @see #getVariable(String) */ public synchronized String getVariable(String name, String defaultValue) { ConfigurationExplorer explorer; // Used to navigate to the variable's parent section. String value; // Buffer for the variable's value. String buffer; // Buffer for the variable's name trimmed of section information. // Navigates to the parent section. We do not have to check for null values here, // as the section will be created if it doesn't exist. buffer = moveToParent(explorer = new ConfigurationExplorer(root), name, true); // If the variable isn't set, set it to defaultValue and triggers an event. if((value = explorer.getSection().getVariable(buffer)) == null) { explorer.getSection().setVariable(buffer, defaultValue); triggerEvent(new ConfigurationEvent(this, name, defaultValue)); return defaultValue; } return value; }