00001
00002 #ifndef TAO_IMR_UTILS_H
00003 #define TAO_IMR_UTILS_H
00004
00005 #include "tao/ImR_Client/ImplRepoC.h"
00006
00007 #include "ace/SString.h"
00008
00009 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00010 # pragma once
00011 #endif
00012
00013 class ImR_Utils {
00014 public:
00015 static ACE_CString activationModeToString(ImplementationRepository::ActivationMode mode)
00016 {
00017 switch (mode )
00018 {
00019 case ImplementationRepository::NORMAL:
00020 return "NORMAL";
00021 case ImplementationRepository::MANUAL:
00022 return "MANUAL";
00023 case ImplementationRepository::PER_CLIENT:
00024 return "PER_CLIENT";
00025 case ImplementationRepository::AUTO_START:
00026 return "AUTO_START";
00027 default:
00028 ACE_ASSERT(mode == ImplementationRepository::NORMAL);
00029 return "";
00030 }
00031 }
00032 static ImplementationRepository::ActivationMode parseActivationMode(const ACE_CString& s)
00033 {
00034 if (s == "NORMAL")
00035 return ImplementationRepository::NORMAL;
00036 if (s == "MANUAL")
00037 return ImplementationRepository::MANUAL;
00038 if (s == "PER_CLIENT")
00039 return ImplementationRepository::PER_CLIENT;
00040 if (s == "AUTO_START")
00041 return ImplementationRepository::AUTO_START;
00042
00043 return ImplementationRepository::NORMAL;
00044 }
00045 static ACE_CString envListToString(const ImplementationRepository::EnvironmentList& lst)
00046 {
00047 ACE_CString ret;
00048 for (CORBA::ULong n = 0; n < lst.length(); ++n)
00049 {
00050 ret += "name=\"";
00051 ret += lst[n].name.in();
00052 ret += "\" value=\"";
00053 ret += lst[n].value.in();
00054 ret += "\"\n";
00055 }
00056 return ret;
00057 }
00058 static ImplementationRepository::EnvironmentList parseEnvList(const ACE_CString& s)
00059 {
00060 ImplementationRepository::EnvironmentList ret(10);
00061
00062 const ACE_CString NAMETAG = "name=\"";
00063 const ACE_CString VALTAG = "value=\"";
00064 const ACE_CString ENDTAG = "\"";
00065
00066 ssize_t i = 0;
00067
00068 for (CORBA::ULong idx = 0; ; ++idx)
00069 {
00070
00071 ssize_t j = s.find(NAMETAG, i);
00072 if (j == ACE_CString::npos) break;
00073 j += NAMETAG.length();
00074 ssize_t k = s.find(ENDTAG, j + 1);
00075 if (k == ACE_CString::npos) break;
00076 ACE_CString name = s.substr(j, k - j);
00077
00078 i = k + 1;
00079
00080
00081 j = s.find(VALTAG, i);
00082 if (j == ACE_CString::npos) break;
00083 j += VALTAG.length();
00084 k = s.find(ENDTAG, j + 1);
00085 if (k == ACE_CString::npos) break;
00086 ACE_CString value = s.substr(j, k - j);
00087
00088 i = k + 1;
00089
00090 ret.length(idx + 1);
00091 ret[idx].name = name.c_str();
00092 ret[idx].value = value.c_str();
00093 }
00094 return ret;
00095 }
00096 };
00097
00098 #endif