BESDapTransmit.cc

Go to the documentation of this file.
00001 // BESDapTransmit.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 <sstream>
00034 
00035 using std::ostringstream;
00036 
00037 #include "BESDapTransmit.h"
00038 #include "DODSFilter.h"
00039 #include "BESContainer.h"
00040 #include "BESDataNames.h"
00041 #include "BESResponseNames.h"
00042 #include "cgi_util.h"
00043 #include "BESDASResponse.h"
00044 #include "BESDDSResponse.h"
00045 #include "BESDataDDSResponse.h"
00046 #include "BESDapError.h"
00047 #include "BESInternalFatalError.h"
00048 #include "Error.h"
00049 
00050 BESDapTransmit::BESDapTransmit()
00051     : BESBasicTransmitter()
00052 {
00053     add_method( DAS_SERVICE, BESDapTransmit::send_basic_das ) ;
00054     add_method( DDS_SERVICE, BESDapTransmit::send_basic_dds ) ;
00055     add_method( DDX_SERVICE, BESDapTransmit::send_basic_ddx ) ;
00056     add_method( DATA_SERVICE, BESDapTransmit::send_basic_data ) ;
00057 }
00058 
00059 void
00060 BESDapTransmit::send_basic_das(BESResponseObject * obj,
00061                                BESDataHandlerInterface & dhi)
00062 {
00063     BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(obj);
00064     if( !bdas )
00065         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00066     DAS *das = bdas->get_das();
00067     dhi.first_container();
00068 
00069     try
00070     {
00071         DODSFilter df ;
00072         df.set_dataset_name( dhi.container->get_real_name() ) ;
00073         df.send_das( dhi.get_output_stream(), *das, "", false ) ;
00074     }
00075     catch( InternalErr &e )
00076     {
00077         string err = "libdap error transmitting DAS: "
00078             + e.get_error_message() ;
00079         throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00080     }
00081     catch( Error &e )
00082     {
00083         string err = "libdap error transmitting DAS: "
00084             + e.get_error_message() ;
00085         throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00086     }
00087     catch(...)
00088     {
00089         string s = "unknown error caught transmitting DAS" ;
00090         BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00091         throw ex;
00092     }
00093 }
00094 
00095 void BESDapTransmit::send_basic_dds(BESResponseObject * obj,
00096                                     BESDataHandlerInterface & dhi)
00097 {
00098     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00099     if( !bdds )
00100         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00101     DDS *dds = bdds->get_dds();
00102     ConstraintEvaluator & ce = bdds->get_ce();
00103     dhi.first_container();
00104 
00105     try {
00106         DODSFilter df;
00107         df.set_dataset_name(dhi.container->get_real_name());
00108         df.set_ce(dhi.data[POST_CONSTRAINT]);
00109         df.send_dds(dhi.get_output_stream(), *dds, ce, true, "", false);
00110     }
00111     catch( InternalErr &e )
00112     {
00113         string err = "libdap error transmitting DDS: "
00114             + e.get_error_message() ;
00115         throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00116     }
00117     catch( Error &e )
00118     {
00119         string err = "libdap error transmitting DDS: "
00120             + e.get_error_message() ;
00121         throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00122     }
00123     catch(...)
00124     {
00125         string s = "unknown error caught transmitting DDS" ;
00126         BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00127         throw ex;
00128     }
00129 }
00130 
00131 void BESDapTransmit::send_basic_data(BESResponseObject * obj,
00132                                      BESDataHandlerInterface & dhi)
00133 {
00134     BESDataDDSResponse *bdds = dynamic_cast < BESDataDDSResponse * >(obj);
00135     if( !bdds )
00136         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00137     DataDDS *dds = bdds->get_dds();
00138     ConstraintEvaluator & ce = bdds->get_ce();
00139     dhi.first_container();
00140 
00141     try {
00142         DODSFilter df;
00143         df.set_dataset_name(dds->filename());
00144         df.set_ce(dhi.data[POST_CONSTRAINT]);
00145         df.send_data(*dds, ce, dhi.get_output_stream(), "", false);
00146     }
00147     catch( InternalErr &e )
00148     {
00149         string err = "libdap error transmitting DataDDS: "
00150             + e.get_error_message() ;
00151         throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00152     }
00153     catch( Error &e )
00154     {
00155         string err = "libdap error transmitting DataDDS: "
00156             + e.get_error_message() ;
00157         throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00158     }
00159     catch(...)
00160     {
00161         string s = "unknown error caught transmitting DataDDS" ;
00162         BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00163         throw ex;
00164     }
00165 }
00166 
00167 void BESDapTransmit::send_basic_ddx(BESResponseObject * obj,
00168                                     BESDataHandlerInterface & dhi)
00169 {
00170     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00171     if( !bdds )
00172         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00173     DDS *dds = bdds->get_dds();
00174     ConstraintEvaluator & ce = bdds->get_ce();
00175     dhi.first_container();
00176 
00177     try {
00178         DODSFilter df;
00179         df.set_dataset_name(dhi.container->get_real_name());
00180         df.set_ce(dhi.data[POST_CONSTRAINT]);
00181         df.send_ddx(*dds, ce, dhi.get_output_stream(), false);
00182     }
00183     catch( InternalErr &e )
00184     {
00185         string err = "libdap error transmitting DDX: "
00186             + e.get_error_message() ;
00187         throw BESDapError( err, true, e.get_error_code(), __FILE__, __LINE__ ) ;
00188     }
00189     catch( Error &e )
00190     {
00191         string err = "libdap error transmitting DDX: "
00192             + e.get_error_message() ;
00193         throw BESDapError( err, false, e.get_error_code(), __FILE__, __LINE__ );
00194     }
00195     catch(...)
00196     {
00197         string s = "unknown error caught transmitting DDX" ;
00198         BESInternalFatalError ex( s, __FILE__, __LINE__ ) ;
00199         throw ex;
00200     }
00201 }
00202 

Generated on Sat Aug 22 06:04:33 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.0