00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "OWBI1_config.h"
00037 #include "OW_ExceptionIds.hpp"
00038 #include "OWBI1_CIMException.hpp"
00039 #include "OWBI1_String.hpp"
00040 #include "OW_Assertion.hpp"
00041 #include "OW_String.hpp"
00042 #include "OW_StringBuffer.hpp"
00043
00044 #include <cstring>
00045 #include <cstdlib>
00046 #include <algorithm>
00047
00048 namespace OWBI1
00049 {
00050 using namespace OpenWBEM;
00051
00052 namespace
00053 {
00054 String createLongMessage(CIMException::ErrNoType errval, const char* msg)
00055 {
00056 const char* rv(0);
00057 try
00058 {
00059 StringBuffer codeDesc(CIMException::getCodeDescription(errval));
00060 OpenWBEM::String msgStr(msg);
00061
00062 if (codeDesc == msgStr.substring(0, codeDesc.length()))
00063 {
00064 codeDesc = msgStr;
00065 }
00066 else if (!msgStr.empty())
00067 {
00068 codeDesc += " (";
00069 codeDesc += msgStr;
00070 codeDesc += ')';
00071 }
00072 return String(codeDesc.c_str());
00073 }
00074 catch (std::bad_alloc&)
00075 {
00076 return String();
00077 }
00078 }
00079
00080 }
00081
00083 CIMException::CIMException(const char* file, int line, CIMException::ErrNoType errval,
00084 const char* msg, const Exception* otherException)
00085 : Exception(file, line, createLongMessage(errval, msg).c_str(), errval, otherException, ExceptionIds::CIMExceptionId)
00086 , m_description(Exception::dupString(msg))
00087 {
00088 }
00090 CIMException::~CIMException() throw()
00091 {
00092 if (m_description)
00093 {
00094 delete[] m_description;
00095 }
00096 }
00098 CIMException::CIMException(const CIMException& x)
00099 : Exception(x)
00100 , m_description(Exception::dupString(x.m_description))
00101 {
00102 }
00104 CIMException&
00105 CIMException::operator=(const CIMException& x)
00106 {
00107 CIMException(x).swap(*this);
00108 return *this;
00109 }
00111 void
00112 CIMException::swap(CIMException& x)
00113 {
00114 std::swap(m_description, x.m_description);
00115 Exception::swap(x);
00116 }
00118 const char*
00119 CIMException::type() const
00120 {
00121 return "CIMException";
00122 }
00123
00125 const char*
00126 CIMException::getDescription() const
00127 {
00128 return m_description;
00129 }
00130
00132 struct MsgRec
00133 {
00134 CIMException::ErrNoType errval;
00135 const char* msg;
00136 };
00137
00138 static MsgRec _pmsgs[] =
00139 {
00140 { CIMException::SUCCESS, "no error" },
00141 { CIMException::FAILED, "general error" },
00142 { CIMException::ACCESS_DENIED, "Access to CIM resource unavailable to client" },
00143 { CIMException::INVALID_NAMESPACE, "namespace does not exist" },
00144 { CIMException::INVALID_PARAMETER, "invalid parameter passed to method" },
00145 { CIMException::INVALID_CLASS, "class does not exist" },
00146 { CIMException::NOT_FOUND, "requested object could not be found" },
00147 { CIMException::NOT_SUPPORTED, "requested operation is not supported" },
00148 { CIMException::CLASS_HAS_CHILDREN, "operation cannot be done on class with subclasses" },
00149 { CIMException::CLASS_HAS_INSTANCES, "operator cannot be done on class with instances" },
00150 { CIMException::INVALID_SUPERCLASS, "specified superclass does not exist" },
00151 { CIMException::ALREADY_EXISTS, "object already exists" },
00152 { CIMException::NO_SUCH_PROPERTY, "specified property does not exist" },
00153 { CIMException::TYPE_MISMATCH, "value supplied is incompatible with type" },
00154 { CIMException::QUERY_LANGUAGE_NOT_SUPPORTED, "query language is not recognized or supported" },
00155 { CIMException::INVALID_QUERY, "query is not valid for the specified query language" },
00156 { CIMException::METHOD_NOT_AVAILABLE, "extrinsic method could not be executed" },
00157 { CIMException::METHOD_NOT_FOUND, "extrinsic method does not exist" }
00158 };
00159
00160
00161 const char*
00162 CIMException::getCodeDescription(ErrNoType errCode)
00163 {
00164 if (errCode >= SUCCESS && errCode <= METHOD_NOT_FOUND)
00165 {
00166 OW_ASSERT(_pmsgs[errCode].errval == errCode);
00167 return _pmsgs[errCode].msg;
00168 }
00169 return "unknown error";
00170 }
00171
00172 CIMException*
00173 CIMException::clone() const throw()
00174 {
00175 return new(std::nothrow) CIMException(*this);
00176 }
00177
00178 }
00179