I will try to explain this the best I can, but please ask me to reiterate if it isn't clear.
What I have are two classes, one class only contains settings that are passed to it from the other class. These classes are called Profile and Settings, Profile reads settings from an XML file and passes it to Settings using the Key and Value as such:
public void readProfile()
{
// Gets our document ready to be read
setProfileDoc();
// Our Root element
Element root = getProfileDoc().getDocumentElement();
// The name of our profile
Node rootAttrItem = getProfileDoc().getChildNodes().item(0);
Node rootAttrName = rootAttrItem.getAttributes().getNamedItem("Name");
// Gets our Name value and stores into an array for later use.
String rootAttrValue = rootAttrName.getNodeValue();
addToArray(rootAttrValue, true);
// Our XML file contains <Database> and <Batch> with all information in between
NodeList dbNodes = root.getElementsByTagName("Database");
NodeList batchNodes = root.getElementsByTagName("Batch");
// Run through our <Database> tags and <Batch tags> and sends the information to Settings
for (int x = 0; x < dbNodes.getLength(); x++)
{
Element eElement = (Element) dbNodes.item(x);
NodeList userInfo = eElement.getChildNodes();
for (int y = 0; y < userInfo.getLength(); y++)
{
Node tempItem = userInfo.item(y);
if (!hasWhiteSpace(tempItem))
{
String tempKey = tempItem.getNodeName().toString().trim();
String tempValue = tempItem.getTextContent().toString().trim();
settings.setAllSettings(tempKey, tempValue);
}
}
}
for (int x = 0; x < batchNodes.getLength(); x++)
{
Element eElement = (Element) batchNodes.item(x);
NodeList batchInfo = eElement.getChildNodes();
for (int y = 0; y < batchInfo.getLength(); y++)
{
Node tempItem = batchInfo.item(y);
if (!hasWhiteSpace(tempItem))
{
String tempKey = tempItem.getNodeName().toString().trim();
String tempValue = tempItem.getTextContent().toString().trim();
settings.setAllSettings(tempKey, tempValue);
}
}
}
}
All the settings read from the XML file go to the Settings class and is set like so:
public void setAllSettings(String keyIn, String valueIn)
{
// Holds our keyIn
String tempKey = keyIn;
String tempValue = valueIn;
// Depending on what String is brought in, the appropriate settings will be applied
switch (tempKey){
/*
* Our main settings
*/
case "FirstRun":
setFirstRun(tempValue);
case "LastProfile":
setLastProfile(tempValue);
case "LastStartedBrewName":
setLastStartedBrewName(tempValue);
case "LastStartedBrewNumber":
setLastStartedBrewNumber(tempValue);
case "LastFinishedBrewName":
setLastFinishedBrewName(tempValue);
case "LastFinishedBrewNumber":
setLastFinishedBrewNumber(tempValue);
case "CurrentBrewFile":
setCurrentBrewFile(tempValue);
case "ProfilePath":
setProfilePath(tempValue);
case "SensorFilePath":
setSensorFilePath(tempValue);
case "DBConnectionFilePath":
setDBConnectionFilePath(tempValue);
case "SensorReadIncremental":
setSensorReadIncremental(tempValue);
/*
* Our profile settings
*/
case "Profile Name":
setProfileName(tempValue);
case "Database Protocol":
setDatabaseProtocol(tempValue);
case "Url":
setDatabaseUrl(tempValue);
case "Port":
setDatabasePort(tempValue);
case "User":
setDatabaseUser(tempValue);
case "Pass":
setDatabasePass(tempValue);
case "Table":
setDatabaseTable(tempValue);
/*
* Our Batch settings
*/
case "Total":
setBatchTotal(tempValue);
case "Current":
setCurrentBatch(tempValue);
}
}
Now I can use System.out.println() to display all the settings being read from the XML file in the format Key : Value and this shows correctly. All information is read correctly and displayed correctly. I can do this in both the Profile Class and the Settings class and it seems like it all works fine.
When I want to retrieve these settings I have a method in Profile as such:
public String getSetting(String whatSetting)
{
return settings.getSetting(whatSetting);
}
Which goes to the method in Settings that is as such:
public String getSetting(String getSetting)
{
String chosenValue = "";
// Depending on what String is brought in, the appropriate settings will be applied
switch (getSetting){
/*
* Our main settings
*/
case "FirstRun":
chosenValue = getFirstRun();
case "LastProfile":
chosenValue = getLastProfile();
case "LastStartedBrewName":
chosenValue = getLastStartedBrewName();
case "LastStartedBrewNumber":
chosenValue = getLastStartedBrewNumber();
case "LastFinishedBrewName":
chosenValue = getLastFinishedBrewName();
case "LastFinishedBrewNumber":
chosenValue = getLastFinishedBrewNumber();
case "CurrentBrewFile":
chosenValue = getCurrentBrewFile();
case "ProfilePath":
chosenValue = getProfilePath();
case "SensorFilePath":
chosenValue = getSensorFilePath();
case "DBConnectionFilePath":
chosenValue = getDBConnectionFilePath();
case "SensorReadIncremental":
chosenValue = getSensorReadIncremental();
/*
* Our profile settings
*/
case "Profile Name":
chosenValue = getProfileName();
case "Database Protocol":
chosenValue = getDatabaseProtocol();
case "Url":
chosenValue = getDatabaseUrl();
case "Port":
chosenValue = getDatabasePort();
case "User":
chosenValue = getDatabaseUser();
case "Pass":
chosenValue = getDatabasePass();
case "Table":
chosenValue = getDatabaseTable();
/*
* Our Batch settings
*/
case "Total":
chosenValue = getBatchTotal();
case "Current":
chosenValue = getCurrentBatch();
}
return chosenValue;
}
The problem here is I can't get the correct setting to be returned. It will usually return null or the wrong value - One of the Settings is if it is the first run of the program, instead of returning "No" it will return "10"
Any ideas on what the problem may be?