checkVariableName (varName);
}
catch (ConfigurationException ex)
{
throw new VariableSubstitutionException (ex);
}
currentVariable = substContext.currentVariable;
if (currentVariable.getName().equals (varName))
{
throw new VariableSubstitutionException
(Package.BUNDLE_NAME,
"Configuration.recursiveSubst",
"Attempt to substitute value for variable " +
"\"{0}\" within itself.",
new Object[] {varName});
}
variableParentSection = substContext.currentVariable.getSection();
i = varName.indexOf (':');
if (i == -1)
{
// No section in the variable reference. Use the variable's
// context.
section = variableParentSection;
sectionName = section.getName();
}
else
{
sectionName = varName.substring (0, i);
varName = varName.substring (i + 1);
if (sectionName.equals (SYSTEM_SECTION_NAME))
section = systemSection;
else if (sectionName.equals (PROGRAM_SECTION_NAME))
section = programSection;
else if (sectionName.equals (ENV_SECTION_NAME))
section = envSection;
else
section = sectionsByName.get (sectionName);
}
if (section == null)
{
if (abortOnUndefinedVariable)
{
throw new VariableSubstitutionException
(Package.BUNDLE_NAME,
"Configuration.nonExistentSection",
"Reference to variable \"{0}\" in nonexistent section " +
"\"{1}\".",
new Object[] {varName, sectionName});
}
}
else
{
if (variableParentSection.getID() < section.getID())
{
String parentSectionName = variableParentSection.getName();
String thisSectionName = section.getName();
throw new VariableSubstitutionException
(Package.BUNDLE_NAME,
"Configuration.badSectionRef",
"Variable \"{0}\" in section \"{1}\" cannot substitute " +
"the value of variable \"{2}\" from section \"{3}\", " +
"because section \"{3}\" appears after section \"{1}\" " +
"in the configuration file.",
new Object[]
{
substContext.currentVariable.getName(),
parentSectionName,
varName,
thisSectionName,
thisSectionName,
parentSectionName
});
}
Variable varToSubst;
try
{
varToSubst = section.getVariable (varName);
}
catch (ConfigurationException ex)
{
throw new VariableSubstitutionException (ex.getMessage());
}
if (varToSubst != null)
{
value = varToSubst.getCookedValue();