bes  Updated for version 3.20.6
BESDataDDXResponseHandler.cc
1 // BESDataDDXResponseHandler.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 <DataDDS.h>
34 
35 #include "BESDataDDXResponseHandler.h"
36 #include "BESDataDDSResponse.h"
37 #include "BESRequestHandlerList.h"
38 #include "BESDapNames.h"
39 #include "BESDataNames.h"
40 #include "BESTransmitter.h"
41 
42 #include "BESDebug.h"
43 
44 using namespace libdap;
45 using namespace std;
46 
47 BESDataDDXResponseHandler::BESDataDDXResponseHandler( const string &name )
48  : BESResponseHandler( name )
49 {
50 }
51 
52 BESDataDDXResponseHandler::~BESDataDDXResponseHandler( )
53 {
54 }
55 
70 void
72 {
73  BESDEBUG( "dap", "Entering BESDataDDXResponseHandler::execute" << endl ) ;
74 
75  dhi.action_name = DATADDX_RESPONSE_STR ;
76  // Create the DDS.
77  // NOTE: It is the responsibility of the specific request handler to set
78  // the BaseTypeFactory. It is set to NULL here
79  DDS *dds = new DDS( NULL, "virtual" ) ;
80  BESDataDDSResponse *bdds = new BESDataDDSResponse( dds ) ;
81  d_response_object = bdds ;
82 
83  // we're actually going to get the data response, it just gets
84  // displayed as a DataDDX
85  d_response_name = DATA_RESPONSE ;
86  dhi.action = DATA_RESPONSE ;
87 
88 #if 0
89  // Read keywords from the CE and use those to set the DAP version; maybe
90  // other things. If the dap version(s) are not included in the CE using
91  // keywords, then see if anything was sent in the Request headers (which
92  // the OLFS will parse); the BES includes that info in the BESDapResponse
93  // object.
94 
95  // Set the DAP protocol version requested by the client. 2/25/11 jhrg
96 
97  dhi.first_container();
98  BESDEBUG("version", "Initial CE: " << dhi.container->get_constraint() << endl);
99  dhi.container->set_constraint(dds->get_keywords().parse_keywords(dhi.container->get_constraint()));
100  BESDEBUG("version", "CE after keyword processing: " << dhi.container->get_constraint() << endl);
101 
102  dhi.data[POST_CONSTRAINT] = dds->get_keywords().parse_keywords(dhi.data[POST_CONSTRAINT]);
103  if (dds->get_keywords().has_keyword("dap")) {
104  dds->set_dap_version(dds->get_keywords().get_keyword_value("dap"));
105  }
106  else if (!bdds->get_dap_client_protocol().empty()) {
107  dds->set_dap_version( bdds->get_dap_client_protocol() );
108  }
109 #endif
110 
111  if (!bdds->get_dap_client_protocol().empty()) {
112  dds->set_dap_version( bdds->get_dap_client_protocol() );
113  }
114 
115  dds->set_request_xml_base( bdds->get_request_xml_base() );
116 
117  BESRequestHandlerList::TheList()->execute_each( dhi ) ;
118 
119  // we've got what we want, now set the action back to data ddx
120  dhi.action = DATADDX_RESPONSE ;
121  d_response_object = bdds ;
122 
123  BESDEBUG( "dap", "Leaving BESDataDDXResponseHandler::execute" << endl ) ;
124 }
125 
138 void
141 {
142  if( d_response_object )
143  {
144  transmitter->send_response( DATADDX_SERVICE, d_response_object, dhi ) ;
145  }
146 }
147 
154 void
155 BESDataDDXResponseHandler::dump( ostream &strm ) const
156 {
157  strm << BESIndent::LMarg << "BESDataDDXResponseHandler::dump - ("
158  << (void *)this << ")" << endl ;
159  BESIndent::Indent() ;
160  BESResponseHandler::dump( strm ) ;
161  BESIndent::UnIndent() ;
162 }
163 
165 BESDataDDXResponseHandler::DataDDXResponseBuilder( const string &name )
166 {
167  return new BESDataDDXResponseHandler( name ) ;
168 }
169 
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
BESResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESResponseHandler.cc:102
BESContainer::get_constraint
std::string get_constraint() const
retrieve the constraint expression for this container
Definition: BESContainer.h:194
BESRequestHandlerList::execute_each
virtual void execute_each(BESDataHandlerInterface &dhi)
for each container in the given data handler interface, execute the given request
Definition: BESRequestHandlerList.cc:167
libdap
Definition: BESDapFunctionResponseCache.h:35
BESDataDDXResponseHandler::execute
virtual void execute(BESDataHandlerInterface &dhi)
executes the command 'get ddx for def_name;'
Definition: BESDataDDXResponseHandler.cc:71
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
BESResponseHandler
handler object that knows how to create a specific response object
Definition: BESResponseHandler.h:77
BESTransmitter
Definition: BESTransmitter.h:47
BESDataDDXResponseHandler::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESDataDDXResponseHandler.cc:155
BESDataDDXResponseHandler
response handler that builds an OPeNDAP DDX object
Definition: BESDataDDXResponseHandler.h:52
BESDataDDSResponse
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
Definition: BESDataDDSResponse.h:46
BESDapResponse::get_dap_client_protocol
std::string get_dap_client_protocol() const
Return the dap version string sent by the client (e.g., the OLFS)
Definition: BESDapResponse.h:64
BESContainer::set_constraint
void set_constraint(const std::string &s)
set the constraint for this container
Definition: BESContainer.h:118
BESDataHandlerInterface::first_container
void first_container()
set the container pointer to the first container in the containers list
Definition: BESDataHandlerInterface.h:135
BESDapResponse::get_request_xml_base
std::string get_request_xml_base() const
Return the xml:base URL for this request.
Definition: BESDapResponse.h:76
BESDataHandlerInterface
Structure storing information used by the BES to handle the request.
Definition: BESDataHandlerInterface.h:56
BESDataDDXResponseHandler::transmit
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &dhi)
transmit the response object built by the execute command
Definition: BESDataDDXResponseHandler.cc:139