bes  Updated for version 3.20.6
SampleSayXMLCommand.cc
1 // SampleSayXMLCommand.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 "config.h"
34 
35 #include "BESXMLUtils.h"
36 #include "BESUtil.h"
37 #include "BESSyntaxUserError.h"
38 #include "BESDebug.h"
39 
40 #include "SampleSayXMLCommand.h"
41 #include "SampleResponseNames.h"
42 
43 using std::endl;
44 using std::ostream;
45 using std::string;
46 using std::map;
47 
48 SampleSayXMLCommand::SampleSayXMLCommand(const BESDataHandlerInterface &base_dhi) :
49  BESXMLCommand(base_dhi)
50 {
51 }
52 
60 {
61  string name;
62  string value;
63  map<string, string> props;
64  BESXMLUtils::GetNodeInfo(node, name, value, props);
65  if (name != SAY_RESPONSE) {
66  string err = "The specified command " + name + " is not a say command";
67  throw BESSyntaxUserError(err, __FILE__, __LINE__);
68  }
69 
70  if (!value.empty()) {
71  string err = name + " command: should not have xml element values";
72  throw BESSyntaxUserError(err, __FILE__, __LINE__);
73  }
74 
75  string child_name;
76  string child_value;
77  map<string, string> child_props;
78  xmlNode *child_node = BESXMLUtils::GetFirstChild(node, child_name, child_value, child_props);
79  if (child_node) {
80  string err = name + " command: should not have child elements";
81  throw BESSyntaxUserError(err, __FILE__, __LINE__);
82  }
83 
84  d_xmlcmd_dhi.data[SAY_WHAT] = props["what"];
85  if (d_xmlcmd_dhi.data[SAY_WHAT].empty()) {
86  string err = name + " command: Must specify to whom to say";
87  throw BESSyntaxUserError(err, __FILE__, __LINE__);
88  }
89 
90  d_xmlcmd_dhi.data[SAY_TO] = props["to"];
91  if (d_xmlcmd_dhi.data[SAY_WHAT].empty()) {
92  string err = name + " command: Must specify what to say";
93  throw BESSyntaxUserError(err, __FILE__, __LINE__);
94  }
95 
96  d_xmlcmd_dhi.action = SAY_RESPONSE;
97 
98  // now that we've set the action, go get the response handler for the
99  // action
101 }
102 
104 {
105 }
106 
113 void SampleSayXMLCommand::dump(ostream &strm) const
114 {
115  strm << BESIndent::LMarg << "SampleSayXMLCommand::dump - (" << (void *) this << ")" << endl;
116  BESIndent::Indent();
117  BESXMLCommand::dump(strm);
118  BESIndent::UnIndent();
119 }
120 
122 SampleSayXMLCommand::CommandBuilder(const BESDataHandlerInterface &base_dhi)
123 {
124  return new SampleSayXMLCommand(base_dhi);
125 }
126 
SampleSayXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: SampleSayXMLCommand.cc:113
BESDataHandlerInterface::action
std::string action
the response object requested, e.g. das, dds
Definition: BESDataHandlerInterface.h:79
BESXMLCommand::set_response
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
Definition: BESXMLCommand.cc:63
BESXMLUtils::GetNodeInfo
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
Definition: BESXMLUtils.cc:105
SampleSayXMLCommand::prep_request
virtual void prep_request()
Prepare any information needed to execute the request of this command.
Definition: SampleSayXMLCommand.cc:103
BESXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:119
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
BESDataHandlerInterface::data
std::map< std::string, std::string > data
the map of string data that will be required for the current request.
Definition: BESDataHandlerInterface.h:90
BESXMLCommand
Base class for the BES's commands.
Definition: BESXMLCommand.h:63
SampleSayXMLCommand
Definition: SampleSayXMLCommand.h:40
SampleSayXMLCommand::parse_request
virtual void parse_request(xmlNode *node)
parse a show command. No properties or children elements
Definition: SampleSayXMLCommand.cc:59
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESXMLUtils::GetFirstChild
static xmlNode * GetFirstChild(xmlNode *node, std::string &child_name, std::string &child_value, std::map< std::string, std::string > &child_props)
get the first element child node for the given node
Definition: BESXMLUtils.cc:137