bes  Updated for version 3.19.1
BESDDXResponseHandler.cc
1 // BESDDXResponseHandler.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 <DDS.h>
34 
35 #include "BESDDXResponseHandler.h"
36 #include "BESDASResponse.h"
37 #include "BESDDSResponse.h"
38 #include "BESDapNames.h"
39 #include "BESDataNames.h"
40 #include "BESRequestHandlerList.h"
41 
42 #include "BESDebug.h"
43 
44 using namespace libdap;
45 
46 BESDDXResponseHandler::BESDDXResponseHandler(const string &name) :
47  BESResponseHandler(name)
48 {
49 }
50 
51 BESDDXResponseHandler::~BESDDXResponseHandler()
52 {
53 }
54 
70 {
71  BESDEBUG( "dap", "Entering BESDDXResponseHandler::execute" << endl );
72 
73  dhi.action_name = DDX_RESPONSE_STR;
74  // Create the DDS.
75  // NOTE: It is the responsibility of the specific request handler to set
76  // the BaseTypeFactory. It is set to NULL here
77  DDS *dds = new DDS(NULL, "virtual");
78 
79  BESDDSResponse *bdds = new BESDDSResponse(dds);
80  _response = bdds;
81  _response_name = DDS_RESPONSE;
82  dhi.action = DDS_RESPONSE;
83 
84  BESDEBUG( "bes", "about to set dap version to: " << bdds->get_dap_client_protocol() << endl);
85  BESDEBUG( "bes", "about to set xml:base to: " << bdds->get_request_xml_base() << endl);
86 
87  // I added these two lines from BESDDXResponse. jhrg 10/05/09
88  // Note that the get_dap_client_protocol(), ..., methods
89  // are defined in BESDapResponse - these are not the methods of the
90  // same name in DDS. 2/23/11 jhrg
91 
92  // Set the DAP protocol version requested by the client. 2/25/11 jhrg
93 
94  dhi.first_container();
95  BESDEBUG("version", "Initial CE: " << dhi.container->get_constraint() << endl);
96  dhi.container->set_constraint(dds->get_keywords().parse_keywords(dhi.container->get_constraint()));
97  BESDEBUG("version", "CE after keyword processing: " << dhi.container->get_constraint() << endl);
98 
99  if (dds->get_keywords().has_keyword("dap")) {
100  BESDEBUG("version",
101  "Has keyword 'dap', setting version to: " << dds->get_keywords().get_keyword_value("dap") << endl);
102  dds->set_dap_version(dds->get_keywords().get_keyword_value("dap"));
103  }
104  else if (!bdds->get_dap_client_protocol().empty()) {
105  BESDEBUG("version",
106  "Has non-empty dap version info in bdds, setting version to: " << bdds->get_dap_client_protocol() << endl);
107  dds->set_dap_version(bdds->get_dap_client_protocol());
108  }
109  else {
110  BESDEBUG("version", "Has no clue about dap version, using default." << endl);
111  }
112 
113  dds->set_request_xml_base(bdds->get_request_xml_base());
114 
115  BESRequestHandlerList::TheList()->execute_each(dhi);
116 
117  dhi.action = DDX_RESPONSE;
118  _response = bdds;
119 
120  BESDEBUG( "dap", "Leaving BESDDXResponseHandler::execute" << endl);
121 }
122 
136 {
137  if (_response) {
138  transmitter->send_response(DDX_SERVICE, _response, dhi);
139  }
140 }
141 
148 void BESDDXResponseHandler::dump(ostream &strm) const
149 {
150  strm << BESIndent::LMarg << "BESDDXResponseHandler::dump - (" << (void *) this << ")" << endl;
151  BESIndent::Indent();
153  BESIndent::UnIndent();
154 }
155 
157 BESDDXResponseHandler::DDXResponseBuilder(const string &name)
158 {
159  return new BESDDXResponseHandler(name);
160 }
161 
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command
Holds a DDS object within the BES.
virtual void dump(ostream &strm) const
dumps information about this object
handler object that knows how to create a specific response object
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request ...
void set_constraint(const string &s)
set the constraint for this container
Definition: BESContainer.h:104
Structure storing information used by the BES to handle the request.
string get_constraint() const
retrieve the constraint expression for this container
Definition: BESContainer.h:170
string get_dap_client_protocol() const
Return the dap version string sent by the client (e.g., the OLFS)
virtual void dump(ostream &strm) const
dumps information about this object
virtual void execute(BESDataHandlerInterface &dhi)
executes the command &#39;get ddx for def_name;&#39;
string get_request_xml_base() const
Return the xml:base URL for this request.
void first_container()
set the container pointer to the first container in the containers list
response handler that builds an OPeNDAP DDX object
string action
the response object requested, e.g. das, dds
BESContainer * container
pointer to current container in this interface