ServiceTypeDescriptionFactory.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 "ServiceTypeDescriptionFactory.hpp"
00034 #include "ServiceInterfaceDescription.hpp"
00035 #include "ServiceTypeDescription.hpp"
00036
00037 #include <Exception.hpp>
00038 #include <XmlElement.hpp>
00039
00040 #include <iostream>
00041
00042 using namespace mermaid::support::service;
00043 using mermaid::support::errorhandling::Exception;
00044 using mermaid::support::xml::XmlElement;
00045
00046 void ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository (shared_ptr<ServiceTypeDescriptionRepository> repository, shared_ptr<XmlElement> serviceTypeDescriptionList)
00047 {
00048 XmlElementVector serviceTypeDescriptionElements = serviceTypeDescriptionList->getChildrenElements().getElementsWithName ("service-type-description");
00049
00050 XmlElementVector::iterator stdeIterator;
00051
00052 for (stdeIterator = serviceTypeDescriptionElements.begin(); stdeIterator != serviceTypeDescriptionElements.end(); stdeIterator++) {
00053 shared_ptr<XmlElement> stde = *stdeIterator;
00054 XmlElementVector stdeChildren = stde->getChildrenElements();
00055
00056 shared_ptr<XmlElement> stdeNameElement = stdeChildren.getFirstElementWithName ("name");
00057 shared_ptr<XmlElement> stdeCommentElement = stdeChildren.getFirstElementWithName ("comment");
00058
00059 std::string stdName;
00060 {
00061 shared_ptr<XmlCharData> nameString = stdeNameElement->getFirstNonBlankCharData();
00062
00063 if (nameString == false) {
00064 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : empty name for Service Type Description");
00065 }
00066
00067 stdName = (std::string) (*nameString);
00068 }
00069
00070 std::string stdComment;
00071 {
00072 shared_ptr<XmlCharData> commentString = stdeCommentElement->getFirstNonBlankCharData();
00073
00074 if (commentString) {
00075 stdComment = (std::string) (*commentString);
00076 }
00077 }
00078
00079
00080
00081 shared_ptr<ServiceTypeDescription> std (new ServiceTypeDescription (stdName, stdComment));
00082 repository->addServiceTypeDescription (std);
00083
00084 XmlElementVector stdeInterfaceElements = stdeChildren.getElementsWithName ("service-interface");
00085 XmlElementVector::iterator stdeieIterator;
00086
00087 for (stdeieIterator = stdeInterfaceElements.begin(); stdeieIterator != stdeInterfaceElements.end(); stdeieIterator++) {
00088 shared_ptr<XmlElement> interfaceElement = *stdeieIterator;
00089 XmlElementVector ieChildren = interfaceElement->getChildrenElements();
00090
00091 shared_ptr<XmlElement> intNameElement = ieChildren.getFirstElementWithName ("name");
00092 shared_ptr<XmlElement> intCommentElement = ieChildren.getFirstElementWithName ("comment");
00093 shared_ptr<XmlElement> intInDataElement = ieChildren.getFirstElementWithName ("in-data");
00094 shared_ptr<XmlElement> intOutDataElement = ieChildren.getFirstElementWithName ("out-data");
00095
00096 if (!intInDataElement)
00097 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : service-request in-data missing.");
00098 if (!intOutDataElement)
00099 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : service-request out-data missing.");
00100
00101 shared_ptr<XmlCharData> intNameChar = intNameElement->getFirstNonBlankCharData();
00102 shared_ptr<XmlCharData> intCommentChar = intCommentElement->getFirstNonBlankCharData();
00103 shared_ptr<XmlCharData> intInDataChar = intInDataElement->getFirstNonBlankCharData();
00104 shared_ptr<XmlCharData> intOutDataChar = intOutDataElement->getFirstNonBlankCharData();
00105
00106 std::string intName;
00107 if (intNameChar == false) {
00108 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : empty name for Service Interface");
00109 }
00110 intName = (std::string) ( (*intNameChar));
00111
00112 std::string intComment;
00113 if (intCommentChar) {
00114 intComment = (std::string) ( (*intCommentChar));
00115 }
00116
00117 std::string intInData;
00118 if (intInDataChar) {
00119 intInData = (std::string) ( (*intInDataChar));
00120 }
00121
00122 std::string intOutData;
00123 if (intOutDataChar) {
00124 intOutData = (std::string) ( (*intOutDataChar));
00125 }
00126
00127
00128
00129 shared_ptr<ServiceInterfaceDescription> sid (new ServiceInterfaceDescription (intName, intComment, intInData, intOutData));
00130 std->addServiceInterfaceDescription (sid);
00131 };
00132
00133 XmlElementVector stdeDatafeedElements = stdeChildren.getElementsWithName ("data-feed");
00134 XmlElementVector::iterator stdedfeIterator;
00135
00136 for (stdedfeIterator = stdeDatafeedElements.begin(); stdedfeIterator != stdeDatafeedElements.end(); stdedfeIterator++) {
00137 shared_ptr<XmlElement> datafeedElement = *stdedfeIterator;
00138 XmlElementVector dfeChildren = datafeedElement->getChildrenElements();
00139
00140 shared_ptr<XmlElement> dfNameElement = dfeChildren.getFirstElementWithName ("name");
00141 shared_ptr<XmlElement> dfCommentElement = dfeChildren.getFirstElementWithName ("comment");
00142 shared_ptr<XmlElement> dfOutDataElement = dfeChildren.getFirstElementWithName ("out-data");
00143
00144 if (!dfOutDataElement)
00145 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : data-feed out-data missing.");
00146 shared_ptr<XmlCharData> dfNameChar = dfNameElement->getFirstNonBlankCharData();
00147 shared_ptr<XmlCharData> dfCommentChar = dfCommentElement->getFirstNonBlankCharData();
00148 shared_ptr<XmlCharData> dfOutDataChar = dfOutDataElement->getFirstNonBlankCharData();
00149
00150 std::string dfName = (std::string) ( (*dfNameChar));
00151 if (dfNameChar == false) {
00152 throw Exception ("ServiceTypeDescriptionFactory::populateServiceTypeDescriptionRepository : empty name for Datafeed");
00153 }
00154 dfName = (std::string) ( (*dfNameChar));
00155
00156 std::string dfComment;
00157 if (dfCommentChar) {
00158 dfComment = (std::string) ( (*dfCommentChar));
00159 }
00160
00161 std::string dfOutData;
00162 if (dfOutDataChar) {
00163 dfOutData = (std::string) ( (*dfOutDataChar));
00164 }
00165
00166
00167
00168 shared_ptr<DataFeedDescription> dfd (new DataFeedDescription (dfName, dfComment, dfOutData));
00169 std->addDataFeedDescription (dfd);
00170 };
00171 };
00172 };