OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESXMLCommand.cc
Go to the documentation of this file.
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 "BESXMLCommand.h"
34 #include "BESResponseHandlerList.h"
35 #include "BESSyntaxUserError.h"
36 #include "BESDataNames.h"
37 #include "BESLog.h"
38 
39 map<string, p_xmlcmd_builder> BESXMLCommand::cmd_list;
40 
49 {
50  _dhi.make_copy(base_dhi);
51 }
52 
57 {
59  if (!_dhi.response_handler) {
60  string err("Command ");
61  err += _dhi.action + " does not have a registered response handler";
62  throw BESSyntaxUserError(err, __FILE__, __LINE__);
63  }
65  *(BESLog::TheLog()) << _dhi.data[SERVER_PID] << " from " << _dhi.data[REQUEST_FROM] << " [" << _str_cmd
66  << "] received" << endl;
67 }
68 
79 void BESXMLCommand::add_command(const string &cmd_str, p_xmlcmd_builder cmd)
80 {
81  BESXMLCommand::cmd_list[cmd_str] = cmd;
82 }
83 
89 bool BESXMLCommand::del_command(const string &cmd_str)
90 {
91  bool ret = false;
92 
93  BESXMLCommand::cmd_iter iter = BESXMLCommand::cmd_list.find(cmd_str);
94  if (iter != BESXMLCommand::cmd_list.end()) {
95  BESXMLCommand::cmd_list.erase(iter);
96  }
97  return ret;
98 }
99 
105 {
106  return BESXMLCommand::cmd_list[cmd_str];
107 }
108 
115 void BESXMLCommand::dump(ostream &strm) const
116 {
117  strm << BESIndent::LMarg << "BESXMLCommand::dump - (" << (void *) this << ")" << endl;
120 }
121 
BESXMLCommand(const BESDataHandlerInterface &base_dhi)
Creates a BESXMLCommand document given a base data handler interface object.
virtual BESResponseHandler * find_handler(const string &handler)
returns the response handler with the given name from the list
#define DATA_REQUEST
Definition: BESDataNames.h:36
static bool del_command(const string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
static void add_command(const string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
BESXMLCommand *(* p_xmlcmd_builder)(const BESDataHandlerInterface &dhi)
Definition: BESXMLCommand.h:49
#define SERVER_PID
Definition: BESDataNames.h:59
BESDataHandlerInterface _dhi
Definition: BESXMLCommand.h:57
static void Indent()
Definition: BESIndent.cc:38
error thrown if there is a user syntax error in the request or any other user error ...
void make_copy(const BESDataHandlerInterface &copy_from)
deprecated
virtual void set_response()
The request has been parsed, use the command action name to set the response handler.
BESResponseHandler * response_handler
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
#define REQUEST_FROM
Definition: BESDataNames.h:38
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.
static BESLog * TheLog()
Definition: BESLog.cc:347
static void UnIndent()
Definition: BESIndent.cc:44
string action
the response object requested, e.g.
virtual void dump(ostream &strm) const
dumps information about this object
static BESResponseHandlerList * TheList()
static p_xmlcmd_builder find_command(const string &cmd_str)
Find the BESXMLCommand creation function with the given name.