CSVRequestHandler.cc

Go to the documentation of this file.
00001 // CSVRequestHandler.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: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
00008 // and Jose Garcia <jgarcia@ucar.edu>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact University Corporation for Atmospheric Research at
00025 // 3080 Center Green Drive, Boulder, CO 80301
00026  
00027 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00028 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00029 //
00030 // Authors:
00031 //      zednik      Stephan Zednik <zednik@ucar.edu>
00032 //      pwest       Patrick West <pwest@ucar.edu>
00033 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00034 
00035 #include "config.h"
00036 
00037 #include "BESDASResponse.h"
00038 #include "BESDDSResponse.h"
00039 #include "BESDataDDSResponse.h"
00040 #include "BESInfo.h"
00041 #include "BESContainer.h"
00042 #include "BESVersionInfo.h"
00043 #include "BESDataNames.h"
00044 #include "CSVRequestHandler.h"
00045 #include "BESResponseHandler.h"
00046 #include "BESResponseNames.h"
00047 #include "CSVResponseNames.h"
00048 #include "BESVersionInfo.h"
00049 #include "BESTextInfo.h"
00050 #include "BESDASResponse.h"
00051 #include "BESDDSResponse.h"
00052 #include "BESDataDDSResponse.h"
00053 #include "DDS.h"
00054 #include "DDS.h"
00055 #include "DAS.h"
00056 #include "BaseTypeFactory.h"
00057 #include "BESConstraintFuncs.h"
00058 #include "InternalErr.h"
00059 #include "BESDapError.h"
00060 #include "BESDebug.h"
00061 
00062 #include "CSVDDS.h"
00063 #include "CSVDAS.h"
00064 
00065 CSVRequestHandler::CSVRequestHandler( string name )
00066     : BESRequestHandler( name )
00067 {
00068     add_handler( DAS_RESPONSE, CSVRequestHandler::csv_build_das ) ;
00069     add_handler( DDS_RESPONSE, CSVRequestHandler::csv_build_dds ) ;
00070     add_handler( DATA_RESPONSE, CSVRequestHandler::csv_build_data ) ;
00071     add_handler( VERS_RESPONSE, CSVRequestHandler::csv_build_vers ) ;
00072     add_handler( HELP_RESPONSE, CSVRequestHandler::csv_build_help ) ;
00073 }
00074 
00075 CSVRequestHandler::~CSVRequestHandler()
00076 {
00077 }
00078 
00079 bool
00080 CSVRequestHandler::csv_build_das( BESDataHandlerInterface &dhi )
00081 {
00082     string error ;
00083     bool ret = true ;
00084     BESResponseObject *response =
00085         dhi.response_handler->get_response_object() ;
00086     BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(response) ;
00087     DAS *das = 0 ;
00088     if (bdas)
00089         das = bdas->get_das() ;
00090     else
00091         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00092   
00093     try
00094     {
00095         csv_read_attributes(*das, dhi.container->access());
00096         return ret;
00097     }
00098     catch(InternalErr &e)
00099     {
00100         BESDapError ex( e.get_error_message(), true,
00101                         e.get_error_code(), __FILE__, __LINE__ ) ;
00102         throw ex ;
00103     }
00104     catch(Error &e)
00105     {
00106         BESDapError ex( e.get_error_message(), false,
00107                         e.get_error_code(), __FILE__, __LINE__);
00108         throw ex;
00109     }
00110     catch(...)
00111     {
00112         BESDapError ex( "Caught unknown error build CSV DAS response", true,
00113                         unknown_error, __FILE__, __LINE__);
00114         throw ex;
00115     }
00116 }
00117 
00118 bool
00119 CSVRequestHandler::csv_build_dds( BESDataHandlerInterface &dhi )
00120 {
00121     bool ret = true ;
00122     BESResponseObject *response =
00123         dhi.response_handler->get_response_object();
00124     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(response);
00125     DDS *dds = 0 ;
00126     if (bdds)
00127         dds = bdds->get_dds();
00128     else
00129         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00130   
00131     BaseTypeFactory *factory = new BaseTypeFactory ;
00132     dds->set_factory(factory);
00133     
00134     try
00135     {
00136         string accessed = dhi.container->access() ;
00137         dds->filename( accessed ) ;
00138         csv_read_descriptors( *dds, accessed ) ;
00139 
00140         DAS das;
00141         csv_read_attributes(das, accessed);
00142         dds->transfer_attributes( &das ) ;
00143 
00144         BESDEBUG( "csv", "dds = " << endl << *dds << endl )
00145         dhi.data[POST_CONSTRAINT] = dhi.container->get_constraint();
00146 
00147         return ret;
00148   }
00149     catch(InternalErr &e)
00150     {
00151         BESDapError ex( e.get_error_message(), true,
00152                         e.get_error_code(), __FILE__, __LINE__);
00153         throw ex;
00154     }
00155     catch(Error &e)
00156     {
00157         BESDapError ex( e.get_error_message(), false,
00158                         e.get_error_code(), __FILE__, __LINE__);
00159         throw ex;
00160     }
00161     catch(...)
00162     {
00163         BESDapError ex( "Caught unknown error build CSV DDS response", true,
00164                         unknown_error, __FILE__, __LINE__);
00165         throw ex;
00166     }
00167 }
00168 
00169 bool
00170 CSVRequestHandler::csv_build_data( BESDataHandlerInterface &dhi )
00171 {
00172     bool ret = true ;
00173     BESResponseObject *response =
00174         dhi.response_handler->get_response_object();
00175     BESDataDDSResponse *bdds =
00176         dynamic_cast < BESDataDDSResponse * >(response);
00177     DataDDS *dds = 0 ;
00178     if (bdds)
00179         dds = bdds->get_dds();
00180     else
00181         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00182   
00183     BaseTypeFactory *factory = new BaseTypeFactory ;
00184     dds->set_factory(factory);
00185 
00186     try
00187     {
00188         string accessed = dhi.container->access() ;
00189         dds->filename( accessed ) ;
00190         csv_read_descriptors(*dds, accessed);
00191 
00192         DAS das;
00193         csv_read_attributes(das, accessed);
00194         dds->transfer_attributes( &das ) ;
00195 
00196         BESDEBUG( "csv", "dds = " << endl << *dds << endl )
00197         dhi.data[POST_CONSTRAINT] = dhi.container->get_constraint();
00198         return ret;
00199     }
00200     catch(InternalErr &e)
00201     {
00202         BESDapError ex( e.get_error_message(), true,
00203                         e.get_error_code(), __FILE__, __LINE__);
00204         throw ex;
00205     }
00206     catch(Error &e)
00207     {
00208         BESDapError ex( e.get_error_message(), false,
00209                         e.get_error_code(), __FILE__, __LINE__);
00210         throw ex;
00211     }
00212     catch(...)
00213     {
00214         BESDapError ex( "Caught unknown error build CSV DataDDS response", true,
00215                         unknown_error, __FILE__, __LINE__);
00216         throw ex;
00217     }
00218 }
00219 
00220 bool
00221 CSVRequestHandler::csv_build_vers( BESDataHandlerInterface &dhi )
00222 {
00223     bool ret = true ;
00224 
00225     BESResponseObject *response =
00226         dhi.response_handler->get_response_object();
00227     BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response);
00228     if( !info )
00229         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00230   
00231     info->add_module( PACKAGE_NAME, PACKAGE_VERSION ) ;
00232     return ret ;
00233 }
00234 
00235 bool
00236 CSVRequestHandler::csv_build_help( BESDataHandlerInterface &dhi )
00237 {
00238     bool ret = true ;
00239     BESInfo *info =
00240         dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
00241     if( !info )
00242         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00243 
00244     map<string,string> attrs ;
00245     attrs["name"] = PACKAGE_NAME ;
00246     attrs["version"] = PACKAGE_VERSION ;
00247     string handles = (string) DAS_RESPONSE
00248         + "," + DDS_RESPONSE
00249         + "," + DATA_RESPONSE
00250         + "," + HELP_RESPONSE
00251         + "," + VERS_RESPONSE;
00252     attrs["handles"] = handles ;
00253     info->begin_tag( "module", &attrs ) ;
00254     info->end_tag( "module" ) ;
00255 
00256     return ret ;
00257 }
00258 
00259 void
00260 CSVRequestHandler::dump( ostream &strm ) const
00261 {
00262     strm << BESIndent::LMarg << "CSVRequestHandler::dump - ("
00263                              << (void *)this << ")" << endl ;
00264     BESIndent::Indent() ;
00265     BESRequestHandler::dump( strm ) ;
00266     BESIndent::UnIndent() ;
00267 }
00268 

Generated on 18 Feb 2010 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.1