summaryrefslogtreecommitdiff
path: root/TAO/tests/Bug_2560_Regression/Stock_Factory_i.cpp
blob: a2f50986f5b20f899e30db88a9f0cbc1152b0cf6 (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
//
// $Id$
//

#include <iostream>
#include "Stock_Factory_i.h"

Quoter_Stock_Factory_i::Quoter_Stock_Factory_i ()
{
  servant1_ = new Quoter_Stock_i("RHAT", "RedHat, Inc.", 210);
  servant2_ = new Quoter_Stock_i("MSFT", "Microsoft, Inc.", 91);

  PortableServer::POA_ptr poa1 = servant1_->_default_POA() ;
  PortableServer::ObjectId_var oid1 = PortableServer::string_to_ObjectId( servant1_->symbol() ) ;
  poa1->activate_object_with_id ( oid1.in(), servant1_ ) ;
  ref1_ = Quoter::Stock::_narrow( poa1->id_to_reference(oid1.in()) ) ;

  PortableServer::POA_ptr poa2 = servant2_->_default_POA() ;
  PortableServer::ObjectId_var oid2 = PortableServer::string_to_ObjectId( servant2_->symbol() ) ;
  poa2->activate_object_with_id ( oid2.in(), servant2_ ) ;
  ref2_ = Quoter::Stock::_narrow( poa2->id_to_reference(oid2.in()) ) ;
}

Quoter::Stock_ptr
Quoter_Stock_Factory_i::get_stock (const char *symbol)
    throw (Quoter::Invalid_Stock_Symbol)
{
  try {
    if (strcmp (symbol, "RHAT") == 0) {
      return Quoter::Stock::_duplicate(ref1_);
    } else if (strcmp (symbol, "MSFT") == 0) {
      return Quoter::Stock::_duplicate(ref2_);
    }
  } catch (CORBA::Exception & e) {
    std::cerr << "CORBA exception raised: " << e << std::endl;
  }
  std::cerr << "Invalid_Stock_Symbol: " << symbol << std::endl ;
  throw Quoter::Invalid_Stock_Symbol ();
}