Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Quoter / Generic_Factory_i.cpp
blob57165cbde26c51d43d8ec5dbb040c50978235aa5
2 //=============================================================================
3 /**
4 * @file Generic_Factory_i.cpp
6 * The implementation of a LifeCycle Service GenericFactory for the
7 * Quoter example.
9 * @author Michael Kircher (mk1@cs.wustl.edu)
11 //=============================================================================
14 #include "Generic_Factory_i.h"
15 #include "QuoterC.h"
17 #include "tao/ORB_Core.h"
19 #include "ace/Get_Opt.h"
21 // Constructor
22 Quoter_Generic_Factory_i::Quoter_Generic_Factory_i (int debug_level)
23 : debug_level_ (debug_level)
27 // Destructor.
28 Quoter_Generic_Factory_i::~Quoter_Generic_Factory_i ()
32 CORBA::Boolean
33 Quoter_Generic_Factory_i::supports (const CosLifeCycle::Key &)
35 return 0;
39 CosNaming::NamingContext_ptr
40 Quoter_Generic_Factory_i::get_naming_context (const CosLifeCycle::Key &factory_key)
42 CosNaming::NamingContext_var quoterNamingContext_var;
43 try
45 // @@ FIXME Get a reference to the ORB.
46 CORBA::ORB_ptr orb_ptr =
47 TAO_ORB_Core_instance ()->orb ();
49 // Get the Naming Service object reference.
50 CORBA::Object_var namingObj_var =
51 orb_ptr->resolve_initial_references ("NameService");
53 if (CORBA::is_nil (namingObj_var.in ()))
54 ACE_ERROR ((LM_ERROR,
55 "(%P|%t) Unable get the Naming Service.\n"));
57 // Narrow the object reference to a Naming Context.
58 CosNaming::NamingContext_var namingContext_var =
59 CosNaming::NamingContext::_narrow (namingObj_var.in ());
61 CosNaming::Name quoterContextName (1); // max = 1
62 quoterContextName.length (1);
63 quoterContextName[0].id = CORBA::string_dup ("IDL_Quoter");
65 // Get the IDL_Quoter naming context.
66 CORBA::Object_var quoterNamingObj_var =
67 namingContext_var->resolve (quoterContextName);
69 quoterNamingContext_var =
70 CosNaming::NamingContext::_narrow (quoterNamingObj_var.in ());
72 catch (const CORBA::Exception&)
74 throw CosLifeCycle::NoFactory (factory_key);
76 return quoterNamingContext_var._retn ();
80 CORBA::Object_ptr
81 Quoter_Generic_Factory_i::create_object (const CosLifeCycle::Key &factory_key,
82 const CosLifeCycle::Criteria &)
84 Stock::Quoter_var quoter_var;
85 try
87 CosNaming::NamingContext_var quoterNamingContext_var =
88 this->get_naming_context (factory_key);
90 // ** now a proper reference to the quoter naming context is
91 // available
93 // Fill in the name of the Quoter Factory.
94 // Take the key supplied to search for a Quoter Factory
95 CosNaming::Name factory_Name = (CosNaming::Name) factory_key;
97 // Try to get a reference to a Quoter Factory
98 CORBA::Object_var quoterFactoryObject_var =
99 quoterNamingContext_var->resolve (factory_Name);
101 // We were able to get a reference to Quoter Factory.
102 // Check if it is a valid Quoter Factory reference
103 if (CORBA::is_nil (quoterFactoryObject_var.in()))
104 { // throw a NoFactory exception
105 throw CosLifeCycle::NoFactory (factory_key);
108 Stock::Quoter_Factory_var factory_var =
109 Stock::Quoter_Factory::_narrow (quoterFactoryObject_var.in ());
111 if (CORBA::is_nil (factory_var.in ()))
113 ACE_ERROR ((LM_ERROR,
114 "invalid factory.\n"));
115 return CORBA::Object::_nil ();
118 if (this->debug_level_ > 1)
119 ACE_DEBUG ((LM_DEBUG, "Generic Factory: Factory reference OK.\n"));
121 // Now retrieve the Quoter obj ref corresponding to the key.
122 quoter_var =
123 factory_var->create_quoter ("test");
125 if (this->debug_level_ > 1)
126 ACE_DEBUG ((LM_DEBUG, "Generic_Factory: Quoter Created\n"));
128 if (CORBA::is_nil (quoter_var.in ()))
130 ACE_ERROR ((LM_ERROR,
131 "null quoter objref returned by factory\n"));
132 return CORBA::Object::_nil ();
135 if (this->debug_level_ > 1)
136 ACE_DEBUG ((LM_DEBUG, "Generic_Factory: Return an object reference to a new object.\n"));
138 catch (const CORBA::Exception&)
140 throw CosLifeCycle::NoFactory (factory_key);
142 return quoter_var._retn ();