bes  Updated for version 3.19.1
BESXMLSetContainerCommand.cc
1 // BESXMLSetContainerCommand.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #include "BESXMLSetContainerCommand.h"
34 #include "BESContainerStorageList.h"
35 #include "BESXMLUtils.h"
36 #include "BESUtil.h"
37 #include "BESResponseNames.h"
38 #include "BESDataNames.h"
39 #include "BESSyntaxUserError.h"
40 #include "BESDebug.h"
41 
42 BESXMLSetContainerCommand::BESXMLSetContainerCommand(const BESDataHandlerInterface &base_dhi) :
43  BESXMLCommand(base_dhi)
44 {
45 }
46 
54 {
55  string action; // name of the node, should be setContainer
56  string name; // symbolic name of the container as name=""
57  string storage; // storage of container, default is default, as space=
58  string value; // real name of the container, e.g. path
59 
60  map<string, string> props;
61  BESXMLUtils::GetNodeInfo(node, action, value, props);
62  if (action != SETCONTAINER_STR) {
63  string err = "The specified command " + action + " is not a set container command";
64  throw BESSyntaxUserError(err, __FILE__, __LINE__);
65  }
66 
67  string cname;
68  string cvalue;
69  map<string, string> cprops;
70  xmlNode *real = BESXMLUtils::GetFirstChild(node, cname, cvalue, cprops);
71 
72  if (value.empty() && !real) {
73  string err = action + " command: container real name missing";
74  throw BESSyntaxUserError(err, __FILE__, __LINE__);
75  }
76 
77  // what is the symbolic name of this container
78  name = props["name"];
79  if (name.empty()) {
80  string err = action + " command: name property missing";
81  throw BESSyntaxUserError(err, __FILE__, __LINE__);
82  }
83  d_xmlcmd_dhi.data[SYMBOLIC_NAME] = name;
84 
85  // where should this container be stored
86  d_xmlcmd_dhi.data[STORE_NAME] = PERSISTENCE_VOLATILE;
87  storage = props["space"];
88  if (!storage.empty()) {
89  d_xmlcmd_dhi.data[STORE_NAME] = storage;
90  }
91  else {
92  storage = PERSISTENCE_VOLATILE;
93  }
94 
95  // this can be the empty string, so just set it this way
96  string container_type = props["type"];
97  d_xmlcmd_dhi.data[CONTAINER_TYPE] = container_type;
98 
99  // now that everything has passed tests, set the value in the dhi
100  d_xmlcmd_dhi.data[REAL_NAME] = value;
101 
102  // if there is a child node, then the real value of the container is
103  // this content, or is set in this content.
104  if (real) {
105  xmlBufferPtr buf = xmlBufferCreate();
106  xmlNodeDump(buf, real->doc, real, 2, 1);
107  if (buf->content) {
108  value = (char *) buf->content;
109  d_xmlcmd_dhi.data[REAL_NAME] = (char *) (buf->content);
110  }
111  }
112 
113  d_xmlcmd_dhi.action = SETCONTAINER;
114 
115  d_cmd_log_info = (string) "set container in " + storage + " values " + name + "," + value;
116  if (!container_type.empty()) {
117  d_cmd_log_info += "," + container_type;
118  }
119  d_cmd_log_info += ";";
120 
121  // now that we've set the action, go get the response handler for the
122  // action
124 }
125 
132 void BESXMLSetContainerCommand::dump(ostream &strm) const
133 {
134  strm << BESIndent::LMarg << "BESXMLSetContainerCommand::dump - (" << (void *) this << ")" << endl;
135  BESIndent::Indent();
136  BESXMLCommand::dump(strm);
137  BESIndent::UnIndent();
138 }
139 
141 BESXMLSetContainerCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
142 {
143  return new BESXMLSetContainerCommand(base_dhi);
144 }
145 
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
Definition: BESXMLUtils.cc:133
virtual void dump(ostream &strm) const
dumps information about this object
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
Definition: BESXMLUtils.cc:101
error thrown if there is a user syntax error in the request or any other user error ...
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
virtual void parse_request(xmlNode *node)
parse a set container command.
virtual void dump(ostream &strm) const
dumps information about this object
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.
string action
the response object requested, e.g. das, dds
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:62