EntityRepository.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 "EntityRepository.hpp"
00034 #include "EntityDescription.hpp"
00035 #include "EntityDescriptionRepository.hpp"
00036 #include "ServiceInterfaceDescription.hpp"
00037 #include "ServiceTypeDescription.hpp"
00038 #include "Service.hpp"
00039
00040 #include <Exception.hpp>
00041
00042 #include <sstream>
00043
00044 using namespace mermaid::support::service;
00045 using mermaid::support::errorhandling::Exception;
00046
00047
00048 void EntityRepository::addEntity (shared_ptr<Entity> entity)
00049 {
00050 std::string entityName = entity->getEntityDescription()->getEntityName();
00051
00052 if (entityMap_.find (entityName) != entityMap_.end()) {
00053 std::stringstream ss;
00054 ss << "EntityRepository::addEntity : repository already has an entity registered with entityName=\"" << entityName << "\"";
00055 throw Exception (ss.str());
00056 }
00057
00058 entityMap_[entityName] = entity;
00059 };
00060
00061 shared_ptr<Entity> EntityRepository::getEntity (std::string entityName)
00062 {
00063 std::map<std::string, shared_ptr<Entity> >::iterator it = entityMap_.find (entityName);
00064
00065 if (it == entityMap_.end()) {
00066 std::stringstream ss;
00067 ss << "EntityRepository::getEntity : repository does not have an entity registered with entityName=\"" << entityName << "\"";
00068 throw Exception (ss.str());
00069 }
00070
00071 return (*it).second;
00072 };
00073
00074 shared_ptr<Entity> EntityRepository::getOrCreateEntity (std::string entityName)
00075 {
00076
00077 std::map<std::string, shared_ptr<Entity> >::iterator it = entityMap_.find (entityName);
00078
00079 if (it == entityMap_.end()) {
00080 shared_ptr<EntityDescription> entityDescription = EntityDescriptionRepository::getInstance()->getEntityDescription (entityName);
00081 shared_ptr<Entity> entity = shared_ptr<Entity> (new Entity (entityDescription));
00082 this->addEntity (entity);
00083 return entity;
00084 }
00085
00086 return (*it).second;
00087 };
00088