1 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 kumpf 1.1 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
27 //
28 // Modified By: Jenny Yu (jenny_yu@am.exch.hp.com)
29 // Carol Ann Krug Graves, Hewlett-Packard Company
30 // (carolann_graves@hp.com)
|
31 mday 1.6.14.1 //
|
32 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <cstdio>
35 #include "InternalException.h"
|
36 kumpf 1.2 #include <Pegasus/Common/CIMExceptionRep.h>
|
37 mday 1.6.14.1 #include <Pegasus/Common/ContentLanguages.h> // l10n
|
38 kumpf 1.1 #include "Tracer.h"
39
40 PEGASUS_NAMESPACE_BEGIN
41
42 AssertionFailureException::AssertionFailureException(
43 const char* file,
44 size_t line,
|
45 kumpf 1.2 const String& message) : Exception(String::EMPTY)
|
46 kumpf 1.1 {
47 char lineStr[32];
|
48 kumpf 1.6 sprintf(lineStr, "%u", Uint32(line));
|
49 kumpf 1.1
|
50 kumpf 1.5 _rep->message = file;
51 _rep->message.append("(");
52 _rep->message.append(lineStr);
53 _rep->message.append("): ");
54 _rep->message.append(message);
|
55 kumpf 1.1
56 // ATTN-RK-P3-20020408: Should define a "test" trace component
|
57 kumpf 1.5 PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, _rep->message);
|
58 kumpf 1.1 }
59
60 const char NullPointer::MSG[] = "null pointer";
|
61 mday 1.6.14.2 const char NullPointer::KEY[] = "Common.InternalException.NullPointer";
|
62 kumpf 1.1
|
63 mday 1.6.14.2 const char UndeclaredQualifier::MSG[] = "undeclared qualifier: $0";
64 const char UndeclaredQualifier::KEY[] = "Common.InternalException.UndeclaredQualifier";
|
65 kumpf 1.1
66 const char BadQualifierScope::MSG[] = "qualifier invalid in this scope: ";
|
67 mday 1.6.14.2 const char BadQualifierScope::KEY[] = "Common.InternalException.BadQualifierScope";
|
68 kumpf 1.1
69 const char BadQualifierOverride::MSG[] = "qualifier not overridable: ";
|
70 mday 1.6.14.2 const char BadQualifierOverride::KEY[] = "Common.InternalException.BadQualifierOverride";
|
71 kumpf 1.1
|
72 mday 1.6.14.2 const char BadQualifierType::MSG[] = "CIMType of qualifier different than its declaration: ";
73 const char BadQualifierType::KEY[] = "Common.InternalException.BadQualifierType";
|
74 kumpf 1.1
|
75 mday 1.6.14.2 const char ClassAlreadyResolved::MSG[] = "attempt to resolve a class that is already resolved: ";
76 const char ClassAlreadyResolved::KEY[] = "Common.InternalException.ClassAlreadyResolved";
|
77 kumpf 1.1
|
78 mday 1.6.14.2 const char ClassNotResolved::MSG[] = "class is not yet resolved: ";
79 const char ClassNotResolved::KEY[] = "Common.InternalException.ClassNotResolved";
|
80 kumpf 1.1
|
81 mday 1.6.14.2 const char InstanceAlreadyResolved::MSG[] = "attempted to resolve a instance that is already resolved";
82 const char InstanceAlreadyResolved::KEY[] = "Common.InternalException.InstanceAlreadyResolved";
|
83 kumpf 1.1
|
84 mday 1.6.14.2 const char InstantiatedAbstractClass::MSG[] = "attempted to instantiate an abstract class ";
85 const char InstantiatedAbstractClass::KEY[] = "Common.InternalException.InstantiatedAbstractClass";
|
86 kumpf 1.1
87 const char NoSuchProperty::MSG[] = "no such property: ";
|
88 mday 1.6.14.2 const char NoSuchProperty::KEY[] = "Common.InternalException.NoSuchProperty";
|
89 kumpf 1.1
90 const char NoSuchFile::MSG[] = "no such file: ";
|
91 mday 1.6.14.2 const char NoSuchFile::KEY[] = "Common.InternalException.NoSuchFile";
|
92 kumpf 1.1
93 const char FileNotReadable::MSG[] = "file not readable: ";
|
94 mday 1.6.14.2 const char FileNotReadable::KEY[] = "Common.InternalException.FileNotReadable";
|
95 kumpf 1.1
96 const char CannotRemoveDirectory::MSG[] = "cannot remove directory: ";
|
97 mday 1.6.14.2 const char CannotRemoveDirectory::KEY[] = "Common.InternalException.CannotRemoveDirectory";
|
98 kumpf 1.1
99 const char CannotRemoveFile::MSG[] = "cannot remove file: ";
|
100 mday 1.6.14.2 const char CannotRemoveFile::KEY[] = "Common.InternalException.CannotRemoveFile";
|
101 kumpf 1.1
102 const char CannotRenameFile::MSG[] = "cannot rename file: ";
|
103 mday 1.6.14.2 const char CannotRenameFile::KEY[] = "Common.InternalException.CannotRenameFile";
|
104 kumpf 1.1
105 const char NoSuchDirectory::MSG[] = "no such directory: ";
|
106 mday 1.6.14.2 const char NoSuchDirectory::KEY[] = "Common.InternalException.NoSuchDirectory";
|
107 kumpf 1.1
108 const char CannotCreateDirectory::MSG[] = "cannot create directory: ";
|
109 mday 1.6.14.2 const char CannotCreateDirectory::KEY[] = "Common.InternalException.CannotCreateDirectory";
|
110 kumpf 1.1
111 const char CannotOpenFile::MSG[] = "cannot open file: ";
|
112 mday 1.6.14.2 const char CannotOpenFile::KEY[] = "Common.InternalException.CannotOpenFile";
|
113 kumpf 1.1
114 const char NotImplemented::MSG[] = "not implemented: ";
|
115 mday 1.6.14.2 const char NotImplemented::KEY[] = "Common.InternalException.NotImplemented";
|
116 kumpf 1.1
117 const char StackUnderflow::MSG[] = "stack underflow";
|
118 mday 1.6.14.2 const char StackUnderflow::KEY[] = "Common.InternalException.StackUnderflow";
|
119 kumpf 1.1
120 const char StackOverflow::MSG[] = "stack overflow";
|
121 mday 1.6.14.2 const char StackOverflow::KEY[] = "Common.InternalException.StackOverflow";
|
122 kumpf 1.1
123 const char QueueUnderflow::MSG[] = "queue Underflow";
|
124 mday 1.6.14.2 const char QueueUnderflow::KEY[] = "Common.InternalException.QueueUnderflow";
|
125 kumpf 1.1
126 const char BadFormat::MSG[] = "bad format passed to Formatter::format()";
|
127 mday 1.6.14.2 const char BadFormat::KEY[] = "Common.InternalException.BadFormat";
|
128 kumpf 1.1
129 const char BadlyFormedCGIQueryString::MSG[] = "badly formed CGI query string";
|
130 mday 1.6.14.2 const char BadlyFormedCGIQueryString::KEY[] = "Common.InternalException.BadlyFormedCGIQueryString";
|
131 kumpf 1.1
132 const char DynamicLoadFailed::MSG[] = "load of dynamic library failed: ";
|
133 mday 1.6.14.2 const char DynamicLoadFailed::KEY[] = "Common.InternalException.DynamicLoadFailed";
|
134 kumpf 1.1
|
135 mday 1.6.14.2 const char DynamicLookupFailed::MSG[] = "lookup of symbol in dynamic library failed: ";
136 const char DynamicLookupFailed::KEY[] = "Common.InternalException.DynamicLookupFailed";
|
137 kumpf 1.1
138 const char CannotOpenDirectory::MSG[] = "cannot open directory: ";
|
139 mday 1.6.14.2 const char CannotOpenDirectory::KEY[] = "Common.InternalException.CannotOpenDirectory";
|
140 kumpf 1.1
141 const char ParseError::MSG[] = "parse error: ";
|
142 mday 1.6.14.2 const char ParseError::KEY[] = "Common.InternalException.ParseError";
|
143 kumpf 1.1
144 const char MissingNullTerminator::MSG[] = "missing null terminator: ";
|
145 mday 1.6.14.2 const char MissingNullTerminator::KEY[] = "Common.InternalException.MissingNullTerminator";
|
146 kumpf 1.1
|
147 mday 1.6.14.1 //l10n
148 const char MalformedLanguageHeader::MSG[] = "malformed language header: ";
|
149 mday 1.6.14.2 const char MalformedLanguageHeader::KEY[] = "Common.InternalException.MalformedLanguageHeader";
|
150 mday 1.6.14.1
151 const char InvalidAcceptLanguageHeader::MSG[] = "invalid acceptlanguage header: ";
|
152 mday 1.6.14.2 const char InvalidAcceptLanguageHeader::KEY[] = "Common.InternalException.InvalidAcceptLanguageHeader";
|
153 mday 1.6.14.1
154 const char InvalidContentLanguageHeader::MSG[] = "invalid contentlanguage header: ";
|
155 mday 1.6.14.2 const char InvalidContentLanguageHeader::KEY[] = "Common.InternalException.InvalidContentLanguageHeader";
|
156 mday 1.6.14.1 //l10n
157
|
158 kumpf 1.1 const char InvalidAuthHeader::MSG[] = "Invalid Authorization header";
|
159 mday 1.6.14.2 const char InvalidAuthHeader::KEY[] = "Common.InternalException.InvalidAuthHeader";
|
160 kumpf 1.1
161 const char UnauthorizedAccess::MSG[] = "Unauthorized access";
|
162 mday 1.6.14.2 const char UnauthorizedAccess::KEY[] = "Common.InternalException.UnauthorizedAccess";
|
163 kumpf 1.1
|
164 kumpf 1.4 IncompatibleTypesException::IncompatibleTypesException()
165 : Exception("incompatible types")
166 {
167 }
168
|
169 kumpf 1.1
170 ////////////////////////////////////////////////////////////////////////////////
171 //
|
172 kumpf 1.2 // TraceableCIMException
|
173 kumpf 1.1 //
174 ////////////////////////////////////////////////////////////////////////////////
175
176 //
177 // Creates a description without source file name and line number.
178 //
179 static String _makeCIMExceptionDescription(
180 CIMStatusCode code,
181 const String& message)
182 {
183 String tmp;
184 tmp.append(cimStatusCodeToString(code));
185 if (message != String::EMPTY)
186 {
187 tmp.append(": \"");
188 tmp.append(message);
189 tmp.append("\"");
190 }
191 return tmp;
192 }
193
|
194 mday 1.6.14.1 // l10n
195 //
196 // Creates a description without source file name and line number.
197 //
198 static String _makeCIMExceptionDescription(
199 CIMStatusCode code,
200 const String& message,
201 ContentLanguages &contentLanguages)
202 {
203 String tmp;
204 tmp = cimStatusCodeToString(code, contentLanguages);
205 if (message != String::EMPTY)
206 {
207 tmp.append(": \"");
208 tmp.append(message);
209 tmp.append("\"");
210 }
211 return tmp;
212 }
213
214 // l10n
215 mday 1.6.14.1 //
216 // Creates a description without source file name and line number.
217 //
218 static String _makeCIMExceptionDescription(
219 const String& cimMessage,
220 const String& extraMessage)
221 {
222 String tmp;
223 tmp = cimMessage;
224 if (extraMessage != String::EMPTY)
225 {
226 tmp.append(": \"");
227 tmp.append(extraMessage);
228 tmp.append("\"");
229 }
230 return tmp;
231 }
232
|
233 kumpf 1.1 //
234 // Creates a description with source file name and line number.
235 //
236 static String _makeCIMExceptionDescription(
237 CIMStatusCode code,
238 const String& message,
239 const char* file,
240 Uint32 line)
241 {
242 String tmp = file;
243 tmp.append("(");
244 char buffer[32];
245 sprintf(buffer, "%d", line);
246 tmp.append(buffer);
247 tmp.append("): ");
248 tmp.append(_makeCIMExceptionDescription(code, message));
249 return tmp;
250 }
251
|
252 mday 1.6.14.2 //l10n
253 TraceableCIMException::TraceableCIMException(
254 CIMStatusCode code,
255 MessageLoaderParms parms,
256 const char* file,
257 Uint32 line)
258 :
259 CIMException(code, parms)
260 {
261 CIMExceptionRep* rep;
262 rep = reinterpret_cast<CIMExceptionRep*>(_rep);
263 rep->file = file;
264 rep->line = line;
265
266 // l10n
267 // Localize the cim message from the code. Use the language of
268 // the current thread.
269 rep->contentLanguages = cimStatusCodeToString_Thread(rep->cimMessage, code);
270 }
271
|
272 kumpf 1.2 TraceableCIMException::TraceableCIMException(
|
273 kumpf 1.1 CIMStatusCode code,
274 const String& message,
275 const char* file,
276 Uint32 line)
277 :
|
278 kumpf 1.2 CIMException(code, message)
|
279 kumpf 1.1 {
|
280 kumpf 1.5 CIMExceptionRep* rep;
281 rep = reinterpret_cast<CIMExceptionRep*>(_rep);
282 rep->file = file;
283 rep->line = line;
|
284 mday 1.6.14.1
285 // l10n
286 // Localize the cim message from the code. Use the language of
287 // the current thread.
288 rep->contentLanguages = cimStatusCodeToString_Thread(rep->cimMessage, code);
289 }
290
291 // l10n
292 TraceableCIMException::TraceableCIMException(
293 const ContentLanguages& langs,
294 CIMStatusCode code,
295 const String& message,
296 const char* file,
297 Uint32 line)
298 :
299 CIMException(code, message)
300 {
301 CIMExceptionRep* rep;
302 rep = reinterpret_cast<CIMExceptionRep*>(_rep);
303 rep->file = file;
304 rep->line = line;
305 mday 1.6.14.1
306 // l10n
307 rep->contentLanguages = langs;
|
308 kumpf 1.2 }
|
309 kumpf 1.1
|
310 kumpf 1.2 TraceableCIMException::TraceableCIMException(const CIMException & cimException)
311 : CIMException(cimException.getCode(), cimException.getMessage())
312 {
313 TraceableCIMException * t = (TraceableCIMException *)&cimException;
|
314 kumpf 1.5 CIMExceptionRep* left;
315 CIMExceptionRep* right;
316 left = reinterpret_cast<CIMExceptionRep*>(_rep);
317 right = reinterpret_cast<CIMExceptionRep*>(t->_rep);
318 left->file = right->file;
319 left->line = right->line;
|
320 mday 1.6.14.1 // l10n
321 left->contentLanguages = right->contentLanguages;
322 left->cimMessage = right->cimMessage;
|
323 kumpf 1.1 }
324
325 //
326 // Returns a description string fit for human consumption
327 //
|
328 kumpf 1.2 String TraceableCIMException::getDescription() const
|
329 kumpf 1.1 {
|
330 kumpf 1.2 #ifdef PEGASUS_DEBUG_CIMEXCEPTION
|
331 kumpf 1.1 return getTraceDescription();
332 #else
|
333 kumpf 1.5 CIMExceptionRep* rep;
334 rep = reinterpret_cast<CIMExceptionRep*>(_rep);
|
335 mday 1.6.14.1 // l10n - TODO uncomment when CIMStatus code is done
|
336 mday 1.6.14.2 //return _makeCIMExceptionDescription(rep->code, getMessage());
337
|
338 mday 1.6.14.1 if (rep->cimMessage == String::EMPTY)
339 {
340 return _makeCIMExceptionDescription(rep->code,
341 getMessage(),
342 rep->contentLanguages);
343 }
344 else
345 {
346 return _makeCIMExceptionDescription(rep->cimMessage,
347 getMessage());
348 }
|
349 mday 1.6.14.2
|
350 kumpf 1.1 #endif
351 }
352
353 //
354 // Returns a description string with filename and line number information
355 // specifically for tracing.
356 //
|
357 kumpf 1.2 String TraceableCIMException::getTraceDescription() const
|
358 kumpf 1.1 {
|
359 kumpf 1.5 CIMExceptionRep* rep;
360 rep = reinterpret_cast<CIMExceptionRep*>(_rep);
|
361 kumpf 1.1 String traceDescription =
|
362 kumpf 1.2 _makeCIMExceptionDescription(
|
363 kumpf 1.5 rep->code, getMessage(), rep->file, rep->line);
|
364 kumpf 1.1
365 return traceDescription;
366 }
367
368 PEGASUS_NAMESPACE_END
|