DeviceLogicalEventElement.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Utilities/ParserElements/DeviceLogicalEventElement.h>
00004 #include <fesa-core/Utilities/ParserElements/ClassElement.h>
00005 #include <fesa-core/Utilities/ParserElements/EventConfigurationElement.h>
00006 #include <fesa-core/Utilities/ParserElements/ParserElementDefs.h>
00007 #include <fesa-core/Exception/FesaExceptionDef.h>
00008 #include <fesa-core/DataStore/AbstractDevice.h>
00009 #include <fesa-core/Utilities/XMLParser.h>
00010 
00011 namespace fesa
00012 {
00013 
00014 DeviceLogicalEventElement::DeviceLogicalEventElement(): isInitialized_(false)
00015 {
00016 
00017 }
00018 
00019 DeviceLogicalEventElement::~DeviceLogicalEventElement()
00020 {
00021 
00022 }
00023 
00024 void DeviceLogicalEventElement::initialize(const std::string& xpath, ElementXML *deviceLogicalEventElement)
00025 {
00026         logicalEventName_ = deviceLogicalEventElement->name_;
00027         loadEventConfigurationNameRef(xpath,deviceLogicalEventElement);
00028 
00029         isInitialized_ = true;
00030 }
00031 
00032 void DeviceLogicalEventElement::loadEventConfigurationNameRef(const std::string& xpath,ElementXML* deviceLogicalEventElement)
00033 {
00034         //only one possible sub-element, which is mandatory
00035         std::string xpathEventConfigRef = xpath +  "/" + EVENT_CONFIGURATION_REF_TAG;
00036     if(deviceLogicalEventElement->childList_.empty())
00037     {
00038         throw FesaException(__FILE__, __LINE__, FesaErrorXMLElementNotFound.c_str(),xpathEventConfigRef.c_str());
00039     }
00040     ElementXML* eventConfigurationRefElement = deviceLogicalEventElement->childList_[0];
00041 
00042     if(eventConfigurationRefElement->name_ != EVENT_CONFIGURATION_REF_TAG)
00043     {
00044         throw FesaException(__FILE__, __LINE__, FesaErrorXMLElementNotFound.c_str(),xpathEventConfigRef.c_str());
00045     }
00046 
00047         //only one possible attribute, which is mandatory
00048     std::string xpathEventConfigRefName = xpathEventConfigRef + "/@name";
00049     if(eventConfigurationRefElement->attributeList_.empty())
00050     {
00051         throw FesaException(__FILE__, __LINE__, FesaErrorXMLAttributeNotFound.c_str(),xpathEventConfigRefName.c_str());
00052     }
00053 
00054     AttributeXML* firstAttribute = (eventConfigurationRefElement->attributeList_)[0];
00055     if(firstAttribute->name_ != EVENT_CONFIGURATION_REF_ATTRIBUTE_TAG)
00056     {
00057         throw FesaException(__FILE__, __LINE__, FesaErrorXMLAttributeNotFound.c_str(),xpathEventConfigRefName.c_str());
00058     }
00059     eventConfigurationRefName_ = firstAttribute->value_;
00060 }
00061 
00062 void DeviceLogicalEventElement::connectEventConfigRef(AbstractDevice* device,boost::shared_ptr<ClassElement> classElement)
00063 {
00064         if(!isInitialized_)
00065                 throw FesaException(__FILE__, __LINE__, FesaErrorParserElementNotInitialized.c_str());
00066 
00067         eventConfigurationElementRef_ = classElement->getEventConfigurationElementRef(logicalEventName_,eventConfigurationRefName_);
00068         eventConfigurationElementRef_->addDeviceRef(device);
00069 }
00070 
00071 }
00072 
00073 
00074 

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1