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 "BESDapNames.h"
00045 #include "CSVRequestHandler.h"
00046 #include "BESResponseHandler.h"
00047 #include "BESResponseNames.h"
00048 #include "CSVResponseNames.h"
00049 #include "BESVersionInfo.h"
00050 #include "BESTextInfo.h"
00051 #include "BESDASResponse.h"
00052 #include "BESDDSResponse.h"
00053 #include "BESDataDDSResponse.h"
00054 #include "DDS.h"
00055 #include "DDS.h"
00056 #include "DAS.h"
00057 #include "BaseTypeFactory.h"
00058 #include "BESConstraintFuncs.h"
00059 #include "InternalErr.h"
00060 #include "BESDapError.h"
00061 #include "BESDebug.h"
00062 
00063 #include "CSVDDS.h"
00064 #include "CSVDAS.h"
00065 
00066 CSVRequestHandler::CSVRequestHandler( string name )
00067     : BESRequestHandler( name )
00068 {
00069     add_handler( DAS_RESPONSE, CSVRequestHandler::csv_build_das ) ;
00070     add_handler( DDS_RESPONSE, CSVRequestHandler::csv_build_dds ) ;
00071     add_handler( DATA_RESPONSE, CSVRequestHandler::csv_build_data ) ;
00072     add_handler( VERS_RESPONSE, CSVRequestHandler::csv_build_vers ) ;
00073     add_handler( HELP_RESPONSE, CSVRequestHandler::csv_build_help ) ;
00074 }
00075 
00076 CSVRequestHandler::~CSVRequestHandler()
00077 {
00078 }
00079 
00080 bool
00081 CSVRequestHandler::csv_build_das( BESDataHandlerInterface &dhi )
00082 {
00083     string error ;
00084     bool ret = true ;
00085     BESResponseObject *response =
00086         dhi.response_handler->get_response_object() ;
00087     BESDASResponse *bdas = dynamic_cast < BESDASResponse * >(response) ;
00088     DAS *das = 0 ;
00089     if (bdas)
00090         das = bdas->get_das() ;
00091     else
00092         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00093   
00094     try
00095     {
00096         csv_read_attributes(*das, dhi.container->access());
00097         return ret;
00098     }
00099     catch(InternalErr &e)
00100     {
00101         BESDapError ex( e.get_error_message(), true,
00102                         e.get_error_code(), __FILE__, __LINE__ ) ;
00103         throw ex ;
00104     }
00105     catch(Error &e)
00106     {
00107         BESDapError ex( e.get_error_message(), false,
00108                         e.get_error_code(), __FILE__, __LINE__);
00109         throw ex;
00110     }
00111     catch(...)
00112     {
00113         BESDapError ex( "Caught unknown error build CSV DAS response", true,
00114                         unknown_error, __FILE__, __LINE__);
00115         throw ex;
00116     }
00117 }
00118 
00119 bool
00120 CSVRequestHandler::csv_build_dds( BESDataHandlerInterface &dhi )
00121 {
00122     bool ret = true ;
00123     BESResponseObject *response =
00124         dhi.response_handler->get_response_object();
00125     BESDDSResponse *bdds = dynamic_cast < BESDDSResponse * >(response);
00126     DDS *dds = 0 ;
00127     if (bdds)
00128         dds = bdds->get_dds();
00129     else
00130         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00131   
00132     BaseTypeFactory *factory = new BaseTypeFactory ;
00133     dds->set_factory(factory);
00134     
00135     try
00136     {
00137         string accessed = dhi.container->access() ;
00138         dds->filename( accessed ) ;
00139         csv_read_descriptors( *dds, accessed ) ;
00140 
00141         DAS das;
00142         csv_read_attributes(das, accessed);
00143         dds->transfer_attributes( &das ) ;
00144 
00145         BESDEBUG( "csv", "dds = " << endl << *dds << endl ) ;
00146         dhi.data[POST_CONSTRAINT] = dhi.container->get_constraint();
00147 
00148         return ret;
00149   }
00150     catch(InternalErr &e)
00151     {
00152         BESDapError ex( e.get_error_message(), true,
00153                         e.get_error_code(), __FILE__, __LINE__);
00154         throw ex;
00155     }
00156     catch(Error &e)
00157     {
00158         BESDapError ex( e.get_error_message(), false,
00159                         e.get_error_code(), __FILE__, __LINE__);
00160         throw ex;
00161     }
00162     catch(...)
00163     {
00164         BESDapError ex( "Caught unknown error build CSV DDS response", true,
00165                         unknown_error, __FILE__, __LINE__);
00166         throw ex;
00167     }
00168 }
00169 
00170 bool
00171 CSVRequestHandler::csv_build_data( BESDataHandlerInterface &dhi )
00172 {
00173     bool ret = true ;
00174     BESResponseObject *response =
00175         dhi.response_handler->get_response_object();
00176     BESDataDDSResponse *bdds =
00177         dynamic_cast < BESDataDDSResponse * >(response);
00178     DataDDS *dds = 0 ;
00179     if (bdds)
00180         dds = bdds->get_dds();
00181     else
00182         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00183   
00184     BaseTypeFactory *factory = new BaseTypeFactory ;
00185     dds->set_factory(factory);
00186 
00187     try
00188     {
00189         string accessed = dhi.container->access() ;
00190         dds->filename( accessed ) ;
00191         csv_read_descriptors(*dds, accessed);
00192 
00193         DAS das;
00194         csv_read_attributes(das, accessed);
00195         dds->transfer_attributes( &das ) ;
00196 
00197         BESDEBUG( "csv", "dds = " << endl << *dds << endl ) ;
00198         dhi.data[POST_CONSTRAINT] = dhi.container->get_constraint();
00199         return ret;
00200     }
00201     catch(InternalErr &e)
00202     {
00203         BESDapError ex( e.get_error_message(), true,
00204                         e.get_error_code(), __FILE__, __LINE__);
00205         throw ex;
00206     }
00207     catch(Error &e)
00208     {
00209         BESDapError ex( e.get_error_message(), false,
00210                         e.get_error_code(), __FILE__, __LINE__);
00211         throw ex;
00212     }
00213     catch(...)
00214     {
00215         BESDapError ex( "Caught unknown error build CSV DataDDS response", true,
00216                         unknown_error, __FILE__, __LINE__);
00217         throw ex;
00218     }
00219 }
00220 
00221 bool
00222 CSVRequestHandler::csv_build_vers( BESDataHandlerInterface &dhi )
00223 {
00224     bool ret = true ;
00225 
00226     BESResponseObject *response =
00227         dhi.response_handler->get_response_object();
00228     BESVersionInfo *info = dynamic_cast < BESVersionInfo * >(response);
00229     if( !info )
00230         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00231   
00232     info->add_module( PACKAGE_NAME, PACKAGE_VERSION ) ;
00233     return ret ;
00234 }
00235 
00236 bool
00237 CSVRequestHandler::csv_build_help( BESDataHandlerInterface &dhi )
00238 {
00239     bool ret = true ;
00240     BESInfo *info =
00241         dynamic_cast<BESInfo *>(dhi.response_handler->get_response_object());
00242     if( !info )
00243         throw BESInternalError( "cast error", __FILE__, __LINE__ ) ;
00244 
00245     map<string,string> attrs ;
00246     attrs["name"] = PACKAGE_NAME ;
00247     attrs["version"] = PACKAGE_VERSION ;
00248     string handles = (string) DAS_RESPONSE
00249         + "," + DDS_RESPONSE
00250         + "," + DATA_RESPONSE
00251         + "," + HELP_RESPONSE
00252         + "," + VERS_RESPONSE;
00253     attrs["handles"] = handles ;
00254     info->begin_tag( "module", &attrs ) ;
00255     info->end_tag( "module" ) ;
00256 
00257     return ret ;
00258 }
00259 
00260 void
00261 CSVRequestHandler::dump( ostream &strm ) const
00262 {
00263     strm << BESIndent::LMarg << "CSVRequestHandler::dump - ("
00264                              << (void *)this << ")" << endl ;
00265     BESIndent::Indent() ;
00266     BESRequestHandler::dump( strm ) ;
00267     BESIndent::UnIndent() ;
00268 }
00269 

Generated on Thu Feb 11 09:13:16 2010 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.4.7