UnitFlowConfiguration.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename UnitFlowConfiguration.cpp
00024  * @Description Implementation of the UnitFlowConfiguration class
00025  * @Status Implementing
00026  * @Version $Id: UnitFlowConfiguration.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Joao Carreira (joao.carreira@ist.utl.pt)
00028  */
00029 
00030 #include "UnitFlowConfiguration.hpp"
00031 
00032 #include <Exception.hpp>
00033 
00034 #include <XmlCharData.hpp>
00035 #include <XmlElement.hpp>
00036 #include <XmlElementVector.hpp>
00037 
00038 #include <vector>
00039 #include <string>
00040 #include <iostream>
00041 
00042 using namespace mermaid::support::unitgenerator;
00043 using namespace std;
00044 
00045 using mermaid::support::errorhandling::Exception;
00046 using mermaid::support::xml::XmlCharData;
00047 using mermaid::support::xml::XmlElement;
00048 using mermaid::support::xml::XmlElementVector;
00049 
00050 void UnitFlowConfiguration::loadConfiguration (shared_ptr<XmlDocument> config)
00051 {
00052   shared_ptr<XmlElement> rootElement = config->getRootElement();
00053   
00054   if (rootElement->getName().compare ("unit-configuration") != 0) {
00055     throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"unit-configuration\" tag");
00056   }
00057   
00058   //shared_ptr<XmlElement> unitNameElement = rootElement->getChildrenElements().getFirstElementWithName("name");
00059   //unitName_ = static_cast<string>(unitNameElement->getFirstNonBlankCharData()(*));
00060   
00061   shared_ptr<XmlElement> unitNameElement = rootElement->getChildrenElements().getFirstElementWithName ("name");
00062   unitName_ = static_cast<string> (* (unitNameElement->getFirstNonBlankCharData()));
00063   
00064   shared_ptr<XmlElement> flowElement = rootElement->getChildrenElements().getFirstElementWithName ("flow-configuration");
00065   if (flowElement->getName().compare ("flow-configuration") != 0) {
00066     throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"flow-configuration\" tag.");
00067   }
00068   
00069   XmlElementVector childrenElements = flowElement->getChildrenElements();
00070   XmlElementVector::iterator it;
00071   
00072   
00073   vector<vector<string> > finalFlowDescription;
00074   
00075   for (it = childrenElements.begin(); it != childrenElements.end(); ++it) {
00076     shared_ptr<XmlElement> e = *it;
00077     
00078     //std::cerr << "UnitFlowConfiguration::loadConfiguration : reading element: " << (string)*e << std::endl;
00079     
00080     vector<string> vectorToAdd;
00081     if (e->getName().compare ("service") == 0) {
00082       XmlElementVector serviceChildren = e->getChildrenElements();
00083       string instanceName = static_cast<string> (* (serviceChildren.getFirstElementWithName ("instance-name")->getFirstNonBlankCharData()));
00084       vectorToAdd.push_back (instanceName);
00085       //throw Exception("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"item\" tag");
00086     }
00087     else if (e->getName().compare ("concurrent") == 0) {
00088       XmlElementVector concurrentChildrenElements = e->getChildrenElements();
00089       for (XmlElementVector::iterator i = concurrentChildrenElements.begin(); i != concurrentChildrenElements.end(); ++i) {
00090         shared_ptr<XmlElement> srvEl = *i;
00091         if (srvEl->getName().compare ("service") != 0)
00092           throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"service\" tag");
00093         XmlElementVector serviceChildren = srvEl->getChildrenElements();
00094         string instanceName = static_cast<string> (* (serviceChildren.getFirstElementWithName ("instance-name")->getFirstNonBlankCharData()));
00095         vectorToAdd.push_back (instanceName);
00096       }
00097     }
00098     
00099     finalFlowDescription.push_back (vectorToAdd);
00100     
00101     /*XmlElementVector devChildren = e->getChildrenElements();
00102     
00103     UnitFlowConfiguration::DevInfo devInfo;
00104     devInfo.name = static_cast<string>(devChildren.getFirstElementWithName("name")->getFirstNonBlankCharData()(*));
00105     devInfo.headerFilePath = static_cast<string>(devChildren.getFirstElementWithName("header-file-path")->getFirstNonBlankCharData()(*));
00106     devInfo.configFilePath = static_cast<string>(devChildren.getFirstElementWithName("config-file-path")->getFirstNonBlankCharData()(*));
00107     
00108     XmlElementVector::iterator it;
00109     XmlElementVector filePathsElements = devChildren.getElementsWithName("file-search-path");
00110     for (it = filePathsElements.begin(); it != filePathsElements.end(); ++it) {
00111         shared_ptr<XmlElement> e = *it;
00112         devInfo.filePaths.push_back(static_cast<string>(e->getFirstNonBlankCharData()(*)));
00113     }*/
00114   }
00115   
00116 }
00117 
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3