BESExceptionManager.cc

Go to the documentation of this file.
00001 // BESExceptionManager.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 "BESExceptionManager.h"
00034 
00035 #include "BESError.h"
00036 #include "TheBESKeys.h"
00037 #include "BESInfoList.h"
00038 
00039 #define DEFAULT_ADMINISTRATOR "support@opendap.org"
00040 
00041 BESExceptionManager *BESExceptionManager::_instance = 0 ;
00042 
00043 BESExceptionManager::BESExceptionManager()
00044 {
00045 }
00046 
00047 BESExceptionManager::~BESExceptionManager()
00048 {
00049 }
00050 
00064 void
00065 BESExceptionManager::add_ehm_callback( p_bes_ehm ehm )
00066 {
00067     _ehm_list.push_back( ehm ) ;
00068 }
00069 
00090 int
00091 BESExceptionManager::handle_exception( BESError &e,
00092                                        BESDataHandlerInterface &dhi )
00093 {
00094     // Let's see if any of these exception callbacks can handle the
00095     // exception. The first callback that can handle the exception wins
00096     ehm_iter i = _ehm_list.begin() ;
00097     for( ; i != _ehm_list.end(); i++ )
00098     {
00099         p_bes_ehm p = *i ;
00100         int handled = p( e, dhi ) ;
00101         if( handled )
00102         {
00103             return handled ;
00104         }
00105     }
00106 
00107     dhi.error_info = BESInfoList::TheList()->build_info() ;
00108     string action_name = dhi.action_name ;
00109     if( action_name == "" )
00110         action_name = "BES" ;
00111     dhi.error_info->begin_response( action_name, dhi ) ;
00112 
00113     string administrator = "" ;
00114     try
00115     {
00116         bool found = false ;
00117         administrator =
00118             TheBESKeys::TheKeys()->get_key( "BES.ServerAdministrator", found ) ;
00119     }
00120     catch( ... )
00121     {
00122         administrator = DEFAULT_ADMINISTRATOR ;
00123     }
00124     dhi.error_info->add_exception( e, administrator ) ;
00125     dhi.error_info->end_response() ;
00126     return e.get_error_type() ;
00127 }
00128 
00138 void
00139 BESExceptionManager::dump( ostream &strm ) const
00140 {
00141     strm << BESIndent::LMarg << "BESExceptionManager::dump - ("
00142                              << (void *)this << ")" << endl ;
00143     BESIndent::Indent() ;
00144     strm << BESIndent::LMarg << "# registered callbacks: " << _ehm_list.size() << endl ;
00145     BESIndent::UnIndent() ;
00146 }
00147 
00148 BESExceptionManager *
00149 BESExceptionManager::TheEHM()
00150 {
00151     if( _instance == 0 )
00152     {
00153         _instance = new BESExceptionManager( ) ;
00154     }
00155     return _instance ;
00156 }
00157 

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