Go to the documentation of this file.00001 #include "robot_instance/RegisterWizardMapLoader.h"
00002
00003 using namespace std;
00004 using namespace log4cpp;
00005
00006 void RegisterWizardMapLoader::loadRegistersFromFile(const string& filename, const string& namePrefix, RegisterWizardMapPtr registerWizardMap)
00007 {
00008 TiXmlDocument file(filename.c_str());
00009 bool loadOkay = file.LoadFile();
00010
00011 if (!loadOkay)
00012 {
00013 stringstream err;
00014 err << "Failed to load file [" << filename << "]";
00015 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::FATAL, err.str());
00016 throw runtime_error(err.str());
00017 }
00018
00019 TiXmlHandle doc(&file);
00020 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "Register file [" + filename + "] successfully loaded.");
00021
00022 string elementString;
00023
00024 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "XML being parsed for [RegisterData]");
00025
00026
00027 if (!(doc.FirstChildElement("RegisterData").ToElement()))
00028 {
00029 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::ERROR, "The file " + filename + " has no element named [RegisterData]");
00030 MissingXMLElementException missingXMLElementException;
00031 throw missingXMLElementException;
00032 }
00033
00034
00035 TiXmlHandle registersElement(doc.FirstChildElement("RegisterData").FirstChildElement("Registers"));
00036
00037 if (registersElement.ToElement())
00038 {
00039 TiXmlHandle currentRegisterElement = 0;
00040
00041
00042 currentRegisterElement = registersElement.FirstChild("Register");
00043
00044 while (currentRegisterElement.ToElement())
00045 {
00046 elementString.clear();
00047 elementString << *(currentRegisterElement.ToElement());
00048 elementString.append("\n");
00049
00050 registerWizardMap->insert(RegisterWizardFactory::fromXml(elementString, namePrefix));
00051
00052 currentRegisterElement = currentRegisterElement.ToElement()->NextSiblingElement("Register");
00053 }
00054 }
00055 else
00056 {
00057 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::ERROR, "The file " + filename + " has no element named [Registers]");
00058 MissingXMLElementException missingXMLElementException;
00059 throw missingXMLElementException;
00060 }
00061
00062 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "Finished parsing [RegisterData]");
00063 }
00064
00065 std::string RegisterWizardMapLoader::getPropertyFromFile(const std::string& filename, const std::string& property)
00066 {
00067 TiXmlDocument file(filename.c_str());
00068 bool loadOkay = file.LoadFile();
00069
00070 if (!loadOkay)
00071 {
00072 stringstream err;
00073 err << "Failed to load file [" << filename << "]";
00074 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::FATAL, err.str());
00075 throw runtime_error(err.str());
00076 }
00077
00078 TiXmlHandle doc(&file);
00079 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "Register file [" + filename + "] successfully loaded.");
00080 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "XML being parsed for [RegisterData]");
00081
00082
00083 if (!(doc.FirstChildElement("RegisterData").ToElement()))
00084 {
00085 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::ERROR, "The file " + filename + " has no element named [RegisterData]");
00086 MissingXMLElementException missingXMLElementException;
00087 throw missingXMLElementException;
00088 }
00089
00090
00091 std::stringstream ss;
00092 TiXmlHandle registersElement(doc.FirstChildElement("RegisterData").FirstChildElement("Properties"));
00093
00094 if (registersElement.ToElement())
00095 {
00096
00097 if (!(registersElement.FirstChildElement(property).ToElement()))
00098 {
00099 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::ERROR, "The file " + filename + " has no property named [" + property + "]");
00100 MissingXMLElementException missingXMLElementException;
00101 throw missingXMLElementException;
00102 }
00103
00104 ss << registersElement.FirstChildElement(property).ToElement()->GetText();
00105 return ss.str();
00106 }
00107 else
00108 {
00109 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::ERROR, "The file " + filename + " has no element named [Properties]");
00110 MissingXMLElementException missingXMLElementException;
00111 throw missingXMLElementException;
00112 }
00113
00114 NasaCommonLogging::Logger::log("gov.nasa.robonet.RegisterWizardMapLoader", Priority::INFO, "Finished parsing [RegisterData]");
00115 }