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         vector<string> vals ;
00118         string key = "BES.ServerAdministrator" ;
00119         TheBESKeys::TheKeys()->get_value( key, administrator, found ) ;
00120     }
00121     catch( ... )
00122     {
00123         administrator = DEFAULT_ADMINISTRATOR ;
00124     }
00125     if( administrator.empty() )
00126     {
00127         administrator = DEFAULT_ADMINISTRATOR ;
00128     }
00129     dhi.error_info->add_exception( e, administrator ) ;
00130     dhi.error_info->end_response() ;
00131     return e.get_error_type() ;
00132 }
00133 
00143 void
00144 BESExceptionManager::dump( ostream &strm ) const
00145 {
00146     strm << BESIndent::LMarg << "BESExceptionManager::dump - ("
00147                              << (void *)this << ")" << endl ;
00148     BESIndent::Indent() ;
00149     strm << BESIndent::LMarg << "# registered callbacks: " << _ehm_list.size() << endl ;
00150     BESIndent::UnIndent() ;
00151 }
00152 
00153 BESExceptionManager *
00154 BESExceptionManager::TheEHM()
00155 {
00156     if( _instance == 0 )
00157     {
00158         _instance = new BESExceptionManager( ) ;
00159     }
00160     return _instance ;
00161 }
00162 

Generated on Wed May 12 09:53:07 2010 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.4.7