Subversion Repositories DevTools

Rev

Rev 2228 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2218 sbetterm 1
//## begin module%1.7%.codegen_version preserve=yes
2
//   Read the documentation to learn more about C++ code generator
3
//   versioning.
4
//## end module%1.7%.codegen_version
5
 
6
//## begin module%41F607FA0261.cm preserve=no
7
//## end module%41F607FA0261.cm
8
 
9
//## begin module%41F607FA0261.cp preserve=no
10
//	C O P Y R I G H T   N O T I C E
11
//	This material is confidential to ERG and may not be disclosed in whole
12
//	or in part to any third party nor used in any manner whatsoever other
13
//	than for the purposes expressly consented to by ERG in writing.
14
//
15
//	This material is also copyright and may not be reproduced, stored in a
16
//	retrieval system or transmitted in any form or by any means in whole or
17
//	in part without the express written consent of ERG.
18
//## end module%41F607FA0261.cp
19
 
20
//## Module: TransactionSpecification%41F607FA0261; Pseudo Package body
21
//## Subsystem: MASS::Dev::Tools::TxnTestManager::src%41F5A79001E4
22
//## Source file: Z:\MASS_Dev\Tools\TxnTestManager\src\TransactionSpecification.cpp
23
 
24
//## begin module%41F607FA0261.additionalIncludes preserve=no
25
//## end module%41F607FA0261.additionalIncludes
26
 
27
//## begin module%41F607FA0261.includes preserve=yes
28
#pragma warn -com
29
#include <LoggingMacros.h>
30
#pragma warn +com
31
//## end module%41F607FA0261.includes
32
 
2228 sbetterm 33
// IXmlSchemaWrapperSchema
34
#include "IXmlSchemaWrapperSchema.h"
35
// IXmlSchemaWrapperString
36
#include "IXmlSchemaWrapperString.h"
2222 sbetterm 37
// Iteration
38
#include "Iteration.h"
39
// TestScenario
40
#include "TestScenario.h"
41
// TimeEstimate
42
#include "TimeEstimate.h"
43
// ProgressBar
44
#include "ProgressBar.h"
2218 sbetterm 45
// IXmlSchemaWrapperByteArray
46
#include "IXmlSchemaWrapperByteArray.h"
47
// IXmlSchemaWrapperElement
48
#include "IXmlSchemaWrapperElement.h"
2222 sbetterm 49
// IXmlSchemaWrapperFactory
50
#include "IXmlSchemaWrapperFactory.h"
51
// IXmlSchemaWrapperStream
52
#include "IXmlSchemaWrapperStream.h"
2228 sbetterm 53
// TransactionSpecificationValue
54
#include "TransactionSpecificationValue.h"
55
// TransactionSpecification
56
#include "TransactionSpecification.h"
2222 sbetterm 57
// MacQualification
58
#include "MacQualification.h"
2218 sbetterm 59
// EvaluationCallback
60
#include "EvaluationCallback.h"
61
// EvaluationContext
62
#include "EvaluationContext.h"
63
// TransactionStream
64
#include "TransactionStream.h"
65
// TransactionStructure
66
#include "TransactionStructure.h"
2228 sbetterm 67
// IHash
68
#include "IHash.h"
2222 sbetterm 69
// IMessageDigest
70
#include "IMessageDigest.h"
2218 sbetterm 71
//## begin module%41F607FA0261.additionalDeclarations preserve=yes
72
#include <sstream>
73
#include "Utilities.h"
2222 sbetterm 74
 
2228 sbetterm 75
#define COMPENSATE_FOR_PARSER_BUG 0
2222 sbetterm 76
#if COMPENSATE_FOR_PARSER_BUG
77
static void rotateBuffer( unsigned char * buffer, const unsigned int & length )
78
{
79
	unsigned char b;
80
 
81
	for ( unsigned int i=0, j=length-1; i<length/2; ++i,--j )
82
	{
83
		b = buffer[ i ];
84
		buffer[ i ] = buffer[ j ];
85
		buffer[ j ] = b;
86
	}
87
}
88
#endif
89
 
2218 sbetterm 90
//## end module%41F607FA0261.additionalDeclarations
91
 
92
 
2228 sbetterm 93
// Class TransactionSpecification 
2218 sbetterm 94
 
95
//## begin TransactionSpecification::headerStructureName%4206D764033E.attr preserve=no  private: static char {RAC} "SysHdr_t"
96
const char *TransactionSpecification::g_headerStructureName = "SysHdr_t";
97
//## end TransactionSpecification::headerStructureName%4206D764033E.attr
98
 
99
//## Operation: TransactionSpecification%41F7060D0204
100
TransactionSpecification::TransactionSpecification (const int &transactionSpecificationNumber)
101
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit preserve=no
2228 sbetterm 102
      : m_structureIndex(0),
103
        m_transactionSpecificationNumber(0),
104
        m_udSubtype(0),
105
        m_udType(0),
106
        m_formatVersion(0),
107
        m_scenario(0),
2218 sbetterm 108
        m_string(0),
109
        m_structure(0),
110
        m_macFields(0)
111
  //## end TransactionSpecification::TransactionSpecification%41F7060D0204.hasinit
112
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.initialization preserve=yes
113
  //## end TransactionSpecification::TransactionSpecification%41F7060D0204.initialization
114
{
115
  //## begin TransactionSpecification::TransactionSpecification%41F7060D0204.body preserve=yes
116
 
117
  m_transactionSpecificationNumber = transactionSpecificationNumber;
118
 
119
  //## end TransactionSpecification::TransactionSpecification%41F7060D0204.body
120
}
121
 
122
//## Operation: TransactionSpecification%42045473030D
123
TransactionSpecification::TransactionSpecification (const int &transactionSpecificationNumber, const std::string &payloadStructureName, TestScenario& scenario)
124
  //## begin TransactionSpecification::TransactionSpecification%42045473030D.hasinit preserve=no
125
      : m_structureIndex(0),
126
        m_transactionSpecificationNumber(0),
127
        m_udSubtype(0),
128
        m_udType(0),
129
        m_formatVersion(0),
130
        m_scenario(0),
131
        m_string(0),
132
        m_structure(0),
133
        m_macFields(0)
134
  //## end TransactionSpecification::TransactionSpecification%42045473030D.hasinit
135
  //## begin TransactionSpecification::TransactionSpecification%42045473030D.initialization preserve=yes
136
  //## end TransactionSpecification::TransactionSpecification%42045473030D.initialization
137
{
138
  //## begin TransactionSpecification::TransactionSpecification%42045473030D.body preserve=yes
139
 
140
	m_formatVersion	= scenario.getIteration().getFormatVersion();
141
	m_scenario		= &scenario;
142
	m_string
143
		= &scenario.getIteration().getSchemaWrapperFactory().createString();
144
	m_structureName	= payloadStructureName;
145
	m_transactionSpecificationNumber
146
		= transactionSpecificationNumber;
147
 
148
	// Allocate the structures that we'll need for this transaction.
149
	TransactionStructure * object = 0;
150
	try
151
	{
152
		object =new TransactionStructure(
153
			g_headerStructureName,
154
			m_scenario->getIteration().getIterationId(),
155
			m_scenario->getIteration().getSchemaWrapperFactory(),
156
			m_scenario->getIteration().getSchema(),
157
			true );
158
		m_structure.push_back( object );
159
		object = 0;
160
 
161
		object =new TransactionStructure(
162
			payloadStructureName,
163
			m_scenario->getIteration().getIterationId(),
164
			m_scenario->getIteration().getSchemaWrapperFactory(),
165
			m_scenario->getIteration().getSchema(),
166
			false );
167
		m_structure.push_back( object );
168
		object = 0;
169
	}
170
	catch ( ... )
171
	{
172
		// Rollback.
173
		delete object;
174
		object = 0;
175
 
176
		for ( std::vector< TransactionStructure * >::iterator
177
				structure = m_structure.begin();
178
			  structure != m_structure.end();
179
			  ++structure )
180
		{
181
			delete *structure;
182
			*structure = 0;
183
		}
184
		m_structure.clear();
185
 
186
		throw;
187
	}
188
 
189
  //## end TransactionSpecification::TransactionSpecification%42045473030D.body
190
}
191
 
192
 
193
TransactionSpecification::~TransactionSpecification()
194
{
195
  //## begin TransactionSpecification::~TransactionSpecification%41F607FA0261_dest.body preserve=yes
196
 
197
	for ( std::map< std::string, TransactionSpecificationValue * >::iterator
198
			transaction = m_value.begin();
199
		  transaction != m_value.end();
200
		  ++transaction )
201
	{
202
		delete transaction->second;
203
		transaction->second = 0;
204
	}
205
	m_value.clear();
206
 
207
	for ( std::vector< TransactionStructure * >::iterator
208
			structure = m_structure.begin();
209
		  structure != m_structure.end();
210
		  ++structure )
211
	{
212
		delete *structure;
213
		*structure = 0;
214
	}
215
	m_structure.clear();
216
 
217
	if ( m_string && m_scenario )
218
	{
219
		m_scenario->getIteration().getSchemaWrapperFactory().destroyString( *m_string );
220
		m_string = 0;
221
	}
222
	m_scenario = 0;	// We don't own this object.
223
 
224
  //## end TransactionSpecification::~TransactionSpecification%41F607FA0261_dest.body
225
}
226
 
227
 
228
 
229
//## Other Operations (implementation)
230
//## Operation: addMacField%4212DBC1031E
231
void TransactionSpecification::addMacField (XMLSchema::IXmlSchemaWrapperElement &element)
232
{
233
  //## begin TransactionSpecification::addMacField%4212DBC1031E.body preserve=yes
234
 
235
	m_macFields.push_back( &element );  
236
 
237
  //## end TransactionSpecification::addMacField%4212DBC1031E.body
238
}
239
 
240
//## Operation: addValue%41F70652035C
241
void TransactionSpecification::addValue (const std::string &xPath, const std::string &value, const bool &obsolete)
242
{
243
  //## begin TransactionSpecification::addValue%41F70652035C.body preserve=yes
244
 
245
	TransactionSpecificationValue * theValue = 0;
246
 
247
	try
248
	{
249
		theValue = new TransactionSpecificationValue( xPath, value, obsolete );
250
 
251
		if ( !m_value.insert(
252
				std::map< std::string, TransactionSpecificationValue * >::value_type(
253
					theValue->getXPath(),
254
					theValue ) ).second )
255
		{
256
			MTHROW( std::runtime_error, \
257
				"Cannot add value \"" \
258
				<< theValue->getXPath() \
259
				<< "\" to transaction " \
260
				<< m_transactionSpecificationNumber \
261
				<< '.' );
262
		}
263
	}
264
	catch ( ... )
265
	{
266
		delete theValue;
267
		theValue = 0;
268
 
269
		throw;
270
	}
271
 
272
  //## end TransactionSpecification::addValue%41F70652035C.body
273
}
274
 
275
//## Operation: clearMacFields%42130B2D0377
276
void TransactionSpecification::clearMacFields ()
277
{
278
  //## begin TransactionSpecification::clearMacFields%42130B2D0377.body preserve=yes
279
 
280
	XMLSchema::IXmlSchemaWrapperFactory & factory
281
		= m_scenario->getIteration().getSchemaWrapperFactory();
282
	for ( std::vector< XMLSchema::IXmlSchemaWrapperElement * >
283
			::iterator element = m_macFields.begin();
284
		  element != m_macFields.end();
285
		  ++element )
286
	{
287
		factory.destroySchemaElement( **element );
288
		*element = 0;
289
	}
290
	m_macFields.clear();
291
 
292
  //## end TransactionSpecification::clearMacFields%42130B2D0377.body
293
}
294
 
295
//## Operation: clearMarks%41F705790276
296
void TransactionSpecification::clearMarks ()
297
{
298
  //## begin TransactionSpecification::clearMarks%41F705790276.body preserve=yes
299
 
300
	for ( std::map< std::string, TransactionSpecificationValue * >::iterator
301
			where = m_value.begin();
302
		  where != m_value.end();
303
		  ++where )
304
	{
305
		where->second->unmark();
306
	}
307
 
308
  //## end TransactionSpecification::clearMarks%41F705790276.body
309
}
310
 
311
//## Operation: generate%4204564D02F3
312
const bool TransactionSpecification::generate (TransactionStream& stream, const bool &generateHeaders, EvaluationContext& evaluationContext)
313
{
314
  //## begin TransactionSpecification::generate%4204564D02F3.body preserve=yes
315
 
2222 sbetterm 316
	XMLSchema::IXmlSchemaWrapperFactory & xmlSchemaWrapperFactory
317
		= m_scenario->getIteration().getSchemaWrapperFactory();
318
 
2218 sbetterm 319
	/**
320
	 *	Traverse the structures associated with this transaction  in order,
321
	 *	querying our collection of defined fields for every schema element
322
	 *	that we encounter.  When we have a match, then we evaluate the
323
	 *	expression found, and assign the result to the schema element currently
324
	 * 	being visited.
325
	 */
326
 
327
	evaluationContext.setTransaction( *this );
328
 
329
	EvaluationCallback callback( *this, evaluationContext );
330
 
331
	bool generated = false;
332
	m_structureIndex = 0;
333
	std::vector< TransactionStructure * >::iterator structure;
334
	for ( structure = m_structure.begin();
335
		  structure != m_structure.end();
336
		  ++structure )
337
	{
338
		if ( generateHeaders || !(*structure)->isHeader() )
339
		{
340
			generated = (*structure)->getSchemaElement().traverse( callback );
341
			if ( !generated )
342
			{
343
				break;
344
			}
345
		}
346
		++m_structureIndex;
347
	}
348
 
349
	if ( generated )
350
	{
351
		/**
352
		 *	If we have any MAC fields, then we must compute the MAC and assign
353
		 *	the MAC to each element in the collection.
354
		 */
355
		if ( m_macFields.size() )
356
		{
357
			if ( evaluationContext.haveMessageDigest() )
358
			{
2222 sbetterm 359
				/**
360
				 *	Create a serialsation stream, and serialise all attributes
361
				 *	into it that are to be included in the MAC.  Then MAC the
362
				 *	stream.  We need to do this because we need to MAC the
363
				 *	serialised form, not the internal binary form.
364
				 */
365
				MacQualification macQualification( evaluationContext );
366
 
367
				XMLSchema::IXmlSchemaWrapperStream *	stream	= 0;
368
				XMLSchema::IXmlSchemaWrapperByteArray *	digest	= 0;
369
 
2218 sbetterm 370
				try
371
				{
2222 sbetterm 372
					stream = &xmlSchemaWrapperFactory.createXdrStream();
373
					digest = &xmlSchemaWrapperFactory.createByteArray();
2218 sbetterm 374
 
375
					for ( structure = m_structure.begin();
376
						  structure != m_structure.end();
377
						  ++structure )
378
					{
2222 sbetterm 379
						// We only include the structure in the MAC computation,
380
						// never the header.
2218 sbetterm 381
						if ( !(*structure)->isHeader() )
382
						{
2222 sbetterm 383
							if ( !(*structure)->write(
384
									*stream,
385
									macQualification ) )
2218 sbetterm 386
							{
2222 sbetterm 387
								generated = false;
2218 sbetterm 388
								break;
389
							}
390
						}
391
					}
392
 
2222 sbetterm 393
					if ( generated )
2218 sbetterm 394
					{
2222 sbetterm 395
						void *			buffer = 0;
396
						unsigned int	length = 0;
397
 
398
						// When we get a zero-length MAC, we don't assign it.
399
						if ( stream->getData( buffer, length ) )
2218 sbetterm 400
						{
2228 sbetterm 401
							evaluationContext.getMessageDigest().reset();
402
 
403
							if ( evaluationContext.haveHash() )
404
							{
405
								IHash & hash = evaluationContext.getHash();
406
								generated = hash.updateByteArray(
407
									buffer,
408
									length );
409
								if ( generated )
410
								{
411
									generated = evaluationContext.
412
										getMessageDigest().updateByteArray(
413
											hash.getValue(),
414
											hash.getLength() );
415
								}
416
							}
417
							else
418
							{
419
								generated = evaluationContext.getMessageDigest().
420
									updateByteArray( buffer, length );
421
							}
2222 sbetterm 422
							if ( generated )
2218 sbetterm 423
							{
2222 sbetterm 424
								if ( evaluationContext.getMessageDigest().digest() )
425
								{
426
									if ( evaluationContext.getMessageDigest().getLength() )
427
									{
428
#if COMPENSATE_FOR_PARSER_BUG
429
										/**
430
										 *	Compensate for the parser treating
431
										 *	an array of 8 U8 as a U64 (Why does
432
										 *	it do that?  Its wrong.).
433
										 */
434
										unsigned char * b = const_cast< unsigned char * >( evaluationContext.getMessageDigest().getValue() );
435
										length = evaluationContext.getMessageDigest().getLength();
436
										rotateBuffer( b, length );
437
										digest->assign( b, length );
438
#else
439
										digest->assign(
440
											evaluationContext.getMessageDigest().getValue(),
441
											evaluationContext.getMessageDigest().getLength() );
442
#endif // #ifdef COMPENSATE_FOR_PARSER_BUG
443
 
444
										for ( std::vector< XMLSchema::IXmlSchemaWrapperElement * >
445
												::iterator macField = m_macFields.begin();
446
											  macField != m_macFields.end();
447
											  ++macField )
448
										{
449
											if ( !(*macField)->setByteArray( *digest ) )
450
											{
451
												generated = false;
452
												break;
453
											}
454
										}
455
									}
456
									else
457
									{
458
										generated = false;
459
									}
460
								}
461
								else
462
								{
463
									generated = false;
464
								}
2218 sbetterm 465
							}
466
						}
467
					}
2222 sbetterm 468
 
2218 sbetterm 469
				}
470
				__finally
471
				{
2222 sbetterm 472
					if ( digest )
2218 sbetterm 473
					{
2222 sbetterm 474
						xmlSchemaWrapperFactory.destroyByteArray( *digest );
475
						digest = 0;
2218 sbetterm 476
					}
2222 sbetterm 477
 
478
					if ( stream )
479
					{
480
						xmlSchemaWrapperFactory.destroyStream( *stream );
481
						stream = 0;
482
					}
2218 sbetterm 483
				}
484
			}
485
			else
486
			{
2222 sbetterm 487
				generated = false;
488
			}
489
 
490
			if ( !generated )
491
			{
2218 sbetterm 492
				std::stringstream message;
493
				message
494
					<< "Cannot compute MAC.  Is the security subsystem operational?";
495
				MERROR( message.str() );
496
				message << "  Ignore the error and continue?";
497
 
2222 sbetterm 498
				generated = ( MessageDlg(
499
									message.str().c_str(),
500
									mtConfirmation,
501
									TMsgDlgButtons() << mbYes << mbNo,
2230 sbetterm 502
 
2218 sbetterm 503
			}
504
			clearMacFields();
505
		}
506
	}
507
 
508
	if ( generated )
509
	{
2222 sbetterm 510
		for ( structure = m_structure.begin();
2218 sbetterm 511
			  structure != m_structure.end();
512
			  ++structure )
513
		{
514
			if ( generateHeaders || !(*structure)->isHeader() )
515
			{
516
				/**
517
				 *	Serialise the structure into the transaction stream.
518
				 */
519
				generated = (*structure)->write( stream );
520
				if ( !generated )
521
				{
522
					break;
523
				}
524
			}
525
		}
2222 sbetterm 526
 
527
		stream.incrementCount();
528
		if ( evaluationContext.haveProgressBar() )
529
		{
530
			evaluationContext.getProgressBar().increment();
531
		}
2218 sbetterm 532
		evaluationContext.getTimeEstimate().increment();
533
	}
534
 
535
	return ( generated );
536
 
537
  //## end TransactionSpecification::generate%4204564D02F3.body
538
}
539
 
540
//## Operation: getCurrentStructure%4213183F01DD
541
const TransactionStructure & TransactionSpecification::getCurrentStructure () const
542
{
543
  //## begin TransactionSpecification::getCurrentStructure%4213183F01DD.body preserve=yes
544
 
545
	return ( *m_structure[ m_structureIndex ] );  
546
 
547
  //## end TransactionSpecification::getCurrentStructure%4213183F01DD.body
548
}
549
 
550
//## Operation: getFormatVersion%4208BB80011D
551
const int & TransactionSpecification::getFormatVersion () const
552
{
553
  //## begin TransactionSpecification::getFormatVersion%4208BB80011D.body preserve=yes
554
 
555
	return ( m_formatVersion );
556
 
557
  //## end TransactionSpecification::getFormatVersion%4208BB80011D.body
558
}
559
 
560
//## Operation: getScenario%420471B00192
561
const TestScenario & TransactionSpecification::getScenario () const
562
{
563
  //## begin TransactionSpecification::getScenario%420471B00192.body preserve=yes
564
 
565
	return ( *m_scenario );
566
 
567
  //## end TransactionSpecification::getScenario%420471B00192.body
568
}
569
 
570
//## Operation: getTransactionField%4204283B033E
571
TransactionSpecificationValue& TransactionSpecification::getTransactionField (const std::string &xpath)
572
{
573
  //## begin TransactionSpecification::getTransactionField%4204283B033E.body preserve=yes
574
 
575
	std::map< std::string, TransactionSpecificationValue * >::const_iterator
576
		instance = m_value.find( xpath );
577
 
578
	if ( instance != m_value.end() )
579
	{
580
		return ( *instance->second );
581
	}
582
	else
583
	{
584
		TransactionSpecificationValue * object = 0;
585
 
586
		try
587
		{
588
			object = new TransactionSpecificationValue( xpath, *this );
589
 
590
			if ( m_value.insert(
591
					std::map< std::string, TransactionSpecificationValue * >::value_type(
592
						xpath,
593
						object ) ).second )
594
			{
595
				return ( *object );
596
			}
597
			else
598
			{
599
				MTHROW( std::runtime_error, \
600
					"Cannot add transaction field \"" \
601
					<< xpath \
602
					<< "\" to transaction " \
603
					<< m_transactionSpecificationNumber \
604
					<< '.' );
605
			}
606
		}
607
		catch ( ... )
608
		{
609
			delete object;
610
			object = 0;
611
 
612
			throw;
613
		}
614
	}
615
 
616
  //## end TransactionSpecification::getTransactionField%4204283B033E.body
617
}
618
 
619
//## Operation: getTransactionSpecificationNumber%41F71AD2002F
620
const int & TransactionSpecification::getTransactionSpecificationNumber () const
621
{
622
  //## begin TransactionSpecification::getTransactionSpecificationNumber%41F71AD2002F.body preserve=yes
623
 
624
	return ( m_transactionSpecificationNumber );
625
 
626
  //## end TransactionSpecification::getTransactionSpecificationNumber%41F71AD2002F.body
627
}
628
 
629
//## Operation: getUdSubtype%4208AFAF01F7
630
const unsigned short & TransactionSpecification::getUdSubtype () const
631
{
632
  //## begin TransactionSpecification::getUdSubtype%4208AFAF01F7.body preserve=yes
633
 
634
	return ( m_udSubtype );
635
 
636
  //## end TransactionSpecification::getUdSubtype%4208AFAF01F7.body
637
}
638
 
639
//## Operation: getUdType%4208AFAF0245
640
const unsigned short & TransactionSpecification::getUdType () const
641
{
642
  //## begin TransactionSpecification::getUdType%4208AFAF0245.body preserve=yes
643
 
644
	return ( m_udType );
645
 
646
  //## end TransactionSpecification::getUdType%4208AFAF0245.body
647
}
648
 
649
//## Operation: getValues%41F705A600AC
650
const std::map< std::string, TransactionSpecificationValue * > & TransactionSpecification::getValues () const
651
{
652
  //## begin TransactionSpecification::getValues%41F705A600AC.body preserve=yes
653
 
654
	return ( m_value );
655
 
656
  //## end TransactionSpecification::getValues%41F705A600AC.body
657
}
658
 
659
//## Operation: isContained%41F70575014E
660
const bool TransactionSpecification::isContained (const std::string &xPath) const
661
{
662
  //## begin TransactionSpecification::isContained%41F70575014E.body preserve=yes
663
 
664
  return ( m_value.find( xPath ) != m_value.end() );
665
 
666
  //## end TransactionSpecification::isContained%41F70575014E.body
667
}
668
 
669
//## Operation: isMarked%41F708CB0307
670
const bool TransactionSpecification::isMarked (const std::string &xPath) const
671
{
672
  //## begin TransactionSpecification::isMarked%41F708CB0307.body preserve=yes
673
 
674
	std::map< std::string, TransactionSpecificationValue * >::const_iterator
675
		instance = m_value.find( xPath );
676
 
677
	if ( instance != m_value.end() )
678
	{
679
		return ( instance->second->isMarked() );
680
	}
681
	else
682
	{
683
		MTHROW( std::runtime_error, \
684
			"Cannot find value " << xPath << '.' );
685
	}
686
 
687
  //## end TransactionSpecification::isMarked%41F708CB0307.body
688
}
689
 
690
//## Operation: markValue%41F7069E002F
691
void TransactionSpecification::markValue (const std::string &xPath)
692
{
693
  //## begin TransactionSpecification::markValue%41F7069E002F.body preserve=yes
694
 
695
	std::map< std::string, TransactionSpecificationValue * >::const_iterator
696
		instance = m_value.find( xPath );
697
 
698
	if ( instance != m_value.end() )
699
	{
700
		instance->second->mark();
701
	}
702
	else
703
	{
704
		MTHROW( std::runtime_error, \
705
			"Cannot find value " << xPath << '.' );
706
	}
707
 
708
  //## end TransactionSpecification::markValue%41F7069E002F.body
709
}
710
 
711
//## Operation: setUdSubtype%42044110019A
712
const unsigned short & TransactionSpecification::setUdSubtype (const unsigned short &value)
713
{
714
  //## begin TransactionSpecification::setUdSubtype%42044110019A.body preserve=yes
715
 
716
	return ( m_udSubtype = value );
717
 
718
  //## end TransactionSpecification::setUdSubtype%42044110019A.body
719
}
720
 
721
//## Operation: setUdType%420440DE038E
722
const unsigned short & TransactionSpecification::setUdType (const unsigned short &value)
723
{
724
  //## begin TransactionSpecification::setUdType%420440DE038E.body preserve=yes
725
 
726
	return ( m_udType = value );
727
 
728
  //## end TransactionSpecification::setUdType%420440DE038E.body
729
}
730
 
731
//## Operation: evaluate%4205C6F500FC
732
const bool TransactionSpecification::evaluate (XMLSchema::IXmlSchemaWrapperElement &element, EvaluationContext& context)
733
{
734
  //## begin TransactionSpecification::evaluate%4205C6F500FC.body preserve=yes
735
 
736
	/**
737
	 *	Build an XPath from the name of the structure that we are traversing
738
	 *	right now and the xpath reported by the element being visited.  Then
739
	 *	look for a field with that XPath.
740
	 */
741
 
742
	std::stringstream xpath;
743
	if ( element.getAttributeValue( "xpath", *m_string ) )
744
	{
745
		xpath
746
			<< '/'
747
			<< m_structure[ m_structureIndex ]->getName()
748
			<< m_string->c_str();
749
 
750
		/**
751
		 *	Find the element if we have it.  We get calls for everything, not
752
		 *	just for what we have.  When we don't have the element, then we
753
		 *	have nothing to set, which is fine.
754
		 */
755
		std::map< std::string, TransactionSpecificationValue * >::iterator
756
			field = m_value.find( xpath.str() );
757
		if ( field != m_value.end() )
758
		{
759
			std::string value;
760
			bool postponed = false;
761
			if ( field->second->evaluate( value, true, context, postponed ) )
762
			{
763
				if ( !postponed )
764
				{
765
					*m_string = value.c_str();
766
					if ( element.setString( *m_string ) )
767
					{
768
						return ( true );
769
					}
770
					else
771
					{
772
						std::string datatype;
773
						if ( element.getAttributeValue( "datatype", *m_string ) )
774
						{
775
							datatype = m_string->c_str();
776
						}
777
 
778
						std::stringstream message;
779
						message
780
							<< "Cannot set value of \""
781
							<< xpath.str()
782
							<< "\" to \""
783
							<< value
784
							<< "\" as \""
785
							<< datatype
786
							<< "\".";
787
						MERROR( message.str() );
788
						message << "  Continue?";
789
 
790
						return ( MessageDlg(
791
									message.str().c_str(),
792
									mtConfirmation,
793
									TMsgDlgButtons() << mbYes << mbNo,
794
 
795
					}
796
				}
797
				else
798
				{
799
					return ( true );
800
				}
801
			}
802
			else
803
			{
804
				std::stringstream message;
805
				message
806
					<< "Cannot evaluate value of \"" \
807
					<< field->second->getExpression() \
808
					<< "\" for \"" \
809
					<< xpath.str() \
810
					<< "\".";
811
				MERROR( message.str() );
812
				message << "  Continue?";
813
 
814
				return ( MessageDlg(
815
							message.str().c_str(),
816
							mtConfirmation,
817
							TMsgDlgButtons() << mbYes << mbNo,
818
 
819
			}
820
		}
821
		else
822
		{
823
			// We have no value for this element, which is fine.
824
			return ( true );
825
		}
826
	}
827
	else
828
	{
829
		MERROR( "Cannot get xpath for schema element " << &element << '.' );
830
	}
831
 
832
	return ( false );
833
 
834
  //## end TransactionSpecification::evaluate%4205C6F500FC.body
835
}
836
 
837
// Additional Declarations
838
  //## begin TransactionSpecification%41F607FA0261.declarations preserve=yes
839
  //## end TransactionSpecification%41F607FA0261.declarations
840
 
841
//## begin module%41F607FA0261.epilog preserve=yes
842
//## end module%41F607FA0261.epilog