Blame view

src/Info/InstrumentParser.cc 5.75 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * InstrumentParser.cc
 *
 *  Created on: Oct 6, 2014
 *      Author: m.mazel
 */

#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "InstrumentParser.hh"
#include "InfoLogger.hh"

using namespace AMDA::XMLConfigurator;

namespace AMDA {
namespace Info {

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument name node
 */
class InstrumentNameNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setName((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief instrument description node
 */
class InstrumentDescriptionNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setDescription((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument url node
 */
class InstrumentUrlNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setUrl((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument measurement node
 */
class InstrumentMeasurementNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setMeasurement((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument PI node
 */
class InstrumentPiNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setPi((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Intrument type node
 */
class InstrumentInstrumentTypeNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setInstrumentType((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument mission id node
 */
class InstrumentMissionIdNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pInstrumentInfo->setMissionId((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Instrument node
 */
class InstrumentInfoNode : public NodeGrpCfg {
public:

	InstrumentInfoNode () : NodeGrpCfg() {
		getChildList()["name"] = NodeCfgSPtr(new InstrumentNameNode);
		getChildList()["description"] = NodeCfgSPtr(new InstrumentDescriptionNode);
		getChildList()["url"] = NodeCfgSPtr(new InstrumentUrlNode);
		getChildList()["measurement_type"] = NodeCfgSPtr(new InstrumentMeasurementNode);
		getChildList()["pi"] = NodeCfgSPtr(new InstrumentPiNode);
		getChildList()["instrument_type"] = NodeCfgSPtr(new InstrumentInstrumentTypeNode);
		getChildList()["mission_id"] = NodeCfgSPtr(new InstrumentMissionIdNode);
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_INFO(gLogger, "InstrumentInfoNode::proceed");

		InstrumentInfo* pInstrumentInfo =  pContext.get<InstrumentInfo*>();

		// read instrument id
		xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "id");
		if (value) {
			pInstrumentInfo->setId ((const char*) value);
			xmlFree(value);
		}

		// Proceed nodes
		NodeGrpCfg::proceed(pNode, pContext);
	}
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Parser of instrument info
 */
InstrumentParser::InstrumentParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,true)
{

	// InstrumentInfo root node
	getXmlConfiguratorMap()["instrument"] = RootNodeCfgSPtr(new InstrumentInfoNode ());
}

boost::shared_ptr<InstrumentInfo> InstrumentParser::parse (const std::string& instrumentFile) {
	LOG4CXX_INFO(gLogger, "InstrumentParser::parse parsing " << instrumentFile);

	AMDA::Parameters::CfgContext ctx;
	boost::shared_ptr<InstrumentInfo> instrumentInfo (new InstrumentInfo ());
	ctx.push<InstrumentInfo *>(instrumentInfo.get());

	// Check schema validity and parse xml file
	try {
ec71f3db   brenard   Return a null poi...
170
171
172
		if (!XMLConfigurator::proceed(instrumentFile.c_str(), ctx, true)) {
			return InstrumentInfoSPtr();
		}
fbe3c2bb   Benjamin Renard   First commit
173
174
175
176
177
178
179
180
181
182
183
	}
	catch (...) {
		LOG4CXX_INFO(gLogger, "InstrumentParser::parse error while parsing file " << instrumentFile);
		// Return a null ptr to InstrumentInfo
		return InstrumentInfoSPtr();
	}
	return instrumentInfo;
}

} /* namespace Info */
} /* namespace AMDA */