bes  Updated for version 3.17.4
BESXMLSetContextCommand.cc
1 // BESXMLSetContextCommand.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 "BESXMLSetContextCommand.h"
34 #include "BESXMLUtils.h"
35 #include "BESUtil.h"
36 #include "BESResponseNames.h"
37 #include "BESDataNames.h"
38 #include "BESSyntaxUserError.h"
39 #include "BESDebug.h"
40 
41 BESXMLSetContextCommand::BESXMLSetContextCommand(const BESDataHandlerInterface &base_dhi) :
42  BESXMLCommand(base_dhi)
43 {
44 }
45 
53 {
54  string value;
55  string name;
56  string action;
57  map<string, string> props;
58  BESXMLUtils::GetNodeInfo(node, action, value, props);
59  if (action != SET_CONTEXT_STR) {
60  string err = "The specified command " + action + " is not a set context command";
61  throw BESSyntaxUserError(err, __FILE__, __LINE__);
62  }
63 
64  _dhi.action = SET_CONTEXT;
65 
66  name = props["name"];
67  if (name.empty()) {
68  string err = action + " command: name property missing";
69  throw BESSyntaxUserError(err, __FILE__, __LINE__);
70  }
71  if (value.empty()) {
72  string err = action + " command: context value missing";
73  throw BESSyntaxUserError(err, __FILE__, __LINE__);
74  }
75  _dhi.data[CONTEXT_NAME] = name;
76  _dhi.data[CONTEXT_VALUE] = value;
77  _str_cmd = (string) "set context " + name + " to " + value + ";";
78 
79  // now that we've set the action, go get the response handler for the
80  // action
82 }
83 
90 void BESXMLSetContextCommand::dump(ostream &strm) const
91 {
92  strm << BESIndent::LMarg << "BESXMLSetContextCommand::dump - (" << (void *) this << ")" << endl;
93  BESIndent::Indent();
94  BESXMLCommand::dump(strm);
95  BESIndent::UnIndent();
96 }
97 
99 BESXMLSetContextCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
100 {
101  return new BESXMLSetContextCommand(base_dhi);
102 }
103 
virtual void dump(ostream &strm) const
dumps information about this object
virtual void parse_request(xmlNode *node)
parse a set context command.
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:99
error thrown if there is a user syntax error in the request or any other user error ...
virtual void dump(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.
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