44 BESXMLCommand(base_dhi), _default_constraint(
""), _default_dap4_constraint(
""), _default_dap4_function(
"")
71 map<string, string> props;
76 string err =
"The specified command " + action +
" is not a set context command";
82 def_name = props[
"name"];
83 if (def_name.empty()) {
84 string err = action +
" command: definition name missing";
89 _str_cmd = (string)
"define " + def_name;
91 def_space = props[
"space"];
92 if (!def_space.empty()) {
97 int num_containers = 0;
103 if (child_name ==
"constraint") {
105 _default_constraint = child_value;
107 else if (child_name ==
"dap4constraint") {
109 _default_dap4_constraint = child_value;
111 else if (child_name ==
"dap4function") {
113 _default_dap4_function = child_value;
115 else if (child_name ==
"container") {
116 handle_container_element(action, child_node, child_value, props);
119 else if (child_name ==
"aggregate") {
120 handle_aggregate_element(action, child_node, child_value, props);
130 if (num_containers < 1) {
131 string err = action +
"The define element must contain at least " +
"one container element";
137 vector<string>::iterator i = _containers.begin();
138 vector<string>::iterator e = _containers.end();
139 for (; i != e; i++) {
145 if (_constraints.size() || _dap4constraints.size() || _dap4functions.size() || _attributes.size()) {
148 i = _containers.begin();
149 e = _containers.end();
150 for (; i != e; i++) {
151 if (_constraints.count((*i))) {
154 _str_cmd += (*i) +
".constraint=\"" + _constraints[(*i)] +
"\"";
156 if (_dap4constraints.count((*i))) {
159 _str_cmd += (*i) +
".dap4constraint=\"" + _dap4constraints[(*i)] +
"\"";
161 if (_dap4functions.count((*i))) {
164 _str_cmd += (*i) +
".dap4function=\"" + _dap4functions[(*i)] +
"\"";
166 if (_attributes.count((*i))) {
169 _str_cmd += (*i) +
".attributes=\"" + _attributes[(*i)] +
"\"";
195 void BESXMLDefineCommand::handle_container_element(
const string &action, xmlNode *
node,
const string &,
196 map<string, string> &props)
198 string name = props[
"name"];
200 string err = action +
" command: container element missing name prop";
204 _containers.push_back(name);
206 string space = props[
"space"];
207 _stores[name] = space;
209 bool have_constraint =
false;
210 bool have_dap4constraint =
false;
211 bool have_dap4function =
false;
212 bool have_attributes =
false;
217 map<string, string> child_props;
220 if (child_name ==
"constraint") {
221 if (child_props.size()) {
222 string err = action +
" command: constraint element " +
"should not contain properties";
225 if (child_value.empty()) {
226 string err = action +
" command: constraint element " +
"missing value";
229 if (have_constraint) {
230 string err = action +
" command: container element " +
"contains multiple constraint elements";
233 have_constraint =
true;
234 _constraints[name] = child_value;
236 else if (child_name ==
"dap4constraint") {
237 if (child_props.size()) {
238 string err = action +
" command: constraint element " +
"should not contain properties";
241 if (child_value.empty()) {
242 string err = action +
" command: constraint element " +
"missing value";
245 if (have_dap4constraint) {
246 string err = action +
" command: container element " +
"contains multiple constraint elements";
249 have_dap4constraint =
true;
250 _dap4constraints[name] = child_value;
252 else if (child_name ==
"dap4function") {
253 if (child_props.size()) {
254 string err = action +
" command: dap4_function element " +
"should not contain properties";
257 if (child_value.empty()) {
258 string err = action +
" command: dap4_function element " +
"missing value";
261 if (have_dap4function) {
262 string err = action +
" command: container element " +
"contains multiple dap4_function elements";
265 have_dap4function =
true;
266 _dap4functions[name] = child_value;
268 else if (child_name ==
"attributes") {
269 if (child_props.size()) {
270 string err = action +
" command: attributes element " +
"should not contain properties";
273 if (child_value.empty()) {
274 string err = action +
" command: attributes element " +
"missing value";
277 if (have_attributes) {
278 string err = action +
" command: container element " +
"contains multiple attributes elements";
281 have_attributes =
true;
282 _attributes[name] = child_value;
304 void BESXMLDefineCommand::handle_aggregate_element(
const string &action, xmlNode *,
const string &,
305 map<string, string> &props)
307 string handler = props[
"handler"];
308 string cmd = props[
"cmd"];
309 if (handler.empty()) {
310 string err = action +
" command: must specify aggregation handler";
314 string err = action +
" command: must specify aggregation cmd";
320 _str_cmd +=
" aggregate using " + handler +
" by " + cmd;
327 vector<string>::iterator i = _containers.begin();
328 vector<string>::iterator e = _containers.end();
329 for (; i != e; i++) {
334 string store = _stores[(*i)];
335 if (!store.empty()) {
343 string s = (string)
"Could not find the container " + (*i);
348 string constraint = _constraints[(*i)];
349 if (constraint.empty()) constraint = _default_constraint;
353 string dap4constraint = _dap4constraints[(*i)];
354 if (dap4constraint.empty()) dap4constraint = _default_dap4_constraint;
358 string function = _dap4functions[(*i)];
359 if (
function.empty())
function = _default_dap4_function;
362 string attrs = _attributes[(*i)];
365 BESDEBUG(
"xml",
"define using container: " << endl << *c << endl );
377 strm <<
BESIndent::LMarg <<
"BESXMLDefineCommand::dump - (" << (
void *)
this <<
")" << endl;
provides persistent storage for data storage information represented by a container.
static xmlNode * GetFirstChild(xmlNode *node, string &child_name, string &child_value, map< string, string > &child_props)
get the first element child node for the given node
BESXMLDefineCommand(const BESDataHandlerInterface &base_dhi)
list< BESContainer * > containers
virtual BESContainerStorage * find_persistence(const string &persist_name)
find the persistence store with the given name
static xmlNode * GetNextChild(xmlNode *child_node, string &next_name, string &next_value, map< string, string > &next_props)
get the next element child node after the given child node
static void GetNodeInfo(xmlNode *node, string &name, string &value, map< string, string > &props)
get the name, value if any, and any properties for the specified node
BESDataHandlerInterface _dhi
virtual BESContainer * look_for(const string &sym_name)=0
looks for a container in this persistent store
error thrown if there is a user syntax error in the request or any other user error ...
virtual void parse_request(xmlNode *node)
parse a show command.
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
virtual void prep_request()
prepare the define command by making sure the containers exist
static ostream & LMarg(ostream &strm)
void set_constraint(const string &s)
set the constraint for this container
void set_dap4_constraint(const string &s)
set the constraint for this container
static BESXMLCommand * CommandBuilder(const BESDataHandlerInterface &base_dhi)
void set_attributes(const string &attrs)
set desired attributes for this container
virtual void dump(ostream &strm) const
dumps information about this object
void set_dap4_function(const string &s)
set the constraint for this container
Structure storing information used by the BES to handle the request.
virtual BESContainer * look_for(const string &sym_name)
look for the specified container information in the list of persistent stores.
static BESContainerStorageList * TheList()
map< string, string > data
the map of string data that will be required for the current request.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
A container is something that holds data.
string action
the response object requested, e.g.
#define DEFINE_RESPONSE_STR
virtual void dump(ostream &strm) const
dumps information about this object