OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESDDXResponseHandler.cc
Go to the documentation of this file.
00001 // BESDDXResponseHandler.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025 
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include "BESDDXResponseHandler.h"
00034 #include "BESDASResponse.h"
00035 #include "BESDDSResponse.h"
00036 #include "BESDapNames.h"
00037 #include "BESDataNames.h"
00038 #include "BESRequestHandlerList.h"
00039 #include "BESDapTransmit.h"
00040 
00041 #include "BESDebug.h"
00042 
00043 BESDDXResponseHandler::BESDDXResponseHandler( const string &name )
00044     : BESResponseHandler( name )
00045 {
00046 }
00047 
00048 BESDDXResponseHandler::~BESDDXResponseHandler( )
00049 {
00050 }
00051 
00066 void
00067 BESDDXResponseHandler::execute( BESDataHandlerInterface &dhi )
00068 {
00069     BESDEBUG( "dap", "Entering BESDDXResponseHandler::execute" << endl ) ;
00070 
00071     dhi.action_name = DDX_RESPONSE_STR ;
00072     // Create the DDS.
00073     // NOTE: It is the responsibility of the specific request handler to set
00074     // the BaseTypeFactory. It is set to NULL here
00075     DDS *dds = new DDS( NULL, "virtual" ) ;
00076 
00077     BESDDSResponse *bdds = new BESDDSResponse( dds ) ;
00078     _response = bdds ;
00079     _response_name = DDS_RESPONSE ;
00080     dhi.action = DDS_RESPONSE ;
00081 
00082     BESDEBUG( "bes", "about to set dap version to: "
00083                 << bdds->get_dap_client_protocol() << endl) ;
00084     BESDEBUG( "bes", "about to set xml:base to: "
00085                 << bdds->get_request_xml_base() << endl) ;
00086 
00087     // I added these two lines from BESDDXResponse. jhrg 10/05/09
00088     // Note that the get_dap_client_protocol(), ..., methods
00089     // are defined in BESDapResponse - these are not the methods of the
00090     // same name in DDS. 2/23/11 jhrg
00091 
00092     // Set the DAP protocol version requested by the client. 2/25/11 jhrg
00093 
00094     dhi.first_container();
00095     BESDEBUG("version", "Initial CE: " << dhi.container->get_constraint() << endl);
00096     dhi.container->set_constraint(dds->get_keywords().parse_keywords(dhi.container->get_constraint()));
00097     BESDEBUG("version", "CE after keyword processing: " << dhi.container->get_constraint() << endl);
00098 
00099     if (dds->get_keywords().has_keyword("dap")) {
00100         BESDEBUG("version", "Has keyword 'dap', setting version to: " << dds->get_keywords().get_keyword_value("dap") << endl);
00101         dds->set_dap_version(dds->get_keywords().get_keyword_value("dap"));
00102     }
00103     else if (!bdds->get_dap_client_protocol().empty()) {
00104         BESDEBUG("version", "Has non-empty dap version info in bdds, setting version to: " << bdds->get_dap_client_protocol() << endl);
00105         dds->set_dap_version( bdds->get_dap_client_protocol() ) ;
00106     }
00107     else {
00108         BESDEBUG("version", "Has no clue about dap version, using default." << endl);
00109     }
00110 
00111     dds->set_request_xml_base( bdds->get_request_xml_base() );
00112 
00113     BESRequestHandlerList::TheList()->execute_each( dhi ) ;
00114 
00115     dhi.action = DDX_RESPONSE ;
00116     _response = bdds ;
00117 
00118     BESDEBUG( "dap", "Leaving BESDDXResponseHandler::execute" << endl ) ;
00119 }
00120 
00133 void
00134 BESDDXResponseHandler::transmit( BESTransmitter * transmitter,
00135                                  BESDataHandlerInterface & dhi )
00136 {
00137     if( _response )
00138     {
00139         transmitter->send_response( DDX_SERVICE, _response, dhi ) ;
00140     }
00141 }
00142 
00149 void
00150 BESDDXResponseHandler::dump( ostream &strm ) const
00151 {
00152     strm << BESIndent::LMarg << "BESDDXResponseHandler::dump - ("
00153                              << (void *)this << ")" << endl ;
00154     BESIndent::Indent() ;
00155     BESResponseHandler::dump( strm ) ;
00156     BESIndent::UnIndent() ;
00157 }
00158 
00159 BESResponseHandler *
00160 BESDDXResponseHandler::DDXResponseBuilder( const string &name )
00161 {
00162     return new BESDDXResponseHandler( name ) ;
00163 }
00164