33 #include "BESXMLDefineCommand.h"
34 #include "BESContainerStorageList.h"
35 #include "BESContainerStorage.h"
37 #include "BESXMLUtils.h"
39 #include "BESResponseNames.h"
40 #include "BESDataNames.h"
42 #include "BESSyntaxUserError.h"
43 #include "BESInternalFatalError.h"
53 BESXMLCommand(base_dhi), _default_constraint(
""), _default_dap4_constraint(
""), _default_dap4_function(
"")
89 map<string, string> props;
92 if (action != DEFINE_RESPONSE_STR) {
93 string err =
"The specified command " + action +
" is not a set context command";
97 d_xmlcmd_dhi.
action = DEFINE_RESPONSE;
99 string def_name = props[
"name"];
100 if (def_name.empty())
101 throw BESSyntaxUserError(
string(action) +
" command: definition name missing", __FILE__, __LINE__);
103 d_xmlcmd_dhi.
data[DEF_NAME] = def_name;
106 d_xmlcmd_dhi.
data[STORE_NAME] = props[
"space"].empty() ? DEFAULT: props[
"space"];
109 int num_containers = 0;
115 if (child_name ==
"constraint") {
117 _default_constraint = child_value;
119 else if (child_name ==
"dap4constraint") {
121 _default_dap4_constraint = child_value;
123 else if (child_name ==
"dap4function") {
125 _default_dap4_function = child_value;
127 else if (child_name ==
"container") {
128 handle_container_element(action, child_node, child_value, props);
132 throw BESSyntaxUserError(
string(action) +
" Unrecognized child element: " + child_name, __FILE__, __LINE__);
135 else if (child_name ==
"aggregate") {
136 handle_aggregate_element(action, child_node, child_value, props);
147 if (num_containers < 1)
148 throw BESSyntaxUserError(
string(action) +
" The define element must contain at least one container element", __FILE__, __LINE__);
152 vector<string>::iterator i = container_names.begin();
153 vector<string>::iterator e = container_names.end();
154 for (; i != e; i++) {
160 if (container_constraints.size() || container_dap4constraints.size() || container_dap4functions.size() || container_attributes.size()) {
163 i = container_names.begin();
164 e = container_names.end();
165 for (; i != e; i++) {
166 if (container_constraints.count((*i))) {
169 d_cmd_log_info += (*i) +
".constraint=\"" + container_constraints[(*i)] +
"\"";
171 if (container_dap4constraints.count((*i))) {
174 d_cmd_log_info += (*i) +
".dap4constraint=\"" + container_dap4constraints[(*i)] +
"\"";
176 if (container_dap4functions.count((*i))) {
179 d_cmd_log_info += (*i) +
".dap4function=\"" + container_dap4functions[(*i)] +
"\"";
181 if (container_attributes.count((*i))) {
184 d_cmd_log_info += (*i) +
".attributes=\"" + container_attributes[(*i)] +
"\"";
218 void BESXMLDefineCommand::handle_container_element(
const string &action, xmlNode *node,
const string &,
219 map<string, string> &props)
221 string name = props[
"name"];
223 string err = action +
" command: container element missing name prop";
227 container_names.push_back(name);
229 container_store_names[name] = props[
"space"];
231 bool have_constraint =
false;
232 bool have_dap4constraint =
false;
233 bool have_dap4function =
false;
234 bool have_attributes =
false;
239 map<string, string> child_props;
242 if (child_name ==
"constraint") {
243 if (child_props.size()) {
244 string err = action +
" command: constraint element " +
"should not contain properties";
247 if (child_value.empty()) {
248 string err = action +
" command: constraint element " +
"missing value";
251 if (have_constraint) {
252 string err = action +
" command: container element " +
"contains multiple constraint elements";
255 have_constraint =
true;
256 container_constraints[name] = child_value;
258 else if (child_name ==
"dap4constraint") {
259 if (child_props.size()) {
260 string err = action +
" command: constraint element " +
"should not contain properties";
263 if (child_value.empty()) {
264 string err = action +
" command: constraint element " +
"missing value";
267 if (have_dap4constraint) {
268 string err = action +
" command: container element " +
"contains multiple constraint elements";
271 have_dap4constraint =
true;
272 container_dap4constraints[name] = child_value;
274 else if (child_name ==
"dap4function") {
275 if (child_props.size()) {
276 string err = action +
" command: dap4_function element " +
"should not contain properties";
279 if (child_value.empty()) {
280 string err = action +
" command: dap4_function element " +
"missing value";
283 if (have_dap4function) {
284 string err = action +
" command: container element " +
"contains multiple dap4_function elements";
287 have_dap4function =
true;
288 container_dap4functions[name] = child_value;
290 else if (child_name ==
"attributes") {
291 if (child_props.size()) {
292 string err = action +
" command: attributes element " +
"should not contain properties";
295 if (child_value.empty()) {
296 string err = action +
" command: attributes element " +
"missing value";
299 if (have_attributes) {
300 string err = action +
" command: container element " +
"contains multiple attributes elements";
303 have_attributes =
true;
304 container_attributes[name] = child_value;
329 void BESXMLDefineCommand::handle_aggregate_element(
const string &action, xmlNode *,
const string &,
330 map<string, string> &props)
332 string handler = props[
"handler"];
333 string cmd = props[
"cmd"];
334 if (handler.empty()) {
335 string err = action +
" command: must specify aggregation handler";
339 string err = action +
" command: must specify aggregation cmd";
343 d_xmlcmd_dhi.
data[AGG_HANDLER] = handler;
344 d_xmlcmd_dhi.
data[AGG_CMD] = cmd;
360 vector<string>::iterator i = container_names.begin();
361 vector<string>::iterator e = container_names.end();
362 for (; i != e; i++) {
368 string store = container_store_names[(*i)];
369 if (!store.empty()) {
374 c = BESContainerStorageList::TheList()->
look_for((*i));
378 throw BESSyntaxUserError(
string(
"Could not find the container ") + (*i), __FILE__, __LINE__);
381 string constraint = container_constraints[(*i)];
382 if (constraint.empty()) constraint = _default_constraint;
386 string dap4constraint = container_dap4constraints[(*i)];
387 if (dap4constraint.empty()) dap4constraint = _default_dap4_constraint;
391 string function = container_dap4functions[(*i)];
392 if (
function.empty())
function = _default_dap4_function;
395 string attrs = container_attributes[(*i)];
397 d_xmlcmd_dhi.containers.push_back(c);
399 BESDEBUG(
"xml",
"BESXMLDefineCommand::prep_request() - define using container: " << endl << *c << endl);
412 strm << BESIndent::LMarg <<
"BESXMLDefineCommand::dump - (" << (
void *)
this <<
")" << endl;
415 BESIndent::UnIndent();