Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / LifeCycle_Service / LifeCycle_Service_i.cpp
blob358ca85d90cb5adcdbf4b28edfbe4dbfe2fdc7e8
2 //=============================================================================
3 /**
4 * @file LifeCycle_Service_i.cpp
6 * The implementation of a LifeCycle Service GenericFactory.
8 * @author Michael Kircher (mk1@cs.wustl.edu)
9 */
10 //=============================================================================
13 #include "orbsvcs/Log_Macros.h"
14 #include "ace/Get_Opt.h"
16 #include "orbsvcs/LifeCycleServiceC.h"
18 #include "LifeCycle_Service_i.h"
20 // Constructor
21 Life_Cycle_Service_i::Life_Cycle_Service_i (int debug_level)
22 : factory_trader_ptr_ (0),
23 debug_level_ (debug_level)
27 // Destructor.
28 Life_Cycle_Service_i::~Life_Cycle_Service_i (void)
33 CORBA::Boolean
34 Life_Cycle_Service_i::supports (const CosLifeCycle::Key &)
36 return 0;
39 CORBA::Object_ptr
40 Life_Cycle_Service_i::create_object (const CosLifeCycle::Key &factory_key,
41 const CosLifeCycle::Criteria &the_criteria)
43 if (this->debug_level_ >= 2)
44 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i:create_object: called.\n"));
45 // Exceptions are forwarded, not handled !!
47 if (factory_trader_ptr_ != 0)
49 Criteria_Evaluator criteria_Evaluator(the_criteria);
51 if (this->debug_level_ >= 2)
52 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i:create_object: new evaluator.\n"));
54 if (this->debug_level_ >= 2)
55 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i:create_object: getFilter will be called.\n"));
57 char* filter = criteria_Evaluator.getFilter ();
59 if (this->debug_level_ >= 2)
60 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i:create_object: query(%s) will be called.\n",filter));
62 CORBA::Object_ptr genericFactoryObj_ptr = factory_trader_ptr_->query (filter);
64 if (this->debug_level_ >= 2)
65 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i:create_object: query was called.\n"));
67 if (CORBA::is_nil (genericFactoryObj_ptr))
68 ORBSVCS_ERROR_RETURN ((LM_ERROR,
69 "Life_Cycle_Service_i::create_object: Factory is nil!\n"),
70 0);
71 else // everyting is ok
72 if (this->debug_level_ >= 2)
73 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i::create_object: Object reference OK.\n"));
75 // Now we have a proper reference to a Generic Factory
76 // the create_object call will be forwarded to this factory
79 // Check if it is a valid Generic Factory reference
80 if (CORBA::is_nil (genericFactoryObj_ptr))
81 throw CosLifeCycle::NoFactory (factory_key);
82 else
84 CosLifeCycle::GenericFactory_var genericFactory_var;
85 try
87 genericFactory_var =
88 CosLifeCycle::GenericFactory::_narrow (genericFactoryObj_ptr);
90 catch (const CORBA::Exception&)
92 // see if there is an exception, if yes then throw the
93 // NoFactory exception throw a NoFactory exception
94 throw CosLifeCycle::NoFactory (factory_key);
97 if (CORBA::is_nil (genericFactory_var.in()))
98 ORBSVCS_ERROR_RETURN ((LM_ERROR,
99 "Life_Cycle_Service_i::create_object: Invalid Generic Factory.\n"),
102 if (this->debug_level_ >= 2)
103 ORBSVCS_DEBUG ((LM_DEBUG, "Life_Cycle_Service_i::create_object: Generic Factory reference OK.\n"));
105 // Now retrieve the Object obj ref corresponding to the key.
106 CORBA::Object_var object_var = genericFactory_var->create_object (factory_key,
107 the_criteria);
109 if (this->debug_level_ >= 2)
110 ORBSVCS_DEBUG ((LM_DEBUG,
111 "Life_Cycle_Service_i::create_object: Forwarded request.\n"));
113 if (CORBA::is_nil (object_var.in()))
114 ORBSVCS_ERROR_RETURN ((LM_ERROR,
115 "Life_Cycle_Service_i::create_object: Null object refeference returned by factory.\n"),
118 if (this->debug_level_ >= 2)
119 ORBSVCS_DEBUG ((LM_DEBUG,
120 "Life_Cycle_Service_i::create_object: Return a object reference to a new object.\n"));
122 return CORBA::Object::_duplicate (object_var.in());
125 else
127 return 0;
131 void
132 Life_Cycle_Service_i::register_factory (const char * name,
133 const char * location,
134 const char * description,
135 CORBA::Object_ptr object)
137 if (factory_trader_ptr_ == 0)
138 ACE_NEW (factory_trader_ptr_, Factory_Trader(this->debug_level_));
139 // we have an proper reference to the Factory Trader
141 // Just forward the call to the factory trader
142 // Exceptions are not handled here, they are returned
143 factory_trader_ptr_->_cxx_export (name, location, description, object);
145 if (this->debug_level_ >= 1)
146 ORBSVCS_DEBUG ((LM_DEBUG, "LifeCycle Server: Registered %s\n"
147 " Location: %s\n"
148 " Description: %s\n",
149 name, location, description));