home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
VISBUILD
/
RAPSHEET
/
CPPOV23
/
IARSRMGR.CPP
< prev
next >
Wrap
Text File
|
1995-05-22
|
11KB
|
296 lines
//****************************************************************************
// IArrestClientMgr Class - C++ Source File (iarsrmgr.cpp) *
// *
// COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
// *
// DISCLAIMER OF WARRANTIES: *
// The following [enclosed] code is sample code created by IBM *
// Corporation. This sample code is not part of any standard IBM product *
// and is provided to you solely for the purpose of assisting you in the *
// development of your applications. The code is provided "AS IS", *
// without warranty of any kind. IBM shall not be liable for any damages *
// arising out of your use of the sample code, even if they have been *
// advised of the possibility of such damages. *
//****************************************************************************
//NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
//
#include "iarsrmgr.hpp" //IArrestClientMgr header
#ifndef _INOTIFEV_
#include "inotifev.hpp"
#endif
#ifndef _ITRACE_
#include <itrace.hpp>
#endif
#include "irsltrec.hpp" //IResultRecord header
#include "iarstrec.hpp" //IArrestRecord header
#include "querydb.hpp" //temp (for scaffold testing)
/*******************************************************************
* Events
*******************************************************************/
INotificationId IArrestClientMgr :: parsedResultId = "IArrestClientMgr::parsedResult";
INotificationId IArrestClientMgr :: requestBufferId = "IArrestClientMgr::requestBuffer";
INotificationId IArrestClientMgr :: resultBufferId = "IArrestClientMgr::resultBuffer";
INotificationId IArrestClientMgr :: resultListId = "IArrestClientMgr::resultList";
INotificationId IArrestClientMgr :: resultListWrapperId = "IArrestClientMgr::resultListWrapper";
INotificationId IArrestClientMgr :: resultObjectId = "IArrestClientMgr::resultObject";
INotificationId IArrestClientMgr :: resultWrapperId = "IArrestClientMgr::resultWrapper";
INotificationId IArrestClientMgr :: sameRequestId = "IArrestClientMgr::sameRequest";
INotificationId IArrestClientMgr :: noObjectsFoundId = "IArrestClientMgr::noObjectsFound";
INotificationId IArrestClientMgr :: oneObjectFoundId = "IArrestClientMgr::oneObjectFound";
INotificationId IArrestClientMgr :: manyObjectsFoundId = "IArrestClientMgr::manyObjectsFound";
/*******************************************************************
* Constructors
*******************************************************************/
IArrestClientMgr :: IArrestClientMgr() :
dRequestBuffer(""),
dResultBuffer(""),
dResultWrapper(0),
dResultListWrapper(new IVSequence<IArrest *>)
{
enableNotification();
dResultListWrapper->enableNotification();
}
/*******************************************************************
* Destructor
*******************************************************************/
IArrestClientMgr :: ~IArrestClientMgr()
{
if (dResultWrapper)
delete dResultWrapper;
if (dResultListWrapper)
delete dResultListWrapper;
}
/*******************************************************************
* Attribute Access Member Functions
*******************************************************************/
/*------------------------------------------------------------------
* requestBuffer
*-----------------------------------------------------------------*/
IString IArrestClientMgr :: requestBuffer () const
{
return dRequestBuffer;
}
IArrestClientMgr & IArrestClientMgr ::
setRequestBuffer (const IString & iRequestBuffer)
{
if (dRequestBuffer != iRequestBuffer)
{
dRequestBuffer = iRequestBuffer;
notifyObservers(INotificationEvent(requestBufferId, *this, true,
IEventData((char *)iRequestBuffer)));
}
else
notifyObservers(INotificationEvent(sameRequestId, *this, false));
return *this;
}
/*------------------------------------------------------------------
* resultBuffer
*-----------------------------------------------------------------*/
IString IArrestClientMgr :: resultBuffer () const
{
return dResultBuffer;
}
IArrestClientMgr & IArrestClientMgr ::
setResultBuffer (const IString & iResultBuffer)
{
if (dResultBuffer != iResultBuffer)
{
dResultBuffer = iResultBuffer;
notifyObservers(INotificationEvent(resultBufferId, *this, true,
IEventData((char *)iResultBuffer)));
} /* endif */
return *this;
}
/*------------------------------------------------------------------
* resultList (read-only) and resultListWrapper
*-----------------------------------------------------------------*/
IVSequence <IArrest *> IArrestClientMgr ::
resultList () const
{
return *dResultListWrapper;
}
IVSequence <IArrest *> * IArrestClientMgr ::
resultListWrapper () const
{
return dResultListWrapper;
}
/*------------------------------------------------------------------
* resultObject and resultWrapper (read-only)
*-----------------------------------------------------------------*/
IArrest * IArrestClientMgr :: resultWrapper () const
{
return dResultWrapper;
}
IArrest IArrestClientMgr :: resultObject () const
{
return *dResultWrapper;
}
/*******************************************************************
* Actions
*******************************************************************/
/*------------------------------------------------------------------
* allbyBookNumber
*-----------------------------------------------------------------*/
IString IArrestClientMgr :: allByBookNumber (unsigned long aBookNumber)
{
IResultRecord rsltRec;
IString suspectKey = IString(aBookNumber);
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("suspectKey: " + suspectKey + ".");
if (dRequestBuffer != suspectKey)
{
setRequestBuffer(suspectKey);
ITRACE_DEVELOP("Calling the DB server.");
rsltRec = getAllArrests(aBookNumber);
ITRACE_DEVELOP("Number arrest records found: " + IString(rsltRec.numResults()));
}
else
setRequestBuffer(suspectKey);
return rsltRec.asString();
}
/*------------------------------------------------------------------
* processResult()
* The user controls when dResultBuffer should be processed.
*-----------------------------------------------------------------*/
IArrestClientMgr & IArrestClientMgr :: processResult ()
{
IArrest * arrestWrapper;
IArrestRecord arrestRec;
unsigned short recOffset, i;
IString buffer;
IFUNCTRACE_DEVELOP();
if (!dResultBuffer.isWhiteSpace())
{
IResultRecord resultRec(dResultBuffer);
//clear the result list if it's not empty (i.e., if it was set in a previous invocation)
if (dResultListWrapper->numberOfElements())
dResultListWrapper->removeAll();
recOffset = 1;
for (i=0 ; i < resultRec.numResults(); i++)
{
arrestWrapper = new IArrest;
buffer = resultRec.resultData().subString(
recOffset,arrestRec.size());
arrestRec = buffer;
arrestWrapper->setCharge(arrestRec.charge());
arrestWrapper->setStatus(arrestRec.status());
arrestWrapper->setStatusDate(arrestRec.statusDate());
addResult(arrestWrapper); //adds arrestWrapper to
//the result list
recOffset += arrestRec.size(); //get the next arrestRec
}
notifyObservers(INotificationEvent(parsedResultId, *this, false));
if (resultRec.numResults() == 1)
notifyObservers(INotificationEvent(oneObjectFoundId, *this, false));
else if (resultRec.numResults() == 0)
{
notifyObservers(INotificationEvent(noObjectsFoundId, *this, false));
throw IException("No aliases exist for the specified suspect."); }
else
notifyObservers(INotificationEvent(manyObjectsFoundId, *this, false));
}
return *this;
}
/*******************************************************************
* Class Member Functions
*******************************************************************/
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
IArrestClientMgr & IArrestClientMgr ::
addResult (IArrest * iArrestWrapper)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(*) of iarsrmgr.");
if (dResultListWrapper->isEmpty())
{
setResultWrapper(iArrestWrapper);
}
dResultListWrapper->add(iArrestWrapper);
return *this;
}
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
IArrestClientMgr & IArrestClientMgr ::
addResult (IArrest & iArrest)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(&) of iarsrmgr.");
if (dResultListWrapper->isEmpty())
{
setResultWrapper(&iArrest);
}
dResultListWrapper->add(&iArrest);
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
IArrestClientMgr & IArrestClientMgr ::
setResultWrapper (IArrest * iResultWrapper)
{
if (dResultWrapper != iResultWrapper)
{
if (dResultWrapper)
delete dResultWrapper;
dResultWrapper = iResultWrapper;
notifyObservers(INotificationEvent(resultObjectId, *this, false));
notifyObservers(INotificationEvent(resultWrapperId, *this, false));
}
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
IArrestClientMgr & IArrestClientMgr ::
setResultWrapper (const IArrest & iResult)
{
/*****************************************************************
* Have to make a copy of the IArrest object passed in since it's
* identified as being a const. That is, the compiler won't
* allow dResultWrapper = &iResultWrapper, since it would allow
* us, via dResultWrapper, to update the IArrest object.
*****************************************************************/
return setResultWrapper(new IArrest(iResult));
}