(file) Return to Exception.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 mike  1.22 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
  4            //
  5            // Permission is hereby granted, free of charge, to any person obtaining a copy
  6            // of this software and associated documentation files (the "Software"), to 
  7            // deal in the Software without restriction, including without limitation the 
  8            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
  9            // sell copies of the Software, and to permit persons to whom the Software is
 10            // furnished to do so, subject to the following conditions:
 11            // 
 12            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 13            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 14            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 15            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 16            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 17            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 18            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 19            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 20            //
 21            //==============================================================================
 22 mike  1.22 //
 23            // Author: Mike Brasher (mbrasher@bmc.com)
 24            //
 25 mike  1.23 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
 26            //
 27 kumpf 1.29 // Modified By: Jenny Yu (jenny_yu@am.exch.hp.com)
 28 mike  1.22 //
 29            //%/////////////////////////////////////////////////////////////////////////////
 30            
 31            #include <cstdio>
 32            #include "Exception.h"
 33 kumpf 1.33 #include "Tracer.h"
 34 mike  1.22 
 35            PEGASUS_NAMESPACE_BEGIN
 36            
 37            Exception::Exception(const String& message) : _message(message) 
 38            { 
 39            
 40            }
 41            
 42            Exception::Exception(const char* message) : _message(message) 
 43            {
 44            
 45            }
 46            
 47            Exception::~Exception()
 48            {
 49            
 50            }
 51            
 52            AssertionFailureException::AssertionFailureException(
 53                const char* file, 
 54                size_t line,
 55 mike  1.22     const String& message) : Exception(String())
 56            {
 57                char lineStr[32];
 58 kumpf 1.30     sprintf(lineStr, "%u", line);
 59 mike  1.22 
 60                _message = file;
 61                _message.append("(");
 62                _message.append(lineStr);
 63                _message.append("): ");
 64                _message.append(message);
 65 kumpf 1.33 
 66                // ATTN-RK-P3-20020408: Should define a "test" trace component
 67                PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, _message);
 68 mike  1.22 }
 69            
 70            const char OutOfBounds::MSG[] = "out of bounds";
 71            
 72            const char AlreadyExists::MSG[] = "already exists: ";
 73            
 74            const char NullPointer::MSG[] = "null pointer";
 75            
 76            const char UnitializedHandle::MSG[] = "unitialized handle";
 77            
 78            const char IllegalName::MSG[] = "illegal CIM name";
 79            
 80            const char InvalidPropertyOverride::MSG[] = "invalid property override: ";
 81            
 82            const char InvalidMethodOverride::MSG[] = "invalid method override: ";
 83            
 84            const char UndeclaredQualifier::MSG[] = "undeclared qualifier: ";
 85            
 86            const char BadQualifierScope::MSG[] = "qualifier invalid in this scope: ";
 87            
 88            const char BadQualifierOverride::MSG[] = "qualifier not overridable: ";
 89 mike  1.22 
 90            const char BadQualifierType::MSG[] = 
 91                "CIMType of qualifier different than its declaration: ";
 92            
 93            const char NullType::MSG[] = "type is null";
 94            
 95            const char AddedReferenceToClass::MSG[] = 
 96                "attempted to add reference to a non-association class: ";
 97            
 98            const char ClassAlreadyResolved::MSG[] = 
 99                "attempt to resolve a class that is already resolved: ";
100            
101            const char ClassNotResolved::MSG[] = 
102                "class is not yet resolved: ";
103            
104            const char InstanceAlreadyResolved::MSG[] = 
105                "attempted to resolve a instance that is already resolved";
106            
107            const char InstantiatedAbstractClass::MSG[] = 
108 karl  1.28     "attempted to instantiate an abstract class ";
109 mike  1.22 
110            const char NoSuchProperty::MSG[] = "no such property: ";
111            
112            const char TruncatedCharacter::MSG[] = 
113                "truncated character during conversion from Char16 to char";
114            
115            const char ExpectedReferenceValue::MSG[] = 
116                "Expected CIMValue object to be CIMType::REFERENCE or CIMType::REFERENCE_ARRAY "
117                "in this context";
118            
119            const char MissingReferenceClassName::MSG[] = "missing reference class name";
120            
121            const char IllegalTypeTag::MSG[] = "illegal type tag";
122            
123            const char TypeMismatch::MSG[] = "type mismatch";
124            
125 karl  1.25 const char CIMValueIsNull::MSG[] = "null CIMValue accessed";
126            
127            const char CIMValueInvalidType::MSG[] = "invalid CIMValue type";
128            
129 mike  1.24 const char DynamicCastFailed::MSG[] = "dynamic cast failed";
130            
131 mike  1.22 const char NoSuchFile::MSG[] = "no such file: ";
132            
133 mike  1.23 const char FileNotReadable::MSG[] = "file not readable: ";
134            
135 mike  1.22 const char CannotBindToAddress::MSG[] = "cannot bind to address: ";
136            
137            const char NoSuchDirectory::MSG[] = "no such directory: ";
138            
139            const char ChangeDirectoryFailed::MSG[] = "cannot change directory: ";
140            
141            const char CannotCreateDirectory::MSG[] = "cannot create directory: ";
142            
143            const char NoSuchNameSpace::MSG[] = "no such namespace: ";
144            
145            const char CannotOpenFile::MSG[] = "cannot open file: ";
146            
147            const char NotImplemented::MSG[] = "not implemented: ";
148            
149            const char CannotRemoveDirectory::MSG[] = "cannot remove directory: ";
150            
151            const char CannotRemoveFile::MSG[] = "cannot remove file: ";
152            
153            const char CannotRenameFile::MSG[] = "cannot rename file: ";
154            
155 mike  1.23 const char StackUnderflow::MSG[] = "stack underflow";
156            
157            const char StackOverflow::MSG[] = "stack overflow";
158 mike  1.22 
159            const char QueueUnderflow::MSG[] = "queue Underflow";
160            
161            const char BadFormat::MSG[] = "bad format passed to Formatter::format()";
162            
163            const char BadDateTimeFormat::MSG[] = "bad datetime format";
164            
165            const char IncompatibleTypes::MSG[] = "incompatible types";
166            
167            const char BadlyFormedCGIQueryString::MSG[] = "badly formed CGI query string";
168            
169            const char IllformedObjectName::MSG[] = "illformed object name: ";
170            
171            const char DynamicLoadFailed::MSG[] = "load of dynamic library failed: ";
172            
173            const char DynamicLookupFailed::MSG[] = 
174                "lookup of symbol in dynamic library failed: ";
175            
176            const char CannotOpenDirectory::MSG[] = "cannot open directory: ";
177            
178            const char CorruptFile::MSG[] = "corrupt file: ";
179 mike  1.23 
180            const char BindFailed::MSG[] = "Bind failed: ";
181            
182            const char InvalidLocator::MSG[] = "Invalid locator: ";
183            
184            const char CannotCreateSocket::MSG[] = "Cannot create socket";
185            
186            const char CannotConnect::MSG[] = "Cannot connect to: ";
187            
188            const char UnexpectedFailure::MSG[] = "Unexpected failure";
189            
190            const char FailedToConnect::MSG[] = "failed to connect";
191            
192            const char AlreadyConnected::MSG[] = "already connected";
193            
194            const char NotConnected::MSG[] = "not connected";
195            
196            const char TimedOut::MSG[] = "timed out";
197            
198            const char ParseError::MSG[] = "parse error: ";
199            
200 mike  1.23 const char MissingNullTerminator::MSG[] = "missing null terminator: ";
201            
202            const char SSL_Exception::MSG[] = "SSL Exception ";
203 mike  1.22 
204 kumpf 1.26 const char InvalidAuthHeader::MSG[] = "Invalid Authorization header";
205            
206            
207 mike  1.22 ////////////////////////////////////////////////////////////////////////////////
208            //
209            // CIMException
210            //
211            ////////////////////////////////////////////////////////////////////////////////
212            
213 kumpf 1.29 //
214            // Creates a message without source file name and line number.
215            //
216            static String _makeCIMExceptionMessage(
217                CIMStatusCode code,
218 kumpf 1.32     const String& description)
219 kumpf 1.29 {
220                String tmp;
221                tmp.append(CIMStatusCodeToString(code));
222                tmp.append(": \"");
223 kumpf 1.32     tmp.append(description);
224 kumpf 1.29     tmp.append("\"");
225                return tmp;
226            }
227            
228            //
229            // Creates a message with source file name and line number.
230            //
231 mike  1.22 static String _makeCIMExceptionMessage(
232                CIMStatusCode code, 
233 kumpf 1.32     const String& description,
234 mike  1.22     const char* file,
235 kumpf 1.31     Uint32 line)
236 mike  1.22 {
237                String tmp = file;
238                tmp.append("(");
239                char buffer[32];
240                sprintf(buffer, "%d", line);
241                tmp.append(buffer);
242                tmp.append("): ");
243            
244                tmp.append(CIMStatusCodeToString(code));
245                tmp.append(": \"");
246 kumpf 1.32     tmp.append(description);
247 mike  1.22     tmp.append("\"");
248                return tmp;
249            }
250            
251 kumpf 1.29 //
252            // Returns a message string specifically for tracing. 
253            //
254 kumpf 1.31 String CIMException::getTraceMessage() const
255 kumpf 1.29 {
256                String traceMsg =
257 kumpf 1.32         _makeCIMExceptionMessage(_code, _description, _file, _line);
258 kumpf 1.29     
259                return traceMsg;
260            }
261            
262 mike  1.22 CIMException::CIMException(
263                CIMStatusCode code, 
264 kumpf 1.32     const String& description,
265 mike  1.22     const char* file,
266 kumpf 1.31     Uint32 line)
267 kumpf 1.29     : 
268            #ifdef DEBUG_CIMEXCEPTION
269 kumpf 1.32     Exception(_makeCIMExceptionMessage(code, description, file, line)),
270 kumpf 1.29 #else
271 kumpf 1.32     Exception(_makeCIMExceptionMessage(code, description)),
272 kumpf 1.29 #endif
273 kumpf 1.31     _code(code),
274 kumpf 1.32     _description(description),
275 kumpf 1.31     _file(file),
276                _line(line)
277 mike  1.22 {
278            
279 kumpf 1.32 }
280            
281            CIMException::CIMException(const CIMException& cimException)
282                : Exception(cimException.getMessage()),
283                _code(cimException._code),
284                _description(cimException._description),
285                _file(cimException._file),
286                _line(cimException._line)
287            {
288 mike  1.22 }
289            
290            void ThrowUnitializedHandle()
291            {
292                throw UnitializedHandle();
293            }
294            
295 kumpf 1.34 ////////////////////////////////////////////////////////////////////////////////
296            //
297            // HTTPError
298            //
299            ////////////////////////////////////////////////////////////////////////////////
300            
301            static String _makeHTTPErrorMessage(
302                Uint32 httpStatusCode, 
303                const String& cimError,
304                const String& pegasusError)
305            {
306                String tmp = "HTTP Error (status code ";
307                char buffer[32];
308                sprintf(buffer, "%u", httpStatusCode);
309                tmp.append(buffer);
310                tmp.append(")");
311            
312                if ((cimError != String::EMPTY) || (pegasusError != String::EMPTY))
313                {
314                    tmp.append(":");
315                    if (cimError != String::EMPTY)
316 kumpf 1.34         {
317                        tmp.append(" CIMError = \"");
318                        tmp.append(cimError);
319                        tmp.append("\"");
320                    }
321                    if (pegasusError != String::EMPTY)
322                    {
323                        tmp.append(" Detail = \"");
324                        tmp.append(pegasusError);
325                        tmp.append("\"");
326                    }
327                }
328                tmp.append(".");
329                return tmp;
330            }
331            
332            HTTPError::HTTPError(
333                Uint32 httpStatusCode, 
334                const String& cimError,
335                const String& pegasusError)
336                : 
337 kumpf 1.34     Exception(_makeHTTPErrorMessage(httpStatusCode, cimError, pegasusError)),
338                _httpStatusCode(httpStatusCode),
339                _cimError(cimError),
340                _pegasusError(pegasusError)
341            {
342            }
343            
344            HTTPError::HTTPError(const HTTPError& httpError)
345                :
346                Exception(httpError.getMessage()),
347                _httpStatusCode(httpError._httpStatusCode),
348                _cimError(httpError._cimError),
349                _pegasusError(httpError._pegasusError)
350            {
351            }
352            
353 mike  1.22 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2