BESExceptionManager.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00095
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