EntityDescriptionFactory.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 EntityDescriptionFactory.cpp
00024  * @Description Support EntityDescriptionFactory implementation
00025  * @Status Work in Progress
00026  * @Version $Id: EntityDescriptionFactory.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer mafb
00028  */
00029 
00030 
00031 #include "config.h"
00032 
00033 #include "EntityDescriptionFactory.hpp"
00034 #include "ServiceInterfaceDescription.hpp"
00035 #include "ServiceTypeDescription.hpp"
00036 
00037 #include <XmlElement.hpp>
00038 #include <XmlElementVector.hpp>
00039 
00040 #include <iostream>
00041 
00042 using namespace mermaid::support::service;
00043 using mermaid::support::xml::XmlElement;
00044 using mermaid::support::xml::XmlElementVector;
00045 
00046 
00047 
00048 void EntityDescriptionFactory::populateEntityDescriptionRepository (shared_ptr<EntityDescriptionRepository> entityDescriptionRepository, shared_ptr<XmlElement> entityDescriptionList, shared_ptr<ServiceTypeDescriptionRepository> serviceTypeDescriptionRepository)
00049 {
00050   XmlElementVector entityDescriptionElements = entityDescriptionList->getChildrenElements().getElementsWithName ("entity");
00051   
00052   XmlElementVector::iterator entityIterator;
00053   
00054   for (entityIterator = entityDescriptionElements.begin(); entityIterator != entityDescriptionElements.end(); entityIterator++) {
00055     shared_ptr<XmlElement> entityElement = *entityIterator;
00056     XmlElementVector entityChildren = entityElement->getChildrenElements();
00057     
00058     shared_ptr<XmlElement> entityNameElement = entityChildren.getFirstElementWithName ("name");
00059     
00060     std::string entityName = static_cast<std::string> (* (entityNameElement->getFirstNonBlankCharData()));
00061     
00062     std::cerr << "EntityDescriptionFactory::populateEntityDescriptionRepository : creating EntityDescription\tentityName=\"" << entityName << "\"" << std::endl;
00063     
00064     shared_ptr<EntityDescription> entityDescription (new EntityDescription (entityName));
00065     
00066     XmlElementVector serviceList = entityElement->getChildrenElements().getElementsWithName ("service");
00067     
00068     XmlElementVector::iterator serviceIterator;
00069     
00070     for (serviceIterator = serviceList.begin(); serviceIterator != serviceList.end(); serviceIterator++) {
00071       shared_ptr<XmlElement> serviceElement = *serviceIterator;
00072       XmlElementVector serviceChildren = serviceElement->getChildrenElements();
00073       
00074       shared_ptr<XmlElement> instanceNameElement = serviceChildren.getFirstElementWithName ("instance-name");
00075       std::string instanceName = static_cast<std::string> (* (instanceNameElement->getFirstNonBlankCharData()));
00076       
00077       std::cerr << "\tservice:\n\t\tserviceInstanceName=\"" << instanceName << "\"" << std::endl;
00078       
00079       //build ServiceInstanceDescription
00080       shared_ptr<ServiceInstanceDescription> serviceInstanceDescription (new ServiceInstanceDescription (entityDescription, instanceName));
00081       
00082       //add ServiceInstanceDescription to EntityDescription
00083       entityDescription->addServiceInstanceDescription (serviceInstanceDescription);
00084       
00085       // add ServiceTypeDescriptions
00086       XmlElementVector typeNameElements = serviceChildren.getElementsWithName ("type-name");
00087       XmlElementVector::iterator typeIterator;
00088       
00089       for (typeIterator = typeNameElements.begin(); typeIterator != typeNameElements.end(); typeIterator++) {
00090         shared_ptr<XmlElement> typeNameElement = *typeIterator;
00091         std::string typeName = static_cast<std::string> (* (typeNameElement->getFirstNonBlankCharData()));
00092         shared_ptr<ServiceTypeDescription> serviceTypeDescription = serviceTypeDescriptionRepository->getServiceTypeDescription (typeName);
00093         std::cerr << "\t\tserviceTypeName=\"" << typeName << "\"" << std::endl;
00094         serviceInstanceDescription->addServiceTypeDescription (serviceTypeDescription);
00095       }
00096       
00097     };
00098     
00099 #ifdef USE_COMM
00100     /* Every entity has a COMM service by default */
00101     std::cerr << "\tservice:\n\t\tserviceInstanceName=\"COMM\"" << std::endl;
00102     std::cerr << "\t\tserviceTypeName=\"COMMService\"" << std::endl;
00103     shared_ptr<ServiceInstanceDescription> serviceInstanceDescription (new ServiceInstanceDescription (entityDescription, "COMM"));
00104     entityDescription->addServiceInstanceDescription (serviceInstanceDescription);
00105     shared_ptr<ServiceTypeDescription> serviceTypeDescription = serviceTypeDescriptionRepository->getServiceTypeDescription ("COMMService");
00106     serviceInstanceDescription->addServiceTypeDescription (serviceTypeDescription);
00107 #endif
00108     
00109     EntityDescriptionRepository::getInstance()->addEntityDescription (entityDescription);
00110   };
00111 }; // populateEntityDescriptionRepository()
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3