home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / RAPSHEET / CPPOV23 / ISUSRMGR.CPP < prev    next >
Text File  |  1995-05-22  |  13KB  |  352 lines

  1. //****************************************************************************
  2. // ISuspectClientMgr Class - C++ Source File (isusrmgr.cpp)                  *
  3. //                                                                           *
  4. // COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
  5. //                                                                           *
  6. // DISCLAIMER OF WARRANTIES:                                                 *
  7. //   The following [enclosed] code is sample code created by IBM             *
  8. //   Corporation.  This sample code is not part of any standard IBM product  *
  9. //   and is provided to you solely for the purpose of assisting you in the   *
  10. //   development of your applications.  The code is provided "AS IS",        *
  11. //   without warranty of any kind.  IBM shall not be liable for any damages  *
  12. //   arising out of your use of the sample code, even if they have been      *
  13. //   advised of the possibility of such damages.                             *
  14. //****************************************************************************
  15. //NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16. //
  17. #include "isusrmgr.hpp"              
  18.  
  19. #ifndef _INOTIFEV_
  20.    #include <inotifev.hpp>
  21. #endif
  22. #ifndef _ITRACE_
  23.    #include <itrace.hpp>
  24. #endif
  25. #ifndef _IEXCBASE_
  26. #include <iexcbase.hpp>
  27. #endif
  28.  
  29. #ifndef _IRSLTREC_
  30. #include "irsltrec.hpp"              
  31. #endif
  32. #ifndef _ISUSREC_
  33. #include "isusrec.hpp"               
  34. #endif
  35. #ifndef _IADD_
  36. #include "iadd.hpp"                  
  37. #endif
  38. #ifndef _QUERYDB_
  39. #include "querydb.hpp"               
  40. #endif
  41.  
  42.  
  43. /*******************************************************************
  44.  * Events
  45.  *******************************************************************/
  46. INotificationId ISuspectClientMgr :: requestBufferId = "ISuspectClientMgr::requestBuffer";
  47. INotificationId ISuspectClientMgr :: resultBufferId = "ISuspectClientMgr::resultBuffer";
  48. INotificationId ISuspectClientMgr :: resultListId = "ISuspectClientMgr::resultList";
  49. INotificationId ISuspectClientMgr :: resultListWrapperId = "ISuspectClientMgr::resultListWrapper";
  50. INotificationId ISuspectClientMgr :: resultObjectId = "ISuspectClientMgr::resultObject";
  51. INotificationId ISuspectClientMgr :: resultWrapperId = "ISuspectClientMgr::resultWrapper";
  52.  
  53. INotificationId ISuspectClientMgr :: parsedResultId = "ISuspectClientMgr::parsedResult";
  54. INotificationId ISuspectClientMgr :: sameRequestId = "ISuspectClientMgr::sameRequest";
  55. INotificationId ISuspectClientMgr :: noObjectsFoundId = "ISuspectClientMgr::noObjectsFound";
  56. INotificationId ISuspectClientMgr :: oneObjectFoundId = "ISuspectClientMgr::oneObjectFound";
  57. INotificationId ISuspectClientMgr :: manyObjectsFoundId = "ISuspectClientMgr::manyObjectsFound";
  58.  
  59.  
  60. /*******************************************************************
  61.  * Constructors
  62.  *******************************************************************/
  63. ISuspectClientMgr :: ISuspectClientMgr() :
  64.         dRequestBuffer(""), 
  65.         dResultBuffer(""),
  66.         dResultWrapper(0),
  67.         dResultListWrapper(new IVSequence<ISuspect *>)
  68. {
  69.    enableNotification();
  70.    dResultListWrapper->enableNotification();
  71. }
  72.  
  73.  
  74. /*******************************************************************
  75.  * Destructor
  76.  *******************************************************************/
  77. ISuspectClientMgr :: ~ISuspectClientMgr()
  78. {
  79.    if (dResultWrapper)
  80.       delete dResultWrapper;
  81.    if (dResultListWrapper)
  82.       delete dResultListWrapper;
  83. }
  84.  
  85.  
  86. /****************************************************************************
  87.  * Attribute Access Member Functions
  88.  ****************************************************************************/
  89. /*------------------------------------------------------------------
  90.  * requestBuffer
  91.  *-----------------------------------------------------------------*/
  92. IString ISuspectClientMgr :: requestBuffer () const
  93. {
  94.   return dRequestBuffer;
  95. }
  96.  
  97. ISuspectClientMgr & ISuspectClientMgr :: 
  98.   setRequestBuffer (const IString & iRequestBuffer)
  99. {
  100.   if (dRequestBuffer != iRequestBuffer)
  101.   {
  102.     dRequestBuffer = iRequestBuffer;      
  103.     notifyObservers(INotificationEvent(requestBufferId, *this, true,
  104.                                        IEventData((char *)iRequestBuffer)));
  105.   } 
  106.   else
  107.     notifyObservers(INotificationEvent(sameRequestId, *this, false));
  108.   return *this;
  109. }
  110.  
  111. /*------------------------------------------------------------------
  112.  * resultBuffer
  113.  *-----------------------------------------------------------------*/
  114. IString ISuspectClientMgr :: resultBuffer () const
  115. {
  116.   return dResultBuffer;
  117. }
  118.  
  119. ISuspectClientMgr & ISuspectClientMgr :: 
  120.   setResultBuffer (const IString & iResultBuffer)
  121. {
  122.   if (dResultBuffer != iResultBuffer)
  123.   {
  124.     dResultBuffer = iResultBuffer;                  //Set class.attribute.title%>
  125.     notifyObservers(INotificationEvent(resultBufferId, *this, true,
  126.                                        IEventData((char *)iResultBuffer)));
  127.   } 
  128.   else
  129.     notifyObservers(INotificationEvent(resultBufferId, *this, false));
  130.     //moved this outside of the test so would fire each time; found wasn't
  131.     //getting message displayed when did 2 consecutive not-found searches
  132.  
  133.   return *this;
  134. }
  135.  
  136. /*------------------------------------------------------------------
  137.  * resultList (read-only) and resultListWrapper
  138.  *-----------------------------------------------------------------*/
  139. IVSequence <ISuspect *> ISuspectClientMgr :: 
  140.   resultList () const
  141. {
  142.   return *dResultListWrapper;
  143. }
  144.  
  145. IVSequence <ISuspect *> * ISuspectClientMgr :: 
  146.   resultListWrapper () const
  147. {
  148.   return dResultListWrapper;
  149. }
  150.  
  151. /*------------------------------------------------------------------
  152.  * resultObject and resultWrapper (read-only)
  153.  *-----------------------------------------------------------------*/
  154. ISuspect * ISuspectClientMgr :: resultWrapper () const
  155. {
  156.   return dResultWrapper;
  157. }
  158.  
  159. ISuspect ISuspectClientMgr :: resultObject () const
  160. {
  161.   return *dResultWrapper;
  162. }
  163.  
  164.  
  165. /*******************************************************************
  166.  * Actions
  167.  *******************************************************************/
  168. /*------------------------------------------------------------------
  169.  * getAll  (retrieves all suspects from DB2/2 database)
  170.  *-----------------------------------------------------------------*/
  171. IString ISuspectClientMgr :: getAll()
  172. {
  173.  
  174.   IResultRecord rsltRec;
  175.  
  176.   IFUNCTRACE_DEVELOP();
  177.   ITRACE_DEVELOP("Calling the DB server.");
  178.   rsltRec = getAllSuspects();
  179.   ITRACE_DEVELOP("Number suspects found: " + IString(rsltRec.numResults()));
  180.  
  181.   return rsltRec.asString();
  182. }
  183.  
  184. /*------------------------------------------------------------------
  185.  * processResult
  186.  *    The user controls when dResultBuffer should be processed.
  187.  *-----------------------------------------------------------------*/
  188. ISuspectClientMgr & ISuspectClientMgr :: processResult ()
  189. {
  190.    ISuspect           *suspect;
  191.    ISuspectRecord     suspectRec;
  192.    IAddress           address;
  193.    unsigned short     recOffset, i;
  194.    IString            buffer;
  195.  
  196.   IFUNCTRACE_DEVELOP();
  197.  
  198.   if (!dResultBuffer.isWhiteSpace())
  199.   {
  200.      ITRACE_DEVELOP("resultBuffer received.");
  201.      IResultRecord resultRec(dResultBuffer);
  202.      ITRACE_DEVELOP(resultRec.asDebugInfo());
  203.  
  204.      //clear the result list if it's not empty (i.e., if it was set in a previous invocation)
  205.      if (dResultListWrapper->numberOfElements())
  206.      {
  207.         ITRACE_DEVELOP("had to empty the resultList");
  208.         dResultListWrapper->removeAll();
  209.      }
  210.  
  211.      if (resultRec.numResults() != 0)
  212.      {
  213.         recOffset = 1;
  214.         Boolean noError = true;
  215.  
  216.         for (i=0 ; i < resultRec.numResults() && noError; i++)
  217.         {
  218.            suspect = new ISuspect;
  219.            if (recOffset + suspectRec.size() - 1 <= resultRec.size() - 2)
  220.            {
  221.               buffer = resultRec.resultData().subString(recOffset,suspectRec.size());
  222.               suspectRec = buffer;
  223.               ITRACE_DEVELOP("Suspect record" + IString(i) + " ...");
  224.               ITRACE_DEVELOP(suspectRec.asDebugInfo());
  225.           
  226.               suspect->setLastName(suspectRec.lastName().strip());
  227.               suspect->setFirstName(suspectRec.firstName().strip());
  228.               suspect->setInfo(suspectRec.description().strip());
  229.               suspect->enableHasMole(suspectRec.hasMole());
  230.               suspect->enableHasScar(suspectRec.hasScar());
  231.               suspect->enableHasTattoo(suspectRec.hasTattoo());
  232.               suspect->setBirthDate(suspectRec.birthDate().strip());
  233.               suspect->setBookNumber(suspectRec.bookNumber());
  234.               suspect->setMO(suspectRec.MO().strip());
  235.               suspect->setMoleDesc(suspectRec.moleDescription().strip());
  236.               suspect->setScarDesc(suspectRec.scarDescription().strip());
  237.               suspect->setTattooDesc(suspectRec.tattooDescription().strip());
  238.               suspect->setEyeColor(suspectRec.eyeColor());
  239.               suspect->setHairColor(suspectRec.hairColor());
  240.               suspect->setGender(suspectRec.gender());
  241.               suspect->setHeight(suspectRec.height());
  242.               suspect->setWeight(suspectRec.weight());
  243.               suspect->setMugFront(suspectRec.mugFront());
  244.               suspect->setMugLeft(suspectRec.mugLeft());
  245.               suspect->setMugRight(suspectRec.mugRight());
  246.           
  247.               address.setStreet(suspectRec.street().strip());
  248.               address.setCity(suspectRec.city().strip());
  249.               address.setState(suspectRec.state().strip());
  250.               address.setZip(suspectRec.zip().strip());
  251. //            address.setCounty(suspectRec.county().strip());
  252.           
  253.               suspect->setAddress(new IAddress( address ));
  254.           
  255.               ITRACE_DEVELOP(suspect->asDebugInfo());
  256.               addResult(suspect);              //adds suspect to dResultList
  257.               recOffset += suspectRec.size();
  258.            }
  259.            else
  260.            {
  261.               ITRACE_DEVELOP("The capacity of the result record buffer has been exceeded.");
  262.               noError = false;
  263.            }
  264.         }
  265.      }
  266.    
  267.      notifyObservers(INotificationEvent(parsedResultId, *this, false));
  268.      if (resultRec.numResults() == 1)
  269.         notifyObservers(INotificationEvent(oneObjectFoundId, *this, false));
  270.      else if (resultRec.numResults() == 0)
  271.      {
  272.         notifyObservers(INotificationEvent(noObjectsFoundId, *this, false));
  273.         throw IException("No information exists for the specified suspect.");
  274.      }
  275.      else
  276.         notifyObservers(INotificationEvent(manyObjectsFoundId, *this, false));
  277.  
  278.   }
  279.    return *this;
  280. }
  281.  
  282. /*------------------------------------------------------------------
  283.  * addResult()
  284.  *-----------------------------------------------------------------*/
  285. ISuspectClientMgr & ISuspectClientMgr :: addResult
  286.    (ISuspect * iSuspectWrapper)
  287. {
  288.    IFUNCTRACE_DEVELOP();
  289.    ITRACE_DEVELOP("addResult(*)");
  290.    ITRACE_DEVELOP(iSuspectWrapper->asDebugInfo());
  291.  
  292.    if (dResultListWrapper->isEmpty())
  293.    {
  294.       setResultWrapper(iSuspectWrapper);
  295.    }
  296.  
  297.    dResultListWrapper->addAsLast(iSuspectWrapper);
  298.    ITRACE_DEVELOP("added a suspect to the resultList");
  299.    return *this;
  300. }
  301.  
  302. /*------------------------------------------------------------------
  303.  * addResult()
  304.  *-----------------------------------------------------------------*/
  305. ISuspectClientMgr & ISuspectClientMgr :: addResult
  306.    (ISuspect & iSuspect)
  307. {
  308.    IFUNCTRACE_DEVELOP();
  309.    ITRACE_DEVELOP("addResult(&)");
  310.  
  311.    if (dResultListWrapper->isEmpty())
  312.    {
  313.       setResultWrapper(&iSuspect);
  314.    }
  315.  
  316.    dResultListWrapper->addAsLast(&iSuspect);
  317.    ITRACE_DEVELOP("added a suspect to the resultList");
  318.    return *this;
  319. }
  320.  
  321. /*------------------------------------------------------------------
  322.  * setResultWrapper()
  323.  *-----------------------------------------------------------------*/
  324. ISuspectClientMgr & ISuspectClientMgr ::
  325.   setResultWrapper (ISuspect * iResultWrapper)
  326. {
  327.   if (dResultWrapper != iResultWrapper)
  328.   {
  329.      if (dResultWrapper)
  330.         delete dResultWrapper;
  331.      dResultWrapper = iResultWrapper;
  332.      notifyObservers(INotificationEvent(resultObjectId, *this, false));
  333.      notifyObservers(INotificationEvent(resultWrapperId, *this, false));
  334.   }
  335.   return *this;
  336. }
  337.  
  338. /*------------------------------------------------------------------
  339.  * setResultWrapper()
  340.  *-----------------------------------------------------------------*/
  341. ISuspectClientMgr & ISuspectClientMgr ::
  342.   setResultWrapper (const ISuspect & iResult)
  343. {
  344.   /*****************************************************************
  345.    * Have to make a copy of the ISuspect object passed in since it's
  346.    * identified as being a const.  That is, the compiler won't
  347.    * allow dResultWrapper = &iResultWrapper, since it would allow
  348.    * us, via dResultWrapper, to update the ISuspect object.
  349.    *****************************************************************/
  350.   return setResultWrapper(new ISuspect(iResult));
  351. }
  352.