/* * ParamParser.cc * * Created on: Oct 6, 2014 * Author: m.mazel */ #include "NodeCfg.hh" #include "AMDA_exception.hh" #include "ParamParser.hh" #include "ParamTableNode.hh" #include "StatusDefNode.hh" #include "InfoLogger.hh" using namespace AMDA::XMLConfigurator; namespace AMDA { namespace Info { /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter name node */ class ParamNameNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setName((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter short name node */ class ParamShortNameNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setShortName((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter components node */ class ParamComponentsNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setComponents((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter units node */ class ParamUnitsNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setUnits((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter coordinates system node */ class ParamCoordinatesSystemNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setCoordinatesSystem((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter tensor order node */ class ParamTensorOrderNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setTensorOrder(atoi((const char*)pNode->children->content)); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter SI Conversion node */ class ParamSiConversionNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setSiConversion((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter fill value node */ class ParamFillValueNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) { double fillVal = atof((const char*)pNode->children->content); pParamInfo->setFillValue(fillVal); pParamInfo->setOriginalFillValue(fillVal); } } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter UCD node */ class ParamUcdNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setUcd((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter dataset id node */ class ParamDatasetIdNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setDatasetId((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Parameter instrument id node */ class ParamInstrumentIdNode : public NodeCfg { public: void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) { ParamInfo* pParamInfo = pContext.get(); if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) pParamInfo->setInstrumentId((const char*)pNode->children->content); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Info node of a parameter */ class ParamInfoNode : public NodeGrpCfg { public: ParamInfoNode () : NodeGrpCfg() { getChildList()["name"] = NodeCfgSPtr(new ParamNameNode); getChildList()["short_name"] = NodeCfgSPtr(new ParamShortNameNode); getChildList()["components"] = NodeCfgSPtr(new ParamComponentsNode); getChildList()["units"] = NodeCfgSPtr(new ParamUnitsNode); getChildList()["coordinates_system"] = NodeCfgSPtr(new ParamCoordinatesSystemNode); getChildList()["tensor_order"] = NodeCfgSPtr(new ParamTensorOrderNode); getChildList()["si_conversion"] = NodeCfgSPtr(new ParamSiConversionNode); getChildList()["table"]=NodeCfgSPtr(new ParamTableNode()); getChildList()["fill_value"] = NodeCfgSPtr(new ParamFillValueNode); getChildList()["ucd"] = NodeCfgSPtr(new ParamUcdNode); getChildList()["status_def"] = NodeCfgSPtr(new StatusDefNode); getChildList()["dataset_id"] = NodeCfgSPtr(new ParamDatasetIdNode); getChildList()["instrument_id"] = NodeCfgSPtr(new ParamInstrumentIdNode); } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_INFO(gLogger, "ParamInfoNode::proceed"); // Proceed nodes NodeGrpCfg::proceed(pNode, pContext); } }; /////////////////////////////////////////////////////////////////////////////// /* * @brief Constructor of the info parser of a parameter */ ParamParser::ParamParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,true) { // read ParamInfo node NodeGrpCfg* lRequestNode = new NodeGrpCfg(); getXmlConfiguratorMap()["param"] = RootNodeCfgSPtr(lRequestNode); lRequestNode->getChildList()["info"] = NodeCfgSPtr(new ParamInfoNode); } /////////////////////////////////////////////////////////////////////////////// /* * @brief Parse info */ boost::shared_ptr ParamParser::parse (const std::string& paramId, const std::string& paramFile) { LOG4CXX_INFO(gLogger, "ParamParser::parse parsing " << paramFile); AMDA::Parameters::CfgContext ctx; boost::shared_ptr paramInfo (new ParamInfo); paramInfo->setId(paramId); ctx.push(paramInfo.get()); // Check schema validity and parse xml file try { XMLConfigurator::proceed(paramFile.c_str(), ctx, true); } catch (...) { LOG4CXX_INFO(gLogger, "ParamParser::parse error while parsing file " << paramFile); // Return a null ptr to ParamInfo return ParamInfoSPtr(); } return paramInfo; } } /* namespace Info */ } /* namespace AMDA */