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,2005 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 "cgi_util.h"
00042 #include "BESDASResponse.h"
00043 #include "BESDDSResponse.h"
00044 #include "BESDataDDSResponse.h"
00045 #include "BESTransmitException.h"
00046 #include "Error.h"
00047 
00048 void
00049 BESDapTransmit::send_basic_das(BESResponseObject * obj,
00050                                BESDataHandlerInterface & dhi)
00051 {
00052     BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(obj);
00053     DAS *das = bdas->get_das();
00054     dhi.first_container();
00055 
00056     try {
00057         DODSFilter df;
00058         df.set_dataset_name(dhi.container->get_real_name());
00059         df.send_das(dhi.get_output_stream(), *das, "", false);
00060         dhi.get_output_stream() << flush ;
00061     }
00062     catch(Error & e) {
00063         ostringstream s;
00064         s << "libdap exception transmitting DAS"
00065             << ": error_code = " << e.get_error_code()
00066             << ": " << e.get_error_message();
00067         BESTransmitException ex(s.str(), __FILE__, __LINE__);
00068         throw ex;
00069     }
00070     catch(...) {
00071         string s = "unknown exception caught transmitting DAS";
00072         BESTransmitException ex(s, __FILE__, __LINE__);
00073         throw ex;
00074     }
00075 }
00076 
00077 void BESDapTransmit::send_http_das(BESResponseObject * obj,
00078                                    BESDataHandlerInterface & dhi)
00079 {
00080     set_mime_text(dhi.get_output_stream(), dods_das);
00081     BESDapTransmit::send_basic_das(obj, dhi);
00082 }
00083 
00084 void BESDapTransmit::send_basic_dds(BESResponseObject * obj,
00085                                     BESDataHandlerInterface & dhi)
00086 {
00087     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00088     DDS *dds = bdds->get_dds();
00089     ConstraintEvaluator & ce = bdds->get_ce();
00090     dhi.first_container();
00091 
00092     try {
00093         DODSFilter df;
00094         df.set_dataset_name(dhi.container->get_real_name());
00095         df.set_ce(dhi.data[POST_CONSTRAINT]);
00096         df.send_dds(dhi.get_output_stream(), *dds, ce, true, "", false);
00097         dhi.get_output_stream() << flush ;
00098     }
00099     catch(Error & e) {
00100         ostringstream s;
00101         s << "libdap exception transmitting DDS"
00102             << ": error_code = " << e.get_error_code()
00103             << ": " << e.get_error_message();
00104         BESTransmitException ex(s.str(), __FILE__, __LINE__);
00105         throw ex;
00106     }
00107     catch(...) {
00108         string s = "unknown exception caught transmitting DDS";
00109         BESTransmitException ex(s, __FILE__, __LINE__);
00110         throw ex;
00111     }
00112 }
00113 
00114 void BESDapTransmit::send_http_dds(BESResponseObject * obj,
00115                                    BESDataHandlerInterface & dhi)
00116 {
00117     set_mime_text(dhi.get_output_stream(), dods_dds);
00118     BESDapTransmit::send_basic_dds(obj, dhi);
00119 }
00120 
00121 void BESDapTransmit::send_basic_data(BESResponseObject * obj,
00122                                      BESDataHandlerInterface & dhi)
00123 {
00124     BESDataDDSResponse *bdds = dynamic_cast < BESDataDDSResponse * >(obj);
00125     DataDDS *dds = bdds->get_dds();
00126     ConstraintEvaluator & ce = bdds->get_ce();
00127     dhi.first_container();
00128 
00129     try {
00130         DODSFilter df;
00131         df.set_dataset_name(dds->filename());
00132         df.set_ce(dhi.data[POST_CONSTRAINT]);
00133         df.send_data(*dds, ce, dhi.get_output_stream(), "", false);
00134         dhi.get_output_stream() << flush ;
00135     }
00136     catch(Error & e) {
00137         ostringstream s;
00138         s << "libdap exception transmitting DataDDS"
00139             << ": error_code = " << e.get_error_code()
00140             << ": " << e.get_error_message();
00141         BESTransmitException ex(s.str(), __FILE__, __LINE__);
00142         throw ex;
00143     }
00144     catch(...) {
00145         string s = "unknown exception caught transmitting DataDDS";
00146         BESTransmitException ex(s, __FILE__, __LINE__);
00147         throw ex;
00148     }
00149 }
00150 
00151 void BESDapTransmit::send_http_data(BESResponseObject * obj,
00152                                     BESDataHandlerInterface & dhi)
00153 {
00154     //set_mime_binary( dhi.get_output_stream(), dods_data ) ;
00155     BESDapTransmit::send_basic_data(obj, dhi);
00156 }
00157 
00158 void BESDapTransmit::send_basic_ddx(BESResponseObject * obj,
00159                                     BESDataHandlerInterface & dhi)
00160 {
00161     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(obj);
00162     DDS *dds = bdds->get_dds();
00163     ConstraintEvaluator & ce = bdds->get_ce();
00164     dhi.first_container();
00165 
00166     try {
00167         DODSFilter df;
00168         df.set_dataset_name(dhi.container->get_real_name());
00169         df.set_ce(dhi.data[POST_CONSTRAINT]);
00170         df.send_ddx(*dds, ce, dhi.get_output_stream(), false);
00171         dhi.get_output_stream() << flush ;
00172     }
00173     catch(Error & e) {
00174         ostringstream s;
00175         s << "libdap exception transmitting DDX"
00176             << ": error_code = " << e.get_error_code()
00177             << ": " << e.get_error_message();
00178         BESTransmitException ex(s.str(), __FILE__, __LINE__);
00179         throw ex;
00180     }
00181     catch(...) {
00182         string s = "unknown exception caught transmitting DAS";
00183         BESTransmitException ex(s, __FILE__, __LINE__);
00184         throw ex;
00185     }
00186 }
00187 
00188 void BESDapTransmit::send_http_ddx(BESResponseObject * obj,
00189                                    BESDataHandlerInterface & dhi)
00190 {
00191     set_mime_text(dhi.get_output_stream(), dods_dds);
00192     BESDapTransmit::send_basic_ddx(obj, dhi);
00193 }

Generated on Fri Nov 30 12:06:46 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1