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" 47 BESXMLCommand(base_dhi), _default_constraint(
""), _default_dap4_constraint(
""), _default_dap4_function(
"")
83 map<string, string> props;
86 if (action != DEFINE_RESPONSE_STR) {
87 string err =
"The specified command " + action +
" is not a set context command";
91 d_xmlcmd_dhi.
action = DEFINE_RESPONSE;
93 string def_name = props[
"name"];
95 throw BESSyntaxUserError(
string(action) +
" command: definition name missing", __FILE__, __LINE__);
97 d_xmlcmd_dhi.
data[DEF_NAME] = def_name;
100 d_xmlcmd_dhi.
data[STORE_NAME] = props[
"space"].empty() ? DEFAULT: props[
"space"];
103 int num_containers = 0;
109 if (child_name ==
"constraint") {
111 _default_constraint = child_value;
113 else if (child_name ==
"dap4constraint") {
115 _default_dap4_constraint = child_value;
117 else if (child_name ==
"dap4function") {
119 _default_dap4_function = child_value;
121 else if (child_name ==
"container") {
122 handle_container_element(action, child_node, child_value, props);
126 throw BESSyntaxUserError(
string(action) +
" Unrecognized child element: " + child_name, __FILE__, __LINE__);
129 else if (child_name ==
"aggregate") {
130 handle_aggregate_element(action, child_node, child_value, props);
141 if (num_containers < 1)
142 throw BESSyntaxUserError(
string(action) +
" The define element must contain at least one container element", __FILE__, __LINE__);
146 vector<string>::iterator i = container_names.begin();
147 vector<string>::iterator e = container_names.end();
148 for (; i != e; i++) {
154 if (container_constraints.size() || container_dap4constraints.size() || container_dap4functions.size() || container_attributes.size()) {
157 i = container_names.begin();
158 e = container_names.end();
159 for (; i != e; i++) {
160 if (container_constraints.count((*i))) {
163 d_cmd_log_info += (*i) +
".constraint=\"" + container_constraints[(*i)] +
"\"";
165 if (container_dap4constraints.count((*i))) {
168 d_cmd_log_info += (*i) +
".dap4constraint=\"" + container_dap4constraints[(*i)] +
"\"";
170 if (container_dap4functions.count((*i))) {
173 d_cmd_log_info += (*i) +
".dap4function=\"" + container_dap4functions[(*i)] +
"\"";
175 if (container_attributes.count((*i))) {
178 d_cmd_log_info += (*i) +
".attributes=\"" + container_attributes[(*i)] +
"\"";
212 void BESXMLDefineCommand::handle_container_element(
const string &action, xmlNode *node,
const string &,
213 map<string, string> &props)
215 string name = props[
"name"];
217 string err = action +
" command: container element missing name prop";
221 container_names.push_back(name);
223 container_store_names[name] = props[
"space"];
225 bool have_constraint =
false;
226 bool have_dap4constraint =
false;
227 bool have_dap4function =
false;
228 bool have_attributes =
false;
233 map<string, string> child_props;
236 if (child_name ==
"constraint") {
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_constraint) {
246 string err = action +
" command: container element " +
"contains multiple constraint elements";
249 have_constraint =
true;
250 container_constraints[name] = child_value;
252 else if (child_name ==
"dap4constraint") {
253 if (child_props.size()) {
254 string err = action +
" command: constraint element " +
"should not contain properties";
257 if (child_value.empty()) {
258 string err = action +
" command: constraint element " +
"missing value";
261 if (have_dap4constraint) {
262 string err = action +
" command: container element " +
"contains multiple constraint elements";
265 have_dap4constraint =
true;
266 container_dap4constraints[name] = child_value;
268 else if (child_name ==
"dap4function") {
269 if (child_props.size()) {
270 string err = action +
" command: dap4_function element " +
"should not contain properties";
273 if (child_value.empty()) {
274 string err = action +
" command: dap4_function element " +
"missing value";
277 if (have_dap4function) {
278 string err = action +
" command: container element " +
"contains multiple dap4_function elements";
281 have_dap4function =
true;
282 container_dap4functions[name] = child_value;
284 else if (child_name ==
"attributes") {
285 if (child_props.size()) {
286 string err = action +
" command: attributes element " +
"should not contain properties";
289 if (child_value.empty()) {
290 string err = action +
" command: attributes element " +
"missing value";
293 if (have_attributes) {
294 string err = action +
" command: container element " +
"contains multiple attributes elements";
297 have_attributes =
true;
298 container_attributes[name] = child_value;
323 void BESXMLDefineCommand::handle_aggregate_element(
const string &action, xmlNode *,
const string &,
324 map<string, string> &props)
326 string handler = props[
"handler"];
327 string cmd = props[
"cmd"];
328 if (handler.empty()) {
329 string err = action +
" command: must specify aggregation handler";
333 string err = action +
" command: must specify aggregation cmd";
337 d_xmlcmd_dhi.
data[AGG_HANDLER] = handler;
338 d_xmlcmd_dhi.
data[AGG_CMD] = cmd;
354 vector<string>::iterator i = container_names.begin();
355 vector<string>::iterator e = container_names.end();
356 for (; i != e; i++) {
362 string store = container_store_names[(*i)];
363 if (!store.empty()) {
368 c = BESContainerStorageList::TheList()->
look_for((*i));
372 throw BESSyntaxUserError(
string(
"Could not find the container ") + (*i), __FILE__, __LINE__);
375 string constraint = container_constraints[(*i)];
376 if (constraint.empty()) constraint = _default_constraint;
380 string dap4constraint = container_dap4constraints[(*i)];
381 if (dap4constraint.empty()) dap4constraint = _default_dap4_constraint;
385 string function = container_dap4functions[(*i)];
386 if (
function.empty())
function = _default_dap4_function;
389 string attrs = container_attributes[(*i)];
391 d_xmlcmd_dhi.containers.push_back(c);
393 BESDEBUG(
"xml",
"BESXMLDefineCommand::prep_request() - define using container: " << endl << *c << endl);
406 strm << BESIndent::LMarg <<
"BESXMLDefineCommand::dump - (" << (
void *)
this <<
")" << endl;
409 BESIndent::UnIndent();
provides persistent storage for data storage information represented by a container.
virtual BESContainer * look_for(const std::string &sym_name)
look for the specified container information in the list of persistent stores.
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
exception thrown if an internal error is found and is fatal to the BES
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object
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
error thrown if there is a user syntax error in the request or any other user error
virtual BESContainerStorage * find_persistence(const std::string &persist_name)
find the persistence store with the given name
virtual BESContainer * look_for(const std::string &sym_name)=0
looks for a container in this persistent store
virtual void parse_request(xmlNode *node)
parse a define 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
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
void set_attributes(const string &attrs)
set desired attributes for this container
void set_dap4_function(const string &s)
set the constraint for this container
Structure storing information used by the BES to handle the request.
map< string, string > data
the map of string data that will be required for the current request.
Base class for the BES's commands.
A container is something that holds data. E.G., a netcdf file or a database entry.
string action
the response object requested, e.g. das, dds
std::string d_cmd_log_info
Used only for the log.