Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / examples / Quoter / Factory_Finder_i.cpp
blobc67a55c1bff2a19069d62547f0dffc35c894eebe
2 //=============================================================================
3 /**
4 * @file Factory_Finder_i.cpp
6 * A Factory Finder for the Quoter example. This example conforms
7 * to the CosLifeCycle Factory Finder notion.
9 * @author Michael Kircher (mk1@cs.wustl.edu)
11 //=============================================================================
14 #include "Factory_Finder_i.h"
15 #include "QuoterC.h"
17 #include "tao/ORB_Core.h"
19 #include "ace/Get_Opt.h"
21 // Constructor
22 Quoter_Factory_Finder_i::Quoter_Factory_Finder_i (int debug_level)
23 : debug_level_ (debug_level)
25 // Nothing
28 // Destructor.
29 Quoter_Factory_Finder_i::~Quoter_Factory_Finder_i ()
31 // Nothing
35 CosLifeCycle::Factories *
36 Quoter_Factory_Finder_i::find_factories (const CosLifeCycle::Key &factory_key)
38 const char *exception_message = "Null Message";
40 CosLifeCycle::Factories *factories_ptr = 0;
42 try
44 // Get a reference to the ORB.
45 CORBA::ORB_ptr orb_ptr = TAO_ORB_Core_instance ()->orb ();
47 // Get the Naming Service object reference.
48 exception_message = "While resolving the Name Service";
49 CORBA::Object_var namingObj_var =
50 orb_ptr->resolve_initial_references ("NameService");
52 if (CORBA::is_nil (namingObj_var.in ()))
53 ACE_ERROR ((LM_ERROR,
54 " (%P|%t) Unable get the Naming Service.\n"));
56 // Narrow the object reference to a Naming Context.
57 exception_message = "While narrowing the Naming Context";
58 CosNaming::NamingContext_var namingContext_var =
59 CosNaming::NamingContext::_narrow (namingObj_var.in ());
61 // Take the key supplied to search for a Quoter Factory
62 CosNaming::Name factoryName = (CosNaming::Name) factory_key;
64 // Try to get a reference to a Quoter Factory
65 exception_message = "While resolving the Factory Object";
66 CORBA::Object_var quoterFactoryObject_var =
67 namingContext_var->resolve (factoryName);
69 // Check if it is a valid Quoter Factory reference
70 if (CORBA::is_nil (quoterFactoryObject_var.in()))
71 throw CosLifeCycle::NoFactory (factory_key);
73 // create a sequence of factories object
74 factories_ptr = new CosLifeCycle::Factories (1);
76 // using the Naming Service only one reference is available
77 factories_ptr->length (1);
79 // Check if it is a valid Quoter Factory reference.
80 if (CORBA::is_nil (quoterFactoryObject_var.in ())) // throw a NoFactory exception.
81 throw CosLifeCycle::NoFactory (factory_key);
83 // insert the object reference
84 (*factories_ptr)[0] = CORBA::Object::_duplicate (quoterFactoryObject_var.in());
86 if (this->debug_level_ > 1)
87 ACE_DEBUG ((LM_DEBUG,
88 "Factory Finder: Have reference to a Quoter Factory.\n"));
90 catch (const CORBA::Exception&)
92 ACE_ERROR ((LM_ERROR, "Quoter_Factory_Finder::find_factories - %C\n", exception_message));
93 throw CosLifeCycle::NoFactory (factory_key);
96 return factories_ptr;