UnitFlowConfiguration.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 #include "UnitFlowConfiguration.hpp"
00031
00032 #include <Exception.hpp>
00033
00034 #include <XmlCharData.hpp>
00035 #include <XmlElement.hpp>
00036 #include <XmlElementVector.hpp>
00037
00038 #include <vector>
00039 #include <string>
00040 #include <iostream>
00041
00042 using namespace mermaid::support::unitgenerator;
00043 using namespace std;
00044
00045 using mermaid::support::errorhandling::Exception;
00046 using mermaid::support::xml::XmlCharData;
00047 using mermaid::support::xml::XmlElement;
00048 using mermaid::support::xml::XmlElementVector;
00049
00050 void UnitFlowConfiguration::loadConfiguration (shared_ptr<XmlDocument> config)
00051 {
00052 shared_ptr<XmlElement> rootElement = config->getRootElement();
00053
00054 if (rootElement->getName().compare ("unit-configuration") != 0) {
00055 throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"unit-configuration\" tag");
00056 }
00057
00058
00059
00060
00061 shared_ptr<XmlElement> unitNameElement = rootElement->getChildrenElements().getFirstElementWithName ("name");
00062 unitName_ = static_cast<string> (* (unitNameElement->getFirstNonBlankCharData()));
00063
00064 shared_ptr<XmlElement> flowElement = rootElement->getChildrenElements().getFirstElementWithName ("flow-configuration");
00065 if (flowElement->getName().compare ("flow-configuration") != 0) {
00066 throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"flow-configuration\" tag.");
00067 }
00068
00069 XmlElementVector childrenElements = flowElement->getChildrenElements();
00070 XmlElementVector::iterator it;
00071
00072
00073 vector<vector<string> > finalFlowDescription;
00074
00075 for (it = childrenElements.begin(); it != childrenElements.end(); ++it) {
00076 shared_ptr<XmlElement> e = *it;
00077
00078
00079
00080 vector<string> vectorToAdd;
00081 if (e->getName().compare ("service") == 0) {
00082 XmlElementVector serviceChildren = e->getChildrenElements();
00083 string instanceName = static_cast<string> (* (serviceChildren.getFirstElementWithName ("instance-name")->getFirstNonBlankCharData()));
00084 vectorToAdd.push_back (instanceName);
00085
00086 }
00087 else if (e->getName().compare ("concurrent") == 0) {
00088 XmlElementVector concurrentChildrenElements = e->getChildrenElements();
00089 for (XmlElementVector::iterator i = concurrentChildrenElements.begin(); i != concurrentChildrenElements.end(); ++i) {
00090 shared_ptr<XmlElement> srvEl = *i;
00091 if (srvEl->getName().compare ("service") != 0)
00092 throw Exception ("UnitFlowConfiguration::loadConfiguration : invalid configuration. Expected \"service\" tag");
00093 XmlElementVector serviceChildren = srvEl->getChildrenElements();
00094 string instanceName = static_cast<string> (* (serviceChildren.getFirstElementWithName ("instance-name")->getFirstNonBlankCharData()));
00095 vectorToAdd.push_back (instanceName);
00096 }
00097 }
00098
00099 finalFlowDescription.push_back (vectorToAdd);
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 }
00115
00116 }
00117