25 #include "XMLSetContextsCommand.h"
27 #include "BESXMLUtils.h"
29 #include "BESDataNames.h"
30 #include "BESSyntaxUserError.h"
33 #include "SetContextsNames.h"
35 #if !USE_CONTEXTS_RESPONSE_HANDLER
36 #include "BESContextManager.h"
63 string value, name, action;
64 map<string, string> props;
66 if (action != SET_CONTEXTS_STR) {
67 string err =
"The specified command " + action +
" is not a set context command";
71 xmlNode *current_node = node->children;
72 while (current_node) {
73 if (current_node->type == XML_ELEMENT_NODE) {
76 map<string, string> attributes;
79 if (name !=
"context")
81 + name +
"'."), __FILE__, __LINE__);
84 throw BESSyntaxUserError(
string(
"The 'context' element must contain a value"), __FILE__,
87 if (attributes.size() != 1 || attributes[
"name"].empty())
88 throw BESSyntaxUserError(
string(
"The 'context' element must contain a 'name' attribute."),
92 #if USE_CONTEXTS_RESPONSE_HANDLER
99 string context_key = string(CONTEXT_PREFIX).append(attributes[
"name"]);
100 d_xmlcmd_dhi.data[CONTEXT_NAMES] = d_xmlcmd_dhi.data[CONTEXT_NAMES].append(
" ").append(context_key);
101 d_xmlcmd_dhi.data[context_key] = value;
103 BESDEBUG(
"besxml",
"d_xmlcmd_dhi.data[" << context_key <<
"] = " << value << endl);
105 BESDEBUG(
"besxml",
"In " << __func__ <<
" BESContextManager::TheManager()->set_context("
106 << name <<
", " << value <<
")" << endl);
108 BESContextManager::TheManager()->
set_context(attributes[
"name"], value);
112 current_node = current_node->next;
115 d_cmd_log_info = string(
"set contexts for ").append(d_xmlcmd_dhi.data[CONTEXT_NAMES]);
118 #if USE_CONTEXTS_RESPONSE_HANDLER
120 d_xmlcmd_dhi.action = SET_CONTEXTS_ACTION;
125 d_xmlcmd_dhi.action_name = SET_CONTEXTS_STR;
126 d_xmlcmd_dhi.action = NULL_ACTION;
143 strm << BESIndent::LMarg <<
"XMLSetContextsCommand::dump - (" << (
void *)
this <<
")" << endl;
146 BESIndent::UnIndent();
virtual void set_context(const std::string &name, const std::string &value)
set context in the BES
Structure storing information used by the BES to handle the request.
error thrown if there is a user syntax error in the request or any other user error
Base class for the BES's commands.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
static void GetNodeInfo(xmlNode *node, std::string &name, std::string &value, std::map< std::string, std::string > &props)
get the name, value if any, and any properties for the specified node
virtual void parse_request(xmlNode *node)
parse a setContexts command.
virtual void dump(std::ostream &strm) const
dumps information about this object