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 >
Wrap
Text File
|
1995-05-22
|
13KB
|
352 lines
//****************************************************************************
// ISuspectClientMgr Class - C++ Source File (isusrmgr.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 "isusrmgr.hpp"
#ifndef _INOTIFEV_
#include <inotifev.hpp>
#endif
#ifndef _ITRACE_
#include <itrace.hpp>
#endif
#ifndef _IEXCBASE_
#include <iexcbase.hpp>
#endif
#ifndef _IRSLTREC_
#include "irsltrec.hpp"
#endif
#ifndef _ISUSREC_
#include "isusrec.hpp"
#endif
#ifndef _IADD_
#include "iadd.hpp"
#endif
#ifndef _QUERYDB_
#include "querydb.hpp"
#endif
/*******************************************************************
* Events
*******************************************************************/
INotificationId ISuspectClientMgr :: requestBufferId = "ISuspectClientMgr::requestBuffer";
INotificationId ISuspectClientMgr :: resultBufferId = "ISuspectClientMgr::resultBuffer";
INotificationId ISuspectClientMgr :: resultListId = "ISuspectClientMgr::resultList";
INotificationId ISuspectClientMgr :: resultListWrapperId = "ISuspectClientMgr::resultListWrapper";
INotificationId ISuspectClientMgr :: resultObjectId = "ISuspectClientMgr::resultObject";
INotificationId ISuspectClientMgr :: resultWrapperId = "ISuspectClientMgr::resultWrapper";
INotificationId ISuspectClientMgr :: parsedResultId = "ISuspectClientMgr::parsedResult";
INotificationId ISuspectClientMgr :: sameRequestId = "ISuspectClientMgr::sameRequest";
INotificationId ISuspectClientMgr :: noObjectsFoundId = "ISuspectClientMgr::noObjectsFound";
INotificationId ISuspectClientMgr :: oneObjectFoundId = "ISuspectClientMgr::oneObjectFound";
INotificationId ISuspectClientMgr :: manyObjectsFoundId = "ISuspectClientMgr::manyObjectsFound";
/*******************************************************************
* Constructors
*******************************************************************/
ISuspectClientMgr :: ISuspectClientMgr() :
dRequestBuffer(""),
dResultBuffer(""),
dResultWrapper(0),
dResultListWrapper(new IVSequence<ISuspect *>)
{
enableNotification();
dResultListWrapper->enableNotification();
}
/*******************************************************************
* Destructor
*******************************************************************/
ISuspectClientMgr :: ~ISuspectClientMgr()
{
if (dResultWrapper)
delete dResultWrapper;
if (dResultListWrapper)
delete dResultListWrapper;
}
/****************************************************************************
* Attribute Access Member Functions
****************************************************************************/
/*------------------------------------------------------------------
* requestBuffer
*-----------------------------------------------------------------*/
IString ISuspectClientMgr :: requestBuffer () const
{
return dRequestBuffer;
}
ISuspectClientMgr & ISuspectClientMgr ::
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 ISuspectClientMgr :: resultBuffer () const
{
return dResultBuffer;
}
ISuspectClientMgr & ISuspectClientMgr ::
setResultBuffer (const IString & iResultBuffer)
{
if (dResultBuffer != iResultBuffer)
{
dResultBuffer = iResultBuffer; //Set class.attribute.title%>
notifyObservers(INotificationEvent(resultBufferId, *this, true,
IEventData((char *)iResultBuffer)));
}
else
notifyObservers(INotificationEvent(resultBufferId, *this, false));
//moved this outside of the test so would fire each time; found wasn't
//getting message displayed when did 2 consecutive not-found searches
return *this;
}
/*------------------------------------------------------------------
* resultList (read-only) and resultListWrapper
*-----------------------------------------------------------------*/
IVSequence <ISuspect *> ISuspectClientMgr ::
resultList () const
{
return *dResultListWrapper;
}
IVSequence <ISuspect *> * ISuspectClientMgr ::
resultListWrapper () const
{
return dResultListWrapper;
}
/*------------------------------------------------------------------
* resultObject and resultWrapper (read-only)
*-----------------------------------------------------------------*/
ISuspect * ISuspectClientMgr :: resultWrapper () const
{
return dResultWrapper;
}
ISuspect ISuspectClientMgr :: resultObject () const
{
return *dResultWrapper;
}
/*******************************************************************
* Actions
*******************************************************************/
/*------------------------------------------------------------------
* getAll (retrieves all suspects from DB2/2 database)
*-----------------------------------------------------------------*/
IString ISuspectClientMgr :: getAll()
{
IResultRecord rsltRec;
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("Calling the DB server.");
rsltRec = getAllSuspects();
ITRACE_DEVELOP("Number suspects found: " + IString(rsltRec.numResults()));
return rsltRec.asString();
}
/*------------------------------------------------------------------
* processResult
* The user controls when dResultBuffer should be processed.
*-----------------------------------------------------------------*/
ISuspectClientMgr & ISuspectClientMgr :: processResult ()
{
ISuspect *suspect;
ISuspectRecord suspectRec;
IAddress address;
unsigned short recOffset, i;
IString buffer;
IFUNCTRACE_DEVELOP();
if (!dResultBuffer.isWhiteSpace())
{
ITRACE_DEVELOP("resultBuffer received.");
IResultRecord resultRec(dResultBuffer);
ITRACE_DEVELOP(resultRec.asDebugInfo());
//clear the result list if it's not empty (i.e., if it was set in a previous invocation)
if (dResultListWrapper->numberOfElements())
{
ITRACE_DEVELOP("had to empty the resultList");
dResultListWrapper->removeAll();
}
if (resultRec.numResults() != 0)
{
recOffset = 1;
Boolean noError = true;
for (i=0 ; i < resultRec.numResults() && noError; i++)
{
suspect = new ISuspect;
if (recOffset + suspectRec.size() - 1 <= resultRec.size() - 2)
{
buffer = resultRec.resultData().subString(recOffset,suspectRec.size());
suspectRec = buffer;
ITRACE_DEVELOP("Suspect record" + IString(i) + " ...");
ITRACE_DEVELOP(suspectRec.asDebugInfo());
suspect->setLastName(suspectRec.lastName().strip());
suspect->setFirstName(suspectRec.firstName().strip());
suspect->setInfo(suspectRec.description().strip());
suspect->enableHasMole(suspectRec.hasMole());
suspect->enableHasScar(suspectRec.hasScar());
suspect->enableHasTattoo(suspectRec.hasTattoo());
suspect->setBirthDate(suspectRec.birthDate().strip());
suspect->setBookNumber(suspectRec.bookNumber());
suspect->setMO(suspectRec.MO().strip());
suspect->setMoleDesc(suspectRec.moleDescription().strip());
suspect->setScarDesc(suspectRec.scarDescription().strip());
suspect->setTattooDesc(suspectRec.tattooDescription().strip());
suspect->setEyeColor(suspectRec.eyeColor());
suspect->setHairColor(suspectRec.hairColor());
suspect->setGender(suspectRec.gender());
suspect->setHeight(suspectRec.height());
suspect->setWeight(suspectRec.weight());
suspect->setMugFront(suspectRec.mugFront());
suspect->setMugLeft(suspectRec.mugLeft());
suspect->setMugRight(suspectRec.mugRight());
address.setStreet(suspectRec.street().strip());
address.setCity(suspectRec.city().strip());
address.setState(suspectRec.state().strip());
address.setZip(suspectRec.zip().strip());
// address.setCounty(suspectRec.county().strip());
suspect->setAddress(new IAddress( address ));
ITRACE_DEVELOP(suspect->asDebugInfo());
addResult(suspect); //adds suspect to dResultList
recOffset += suspectRec.size();
}
else
{
ITRACE_DEVELOP("The capacity of the result record buffer has been exceeded.");
noError = false;
}
}
}
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 information exists for the specified suspect.");
}
else
notifyObservers(INotificationEvent(manyObjectsFoundId, *this, false));
}
return *this;
}
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
ISuspectClientMgr & ISuspectClientMgr :: addResult
(ISuspect * iSuspectWrapper)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(*)");
ITRACE_DEVELOP(iSuspectWrapper->asDebugInfo());
if (dResultListWrapper->isEmpty())
{
setResultWrapper(iSuspectWrapper);
}
dResultListWrapper->addAsLast(iSuspectWrapper);
ITRACE_DEVELOP("added a suspect to the resultList");
return *this;
}
/*------------------------------------------------------------------
* addResult()
*-----------------------------------------------------------------*/
ISuspectClientMgr & ISuspectClientMgr :: addResult
(ISuspect & iSuspect)
{
IFUNCTRACE_DEVELOP();
ITRACE_DEVELOP("addResult(&)");
if (dResultListWrapper->isEmpty())
{
setResultWrapper(&iSuspect);
}
dResultListWrapper->addAsLast(&iSuspect);
ITRACE_DEVELOP("added a suspect to the resultList");
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
ISuspectClientMgr & ISuspectClientMgr ::
setResultWrapper (ISuspect * iResultWrapper)
{
if (dResultWrapper != iResultWrapper)
{
if (dResultWrapper)
delete dResultWrapper;
dResultWrapper = iResultWrapper;
notifyObservers(INotificationEvent(resultObjectId, *this, false));
notifyObservers(INotificationEvent(resultWrapperId, *this, false));
}
return *this;
}
/*------------------------------------------------------------------
* setResultWrapper()
*-----------------------------------------------------------------*/
ISuspectClientMgr & ISuspectClientMgr ::
setResultWrapper (const ISuspect & iResult)
{
/*****************************************************************
* Have to make a copy of the ISuspect 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 ISuspect object.
*****************************************************************/
return setResultWrapper(new ISuspect(iResult));
}