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 <sstream>
00034
00035 using std::istringstream ;
00036
00037 #include "BESShowErrorResponseHandler.h"
00038 #include "BESDataNames.h"
00039 #include "BESInternalError.h"
00040 #include "BESInternalFatalError.h"
00041 #include "BESSyntaxUserError.h"
00042 #include "BESForbiddenError.h"
00043 #include "BESNotFoundError.h"
00044
00045 BESShowErrorResponseHandler::BESShowErrorResponseHandler( const string &name )
00046 : BESResponseHandler( name )
00047 {
00048 }
00049
00050 BESShowErrorResponseHandler::~BESShowErrorResponseHandler( )
00051 {
00052 }
00053
00068 void
00069 BESShowErrorResponseHandler::execute( BESDataHandlerInterface &dhi )
00070 {
00071 string etype_s = dhi.data[SHOW_ERROR_TYPE] ;
00072 if( etype_s.empty() )
00073 {
00074 string err = dhi.action + " error type missing" ;
00075 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00076 }
00077 istringstream strm( etype_s ) ;
00078 unsigned int etype = 0 ;
00079 strm >> etype ;
00080 if( !etype || etype > 5 )
00081 {
00082 string err = dhi.action + " invalid error type, should be 1-5" ;
00083 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00084 }
00085 switch( etype )
00086 {
00087 case BES_INTERNAL_ERROR:
00088 {
00089 string err = dhi.action + " Internal Error" ;
00090 throw BESInternalError( err, __FILE__, __LINE__ ) ;
00091 break ;
00092 }
00093 case BES_INTERNAL_FATAL_ERROR:
00094 {
00095 string err = dhi.action + " Internal Fatal Error" ;
00096 throw BESInternalFatalError( err, __FILE__, __LINE__ ) ;
00097 break ;
00098 }
00099 case BES_SYNTAX_USER_ERROR:
00100 {
00101 string err = dhi.action + " Syntax User Error" ;
00102 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00103 break ;
00104 }
00105 case BES_FORBIDDEN_ERROR:
00106 {
00107 string err = dhi.action + " Forbidden Error" ;
00108 throw BESForbiddenError( err, __FILE__, __LINE__ ) ;
00109 break ;
00110 }
00111 case BES_NOT_FOUND_ERROR:
00112 {
00113 string err = dhi.action + " Not Found Error" ;
00114 throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
00115 break ;
00116 }
00117 }
00118 }
00119
00132 void
00133 BESShowErrorResponseHandler::transmit( BESTransmitter *transmitter,
00134 BESDataHandlerInterface &dhi )
00135 {
00136 string err = "An exception should have been thrown, nothing to transmit" ;
00137 throw BESInternalError( err, __FILE__, __LINE__ ) ;
00138 }
00139
00146 void
00147 BESShowErrorResponseHandler::dump( ostream &strm ) const
00148 {
00149 strm << BESIndent::LMarg << "BESShowErrorResponseHandler::dump - ("
00150 << (void *)this << ")" << endl ;
00151 BESIndent::Indent() ;
00152 BESResponseHandler::dump( strm ) ;
00153 BESIndent::UnIndent() ;
00154 }
00155
00156 BESResponseHandler *
00157 BESShowErrorResponseHandler::ResponseBuilder( const string &name )
00158 {
00159 return new BESShowErrorResponseHandler( name ) ;
00160 }
00161