bes  Updated for version 3.20.6
BESXMLCommand.cc
1 // BESXMLCommand.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 <iostream>
34 
35 #include "BESXMLCommand.h"
36 #include "BESResponseHandlerList.h"
37 #include "BESSyntaxUserError.h"
38 #include "BESDataNames.h"
39 #include "BESLog.h"
40 
41 using std::endl;
42 using std::ostream;
43 using std::map;
44 using std::string;
45 
46 map<string, p_xmlcmd_builder> BESXMLCommand::factory;
47 
56 {
57  d_xmlcmd_dhi.make_copy(base_dhi);
58 }
59 
64 {
65  d_xmlcmd_dhi.response_handler = BESResponseHandlerList::TheList()->find_handler(d_xmlcmd_dhi.action);
66  if (!d_xmlcmd_dhi.response_handler) {
67  throw BESSyntaxUserError(string("Command '") + d_xmlcmd_dhi.action
68  + "' does not have a registered response handler", __FILE__, __LINE__);
69  }
70 
71  d_xmlcmd_dhi.data[LOG_INFO] = d_cmd_log_info;
72 
73  VERBOSE(d_xmlcmd_dhi.data[REQUEST_FROM] << " [" << d_xmlcmd_dhi.data[LOG_INFO] << "] parsed" << endl);
74 }
75 
86 void BESXMLCommand::add_command(const string &cmd_str, p_xmlcmd_builder cmd)
87 {
88  BESXMLCommand::factory[cmd_str] = cmd;
89 }
90 
96 void BESXMLCommand::del_command(const string &cmd_str)
97 {
98  BESXMLCommand::cmd_iter iter = BESXMLCommand::factory.find(cmd_str);
99  if (iter != BESXMLCommand::factory.end()) {
100  BESXMLCommand::factory.erase(iter);
101  }
102 }
103 
108 p_xmlcmd_builder BESXMLCommand::find_command(const string &cmd_str)
109 {
110  return BESXMLCommand::factory[cmd_str];
111 }
112 
119 void BESXMLCommand::dump(ostream &strm) const
120 {
121  strm << BESIndent::LMarg << "BESXMLCommand::dump - (" << (void *) this << ")" << endl;
122  BESIndent::Indent();
123  BESIndent::UnIndent();
124 }
125 
BESXMLCommand::BESXMLCommand
BESXMLCommand(const BESDataHandlerInterface &base_dhi)
Creates a BESXMLCommand document given a base data handler interface object.
Definition: BESXMLCommand.cc:55
BESXMLCommand::d_cmd_log_info
std::string d_cmd_log_info
Used only for the log.
Definition: BESXMLCommand.h:74
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
BESDataHandlerInterface::make_copy
void make_copy(const BESDataHandlerInterface &copy_from)
deprecated
Definition: BESDataHandlerInterface.cc:58
BESXMLCommand::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESXMLCommand.cc:119
BESXMLCommand::add_command
static void add_command(const std::string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
Definition: BESXMLCommand.cc:86
BESSyntaxUserError
error thrown if there is a user syntax error in the request or any other user error
Definition: BESSyntaxUserError.h:41
BESResponseHandlerList::find_handler
virtual BESResponseHandler * find_handler(const std::string &handler)
returns the response handler with the given name from the list
Definition: BESResponseHandlerList.cc:97
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::find_command
static p_xmlcmd_builder find_command(const std::string &cmd_str)
Find the BESXMLCommand creation function with the given name.
Definition: BESXMLCommand.cc:108
BESXMLCommand::del_command
static void del_command(const std::string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
Definition: BESXMLCommand.cc:96
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56