ALMA Computing Group

acsexmplClientErrorComponent.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 *    ALMA - Atacama Large Millimiter Array
00003 *    (c) European Southern Observatory, 2002
00004 *    Copyright by ESO (in the framework of the ALMA collaboration)
00005 *    and Cosylab 2002, All rights reserved
00006 *
00007 *    This library is free software; you can redistribute it and/or
00008 *    modify it under the terms of the GNU Lesser General Public
00009 *    License as published by the Free Software Foundation; either
00010 *    version 2.1 of the License, or (at your option) any later version.
00011 *
00012 *    This library is distributed in the hope that it will be useful,
00013 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 *    Lesser General Public License for more details.
00016 *
00017 *    You should have received a copy of the GNU Lesser General Public
00018 *    License along with this library; if not, write to the Free Software
00019 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 *
00022 *
00023 * "@(#) $Id: acsexmplClientErrorComponent.cpp,v 1.13 2008/10/09 08:41:11 cparedes Exp $"
00024 *
00025 * who       when      what
00026 * --------  --------  ----------------------------------------------
00027 * david 2002-10-31 created
00028 */
00029 
00053 
00058 
00097 #include <maciSimpleClient.h>
00098 #include <acsexmplErrorComponentC.h>
00099 #include <ACSErrTypeCommon.h>
00100 #include <acsutilTimeStamp.h>
00101 #include <string.h>
00102 
00103 ACE_RCSID(acsexmpl, acsexmplErrorComponentClient, "$Id: acsexmplClientErrorComponent.cpp,v 1.13 2008/10/09 08:41:11 cparedes Exp $")
00104 using namespace maci;
00105 
00106 /*******************************************************************************/
00107 
00124 class ClientErrorComponent
00125 {
00126   public:
00130     ClientErrorComponent(SimpleClient &client, char *errorComponent) ;
00131     virtual ~ClientErrorComponent();
00132 
00137     void TestOk();
00138 
00149     void TestReceiveRemoteException() ;
00150 
00161     void TestReceiveRemoteCompletion();
00162 
00173     void testExceptionFromCompletion();
00174 
00185     void testTypeException();
00196     void TestReceiveCorbaSystemException();
00197 
00208     void testCompletionFromCompletion(); 
00209 
00220     void testCompletionOnStack(); 
00221 
00222 
00227     void testOutCompletion(); 
00228 
00229   private:
00230     SimpleClient &client_m;
00231     std::string   errorComponent_m;
00232     acsexmplErrorComponent::ErrorComponent_var foo_m;
00233 };
00234 
00238 ClientErrorComponent::ClientErrorComponent(SimpleClient &client, 
00239                                            char *errorComponent): 
00240     client_m(client), errorComponent_m(errorComponent)
00241 {
00242     ACS_TRACE("ClientErrorComponent::ClientErrorComponent");
00243 
00244     try
00245         {
00246     /*
00247      * Get the specific component we have requested
00248      * Add exception handling.
00249      */
00250 
00251     foo_m = 
00252         client_m.getComponent<acsexmplErrorComponent::ErrorComponent>(errorComponent_m.c_str(), 0, true);    
00253         }
00254     catch(maciErrType::CannotGetComponentExImpl &_ex)
00255         {
00256         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(_ex,
00257                                                              __FILE__, __LINE__,
00258                                                              "ClientErrorComponent::ClientErrorComponent");
00259         
00260         }//try-catch
00261 }//ClientErrorComponent
00262 
00263 ClientErrorComponent::~ClientErrorComponent()
00264 { 
00265     ACS_TRACE("ClientErrorComponent::~ClientErrorComponent");
00266 
00267     try
00268         {
00269    /*
00270      * Release the component
00271      */
00272     client_m.releaseComponent( errorComponent_m.c_str());
00273         }
00274     catch(maciErrType::CannotReleaseComponentExImpl &_ex)
00275         {
00276         _ex.log();
00277         }
00278 }//~ClientErrorComponent
00279 
00283 void ClientErrorComponent::TestOk() 
00284 {
00285     ACS_TRACE("ClientErrorComponent::TestOk");
00286     if (CORBA::is_nil(foo_m.in()) == true)
00287         {
00288         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00289                                    __FILE__, __LINE__,
00290                                    "ClientErrorComponent::TestOk");
00291         }
00292 
00293     try
00294         {
00295         foo_m->displayMessage();
00296         }
00297     catch(CORBA::SystemException &ex)
00298         {
00299         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00300                                    __FILE__, __LINE__,
00301                                    "ClientErrorComponent::TestOk");
00302         corbaProblemEx.setMinor(ex.minor());
00303         corbaProblemEx.setCompletionStatus(ex.completed());
00304         corbaProblemEx.setInfo(ex._info().c_str());
00305         corbaProblemEx.log();
00306         }
00307     catch(...)
00308         {
00309         ACSErrTypeCommon::GenericErrorExImpl displayMessageEx(__FILE__, __LINE__,
00310                                                  "ClientErrorComponent::TestReceiveRemoteException");
00311         displayMessageEx.setErrorDesc("UNEXPECTED: displayMessage has thrown an UNEXPECTED exception");
00312         displayMessageEx.log();
00313         }
00314 }
00315 
00316 void ClientErrorComponent::TestReceiveRemoteException() 
00317 {
00318     ACS_TRACE("ClientErrorComponent::TestReceiveRemoteException");
00319 
00320     if (CORBA::is_nil(foo_m.in()) == true)
00321         {
00322         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00323                                    __FILE__, __LINE__,
00324                                    "ClientErrorComponent::TestReceiveRemoteException");
00325         }
00326     ACS_SHORT_LOG((LM_INFO, "Example 1: Calls a method that throws an exception."));
00327     try
00328         {
00329         foo_m->badMethod(5);
00330         ACS_SHORT_LOG((LM_INFO, "UNEXPECTED: should have thrown an exception"));
00331         }
00332     catch(ACSErrTypeCommon::GenericErrorEx &ex)
00333         {
00334         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex,
00335                                    __FILE__, __LINE__,
00336                                    "ClientErrorComponent::TestReceiveRemoteException");
00337         badMethodEx.setErrorDesc("badMethod has thrown the expected exception");
00338         badMethodEx.log();
00339 
00340         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00341         ACE_CString tString = getStringifiedUTC(timeStamp);
00342         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00343                         "Time of the exception: %s\n", tString.c_str());
00344         }
00345     catch(CORBA::SystemException &ex)
00346         {
00347         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00348                                    __FILE__, __LINE__,
00349                                    "ClientErrorComponent::TestReceiveRemoteException");
00350         corbaProblemEx.setMinor(ex.minor());
00351         corbaProblemEx.setCompletionStatus(ex.completed());
00352         corbaProblemEx.setInfo(ex._info().c_str());
00353         corbaProblemEx.log();
00354 
00355         //Is this really necessary? The exceptions already have a timeStamp
00356         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00357         ACE_CString tString = getStringifiedUTC(timeStamp);
00358         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00359                         "Time of the CORBA exception: %s\n", tString.c_str());
00360         }
00361     catch(...)
00362         {
00363         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00364                                                  "ClientErrorComponent::TestReceiveRemoteException");
00365         badMethodEx.setErrorDesc("badMethod has thrown an UNEXPECTED exception");
00366         badMethodEx.log();
00367 
00368         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00369         ACE_CString tString = getStringifiedUTC(timeStamp);
00370         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00371                         "Time of the unexpected exception: %s\n", tString.c_str());
00372         }
00373 
00374 }
00375 void ClientErrorComponent::testTypeException() 
00376 {
00377     ACS_TRACE("ClientErrorComponent::testTypeException");
00378 
00379     if (CORBA::is_nil(foo_m.in()) == true)
00380         {
00381         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00382                                    __FILE__, __LINE__,
00383                                    "ClientErrorComponent::testTypeException");
00384         }
00385     ACS_SHORT_LOG((LM_INFO, "Example 4a: typeException with depth 0"));
00386     try
00387         {
00388         foo_m->typeException(0);
00389         ACS_SHORT_LOG((LM_INFO, "OK: No exception thrown"));
00390         }
00391     catch(ACSErrTypeCommon::GenericErrorEx &ex)
00392         {
00393         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex,
00394                                    __FILE__, __LINE__,
00395                                    "ClientErrorComponent::testTypeException");
00396         badMethodEx.setErrorDesc("UNEXPECTED: shouldn't have thrown an exception");
00397         badMethodEx.log();
00398 
00399         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00400         ACE_CString tString = getStringifiedUTC(timeStamp);
00401         ACS_DEBUG_PARAM("ClientErrorComponent::testTypeException", 
00402                         "Time of the exception: %s\n", tString.c_str());
00403         }
00404     catch(CORBA::SystemException &ex)
00405         {
00406         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00407                                    __FILE__, __LINE__,
00408                                    "ClientErrorComponent::TestTypeException");
00409         corbaProblemEx.setMinor(ex.minor());
00410         corbaProblemEx.setCompletionStatus(ex.completed());
00411         corbaProblemEx.setInfo(ex._info().c_str());
00412         corbaProblemEx.log();
00413 
00414         //Is this really necessary? The exceptions already have a timeStamp
00415         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00416         ACE_CString tString = getStringifiedUTC(timeStamp);
00417         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00418                         "Time of the CORBA exception: %s\n", tString.c_str());
00419         }
00420     catch(...)
00421         {
00422         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00423                                                  "ClientErrorComponent::testTypeException");
00424         badMethodEx.setErrorDesc("UNEXPECTED: typeException has thrown an UNKNOWN exception");
00425         badMethodEx.log();
00426 
00427         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00428         ACE_CString tString = getStringifiedUTC(timeStamp);
00429         ACS_DEBUG_PARAM("ClientErrorComponent::testTypeException", 
00430                         "Time of the unexpected exception: %s\n", tString.c_str());
00431         }
00432     ACS_SHORT_LOG((LM_INFO, "Example 4b: typeException with depth 5"));
00433     try
00434         {
00435         foo_m->typeException(5);
00436         ACS_SHORT_LOG((LM_INFO, "UNEXPECTED: should have thrown an exception"));
00437         }
00438     catch(ACSErrTypeCommon::ACSErrTypeCommonEx &ex)
00439         {
00440         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex,
00441                                    __FILE__, __LINE__,
00442                                    "ClientErrorComponent::testTypeException");
00443         badMethodEx.setErrorDesc("typeException has thrown the expected exception");
00444         badMethodEx.log();
00445 
00446         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00447         ACE_CString tString = getStringifiedUTC(timeStamp);
00448         ACS_DEBUG_PARAM("ClientErrorComponent::testTypeException", 
00449                         "Time of the exception: %s\n", tString.c_str());
00450         }
00451     catch(CORBA::SystemException &ex)
00452         {
00453         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00454                                    __FILE__, __LINE__,
00455                                    "ClientErrorComponent::TestReceiveRemoteException");
00456         corbaProblemEx.setMinor(ex.minor());
00457         corbaProblemEx.setCompletionStatus(ex.completed());
00458         corbaProblemEx.setInfo(ex._info().c_str());
00459         corbaProblemEx.log();
00460 
00461         //Is this really necessary? The exceptions already have a timeStamp
00462         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00463         ACE_CString tString = getStringifiedUTC(timeStamp);
00464         ACS_DEBUG_PARAM("ClientErrorComponent::testTypeException", 
00465                         "Time of the CORBA exception: %s\n", tString.c_str());
00466         }
00467     catch(...)
00468         {
00469         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00470                                                  "ClientErrorComponent::testTypeException");
00471         badMethodEx.setErrorDesc("typeException has thrown an UNEXPECTED exception");
00472         badMethodEx.log();
00473 
00474         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00475         ACE_CString tString = getStringifiedUTC(timeStamp);
00476         ACS_DEBUG_PARAM("ClientErrorComponent::testTypeException", 
00477                         "Time of the unexpected exception: %s\n", tString.c_str());
00478         }
00479 
00480 }
00481 void ClientErrorComponent::testExceptionFromCompletion() 
00482 {
00483     ACS_TRACE("ClientErrorComponent::testExceptionFromCompletion");
00484 
00485     if (CORBA::is_nil(foo_m.in()) == true)
00486         {
00487         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00488                                    __FILE__, __LINE__,
00489                                    "ClientErrorComponent::testExceptionFromCompletion");
00490         }
00491     ACS_SHORT_LOG((LM_INFO, "Example 3a: ExceptionFromCompletion with depth 0"));
00492     try
00493         {
00494         foo_m->exceptionFromCompletion(0);
00495         ACS_SHORT_LOG((LM_INFO, "OK: No exception thrown"));
00496         }
00497     catch(ACSErrTypeCommon::GenericErrorEx &ex)
00498         {
00499         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex,
00500                                    __FILE__, __LINE__,
00501                                    "ClientErrorComponent::testExceptionFromCompletion");
00502         badMethodEx.setErrorDesc("UNEXPECTED: shouldn't have thrown an exception");
00503         badMethodEx.log();
00504 
00505         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00506         ACE_CString tString = getStringifiedUTC(timeStamp);
00507         ACS_DEBUG_PARAM("ClientErrorComponent::testExceptionFromCompletion", 
00508                         "Time of the exception: %s\n", tString.c_str());
00509         }
00510     catch(CORBA::SystemException &ex)
00511         {
00512         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00513                                    __FILE__, __LINE__,
00514                                    "ClientErrorComponent::TestExceptionFromCompletion");
00515         corbaProblemEx.setMinor(ex.minor());
00516         corbaProblemEx.setCompletionStatus(ex.completed());
00517         corbaProblemEx.setInfo(ex._info().c_str());
00518         corbaProblemEx.log();
00519 
00520         //Is this really necessary? The exceptions already have a timeStamp
00521         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00522         ACE_CString tString = getStringifiedUTC(timeStamp);
00523         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00524                         "Time of the CORBA exception: %s\n", tString.c_str());
00525         }
00526     catch(...)
00527         {
00528         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00529                                                  "ClientErrorComponent::testExceptionFromCompletion");
00530         badMethodEx.setErrorDesc("UNEXPECTED: exceptionFromCompletion has thrown an UNKNOWN exception");
00531         badMethodEx.log();
00532 
00533         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00534         ACE_CString tString = getStringifiedUTC(timeStamp);
00535         ACS_DEBUG_PARAM("ClientErrorComponent::testExceptionFromCompletion", 
00536                         "Time of the unexpected exception: %s\n", tString.c_str());
00537         }
00538     ACS_SHORT_LOG((LM_INFO, "Example 3b: ExceptionFromCompletion with depth 5"));
00539     try
00540         {
00541         foo_m->exceptionFromCompletion(5);
00542         ACS_SHORT_LOG((LM_INFO, "UNEXPECTED: should have thrown an exception"));
00543         }
00544     catch(ACSErrTypeCommon::GenericErrorEx &ex)
00545         {
00546         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex,
00547                                    __FILE__, __LINE__,
00548                                    "ClientErrorComponent::testExceptionFromCompletion");
00549         badMethodEx.setErrorDesc("exceptionFromCompletion has thrown the expected exception");
00550         badMethodEx.log();
00551 
00552         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00553         ACE_CString tString = getStringifiedUTC(timeStamp);
00554         ACS_DEBUG_PARAM("ClientErrorComponent::testExceptionFromCompletion", 
00555                         "Time of the exception: %s\n", tString.c_str());
00556         }
00557     catch(CORBA::SystemException &ex)
00558         {
00559         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00560                                    __FILE__, __LINE__,
00561                                    "ClientErrorComponent::TestExceptionFromCompletion");
00562         corbaProblemEx.setMinor(ex.minor());
00563         corbaProblemEx.setCompletionStatus(ex.completed());
00564         corbaProblemEx.setInfo(ex._info().c_str());
00565         corbaProblemEx.log();
00566 
00567         //Is this really necessary? The exceptions already have a timeStamp
00568         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00569         ACE_CString tString = getStringifiedUTC(timeStamp);
00570         ACS_DEBUG_PARAM("ClientErrorComponent::testExceptionFromCompletion", 
00571                         "Time of the CORBA exception: %s\n", tString.c_str());
00572         }
00573     catch(...)
00574         {
00575         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00576                                                  "ClientErrorComponent::testExceptionFromCompletion");
00577         badMethodEx.setErrorDesc("exceptionFromCompletion has thrown an UNEXPECTED exception");
00578         badMethodEx.log();
00579 
00580         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00581         ACE_CString tString = getStringifiedUTC(timeStamp);
00582         ACS_DEBUG_PARAM("ClientErrorComponent::testExceptionFromCompletion", 
00583                         "Time of the unexpected exception: %s\n", tString.c_str());
00584         }
00585 
00586 }
00587 
00588 void ClientErrorComponent::TestReceiveRemoteCompletion() 
00589 {
00590     ACS_TRACE("ClientErrorComponent::TestReceiveRemoteCompletion");
00591 
00592     if (CORBA::is_nil(foo_m.in()) == true)
00593         {
00594         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00595                                    __FILE__, __LINE__,
00596                                    "ClientErrorComponent::TestReceiveRemoteCompletion");
00597         }
00598     try
00599         {
00600         CompletionImpl comp;
00601 
00602         // OK Completion
00603         ACS_SHORT_LOG((LM_INFO, "Example 2a: Calls a method that returns an OK completion."));
00604         comp = foo_m->completionFromException(0);
00605         comp.log();
00606 
00607         // ERROR completion with an error trace inside.
00608         ACS_SHORT_LOG((LM_INFO, "Example 2b: Calls a method that returns an Error completion."));
00609         comp = foo_m->completionFromException(3);
00610         comp.log();
00611         }
00612     catch(CORBA::SystemException &ex)
00613         {
00614         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00615                                    __FILE__, __LINE__,
00616                                    "ClientErrorComponent::TestReceiveRemoteCompletion");
00617         corbaProblemEx.setMinor(ex.minor());
00618         corbaProblemEx.setCompletionStatus(ex.completed());
00619         corbaProblemEx.setInfo(ex._info().c_str());
00620         corbaProblemEx.log();
00621 
00622         }
00623     catch(...)
00624         {
00625         ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__,
00626                                                          "ClientErrorComponent::TestReceiveRemoteCompletion");
00627         ex.setErrorDesc("completionFromException has thrown an UNEXPECTED exception");
00628         ex.log();
00629         }
00630 }
00631 void ClientErrorComponent::testCompletionOnStack() 
00632 {
00633     ACS_TRACE("ClientErrorComponent::testCompletionOnStack");
00634 
00635     if (CORBA::is_nil(foo_m.in()) == true)
00636         {
00637         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00638                                    __FILE__, __LINE__,
00639                                    "ClientErrorComponent::testCompletionOnStack");
00640         }
00641     try
00642         {
00643         CompletionImpl comp;
00644 
00645         // OK Completion
00646         ACS_SHORT_LOG((LM_INFO, "Example 7a: completionOnStack with depth 0."));
00647         comp = foo_m->completionOnStack(0);
00648         comp.log();
00649 
00650         // ERROR completion with an error trace inside.
00651         ACS_SHORT_LOG((LM_INFO, "Example 7b: completionOnStack with depth 3."));
00652         comp = foo_m->completionOnStack(3);
00653         comp.log();
00654         }
00655     catch(CORBA::SystemException &ex)
00656         {
00657         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00658                                    __FILE__, __LINE__,
00659                                    "ClientErrorComponent::TestCompletionOnStack");
00660         corbaProblemEx.setMinor(ex.minor());
00661         corbaProblemEx.setCompletionStatus(ex.completed());
00662         corbaProblemEx.setInfo(ex._info().c_str());
00663         corbaProblemEx.log();
00664         }
00665     catch(...)
00666         {
00667         ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__,
00668                                                          "ClientErrorComponent::testCompletionOnStack");
00669         ex.setErrorDesc("CompletionOnStack has thrown an UNEXPECTED exception");
00670         ex.log();
00671         }
00672 }
00673 
00674 void ClientErrorComponent::testCompletionFromCompletion() 
00675 {
00676     ACS_TRACE("ClientErrorComponent::testCompletionFromCompletion");
00677 
00678     if (CORBA::is_nil(foo_m.in()) == true)
00679         {
00680         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00681                                    __FILE__, __LINE__,
00682                                    "ClientErrorComponent::testCompletionFromCompletion");
00683         }
00684     try
00685         {
00686         CompletionImpl comp;
00687 
00688         // OK Completion
00689         ACS_SHORT_LOG((LM_INFO, "Example 6a: completionFromCompletion with depth 0."));
00690         comp = foo_m->completionFromException(0);
00691         comp.log();
00692 
00693         // ERROR completion with an error trace inside.
00694         ACS_SHORT_LOG((LM_INFO, "Example 6b: completionFromCompletion with depth 3."));
00695         comp = foo_m->completionFromException(3);
00696         comp.log();
00697         }
00698     catch(CORBA::SystemException &ex)
00699         {
00700         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00701                                    __FILE__, __LINE__,
00702                                    "ClientErrorComponent::TestCompletionFromCompletion");
00703         corbaProblemEx.setMinor(ex.minor());
00704         corbaProblemEx.setCompletionStatus(ex.completed());
00705         corbaProblemEx.setInfo(ex._info().c_str());
00706         corbaProblemEx.log();
00707         }
00708     catch(...)
00709         {
00710         ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__,
00711                                                          "ClientErrorComponent::testCompletionFromCompletion");
00712         ex.setErrorDesc("completionFromCompletion has thrown an UNEXPECTED exception");
00713         ex.log();
00714         }
00715 }
00716 
00717 void ClientErrorComponent::TestReceiveCorbaSystemException() 
00718 {
00719     ACS_TRACE("ClientErrorComponent::TestReceiveCorbaSystemException");
00720 
00721     if (CORBA::is_nil(foo_m.in()) == true)
00722         {
00723         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00724                                    __FILE__, __LINE__,
00725                                    "ClientErrorComponent::TestReceiveRemoteException");
00726         }
00727     ACS_SHORT_LOG((LM_INFO, "Example 5: Calls a method that throws a CORBA System Exception."));
00728     try
00729         {
00730         foo_m->corbaSystemException();
00731         }
00732     catch(CORBA::SystemException &ex)
00733         {
00734         // This show how to map a CORBA System exception from TAO
00735         // in the ACS wrapper ACSErrTypeCommon::CORBAProblemExImpl.
00740         ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00741                                    __FILE__, __LINE__,
00742                                    "ClientErrorComponent::TestReceiveRemoteException");
00743         corbaProblemEx.setMinor(ex.minor());
00744         corbaProblemEx.setCompletionStatus(ex.completed());
00745         corbaProblemEx.setInfo(ex._info().c_str());
00746         corbaProblemEx.log();
00747 
00748         ACS::Time timeStamp = corbaProblemEx.getTimeStamp();
00749         ACE_CString tString = getStringifiedUTC(timeStamp);
00750         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00751                         "Time of the CORBA::SystemException exception: %s\n", tString.c_str());
00752         }
00753     catch(...)
00754         {
00755         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00756                                                  "ClientErrorComponent::TestReceiveRemoteException");
00757         badMethodEx.setErrorDesc("corbaSystemException has thrown an UNEXPECTED exception");
00758         badMethodEx.log();
00759 
00760         ACS::Time timeStamp = badMethodEx.getTimeStamp();
00761         ACE_CString tString = getStringifiedUTC(timeStamp);
00762         ACS_DEBUG_PARAM("ClientErrorComponent::TestReceiveRemoteException", 
00763                         "Time of the unexpected exception: %s\n", tString.c_str());
00764         }
00765 
00766 }
00767 void 
00768 ClientErrorComponent::testOutCompletion() 
00769 {
00770     ACS_TRACE("ClientErrorComponent::testOutCompletion");
00771 
00772     if (CORBA::is_nil(foo_m.in()) == true)
00773         {
00774         throw ACSErrTypeCommon::CouldntAccessComponentExImpl(
00775                                    __FILE__, __LINE__,
00776                                    "ClientErrorComponent::testCompletionFromCompletion");
00777         }
00778     try
00779         {
00780         ACSErr::Completion_var comp_var;
00781 
00782         // OK Completion
00783         ACS_SHORT_LOG((LM_INFO, "Example 8: outCompletion"));
00784         foo_m->outCompletion(comp_var.out());
00785         CompletionImpl compImpl(comp_var.in());
00786         compImpl.log();
00787 
00788         }
00789     catch(CORBA::SystemException &ex)
00790         {
00791        ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(
00792                                    __FILE__, __LINE__,
00793                                    "ClientErrorComponent::TestReceiveRemoteException");
00794         corbaProblemEx.setMinor(ex.minor());
00795         corbaProblemEx.setCompletionStatus(ex.completed());
00796         corbaProblemEx.setInfo(ex._info().c_str());
00797         corbaProblemEx.log();
00798 
00799         }
00800     catch(...)
00801         {
00802         ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__,
00803                                                          "ClientErrorComponent::outCompletion");
00804         ex.setErrorDesc("outCompletion has thrown an UNEXPECTED exception");
00805         ex.log();
00806         }
00807     
00808 }
00809 /* @}*/
00810 /* @}*/
00811 
00812 /*******************************************************************************/
00816 int main(int argc, char *argv[])
00817 {
00818     // Creates and initializes the SimpleClient object
00819     SimpleClient client;
00820     if (client.init(argc,argv) == 0)
00821         {
00822         ACS_SHORT_LOG((LM_ERROR, "acsexmplClientErrorComponent::main, Failed to initialize"));
00823         return -1;
00824         }
00825     else
00826         {
00827         //Must log into manager before we can really do anything
00828         client.login();
00829         }
00830 
00831         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main")); 
00832     /**************************************************************************
00833      * Here we instantiate the object used to show examples of error handling.
00834      * Each method call demonstrate one aspect of error hanlding.
00835      * See the class documentation for details.
00836      */
00837     try
00838         {
00839         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, created instance of ClientErrorComponent"));
00840         ClientErrorComponent clientErrorComponent(client, argv[1]);
00841         
00842         //Call the displayMessage() method existing in the interface for ErrorComponent
00843         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling TestOk()"));
00844         clientErrorComponent.TestOk();
00845         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling TestReceiveRemoteException()"));
00846         clientErrorComponent.TestReceiveRemoteException();
00847         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling TestReceiveRemoteCompletion()"));
00848         clientErrorComponent.TestReceiveRemoteCompletion();
00849         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling TestReceiveCorbaSystemException()"));
00850         clientErrorComponent.TestReceiveCorbaSystemException();
00851         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling testCompletionFromCompletion()"));
00852         clientErrorComponent.testCompletionFromCompletion();
00853         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling testExceptionFromCompletion()"));
00854         clientErrorComponent.testExceptionFromCompletion();
00855         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling testTypeException()"));
00856         clientErrorComponent.testTypeException();
00857         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling testCompletionOnStack()"));
00858         clientErrorComponent.testCompletionOnStack();
00859         ACS_SHORT_LOG((LM_TRACE, "acsexmplClientErrorComponent::main, calling testOutCompletion()"));
00860         clientErrorComponent.testOutCompletion();
00861         }
00862     catch(ACSErr::ACSbaseExImpl ex)
00863         {
00864         /*
00865          * We should never get here, because the methods in the example
00866          * should be all self contained and none of them should throw
00867          * any exception.
00868          */
00869         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(ex, __FILE__, __LINE__,
00870                                                          "main");
00871         badMethodEx.setErrorDesc("Examples of error handling have thrown an ACS exception");
00872         badMethodEx.log();
00873         }
00874     catch(...)
00875         {
00876         /*
00877          * We should never get here, because the methods in the example
00878          * should be all self contained and none of them should throw
00879          * any exception.
00880          */
00881         ACSErrTypeCommon::GenericErrorExImpl badMethodEx(__FILE__, __LINE__,
00882                                                          "main");
00883         badMethodEx.setErrorDesc("Examples of error handling have thrown an UNEXPECTED exception");
00884         badMethodEx.log();
00885         }
00886 
00887     /****************************************************
00888      * We logout from manager
00889      */
00890     client.logout();
00891     
00892     //Sleep for 3 sec to allow everything to cleanup and stablize
00893     ACE_OS::sleep(3);
00894     return 0;
00895 }
00899 /*___oOo___*/
00900 
00901 
00902