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