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