Subversion Repositories DevTools

Rev

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