DeploymentConfiguration.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 DeploymentConfiguration.cpp
00024  * @Description Implementation of the DeploymentConfiguration class
00025  * @Status Implementing
00026  * @Version $Id: DeploymentConfiguration.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Marco Barbosa (mafb@isr.ist.utl.pt)
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include "DeploymentConfiguration.hpp"
00033 
00034 #include <Exception.hpp>
00035 
00036 #include <XmlCharData.hpp>
00037 #include <XmlElement.hpp>
00038 #include <XmlElementVector.hpp>
00039 
00040 
00041 #include <ActiveObjectConfiguration.hpp>
00042 #include <ServiceDeploymentConfiguration.hpp>
00043 
00044 #include <iostream>
00045 #include <iterator>
00046 #include <sstream>
00047 
00048 using namespace mermaid::mermaidloader;
00049 
00050 using std::string;
00051 
00052 using mermaid::support::errorhandling::Exception;
00053 
00054 using mermaid::support::xml::XmlCharData;
00055 using mermaid::support::xml::XmlElement;
00056 using mermaid::support::xml::XmlElementVector;
00057 
00058 void DeploymentConfiguration::loadConfiguration (shared_ptr<XmlDocument> config)
00059 {
00060   //std::cerr << "DeploymentConfiguration::loadConfiguration" << std::endl;
00061   
00062   _dataDescriptionFileList.clear();
00063   _serviceTypeDescriptionFileList.clear();
00064   _entityDescriptionFileList.clear();
00065   _activeObjectMap.clear();
00066   _activeObjectBelongedServices.clear();
00067   _serviceMap.clear();
00068   
00069   
00070   shared_ptr<XmlElement> rootElement = config->getRootElement();
00071   
00072   if (rootElement->getName().compare ("deployment-configuration") != 0) {
00073     throw Exception ("DeploymentConfiguration::loadConfiguration : invalid configuration");
00074   }
00075   
00076   XmlElementVector childrenElements = rootElement->getChildrenElements();
00077   
00078   XmlElementVector::iterator it;
00079   
00080   for (it = childrenElements.begin(); it != childrenElements.end(); it++) {
00081     shared_ptr<XmlElement> e = *it;
00082     
00083     //std::cerr << "DeploymentConfiguration::loadConfiguration : reading element: " << (string)*e << std::endl;
00084     
00085     if (e->getName().compare ("file-search-path") == 0) {
00086       shared_ptr<XmlCharData> pathCharData = e->getFirstNonBlankCharData();
00087       std::string path = (std::string) ( (*pathCharData));
00088       _fileSearchPathList.push_back (path);
00089     }
00090     else if (e->getName().compare ("data-description-file") == 0) {
00091       shared_ptr<XmlCharData> filenameCharData = e->getFirstNonBlankCharData();
00092       std::string filename = (std::string) ( (*filenameCharData));
00093       _dataDescriptionFileList.push_back (filename);
00094     }
00095     else if (e->getName().compare ("service-type-description-file") == 0) {
00096       shared_ptr<XmlCharData> filenameCharData = e->getFirstNonBlankCharData();
00097       std::string filename = (std::string) ( (*filenameCharData));
00098       _serviceTypeDescriptionFileList.push_back (filename);
00099     }
00100     else if (e->getName().compare ("entity-description-file") == 0) {
00101       shared_ptr<XmlCharData> filenameCharData = e->getFirstNonBlankCharData();
00102       std::string filename = (std::string) ( (*filenameCharData));
00103       _entityDescriptionFileList.push_back (filename);
00104     }
00105     else if (e->getName().compare ("active-object") == 0) {
00106       //std::cerr << "Processing active-object configuration" << std::endl;
00107       shared_ptr<ActiveObjectConfiguration> aoc = shared_ptr<ActiveObjectConfiguration> (new ActiveObjectConfiguration (e));
00108       if (_activeObjectMap.count (aoc->getName()) != 0) {
00109         throw Exception ("DeploymentConfiguration::loadConfiguration : more than one Active Object with the same name:" + aoc->getName());
00110       }
00111       _activeObjectMap[aoc->getName() ] = aoc;
00112       _activeObjectBelongedServices[aoc->getName() ] = vector< shared_ptr<ServiceDeploymentConfiguration> >();
00113     }
00114     else if (e->getName().compare ("service") == 0) {
00115       //std::cerr << "Processing service configuration" << std::endl;
00116       shared_ptr<ServiceDeploymentConfiguration> sc = shared_ptr<ServiceDeploymentConfiguration> (new ServiceDeploymentConfiguration (e));
00117       if (_serviceMap.count (sc->getServiceInstanceName()) != 0) {
00118         throw Exception ("DeploymentConfiguration::loadConfiguration : more than one Service with the same instance name:" + sc->getServiceInstanceName());
00119       }
00120       _serviceMap[sc->getServiceInstanceName() ] = sc;
00121       
00122       vector< shared_ptr<ServiceDeploymentConfiguration> > aoBelongedServiceVector = _activeObjectBelongedServices[sc->getServiceActiveObjectName() ];
00123       aoBelongedServiceVector.push_back (sc);
00124       _activeObjectBelongedServices[sc->getServiceActiveObjectName() ] = aoBelongedServiceVector;
00125     }
00126     else {
00127       throw Exception ("DeploymentConfiguration::loadConfiguration : invalid configuration");
00128     }
00129   }
00130   
00131 }; // DeploymentConfiguration::loadConfiguration
00132 
00133 FileSearchPathList DeploymentConfiguration::getFileSearchPathList()
00134 {
00135   return _fileSearchPathList;
00136 }; // DeploymentConfiguration::getFileSearchPathList()
00137 
00138 DataDescriptionFileList DeploymentConfiguration::getDataDescriptionFileList()
00139 {
00140   return _dataDescriptionFileList;
00141 }; // DeploymentConfiguration::getDataDescriptionFileList()
00142 
00143 ServiceTypeDescriptionFileList DeploymentConfiguration::getServiceTypeDescriptionFileList()
00144 {
00145   return _serviceTypeDescriptionFileList;
00146 }; // DeploymentConfiguration::getServiceTypeDescriptionFileList()
00147 
00148 EntityDescriptionFileList DeploymentConfiguration::getEntityDescriptionFileList()
00149 {
00150   return _entityDescriptionFileList;
00151 }; // DeploymentConfiguration::getEntityDescriptionFileList()
00152 
00153 ActiveObjectConfigurationNameMap DeploymentConfiguration::getActiveObjectConfigurationNameMap()
00154 {
00155   return ActiveObjectConfigurationNameMap (_activeObjectMap);
00156 }; // DeploymentConfiguration::getActiveObjectConfigurationNameMap()
00157 
00158 ActiveObjectConfigurationServiceMap DeploymentConfiguration::getActiveObjectConfigurationServiceMap()
00159 {
00160   return ActiveObjectConfigurationServiceMap (_activeObjectBelongedServices);
00161 }; // DeploymentConfiguration::getActiveObjectConfigurationServiceMap()
00162 
00163 ServiceDeploymentConfigurationNameMap DeploymentConfiguration::getServiceDeploymentConfigurationNameMap()
00164 {
00165   return ServiceDeploymentConfigurationNameMap (_serviceMap);
00166 }; // DeploymentConfiguration::getServiceDeploymentConfigurationNameMap()
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3