00001
00002 #include <fesa-core/Utilities/ParserElements/ClassElement.h>
00003 #include <fesa-core/Utilities/ParserElements/ParserElementFactory.h>
00004 #include <fesa-core/Utilities/ParserElements/EventConfigurationElement.h>
00005 #include <fesa-core/Utilities/ParserElements/LogicalEventElement.h>
00006 #include <fesa-core/Utilities/ParserElements/DeviceElement2.h>
00007 #include <fesa-core/Utilities/ParserElements/EventElement.h>
00008 #include <fesa-core/Utilities/ParserElements/ParserElementDefs.h>
00009 #include <fesa-core/Exception/FesaExceptionDef.h>
00010 #include <fesa-core/Core/AbstractDeviceClass.h>
00011 #include <fesa-core/Utilities/XMLParser.h>
00012
00013 namespace fesa
00014 {
00015
00016 ClassElement::ClassElement(AbstractDeviceClass* classRef):
00017 classRef_(classRef), isInitialized_(false), eventConfigRefsConnected_(false)
00018 {
00019
00020 }
00021
00022 ClassElement::ClassElement()
00023 {
00024
00025 }
00026
00027 ClassElement::~ClassElement()
00028 {
00029
00030 }
00031
00032 void ClassElement::initialize(const std::string& xpath, ElementXML *classElement, ParserElementFactory& parserElementFactory)
00033 {
00034 if(classElement == NULL)
00035 {
00036
00037
00038 throw FesaException(__FILE__, __LINE__, FesaErrorXMLElementNotFound.c_str(),xpath.c_str());
00039 }
00040 loadEventsMappingElement(xpath,classElement,parserElementFactory);
00041 loadDeviceElements(xpath,classElement,parserElementFactory);
00042
00043 isInitialized_ = true;
00044
00045 connectEventConfigRefs();
00046 fillActiveEventMap();
00047
00048 eventConfigRefsConnected_ = true;
00049 }
00050
00051 void ClassElement::connectEventConfigRefs()
00052 {
00053 std::vector<boost::shared_ptr<DeviceElement2> >::iterator iter;
00054 for(iter=deviceElementCol_.begin();iter!=deviceElementCol_.end();++iter)
00055 {
00056 (*iter)->connectEventConfigRefs();
00057 }
00058 }
00059
00060 void ClassElement::loadEventsMappingElement(const std::string& xpath,ElementXML* classElement,ParserElementFactory& parserElementFactory)
00061 {
00062 std::vector<ElementXML*>::iterator iter;
00063 for (iter=classElement->childList_.begin();iter!=classElement->childList_.end();++iter)
00064 {
00065 if((*iter)->name_ == EVENTS_MAPPING_ELEMENT_TAG)
00066 {
00067 std::string xpathLogicalEvent = xpath + "/" + EVENTS_MAPPING_ELEMENT_TAG;
00068 loadLogicalEventElements(xpathLogicalEvent,*iter,parserElementFactory);
00069 }
00070 }
00071 }
00072
00073 void ClassElement::loadLogicalEventElements(const std::string& xpath,ElementXML* eventsMappingElement, ParserElementFactory& parserElementFactory)
00074 {
00075 std::vector<ElementXML*>::iterator iter;
00076 for (iter=eventsMappingElement->childList_.begin();iter!=eventsMappingElement->childList_.end();++iter)
00077 {
00078 std::string xpathName = xpath + "/" + (*iter)->name_;
00079 boost::shared_ptr<LogicalEventElement> temp = parserElementFactory.createLogicalEventElement(shared_from_this());
00080 temp->initialize(xpathName,*iter,parserElementFactory);
00081 logicalEventElementCol_.push_back(temp);
00082 }
00083 }
00084
00085 void ClassElement::loadDeviceElements(const std::string& xpath,ElementXML* classElement, ParserElementFactory& parserElementFactory)
00086 {
00087 std::vector<ElementXML*>::iterator iter;
00088 for (iter=classElement->childList_.begin();iter!=classElement->childList_.end();++iter)
00089 {
00090 if((*iter)->name_ == DEVICE_ELEMENT_TAG)
00091 {
00092 std::string xpathDeviceElement = xpath + "/" + DEVICE_ELEMENT_TAG;
00093 boost::shared_ptr<DeviceElement2> temp = parserElementFactory.createDeviceElement2(shared_from_this(),false);
00094 temp->initialize(xpathDeviceElement,*iter,classRef_->getDeviceFactory(),parserElementFactory);
00095 deviceElementCol_.push_back(temp);
00096 }
00097 if((*iter)->name_ == GLOBAL_DEVICE_ELEMENT_TAG)
00098 {
00099 std::string xpathGlobalElement = xpath + "/" + GLOBAL_DEVICE_ELEMENT_TAG;
00100 boost::shared_ptr<DeviceElement2> temp = parserElementFactory.createDeviceElement2(shared_from_this(),true);
00101 temp->initialize(xpathGlobalElement,*iter,classRef_->getDeviceFactory(),parserElementFactory);
00102 deviceElementCol_.push_back(temp);
00103 }
00104 }
00105 }
00106
00107 boost::shared_ptr<EventConfigurationElement> ClassElement::getEventConfigurationElementRef(const std::string& logicalEventName,const std::string& eventConfigurationName) const
00108 {
00109 if(!isInitialized_)
00110 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00111
00112 std::vector<boost::shared_ptr<LogicalEventElement> >::const_iterator iter;
00113 for(iter=logicalEventElementCol_.begin();iter!=logicalEventElementCol_.end();++iter)
00114 {
00115 if((*iter)->getName() == logicalEventName)
00116 {
00117 return (*iter)->getEventConfigurationElementRef(eventConfigurationName);
00118 }
00119 }
00120
00121
00122 throw FesaException(__FILE__, __LINE__, FesaErrorTimingMappingNotConform.c_str(),logicalEventName.c_str());
00123 }
00124
00125 const std::vector<boost::shared_ptr<LogicalEventElement> >& ClassElement::getLogicalElementCol() const
00126 {
00127 if(!eventConfigRefsConnected_)
00128 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00129
00130 return logicalEventElementCol_;
00131 }
00132
00133 AbstractDeviceClass* ClassElement::getClassRef() const
00134 {
00135 return classRef_;
00136 }
00137
00138 const std::string& ClassElement::getClassName() const
00139 {
00140 return classRef_->getName();
00141 }
00142
00143 void ClassElement::fillActiveEventMap()
00144 {
00145 std::vector<boost::shared_ptr<LogicalEventElement> >::iterator logicalEventIter;
00146 for(logicalEventIter=logicalEventElementCol_.begin();logicalEventIter!=logicalEventElementCol_.end();logicalEventIter++)
00147 {
00148 activeEventMap_.insert(make_pair((*logicalEventIter)->getName(),(*logicalEventIter)->getActiveEventElements()));
00149 }
00150 }
00151
00152 const EventMap& ClassElement::getActiveEventMap() const
00153 {
00154 if(!eventConfigRefsConnected_)
00155 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00156
00157 return activeEventMap_;
00158 }
00159
00160 std::vector< EventElementPointer > ClassElement::getActiveEvents(const std::string& logicalEventName) const
00161 {
00162 if(!eventConfigRefsConnected_)
00163 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00164
00165 std::vector<boost::shared_ptr<LogicalEventElement> >::const_iterator logicalEventIter;
00166 for(logicalEventIter=logicalEventElementCol_.begin();logicalEventIter!=logicalEventElementCol_.end();logicalEventIter++)
00167 {
00168 if((*logicalEventIter)->getName() == logicalEventName )
00169 return (*logicalEventIter)->getActiveEventElements();
00170 }
00171
00172
00173 throw FesaException(__FILE__, __LINE__, FesaErrorLogicalEventNotFound.c_str(),logicalEventName.c_str());
00174 }
00175
00176 }
00177
00178