EntityDescriptionFactory.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00080 shared_ptr<ServiceInstanceDescription> serviceInstanceDescription (new ServiceInstanceDescription (entityDescription, instanceName));
00081
00082
00083 entityDescription->addServiceInstanceDescription (serviceInstanceDescription);
00084
00085
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
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 };