00001
00002
00003 #include "tao/PortableServer/LifespanStrategyFactoryImpl.h"
00004 #include "tao/PortableServer/LifespanStrategy.h"
00005 #include "ace/Dynamic_Service.h"
00006
00007 ACE_RCSID (PortableServer,
00008 LifespanStrategyFactoryImpl,
00009 "$Id: LifespanStrategyFactoryImpl.cpp 76898 2007-02-04 18:58:07Z johnnyw $")
00010
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 namespace TAO
00014 {
00015 namespace Portable_Server
00016 {
00017 LifespanStrategy*
00018 LifespanStrategyFactoryImpl::create (
00019 ::PortableServer::LifespanPolicyValue value)
00020 {
00021 LifespanStrategy *strategy = 0;
00022 const char *strategy_name = 0;
00023
00024 switch (value)
00025 {
00026 case ::PortableServer::PERSISTENT :
00027 {
00028 strategy_name = "LifespanStrategyPersistentFactory";
00029 break;
00030 }
00031 case ::PortableServer::TRANSIENT :
00032 {
00033 strategy_name = "LifespanStrategyTransientFactory";
00034 break;
00035 }
00036 }
00037
00038 LifespanStrategyFactory *strategy_factory =
00039 ACE_Dynamic_Service<LifespanStrategyFactory>::instance (strategy_name);
00040
00041 if (strategy_factory != 0)
00042 strategy = strategy_factory->create (value);
00043 else
00044 ACE_ERROR ((LM_ERROR,
00045 ACE_TEXT ("(%P|%t) ERROR, Unable to get %s\n"),
00046 strategy_name));
00047
00048
00049 return strategy;
00050 }
00051
00052 void
00053 LifespanStrategyFactoryImpl::destroy (LifespanStrategy *strategy)
00054 {
00055 switch (strategy->type ())
00056 {
00057 case ::PortableServer::PERSISTENT :
00058 {
00059 LifespanStrategyFactory *strategy_factory =
00060 ACE_Dynamic_Service<LifespanStrategyFactory>::instance ("LifespanStrategyPersistentFactory");
00061
00062 if (strategy_factory != 0)
00063 {
00064 strategy_factory->destroy (strategy);
00065 }
00066 break;
00067 }
00068 case ::PortableServer::TRANSIENT :
00069 {
00070 LifespanStrategyFactory *strategy_factory =
00071 ACE_Dynamic_Service<LifespanStrategyFactory>::instance ("LifespanStrategyTransientFactory");
00072
00073 if (strategy_factory != 0)
00074 {
00075 strategy_factory->destroy (strategy);
00076 }
00077 break;
00078 }
00079 }
00080 }
00081 }
00082 }
00083
00084 TAO_END_VERSIONED_NAMESPACE_DECL
00085
00086 ACE_STATIC_SVC_DEFINE (
00087 LifespanStrategyFactoryImpl,
00088 ACE_TEXT ("LifespanStrategyFactory"),
00089 ACE_SVC_OBJ_T,
00090 &ACE_SVC_NAME (LifespanStrategyFactoryImpl),
00091 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00092 0)
00093
00094 ACE_FACTORY_NAMESPACE_DEFINE (
00095 ACE_Local_Service,
00096 LifespanStrategyFactoryImpl,
00097 TAO::Portable_Server::LifespanStrategyFactoryImpl)