1.2.2 - Using ConfigString class

The power to expand property values comes from ConfigString class. This is a class that binds itself with JConfig properties and variable table and can recursively expand any property or variable references within the string.

ConfigString class comes with a public constructor so anyone can create an instance of one. You can use JConfig.getTopProperties() and JConfig.getGlobalVariables() calls to acquire the JConfig configuration tables, or as a convenience you can call JConfig.createConfigString(). The result will be a ConfigString object already property intialized.

Once you have a ConfigString object, you can call on its ConfigString.expand(String name) method. Where the parameter name is a runtime variable that is expanded for ${name} references within the original string. If name is known not to be used within the string, it is customary to provide an empty double quote string literal "" for that parameter.

ConfigString.expand() returns a boolean value. True means that string was expanded fully, or false if a unresolved reference was encountered. The unresolved reference can be in the immediate source string or any of the sub properties it referenced, may levels deep. In any case, an unresolved property reference or variable usually means that the value of the string is useless.

ConfigString objects can also have single quoted strings within. Any single quoted strings will be escaped from expansion algorithm.

The original string that was supplied to the ConfigString construtor is set as a template string, untouched through out the expansion process. ConfigString.reset() method will restore a ConfigString to its initial state, with the template string being used as the basis for the next expansion. This is a good way to repeach the expansion process under new set of properties or variables.