bes  Updated for version 3.20.6
BESDataHandlerInterface.cc
1 // BESDataHandlerInterface.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 "BESDataHandlerInterface.h"
34 #include "BESContainer.h"
35 #include "BESResponseHandler.h"
36 #include "BESInfo.h"
37 #include "BESIndent.h"
38 
39 using std::endl;
40 using std::list;
41 using std::ostream;
42 
59 {
60  clone(copy_from);
61 }
62 
72 void BESDataHandlerInterface::clone(const BESDataHandlerInterface &copy_from)
73 {
74 #if 0
75  // Added because this can be called from make_copy() which is public.
76  // jhrg 4/18/14
77  // I removed this because I think it's bogus but having it here confuses
78  // coverity into thinking that parts of the object built be the copy ctor
79  // might be uninitialized. All of the NCML handler tests pass with this
80  // modification. jhrg 9/17/15
81  if (this == &copy_from)
82  return;
83 #endif
84  output_stream = copy_from.output_stream;
85  response_handler = copy_from.response_handler;
86 
87  containers = copy_from.containers;
88  containers_iterator = copy_from.containers_iterator;
89  container = copy_from.container;
90 
91  action = copy_from.action;
92  action_name = copy_from.action_name;
93  executed = copy_from.executed;
94 
96 
97  // I do this because clang 5 (on OSX 10.9) will remove everything from 'data'
98  // if copy_from.data and 'data' are the same object. Since the ncml handler uses
99  // make_copy() and may be using a reference to a DHI and/or the DHI's 'data' map,
100  // I'm leaving the test in here. That is, it could be building a new DHI instance
101  // that uses a reference to an existing 'data' field and then assign the original
102  // DHI instance to the new one. The DHIs are different, but the 'data' map are
103  // not. jhrg 4/18/14
104  if (&data != &copy_from.data)
105  data = copy_from.data;
106 
107  error_info = copy_from.error_info;
108 }
109 
110 BESDataHandlerInterface::BESDataHandlerInterface(const BESDataHandlerInterface &from)
111 {
112  clone(from);
113 }
114 
116 BESDataHandlerInterface::operator=(const BESDataHandlerInterface &rhs)
117 {
118  if (&rhs == this) {
119  return *this;
120  }
121 
122  clone(rhs);
123 
124  return *this;
125 }
126 
135 {
136  if (response_handler) {
137  delete response_handler;
138  }
139  response_handler = 0;
140 }
141 
151 {
152  BESResponseObject *response = 0;
153 
154  if (response_handler) {
155  response = response_handler->get_response_object();
156  }
157  return response;
158 }
159 
167 void BESDataHandlerInterface::dump(ostream &strm) const
168 {
169  strm << BESIndent::LMarg << "BESDataHandlerInterface::dump" << endl;
170  BESIndent::Indent();
171  if (response_handler) {
172  strm << BESIndent::LMarg << "response handler:" << endl;
173  BESIndent::Indent();
174  response_handler->dump(strm);
175  BESIndent::UnIndent();
176  }
177  else {
178  strm << BESIndent::LMarg << "response handler: not set" << endl;
179  }
180 
181  if (container) {
182  strm << BESIndent::LMarg << "current container:" << endl;
183  BESIndent::Indent();
184  container->dump(strm);
185  BESIndent::UnIndent();
186  }
187  else {
188  strm << BESIndent::LMarg << "current container: not set" << endl;
189  }
190 
191  if (containers.size()) {
192  strm << BESIndent::LMarg << "container list:" << endl;
193  BESIndent::Indent();
194  list<BESContainer *>::const_iterator i = containers.begin();
195  list<BESContainer *>::const_iterator ie = containers.end();
196  for (; i != ie; i++) {
197  (*i)->dump(strm);
198  }
199  BESIndent::UnIndent();
200  }
201  else {
202  strm << BESIndent::LMarg << "container list: empty" << endl;
203  }
204 
205  strm << BESIndent::LMarg << "action: " << action << endl;
206  strm << BESIndent::LMarg << "action name: " << action_name << endl;
207  strm << BESIndent::LMarg << "transmit protocol: " << transmit_protocol << endl;
208  if (data.size()) {
209  strm << BESIndent::LMarg << "data:" << endl;
210  BESIndent::Indent();
211  data_citer i = data.begin();
212  data_citer ie = data.end();
213  for (; i != ie; i++) {
214  strm << BESIndent::LMarg << (*i).first << ": " << (*i).second << endl;
215  }
216  BESIndent::UnIndent();
217  }
218  else {
219  strm << BESIndent::LMarg << "data: none" << endl;
220  }
221 
222  if (error_info) {
223  strm << BESIndent::LMarg << "error info:" << endl;
224  BESIndent::Indent();
225  error_info->dump(strm);
226  BESIndent::UnIndent();
227  }
228  else {
229  strm << BESIndent::LMarg << "error info: null" << endl;
230  }
231  BESIndent::UnIndent();
232 }
233 
BESDataHandlerInterface::container
BESContainer * container
pointer to current container in this interface
Definition: BESDataHandlerInterface.h:75
BESDataHandlerInterface::action
std::string action
the response object requested, e.g. das, dds
Definition: BESDataHandlerInterface.h:79
BESDataHandlerInterface::clean
void clean()
clean up any information created within this data handler interface
Definition: BESDataHandlerInterface.cc:134
BESDataHandlerInterface::transmit_protocol
std::string transmit_protocol
request protocol, such as HTTP
Definition: BESDataHandlerInterface.h:85
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESDataHandlerInterface::make_copy
void make_copy(const BESDataHandlerInterface &copy_from)
deprecated
Definition: BESDataHandlerInterface.cc:58
BESDataHandlerInterface::get_response_object
BESResponseObject * get_response_object()
returns the response object using the response handler
Definition: BESDataHandlerInterface.cc:150
BESResponseHandler::get_response_object
virtual BESResponseObject * get_response_object()
return the current response object
Definition: BESResponseHandler.cc:82
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
BESDataHandlerInterface::dump
void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDataHandlerInterface.cc:167
BESInfo::dump
virtual void dump(std::ostream &strm) const
Displays debug information about this object.
Definition: BESInfo.cc:275
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESDataHandlerInterface::error_info
BESInfo * error_info
error information object
Definition: BESDataHandlerInterface.h:94
BESContainer::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESContainer.cc:73
BESResponseObject
Abstract base class representing a specific set of information in response to a request to the BES.
Definition: BESResponseObject.h:45