home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / rapsheet / cppwv23 / iarsrmgr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  11.5 KB  |  315 lines

  1. /******************************************************************************
  2. * .FILE:        iarsrmgr.cpp                                                  *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation for the class, IArrestClientMgr                *
  5. *                                                                             *
  6. * .CLASSES:     IArrestClientMgr                                              *
  7. *                                                                             *
  8. * .COPYRIGHT:                                                                 *
  9. *    Licensed Material - Program-Property of IBM                              *
  10. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  11. *                                                                             *
  12. * .DISCLAIMER:                                                                *
  13. *   The following [enclosed] code is sample code created by IBM               *
  14. *   Corporation.  This sample code is not part of any standard IBM product    *
  15. *   and is provided to you solely for the purpose of assisting you in the     *
  16. *   development of your applications.  The code is provided 'AS IS',          *
  17. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  18. *   arising out of your use of the sample code, even if they have been        *
  19. *   advised of the possibility of such damages.                               *
  20. *                                                                             *
  21. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  22. *                                                                             *
  23. ******************************************************************************/
  24. #include "iarsrmgr.hpp"               //IArrestClientMgr header
  25. #include <inotifev.hpp>
  26. #include <itrace.hpp>
  27. #include "irsltrec.hpp"               //IResultRecord header
  28. #include "iarstrec.hpp"               //IArrestRecord header
  29. #include "querydb.hpp"
  30.  
  31. /*******************************************************************
  32.  * Events
  33.  *******************************************************************/
  34. INotificationId IArrestClientMgr :: parsedResultId = "IArrestClientMgr::parsedResult";
  35. INotificationId IArrestClientMgr :: requestBufferId = "IArrestClientMgr::requestBuffer";
  36. INotificationId IArrestClientMgr :: resultBufferId = "IArrestClientMgr::resultBuffer";
  37. INotificationId IArrestClientMgr :: resultListId = "IArrestClientMgr::resultList";
  38. INotificationId IArrestClientMgr :: resultListWrapperId = "IArrestClientMgr::resultListWrapper";
  39. INotificationId IArrestClientMgr :: resultObjectId = "IArrestClientMgr::resultObject";
  40. INotificationId IArrestClientMgr :: resultWrapperId = "IArrestClientMgr::resultWrapper";
  41. INotificationId IArrestClientMgr :: sameRequestId = "IArrestClientMgr::sameRequest";
  42. INotificationId IArrestClientMgr :: noObjectsFoundId = "IArrestClientMgr::noObjectsFound";
  43. INotificationId IArrestClientMgr :: oneObjectFoundId = "IArrestClientMgr::oneObjectFound";
  44. INotificationId IArrestClientMgr :: manyObjectsFoundId = "IArrestClientMgr::manyObjectsFound";
  45.  
  46. /*******************************************************************
  47.  * Constructors
  48.  *******************************************************************/
  49. IArrestClientMgr :: IArrestClientMgr() :
  50.         dRequestBuffer(""),
  51.         dResultBuffer(""),
  52.         dResultWrapper(0),
  53.         dResultListWrapper(new IVSequence<IArrest *>)
  54. {
  55.    enableNotification();
  56.    dResultListWrapper->enableNotification();
  57. }
  58.  
  59. /*******************************************************************
  60.  * Destructor
  61.  *******************************************************************/
  62. IArrestClientMgr :: ~IArrestClientMgr()
  63. {
  64.   ISequence<IArrest *> tempList;
  65.   IArrest *            arrest;
  66.  
  67. // if (dResultWrapper)
  68. //    delete dResultWrapper;
  69.   if (dResultListWrapper)
  70.   {
  71.      IVSequence<IArrest*>::Cursor cursor(*dResultListWrapper);
  72.      forCursor( cursor )
  73.        tempList.addAsFirst( dResultListWrapper->elementAt( cursor ) );
  74.  
  75.      dResultListWrapper->removeAll( );
  76.  
  77.      ISequence<IArrest*>::Cursor tempCursor( tempList );
  78.      forCursor( cursor )
  79.      {
  80.        arrest = tempList.elementAt ( tempCursor );
  81.        delete arrest;
  82.      }
  83.      tempList.removeAll( );
  84.  
  85.      delete dResultListWrapper;
  86.   }
  87. }
  88.  
  89.  
  90. /*******************************************************************
  91.  * Attribute Access Member Functions
  92.  *******************************************************************/
  93. /*------------------------------------------------------------------
  94.  * requestBuffer
  95.  *-----------------------------------------------------------------*/
  96. IString IArrestClientMgr :: requestBuffer () const
  97. {
  98.   return dRequestBuffer;
  99. }
  100.  
  101. IArrestClientMgr & IArrestClientMgr ::
  102.   setRequestBuffer (const IString & iRequestBuffer)
  103. {
  104.   if (dRequestBuffer != iRequestBuffer)
  105.   {
  106.     dRequestBuffer = iRequestBuffer;
  107.     notifyObservers(INotificationEvent(requestBufferId, *this, true,
  108.                                        IEventData((char *)iRequestBuffer)));
  109.   }
  110.   else
  111.     notifyObservers(INotificationEvent(sameRequestId, *this, false));
  112.   return *this;
  113. }
  114.  
  115. /*------------------------------------------------------------------
  116.  * resultBuffer
  117.  *-----------------------------------------------------------------*/
  118. IString IArrestClientMgr :: resultBuffer () const
  119. {
  120.   return dResultBuffer;
  121. }
  122.  
  123. IArrestClientMgr & IArrestClientMgr ::
  124.   setResultBuffer (const IString & iResultBuffer)
  125. {
  126.   if (dResultBuffer != iResultBuffer)
  127.   {
  128.     dResultBuffer = iResultBuffer;
  129.     notifyObservers(INotificationEvent(resultBufferId, *this, true,
  130.                                IEventData((char *)iResultBuffer)));
  131.   } /* endif */
  132.   return *this;
  133. }
  134.  
  135. /*------------------------------------------------------------------
  136.  * resultList (read-only) and resultListWrapper
  137.  *-----------------------------------------------------------------*/
  138. IVSequence <IArrest *> IArrestClientMgr ::
  139.   resultList () const
  140. {
  141.   return *dResultListWrapper;
  142. }
  143.  
  144. IVSequence <IArrest *> * IArrestClientMgr ::
  145.   resultListWrapper () const
  146. {
  147.   return dResultListWrapper;
  148. }
  149.  
  150. /*------------------------------------------------------------------
  151.  * resultObject and resultWrapper (read-only)
  152.  *-----------------------------------------------------------------*/
  153. IArrest * IArrestClientMgr :: resultWrapper () const
  154. {
  155.   return dResultWrapper;
  156. }
  157.  
  158. IArrest IArrestClientMgr :: resultObject () const
  159. {
  160.   return *dResultWrapper;
  161. }
  162.  
  163.  
  164. /*******************************************************************
  165.  * Actions
  166.  *******************************************************************/
  167. /*------------------------------------------------------------------
  168.  * allbyBookNumber
  169.  *-----------------------------------------------------------------*/
  170. IString IArrestClientMgr :: allByBookNumber (unsigned long aBookNumber)
  171. {
  172.   IResultRecord rsltRec;
  173.   IString suspectKey = IString(aBookNumber);
  174.  
  175.   IFUNCTRACE_DEVELOP();
  176.   ITRACE_DEVELOP("suspectKey: " + suspectKey + ".");
  177.  
  178.   if (dRequestBuffer != suspectKey)
  179.   {
  180.      setRequestBuffer(suspectKey);
  181.      ITRACE_DEVELOP("Calling the DB server.");
  182.      rsltRec = getAllArrests(aBookNumber);
  183.      ITRACE_DEVELOP("Number arrest records found: " + IString(rsltRec.numResults()));
  184.   }
  185.   else
  186.      setRequestBuffer(suspectKey);
  187.  
  188.   return rsltRec.asString();
  189. }
  190.  
  191. /*------------------------------------------------------------------
  192.  * processResult()
  193.  *    The user controls when dResultBuffer should be processed.
  194.  *-----------------------------------------------------------------*/
  195. IArrestClientMgr & IArrestClientMgr :: processResult ()
  196. {
  197.    IArrest *          arrestWrapper;
  198.    IArrestRecord      arrestRec;
  199.    unsigned short     recOffset, i;
  200.    IString            buffer;
  201.  
  202.   IFUNCTRACE_DEVELOP();
  203.  
  204.   if (!dResultBuffer.isWhiteSpace())
  205.   {
  206.    IResultRecord resultRec(dResultBuffer);
  207.  
  208.    //clear the result list if it's not empty (i.e., if it was set in a previous invocation)
  209.    if (dResultListWrapper->numberOfElements())
  210.       dResultListWrapper->removeAll();
  211.  
  212.    recOffset = 1;
  213.    for (i=0 ; i < resultRec.numResults(); i++)
  214.    {
  215.       arrestWrapper = new IArrest;
  216.  
  217.       buffer = resultRec.resultData().subString(
  218.                recOffset,arrestRec.size());
  219.       arrestRec = buffer;
  220.  
  221.       arrestWrapper->setCharge(arrestRec.charge());
  222.       arrestWrapper->setStatus(arrestRec.status());
  223.       arrestWrapper->setStatusDate(arrestRec.statusDate());
  224.  
  225.       addResult(arrestWrapper);  //adds arrestWrapper to
  226.                                  //the result list
  227.  
  228.       recOffset += arrestRec.size();  //get the next arrestRec
  229.    }
  230.  
  231.    notifyObservers(INotificationEvent(parsedResultId, *this, false));
  232.    if (resultRec.numResults() == 1)
  233.       notifyObservers(INotificationEvent(oneObjectFoundId, *this, false));
  234.    else if (resultRec.numResults() == 0)
  235.    {
  236.       notifyObservers(INotificationEvent(noObjectsFoundId, *this, false));
  237.       throw IException("No aliases exist for the specified suspect."); }
  238.    else
  239.       notifyObservers(INotificationEvent(manyObjectsFoundId, *this, false));
  240.   }
  241.  
  242.    return *this;
  243. }
  244.  
  245. /*******************************************************************
  246.  * Class Member Functions
  247.  *******************************************************************/
  248. /*------------------------------------------------------------------
  249.  * addResult()
  250.  *-----------------------------------------------------------------*/
  251. IArrestClientMgr & IArrestClientMgr ::
  252.   addResult (IArrest * iArrestWrapper)
  253. {
  254.    IFUNCTRACE_DEVELOP();
  255.    ITRACE_DEVELOP("addResult(*) of iarsrmgr.");
  256.  
  257.    if (dResultListWrapper->isEmpty())
  258.    {
  259.       setResultWrapper(iArrestWrapper);
  260.    }
  261.  
  262.    dResultListWrapper->add(iArrestWrapper);
  263.    return *this;
  264. }
  265.  
  266. /*------------------------------------------------------------------
  267.  * addResult()
  268.  *-----------------------------------------------------------------*/
  269. IArrestClientMgr & IArrestClientMgr ::
  270.   addResult (IArrest & iArrest)
  271. {
  272.    IFUNCTRACE_DEVELOP();
  273.    ITRACE_DEVELOP("addResult(&) of iarsrmgr.");
  274.  
  275.    if (dResultListWrapper->isEmpty())
  276.    {
  277.       setResultWrapper(&iArrest);
  278.    }
  279.  
  280.    dResultListWrapper->add(&iArrest);
  281.    return *this;
  282. }
  283.  
  284. /*------------------------------------------------------------------
  285.  * setResultWrapper()
  286.  *-----------------------------------------------------------------*/
  287. IArrestClientMgr & IArrestClientMgr ::
  288.   setResultWrapper (IArrest * iResultWrapper)
  289. {
  290.   if (dResultWrapper != iResultWrapper)
  291.   {
  292.      if (dResultWrapper)
  293.         delete dResultWrapper;
  294.      dResultWrapper = iResultWrapper;
  295.      notifyObservers(INotificationEvent(resultObjectId, *this, false));
  296.      notifyObservers(INotificationEvent(resultWrapperId, *this, false));
  297.   }
  298.   return *this;
  299. }
  300.  
  301. /*------------------------------------------------------------------
  302.  * setResultWrapper()
  303.  *-----------------------------------------------------------------*/
  304. IArrestClientMgr & IArrestClientMgr ::
  305.   setResultWrapper (const IArrest & iResult)
  306. {
  307.   /*****************************************************************
  308.    * Have to make a copy of the IArrest object passed in since it's
  309.    * identified as being a const.  That is, the compiler won't
  310.    * allow dResultWrapper = &iResultWrapper, since it would allow
  311.    * us, via dResultWrapper, to update the IArrest object.
  312.    *****************************************************************/
  313.   return setResultWrapper(new IArrest(iResult));
  314. }
  315.