summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Trader/Trader.cpp
blob: 7610561a7c25b2bda6bfa726b0eed5c360cccfe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
// $Id$

#include "orbsvcs/Trader/Trader.h"
#include "orbsvcs/Trader/Offer_Iterators_T.h"
#include "ace/Thread_Mutex.h"
#include "ace/RW_Thread_Mutex.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_ctype.h"

// The following #include is needed only for the instantiation pragmas.
#include "orbsvcs/Trader/Trader_Interfaces.h"

ACE_RCSID (Trader,
           Trader,
           "$Id$")

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Trader_Base::TAO_Trader_Base (void)
  : trading_components_ (*this),
    import_attributes_ (*this),
    support_attributes_ (*this),
    link_attributes_ (*this)
{
}

TAO_Trader_Base::~TAO_Trader_Base (void)
{
}

TAO_Import_Attributes_i &
TAO_Trader_Base::import_attributes (void)
{
  return this->import_attributes_;
}

const TAO_Import_Attributes_i &
TAO_Trader_Base::import_attributes (void) const
{
  return this->import_attributes_;
}

TAO_Support_Attributes_i &
TAO_Trader_Base::support_attributes (void)
{
  return this->support_attributes_;
}

const TAO_Support_Attributes_i &
TAO_Trader_Base::support_attributes (void) const
{
  return this->support_attributes_;
}

TAO_Link_Attributes_i &
TAO_Trader_Base::link_attributes (void)
{
  return this->link_attributes_;
}

const TAO_Link_Attributes_i &
TAO_Trader_Base::link_attributes (void) const
{
  return this->link_attributes_;
}

TAO_Trading_Components_i &
TAO_Trader_Base::trading_components (void)
{
  return this->trading_components_;
}

const TAO_Trading_Components_i &
TAO_Trader_Base::trading_components (void) const
{
  return this->trading_components_;
}

CORBA::Boolean
TAO_Trader_Base::is_valid_property_name (const char* ident)
{
  bool return_value = false;

  if (ident == 0)
    return return_value;

  size_t length = ACE_OS::strlen (ident);
  if (length >= 1 && ACE_OS::ace_isalpha (ident[0]))
    {
      return_value = true;
      for (size_t i = 0; i < length; i++)
        {
          if (! (ACE_OS::ace_isalnum (ident[i]) || ident[i] == '_'))
            {
              return_value = false;
              break;
            }
        }
    }

  return return_value;
}

CORBA::Boolean
TAO_Trader_Base::is_valid_identifier_name (const char* ident)
{
  static char const * const double_colon = "::";

  if (ident == 0)
    return 0;

  int return_value = 1;

  // Allow scoped identifiers
  CORBA::Boolean done = 0;
  char const * pos =
    ACE_OS::strstr (ident,
                    double_colon);

  do
  {
    if ('_' == ident[0])
      {
        // Treat escaped identifiers the same way as IDL
        ++ident;
      }

    size_t length =
      pos ? pos - ident : ACE_OS::strlen (ident);

    if (length >= 1 && ACE_OS::ace_isalpha (ident[0]))
      {
        // First character must be alpha
        for (size_t i = 0; i < length; ++i)
          {
            if (! (ACE_OS::ace_isalnum (ident[i])
                   || ident[i] == '_'))
              {
                // Subsequent characters is not alpha, numeric, or '_'
                return_value = 0;
                break;
              }
          }
      }
    else
      return_value = 0;

    if (pos)
      {
        // More identifiers
        ident = pos + 2;
        pos = ACE_OS::strstr (ident, double_colon);
      }
    else
      {
        // Last or only identifier
        done = 1;
      }
  }
  while (!done);

  return return_value;
}

TAO_Lockable::~TAO_Lockable (void)
{
}

TAO_Support_Attributes_i::
TAO_Support_Attributes_i (TAO_Lockable &locker)
  : locker_ (locker),
    supports_modifiable_properties_ (1),
    supports_dynamic_properties_ (1),
    supports_proxy_offers_ (0),
    type_repos_ (CosTrading::TypeRepository::_nil ()),
    service_type_repos_ (CosTradingRepos::ServiceTypeRepository::_nil ())
{
}

TAO_Support_Attributes_i::~TAO_Support_Attributes_i (void)
{
}

CORBA::Boolean
TAO_Support_Attributes_i::supports_modifiable_properties (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         0);
  return this->supports_modifiable_properties_;
}

void
TAO_Support_Attributes_i::
supports_modifiable_properties (CORBA::Boolean new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->supports_modifiable_properties_ = new_value;
}

CORBA::Boolean
TAO_Support_Attributes_i::supports_dynamic_properties (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         0);

  return this->supports_dynamic_properties_;
}

void
TAO_Support_Attributes_i::
supports_dynamic_properties (CORBA::Boolean new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->supports_dynamic_properties_ = new_value;
}

CORBA::Boolean
TAO_Support_Attributes_i::supports_proxy_offers (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         0);

  return this->supports_proxy_offers_;
}

void
TAO_Support_Attributes_i::
supports_proxy_offers (CORBA::Boolean new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->supports_proxy_offers_ = new_value;
}

CosTrading::TypeRepository_ptr
TAO_Support_Attributes_i::type_repos (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::TypeRepository::_nil ());
  return this->type_repos_.ptr ();
}

void
TAO_Support_Attributes_i::
type_repos (CosTrading::TypeRepository_ptr new_value)
{
  // @@ Seth, There is no way to propagate the exception out.
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  this->type_repos_ = new_value;
  // @@ What can we do even if we catch this?
  this->service_type_repos_ =
    CosTradingRepos::ServiceTypeRepository::_narrow (new_value);
}

CosTradingRepos::ServiceTypeRepository_ptr
TAO_Support_Attributes_i::service_type_repos (void) const
{
  return this->service_type_repos_.ptr ();
}


TAO_Import_Attributes_i::
TAO_Import_Attributes_i (TAO_Lockable &locker)
  : locker_ (locker),
    def_search_card_ (200),
    max_search_card_ (500),
    def_match_card_ (200),
    max_match_card_ (500),
    def_return_card_ (200),
    max_return_card_ (500),
    max_list_ (0),
    def_hop_count_ (5),
    max_hop_count_ (10),
    def_follow_policy_ (CosTrading::if_no_local),
    max_follow_policy_ (CosTrading::always)
{
}


TAO_Import_Attributes_i::~TAO_Import_Attributes_i (void)
{
}

CORBA::ULong
TAO_Import_Attributes_i::def_search_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->def_search_card_;
}

void
TAO_Import_Attributes_i::def_search_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  if (new_value > this->max_search_card_)
    this->def_search_card_ = this->max_search_card_;
  else
    this->def_search_card_ = new_value;
}

CORBA::ULong
TAO_Import_Attributes_i::max_search_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->max_search_card_;
}

void
TAO_Import_Attributes_i::max_search_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  this->max_search_card_ = new_value;

  if (this->def_search_card_ > this->max_search_card_)
    this->def_search_card_ = this->max_search_card_;
}

CORBA::ULong
TAO_Import_Attributes_i::def_match_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->def_match_card_;
}

void
TAO_Import_Attributes_i::def_match_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  if (new_value > this->max_match_card_)
    this->def_match_card_ = this->max_match_card_;
  else
    this->def_match_card_ = new_value;
}

CORBA::ULong
TAO_Import_Attributes_i::max_match_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->max_match_card_;
}

void
TAO_Import_Attributes_i::max_match_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_match_card_ = new_value;

  if (this->def_match_card_ > this->max_match_card_)
    this->def_match_card_ = this->max_match_card_;
}

CORBA::ULong
TAO_Import_Attributes_i::def_return_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->def_return_card_;
}

void
TAO_Import_Attributes_i::def_return_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  if (new_value > this->max_return_card_)
    this->def_return_card_ = this->max_return_card_;
  else
    this->def_return_card_ = new_value;
}

CORBA::ULong
TAO_Import_Attributes_i::max_return_card (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 10);
  return this->max_return_card_;
}

void
TAO_Import_Attributes_i::max_return_card (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_return_card_ = new_value;

  if (this->def_return_card_ > this->max_return_card_)
    this->def_return_card_ = this->max_return_card_;
}

CORBA::ULong
TAO_Import_Attributes_i::max_list (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 0);
  return this->max_list_;
}

void
TAO_Import_Attributes_i::max_list (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_list_ = new_value;
}

CORBA::ULong
TAO_Import_Attributes_i::def_hop_count (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 0);
  return this->def_hop_count_;
}

void
TAO_Import_Attributes_i::def_hop_count (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  if (new_value > this->max_hop_count_)
    this->def_hop_count_ = this->max_hop_count_;
  else
    this->def_hop_count_ = new_value;
}

CORBA::ULong
TAO_Import_Attributes_i::max_hop_count (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), 0);
  return this->max_hop_count_;
}

void
TAO_Import_Attributes_i::max_hop_count (CORBA::ULong new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_hop_count_ = new_value;

  if (this->def_hop_count_ > this->max_hop_count_)
    this->def_hop_count_ = this->max_hop_count_;
}

CosTrading::FollowOption
TAO_Import_Attributes_i::def_follow_policy (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), CosTrading::local_only);
  return this->def_follow_policy_;
}

void
TAO_Import_Attributes_i::def_follow_policy (CosTrading::FollowOption new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());

  if (new_value > this->max_follow_policy_)
    this->def_follow_policy_ = this->max_follow_policy_;
  else
    this->def_follow_policy_ = new_value;
}

CosTrading::FollowOption
TAO_Import_Attributes_i::max_follow_policy (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (), CosTrading::local_only);
  return this->max_follow_policy_;
}

void
TAO_Import_Attributes_i::max_follow_policy (CosTrading::FollowOption new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_follow_policy_ = new_value;

  if (this->def_follow_policy_ > this->max_follow_policy_)
    this->def_follow_policy_ = this->max_follow_policy_;
}


TAO_Trading_Components_i::TAO_Trading_Components_i (TAO_Lockable &locker)
  : locker_ (locker),
    lookup_ (CosTrading::Lookup::_nil ()),
    register_ (CosTrading::Register::_nil ()),
    link_ (CosTrading::Link::_nil ()),
    proxy_ (CosTrading::Proxy::_nil ()),
    admin_ (CosTrading::Admin::_nil ())
{
}

TAO_Trading_Components_i::~TAO_Trading_Components_i (void)
{
}

CosTrading::Lookup_ptr
TAO_Trading_Components_i::lookup_if (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::Lookup::_nil ());
  return this->lookup_.ptr ();
}

void
TAO_Trading_Components_i::lookup_if (CosTrading::Lookup_ptr new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->lookup_ = new_value;
}

CosTrading::Register_ptr
TAO_Trading_Components_i::register_if (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::Register::_nil ());
  return this->register_.ptr ();
}

void
TAO_Trading_Components_i::register_if (CosTrading::Register_ptr new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->register_ = new_value;
}

CosTrading::Link_ptr
TAO_Trading_Components_i::link_if (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::Link::_nil ());
  return this->link_.ptr ();
}

void
TAO_Trading_Components_i::link_if (CosTrading::Link_ptr new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->link_ = new_value;
}

CosTrading::Proxy_ptr
TAO_Trading_Components_i::proxy_if (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::Proxy::_nil ());
  return this->proxy_.ptr ();
}

void
TAO_Trading_Components_i::proxy_if (CosTrading::Proxy_ptr new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->proxy_ = new_value;
}

CosTrading::Admin_ptr
TAO_Trading_Components_i::admin_if (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::Admin::_nil ());
  return this->admin_.ptr ();
}

void
TAO_Trading_Components_i::admin_if (CosTrading::Admin_ptr new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->admin_ = new_value;
}


TAO_Link_Attributes_i::TAO_Link_Attributes_i (TAO_Lockable &locker)
  :locker_ (locker),
   max_link_follow_policy_ (CosTrading::local_only)
{
}

TAO_Link_Attributes_i::~TAO_Link_Attributes_i (void)
{
}

CosTrading::FollowOption
TAO_Link_Attributes_i::max_link_follow_policy (void) const
{
  ACE_READ_GUARD_RETURN (ACE_Lock, ace_mon, this->locker_.lock (),
                         CosTrading::local_only);
  return this->max_link_follow_policy_;
}

void
TAO_Link_Attributes_i::max_link_follow_policy (CosTrading::FollowOption new_value)
{
  ACE_WRITE_GUARD (ACE_Lock, ace_mon, this->locker_.lock ());
  this->max_link_follow_policy_ = new_value;
}

bool
operator< (const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &l,
           const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &r)
{
  if (l.high < r.high)
    return true;
  else if (l.high == r.high)
    return (l.low < r.low);
  else
    return false;
}

bool
operator> (const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &l,
           const CosTradingRepos::ServiceTypeRepository::IncarnationNumber &r)
{
  return (r < l);
}

bool
operator== (const CosTrading::Admin::OctetSeq& left,
            const CosTrading::Admin::OctetSeq& right)
{
  bool return_value = false;

  const CORBA::ULong left_length = left.length ();
  const CORBA::ULong right_length = right.length ();

  if (left_length == right_length)
    {
      return_value = true;

      for (CORBA::ULong i = 0; i < left_length; ++i)
        {
          if (left[i] != right[i])
            {
              return_value = false;
              break;
            }
        }
    }

  return return_value;
}

TAO_END_VERSIONED_NAMESPACE_DECL

#include "ace/Arg_Shifter.h"
#include "orbsvcs/Trader/Trader_T.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Trader_Factory::TAO_TRADER*
TAO_Trader_Factory::create_trader (int& argc, ACE_TCHAR** argv)
{
  TAO_Trader_Factory trader_factory (argc, argv);
  return trader_factory.manufacture_trader ();
}

TAO_Trader_Factory::TAO_Trader_Factory (int& argc, ACE_TCHAR** argv)
  : conformance_ (TAO_TRADER_LINKED),
    threadsafe_ (0),
    supports_dynamic_properties_ (1),
    supports_modifiable_properties_ (1),
    def_search_card_ (20),
    max_search_card_ (50),
    def_match_card_ (20),
    max_match_card_ (50),
    def_return_card_ (20),
    max_return_card_ (50),
    def_hop_count_ (5),
    max_hop_count_ (10),
    def_follow_policy_ (CosTrading::if_no_local),
    max_follow_policy_ (CosTrading::always)
{
  this->parse_args (argc, argv);
}

TAO_Trader_Factory::TAO_TRADER *
TAO_Trader_Factory::manufacture_trader (void)
{
  typedef TAO_Trader<ACE_Null_Mutex, ACE_Null_Mutex> TRADER;

#if defined ACE_HAS_THREADS
  typedef TAO_Trader<TAO_SYNCH_MUTEX, TAO_SYNCH_RW_MUTEX>  MT_TRADER;
#else
  typedef TAO_Trader<ACE_Null_Mutex, ACE_Null_Mutex>  MT_TRADER;
#endif /* ACE_HAS_THREADS */

  TAO_TRADER* return_value = 0;
  int components = static_cast<int> (TAO_Trader_Base::LOOKUP);

  if (this->conformance_ >= TAO_TRADER_SIMPLE)
    components |= static_cast<int> (TAO_Trader_Base::REGISTER);

  if (this->conformance_ >= TAO_TRADER_STANDALONE)
    components |= static_cast<int> (TAO_Trader_Base::ADMIN);

  if (this->conformance_ >= TAO_TRADER_LINKED)
    components |= static_cast<int> (TAO_Trader_Base::LINK);

  if (this->threadsafe_)
    ACE_NEW_RETURN (return_value,
                    MT_TRADER (static_cast<TAO_Trader_Base::Trader_Components> (components)),
                    0);
  else
    ACE_NEW_RETURN (return_value,
                    TRADER (static_cast<TAO_Trader_Base::Trader_Components> (components)),
                    0);

  TAO_Import_Attributes_i &import_attributes =
    return_value->import_attributes ();
  TAO_Support_Attributes_i &support_attributes =
    return_value->support_attributes ();

  import_attributes.def_search_card (this->def_search_card_);
  import_attributes.max_search_card (this->max_search_card_);
  import_attributes.def_match_card (this->def_match_card_);
  import_attributes.max_match_card (this->max_match_card_);
  import_attributes.def_return_card (this->def_return_card_);
  import_attributes.max_return_card (this->max_return_card_);
  import_attributes.def_hop_count (this->def_hop_count_);
  import_attributes.max_hop_count (this->max_hop_count_);
  import_attributes.def_follow_policy (this->def_follow_policy_);
  import_attributes.max_follow_policy (this->max_follow_policy_);
  support_attributes.supports_modifiable_properties (this->supports_modifiable_properties_);
  support_attributes.supports_dynamic_properties (this->supports_dynamic_properties_);

  return return_value;
}

void
TAO_Trader_Factory::parse_args (int& argc, ACE_TCHAR** argv)
{
  ACE_Arg_Shifter arg_shifter (argc, argv);

  while (arg_shifter.is_anything_left ())
    {
      const ACE_TCHAR* current_arg = arg_shifter.get_current ();

      if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSthreadsafe")) == 0)
        {
          arg_shifter.consume_arg ();
          this->threadsafe_ = 1;
        }
      else if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSconformance")) == 0)
        {
          arg_shifter.consume_arg ();
          if (arg_shifter.is_parameter_next ())
            {
              const ACE_TCHAR* conformance_str = arg_shifter.get_current ();

              if (ACE_OS::strcasecmp (conformance_str, ACE_TEXT("Linked")) == 0)
                this->conformance_ = TAO_TRADER_LINKED;
              else if (ACE_OS::strcasecmp (conformance_str, ACE_TEXT("Query")) == 0)
                this->conformance_ = TAO_TRADER_QUERY;
              else if (ACE_OS::strcasecmp (conformance_str, ACE_TEXT("Simple")) == 0)
                this->conformance_ = TAO_TRADER_SIMPLE;
              else if (ACE_OS::strcasecmp (conformance_str, ACE_TEXT("Standalone")) == 0)
                this->conformance_ = TAO_TRADER_STANDALONE;

              arg_shifter.consume_arg ();
            }
        }
      else if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSsupports_dynamic_properties")) == 0)
        {
          arg_shifter.consume_arg ();
          if (arg_shifter.is_parameter_next ())
            {
              const ACE_TCHAR* arg_str = arg_shifter.get_current ();

              if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("true")) == 0)
                this->supports_dynamic_properties_ = 1;
              else if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("false")) == 0)
                this->supports_dynamic_properties_ = 0;

              arg_shifter.consume_arg ();
            }

        }
      else if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSsupports_modifiable_properties")) == 0)
        {
          arg_shifter.consume_arg ();
          if (arg_shifter.is_parameter_next ())
            {
              const ACE_TCHAR* arg_str = arg_shifter.get_current ();

              if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("true")) == 0)
                this->supports_modifiable_properties_ = 1;
              else if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("false")) == 0)
                this->supports_modifiable_properties_ = 0;

              arg_shifter.consume_arg ();
            }
        }
      else if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSdef_search_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSmax_search_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSdef_match_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSmax_match_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSdef_return_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSmax_return_card")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSdef_hop_count")) == 0 ||
               ACE_OS::strcmp (current_arg, ACE_TEXT("-TSmax_hop_count")) == 0)
        {
          arg_shifter.consume_arg ();
          if (arg_shifter.is_parameter_next ())
            {
              CORBA::ULong value =
                static_cast<CORBA::ULong> (ACE_OS::atoi (arg_shifter.get_current ()));
              arg_shifter.consume_arg ();

              if (ACE_OS::strstr (current_arg, ACE_TEXT("card")))
                {
                  if (ACE_OS::strstr (current_arg, ACE_TEXT("max")))
                    {
                      if (ACE_OS::strstr (current_arg, ACE_TEXT("search")))
                        this->max_search_card_ = value;
                      else if (ACE_OS::strstr (current_arg, ACE_TEXT("match")))
                        this->max_match_card_ = value;
                      else
                        this->max_return_card_ = value;
                    }
                  else
                    {
                      if (ACE_OS::strstr (current_arg, ACE_TEXT("search")))
                        this->def_search_card_ = value;
                      else if (ACE_OS::strstr (current_arg, ACE_TEXT("match")))
                        this->def_match_card_ = value;
                      else
                        this->def_return_card_ = value;
                    }
                }
              else
                {
                  if (ACE_OS::strstr (current_arg, ACE_TEXT("max")))
                    this->max_hop_count_ = value;
                  else
                    this->def_hop_count_ = value;
                }
            }
        }
      else if (ACE_OS::strcmp (current_arg, ACE_TEXT("-TSdef_follow_policy")) == 0
               || ACE_OS::strcmp (current_arg, ACE_TEXT("-TSmax_follow_policy")) == 0)
        {
          arg_shifter.consume_arg ();
          if (arg_shifter.is_parameter_next ())
            {
              const ACE_TCHAR* arg_str = arg_shifter.get_current ();
              CosTrading::FollowOption follow_option;

              if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("always")) == 0)
                follow_option = CosTrading::always;
              else if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("if_no_local")) == 0)
                follow_option = CosTrading::if_no_local;
              else if (ACE_OS::strcasecmp (arg_str, ACE_TEXT("local_only")) == 0)
                follow_option = CosTrading::local_only;
              else if (ACE_OS::strstr (current_arg, ACE_TEXT("def")))
                follow_option = this->def_follow_policy_;
              else
                follow_option = this->max_follow_policy_;

              if (ACE_OS::strstr (current_arg, ACE_TEXT("def")))
                this->def_follow_policy_ = follow_option;
              else
                this->max_follow_policy_ = follow_option;

              arg_shifter.consume_arg ();
            }
        }
      else
        arg_shifter.ignore_arg ();
    }
}

TAO_END_VERSIONED_NAMESPACE_DECL