OWBI1_CIMException.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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> // for std::swap
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         // avoid multiple appendings of the exception message
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 // static
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 } // end namespace OWBI1
00179 

Generated on Thu Feb 9 08:48:25 2006 for openwbem by  doxygen 1.4.6