DeviceElement2.cpp
Go to the documentation of this file.00001
00002
00003 #include <fesa-core/Utilities/ParserElements/DeviceElement2.h>
00004 #include <fesa-core/Utilities/ParserElements/ClassElement.h>
00005 #include <fesa-core/Utilities/ParserElements/ParserElementFactory.h>
00006 #include <fesa-core/Utilities/ParserElements/DeviceLogicalEventElement.h>
00007 #include <fesa-core/Utilities/ParserElements/ParserElementDefs.h>
00008 #include <fesa-core/Exception/FesaExceptionDef.h>
00009 #include <fesa-core/DataStore/AbstractDeviceFactory.h>
00010 #include <fesa-core/Core/AbstractDeviceClass.h>
00011 #include <fesa-core/DataStore/AbstractDevice.h>
00012 #include <fesa-core/Utilities/XMLParser.h>
00013
00014 namespace fesa
00015 {
00016
00017 DeviceElement2::DeviceElement2(boost::shared_ptr<ClassElement> parent,bool isGlobalDevice):
00018 parentClassElement_(parent), isInitialized_(false), isGlobalDevice_(isGlobalDevice)
00019 {
00020
00021 }
00022
00023 DeviceElement2::DeviceElement2()
00024 {
00025
00026 }
00027
00028 DeviceElement2::~DeviceElement2()
00029 {
00030
00031 }
00032
00033 void DeviceElement2::initialize(const std::string& xpath, ElementXML *deviceElement,AbstractDeviceFactory* factory, ParserElementFactory& parserElementFactory)
00034 {
00035 std::string deviceName = loadAttribute(xpath,deviceElement,DEVICE_ELEMENT_ATTRIBUTE_TAG);
00036
00037 if(isGlobalDevice_)
00038 {
00039 deviceRef_ = (AbstractDevice*)factory->getGlobalDevice();
00040 }
00041 else
00042 {
00043 deviceRef_ = factory->getDevice(deviceName);
00044 }
00045
00046 loadEventsMappingElement(xpath,deviceElement,parserElementFactory);
00047 isInitialized_ = true;
00048 }
00049
00050 void DeviceElement2::loadEventsMappingElement(const std::string& xpath,ElementXML* deviceElement, ParserElementFactory& parserElementFactory)
00051 {
00052 std::vector<ElementXML*>::iterator iter;
00053 for (iter=deviceElement->childList_.begin();iter!=deviceElement->childList_.end();++iter)
00054 {
00055 if((*iter)->name_ == EVENTS_MAPPING_ELEMENT_TAG)
00056 {
00057 std::string xpathEventsMappingElement = xpath + "/" + EVENTS_MAPPING_ELEMENT_TAG;
00058 loadLogicalEventElements(xpathEventsMappingElement,*iter,parserElementFactory);
00059 }
00060 }
00061 }
00062
00063 void DeviceElement2::loadLogicalEventElements(const std::string& xpath,ElementXML* eventsMappingElement, ParserElementFactory& parserElementFactory)
00064 {
00065 std::vector<ElementXML*>::iterator iter;
00066 for (iter=eventsMappingElement->childList_.begin();iter!=eventsMappingElement->childList_.end();++iter)
00067 {
00068 std::string xpathLogicalEventElement = xpath + "/" + (*iter)->name_;
00069 boost::shared_ptr<DeviceLogicalEventElement> temp = parserElementFactory.createDeviceLogicalEventElement();
00070 temp->initialize(xpathLogicalEventElement,*iter);
00071 logicalEventElementCol_.push_back(temp);
00072 }
00073 }
00074
00075 void DeviceElement2::connectEventConfigRefs()
00076 {
00077 if(!isInitialized_)
00078 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00079
00080 std::vector<boost::shared_ptr<DeviceLogicalEventElement> >::iterator iter;
00081 for (iter=logicalEventElementCol_.begin();iter!=logicalEventElementCol_.end();++iter)
00082 {
00083 (*iter)->connectEventConfigRef(deviceRef_,parentClassElement_);
00084 }
00085 }
00086
00087 std::string DeviceElement2::loadAttribute(const std::string& xpath, ElementXML* element,const std::string& attributeName)
00088 {
00089 std::vector<AttributeXML*>::iterator attributeIter;
00090 for(attributeIter = element->attributeList_.begin();attributeIter != element->attributeList_.end();attributeIter++)
00091 {
00092 if((*attributeIter)->name_ == attributeName)
00093 {
00094 return (*attributeIter)->value_;
00095 }
00096 }
00097
00098
00099 throw FesaException(__FILE__, __LINE__, FesaErrorXMLAttributeNotFound.c_str(),xpath.c_str(),attributeName.c_str());
00100 }
00101
00102 AbstractDevice* DeviceElement2::getDeviceRef() const
00103 {
00104 if(!isInitialized_)
00105 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00106
00107 return deviceRef_;
00108 }
00109
00110 }
00111
00112
00113