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

  1 karl  1.77 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.22 //
  3 karl  1.73 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.68 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.73 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.74 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.77 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.22 //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 chip  1.39 // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.22 // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.68 // 
 21 chip  1.39 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 chip  1.39 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.22 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #include <cstdio>
 35            #include "Exception.h"
 36 kumpf 1.59 #include <Pegasus/Common/ExceptionRep.h>
 37 kumpf 1.53 #include <Pegasus/Common/CIMExceptionRep.h>
 38 kumpf 1.33 #include "Tracer.h"
 39 mike  1.22 
 40            PEGASUS_NAMESPACE_BEGIN
 41            
 42 kumpf 1.59 Exception::Exception(const String& message)
 43            {
 44                _rep = new ExceptionRep();
 45                _rep->message = message;
 46 kumpf 1.75     _rep->contentLanguages.clear();
 47 kumpf 1.59 }
 48            
 49            Exception::Exception(const Exception& exception)
 50            {
 51                _rep = new ExceptionRep();
 52                _rep->message = exception._rep->message;
 53 kumpf 1.80     _rep->contentLanguages = exception._rep->contentLanguages;
 54 chuck 1.64 }
 55            
 56            Exception::Exception(const MessageLoaderParms& msgParms)
 57            {
 58                _rep = new ExceptionRep();
 59                _rep->message = MessageLoader::getMessage(
 60 kumpf 1.80         const_cast<MessageLoaderParms &>(msgParms));
 61 karl  1.78     // Must be after MessageLoader::getMessage call
 62 chuck 1.64     _rep->contentLanguages = msgParms.contentlanguages;
 63 kumpf 1.59 }
 64            
 65            Exception::Exception()
 66 chip  1.39 {
 67 a.arora 1.71     _rep = NULL;
 68 mike    1.22 }
 69              
 70 kumpf   1.54 Exception::~Exception()
 71 mike    1.22 {
 72 kumpf   1.59     delete _rep;
 73 mike    1.22 }
 74              
 75 kumpf   1.54 const String& Exception::getMessage() const
 76 mike    1.22 {
 77 kumpf   1.59     return _rep->message;
 78 mike    1.22 }
 79              
 80 kumpf   1.76 const ContentLanguageList& Exception::getContentLanguages() const
 81 chuck   1.64 {
 82 kumpf   1.80     return _rep->contentLanguages;
 83 karl    1.78 }
 84 chuck   1.64 
 85 kumpf   1.76 void Exception::setContentLanguages(const ContentLanguageList& langs)
 86 chuck   1.64 {
 87 kumpf   1.80     _rep->contentLanguages = langs;
 88 kumpf   1.54 }
 89 mike    1.22 
 90 chuck   1.64 IndexOutOfBoundsException::IndexOutOfBoundsException()
 91 kumpf   1.80     : Exception(MessageLoaderParms(
 92                        "Common.Exception.INDEX_OUT_OF_BOUNDS_EXCEPTION",
 93                        "index out of bounds"))
 94 chuck   1.64 {
 95              }
 96              
 97 kumpf   1.55 AlreadyExistsException::AlreadyExistsException(const String& message)
 98 kumpf   1.80     : Exception(MessageLoaderParms(
 99                        "Common.Exception.ALREADY_EXISTS_EXCEPTION",
100                        "already exists: $0",
101                        message))
102 chuck   1.64 {
103              }
104              
105 chuck   1.65 AlreadyExistsException::AlreadyExistsException(MessageLoaderParms& msgParms)
106 kumpf   1.80     : Exception(MessageLoaderParms(
107                        "Common.Exception.ALREADY_EXISTS_EXCEPTION",
108                        "already exists: "))
109 kumpf   1.54 {
110 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
111 kumpf   1.54 }
112 mike    1.22 
113 chuck   1.64 InvalidNameException::InvalidNameException(const String& message)
114 kumpf   1.80     : Exception(MessageLoaderParms(
115                        "Common.Exception.INVALID_NAME_EXCEPTION",
116                        "invalid CIM name: $0",
117                        message))
118 chuck   1.64 {
119              }
120              
121 chuck   1.65 InvalidNameException::InvalidNameException(MessageLoaderParms& msgParms)
122 kumpf   1.80     : Exception(MessageLoaderParms(
123                        "Common.Exception.INVALID_NAME_EXCEPTION",
124                        "invalid CIM name: "))
125 chuck   1.64 {
126 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
127 chuck   1.64 }
128              
129 kumpf   1.54 InvalidNamespaceNameException::InvalidNamespaceNameException(const String& name)
130 kumpf   1.80     : Exception(MessageLoaderParms(
131                        "Common.Exception.INVALID_NAMESACE_NAME_EXCEPTION",
132                        "invalid CIM namespace name: $0",
133                        name))
134 kumpf   1.54 {
135              }
136 chuck   1.65 
137 kumpf   1.80 InvalidNamespaceNameException::InvalidNamespaceNameException(
138                  MessageLoaderParms& msgParms)
139                  : Exception(MessageLoaderParms(
140                        "Common.Exception.INVALID_NAMESPACE_NAME_EXCEPTION",
141                        "invalid CIM namespace name: "))
142 chuck   1.64 {
143 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
144 chuck   1.64 }
145              
146              UninitializedObjectException::UninitializedObjectException()
147 kumpf   1.80     : Exception(MessageLoaderParms(
148                        "Common.Exception.UNINITIALIZED_OBJECT_EXCEPTION",
149                        "uninitialized object"))
150 chuck   1.64 {
151              }
152              
153 kumpf   1.55 TypeMismatchException::TypeMismatchException()
154 kumpf   1.80     : Exception(MessageLoaderParms(
155                        "Common.Exception.TYPE_MISMATCH_EXCEPTION",
156                        "type mismatch"))
157 chuck   1.64 {
158              }
159              
160 marek   1.69 TypeMismatchException::TypeMismatchException(const String& message)
161 kumpf   1.80     : Exception(MessageLoaderParms(
162                        "Common.Exception.TYPE_MISMATCH_EXCEPTION",
163                        "type mismatch: $0",message))
164 marek   1.69 {
165              
166              }
167              
168              TypeMismatchException::TypeMismatchException(MessageLoaderParms& msgParms)
169 kumpf   1.80     : Exception(MessageLoaderParms(
170                        "Common.Exception.TYPE_MISMATCH_EXCEPTION",
171                        "type mismatch: "))
172 marek   1.69 {
173                  _rep->message.append(MessageLoader::getMessage(msgParms));
174              }
175              
176 chuck   1.64 DynamicCastFailedException::DynamicCastFailedException()
177 kumpf   1.80     : Exception(MessageLoaderParms(
178                        "Common.Exception.DYNAMIC_CAST_FAILED_EXCEPTION",
179                        "dynamic cast failed"))
180 chuck   1.64 {
181              }
182              
183 kumpf   1.55 InvalidDateTimeFormatException::InvalidDateTimeFormatException()
184 kumpf   1.80     : Exception(MessageLoaderParms(
185                        "Common.Exception.INVALID_DATETIME_FORMAT_EXCEPTION",
186                        "invalid datetime format"))
187 kumpf   1.54 {
188              }
189 mike    1.22 
190 kumpf   1.80 MalformedObjectNameException::MalformedObjectNameException(
191                  const String& message)
192                  : Exception(MessageLoaderParms(
193                        "Common.Exception.MALFORMED_OBJECT_NAME_EXCEPTION",
194                        "malformed object name: $0",
195                        message))
196 chuck   1.64 {
197              }
198              
199 kumpf   1.54 MalformedObjectNameException::MalformedObjectNameException(
200 kumpf   1.80     MessageLoaderParms& msgParms)
201                  : Exception(MessageLoaderParms(
202                        "Common.Exception.MALFORMED_OBJECT_NAME_EXCEPTION",
203                        "malformed object name: "))
204 kumpf   1.54 {
205 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
206 kumpf   1.54 }
207 mike    1.23 
208 chuck   1.64 BindFailedException::BindFailedException(const String& message)
209 kumpf   1.80     : Exception(MessageLoaderParms(
210                        "Common.Exception.BIND_FAILED_EXCEPTION",
211                        "Bind failed: $0",
212                        message))
213 chuck   1.64 {
214              }
215              
216 chuck   1.65 BindFailedException::BindFailedException(MessageLoaderParms& msgParms)
217 kumpf   1.80     : Exception(MessageLoaderParms(
218                        "Common.Exception.BIND_FAILED_EXCEPTION",
219                        "Bind failed: "))
220 chuck   1.64 {
221 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
222 chuck   1.64 }
223              
224              InvalidLocatorException::InvalidLocatorException(const String& message)
225 kumpf   1.80     : Exception(MessageLoaderParms(
226                        "Common.Exception.INVALID_LOCATOR_EXCEPTION",
227                        "Invalid locator: $0",
228                        message))
229 chuck   1.64 {
230              }
231              
232 chuck   1.65 InvalidLocatorException::InvalidLocatorException(MessageLoaderParms& msgParms)
233 kumpf   1.80     : Exception(MessageLoaderParms(
234                        "Common.Exception.INVALID_LOCATOR_EXCEPTION",
235                        "Invalid locator: "))
236 kumpf   1.54 {
237 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
238 kumpf   1.54 }
239 mike    1.23 
240 chuck   1.64 CannotCreateSocketException::CannotCreateSocketException()
241 kumpf   1.80     : Exception(MessageLoaderParms(
242                        "Common.Exception.CANNOT_CREATE_SOCKET_EXCEPTION",
243                        "Cannot create socket"))
244 chuck   1.64 {
245              }
246              
247 chuck   1.65 
248              CannotConnectException::CannotConnectException(const String& message)//???
249 kumpf   1.63     : Exception(message)
250 kumpf   1.54 {
251              }
252 chuck   1.65 
253              
254              CannotConnectException::CannotConnectException(MessageLoaderParms& msgParms)
255 chuck   1.64     : Exception(msgParms)
256              {
257              }
258 mike    1.23 
259 kumpf   1.54 AlreadyConnectedException::AlreadyConnectedException()
260 kumpf   1.80     : Exception(MessageLoaderParms(
261                        "Common.Exception.ALREADY_CONNECTED_EXCEPTION",
262                        "already connected"))
263 kumpf   1.54 {
264              }
265 mike    1.23 
266 chuck   1.64 
267 kumpf   1.54 NotConnectedException::NotConnectedException()
268 kumpf   1.80     : Exception(MessageLoaderParms(
269                        "Common.Exception.NOT_CONNECTED_EXCEPTION",
270                        "not connected"))
271 kumpf   1.54 {
272              }
273 kumpf   1.26 
274 chuck   1.64 ConnectionTimeoutException::ConnectionTimeoutException()
275 kumpf   1.80     : Exception(MessageLoaderParms(
276                        "Common.Exception.CONNECTION_TIMEOUT_EXCEPTION",
277                        "connection timed out"))
278 chuck   1.64 {
279              }
280              
281 kumpf   1.54 SSLException::SSLException(const String& message)
282 kumpf   1.80     : Exception(MessageLoaderParms(
283                        "Common.Exception.SSL_EXCEPTION",
284                        "SSL Exception: $0" ,
285                        message))
286 chuck   1.64 {
287              }
288              
289 chuck   1.65 SSLException::SSLException(MessageLoaderParms& msgParms)
290 kumpf   1.80     : Exception(MessageLoaderParms(
291                        "Common.Exception.SSL_EXCEPTION",
292                        "SSL Exception: " ))
293 chuck   1.64 {
294 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
295 chuck   1.64 }
296              
297 kumpf   1.62 DateTimeOutOfRangeException::DateTimeOutOfRangeException(const String& message)
298 kumpf   1.80     : Exception(MessageLoaderParms(
299                        "Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
300                        "DateTime is out of range : $0" ,
301                        message))
302 kumpf   1.62 {
303              }
304 kumpf   1.26 
305 kumpf   1.80 DateTimeOutOfRangeException::DateTimeOutOfRangeException(
306                  MessageLoaderParms& msgParms)
307                  : Exception(MessageLoaderParms(
308                        "Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
309                        "DateTime is out of range : " ))
310 chuck   1.64 {
311 kumpf   1.80     _rep->message.append(MessageLoader::getMessage(msgParms));
312 chuck   1.64 }
313 chuck   1.65 
314 mike    1.22 ////////////////////////////////////////////////////////////////////////////////
315              //
316              // CIMException
317              //
318              ////////////////////////////////////////////////////////////////////////////////
319              
320 chuck   1.64 // l10n - note - use this when you have an exception with no
321              // detail message, or one with an untranslated detail message
322              // The pegasus message associated with code will be translated.
323 kumpf   1.53 CIMException::CIMException(
324 kumpf   1.29     CIMStatusCode code,
325 kumpf   1.37     const String& message)
326 kumpf   1.61     : Exception()
327 kumpf   1.29 {
328 kumpf   1.59     CIMExceptionRep * tmp = new CIMExceptionRep ();
329                  tmp->message = message;
330                  tmp->code = code;
331                  tmp->file = "";
332                  tmp->line = 0;
333 kumpf   1.75     tmp->contentLanguages.clear();
334 karl    1.78     tmp->cimMessage = String::EMPTY;
335                  _rep = tmp;
336              }
337              
338              
339 kumpf   1.80 // l10n - note - use this when you have an exception
340 karl    1.78 // an untranslated detail message and an attached CIM_Error
341              // The pegasus message associated with code will be translated.
342              CIMException::CIMException(
343                  CIMStatusCode code,
344                  const String& message,
345                  const CIMInstance& instance)
346                  : Exception()
347              {
348                  CIMExceptionRep * tmp = new CIMExceptionRep ();
349                  tmp->message = message;
350                  tmp->code = code;
351                  tmp->file = "";
352                  tmp->errors.append(instance);
353                  tmp->line = 0;
354                  tmp->contentLanguages.clear();
355 kumpf   1.80     tmp->cimMessage = String::EMPTY;
356 chuck   1.64     _rep = tmp;
357              }
358              
359 kumpf   1.80 // l10n - note - use this when you have an exception
360 karl    1.78 // an untranslated detail message and an attached CIM_Error
361              // array
362              // The pegasus message associated with code will be translated.
363              CIMException::CIMException(
364                  CIMStatusCode code,
365                  const String& message,
366                  const Array<CIMInstance>& instances)
367                  : Exception()
368              {
369                  CIMExceptionRep * tmp = new CIMExceptionRep ();
370                  tmp->message = message;
371                  tmp->code = code;
372                  tmp->file = "";
373                  tmp->errors.appendArray(instances);
374                  tmp->line = 0;
375                  tmp->contentLanguages.clear();
376 kumpf   1.80     tmp->cimMessage = String::EMPTY;
377 karl    1.78     _rep = tmp;
378              }
379 chuck   1.64 // l10n - note use this when you have an exception with a translated
380              // detail message
381              CIMException::CIMException(
382                  CIMStatusCode code,
383                  const MessageLoaderParms& msgParms)
384                  : Exception()
385              {
386 kumpf   1.80     CIMExceptionRep* tmp = new CIMExceptionRep();
387 chuck   1.64     tmp->message = MessageLoader::getMessage(
388 kumpf   1.80         const_cast<MessageLoaderParms &>(msgParms));
389 chuck   1.64     // Must be after MessageLoader::getMessage call
390 karl    1.78     tmp->contentLanguages = msgParms.contentlanguages;
391                  tmp->cimMessage = String::EMPTY;
392                  tmp->code = code;
393                  tmp->file = "";
394                  tmp->line = 0;
395                  _rep = tmp;
396              }
397              
398              CIMException::CIMException(
399                  CIMStatusCode code,
400                  const MessageLoaderParms& msgParms,
401                  const CIMInstance& instance)
402                  : Exception()
403              {
404 kumpf   1.80     CIMExceptionRep* tmp = new CIMExceptionRep();
405 karl    1.78     tmp->message = MessageLoader::getMessage(
406 kumpf   1.80         const_cast<MessageLoaderParms &>(msgParms));
407 karl    1.78     // Must be after MessageLoader::getMessage call
408 kumpf   1.80     tmp->contentLanguages = msgParms.contentlanguages;
409 chuck   1.64     tmp->cimMessage = String::EMPTY;
410 karl    1.78     tmp->errors.append(instance);
411 chuck   1.64     tmp->code = code;
412                  tmp->file = "";
413                  tmp->line = 0;
414 kumpf   1.59     _rep = tmp;
415 kumpf   1.29 }
416              
417 karl    1.78 CIMException::CIMException(
418                  CIMStatusCode code,
419                  const MessageLoaderParms& msgParms,
420                  const Array<CIMInstance>& instances)
421                  : Exception()
422              {
423 kumpf   1.80     CIMExceptionRep* tmp = new CIMExceptionRep();
424 karl    1.78     tmp->message = MessageLoader::getMessage(
425 kumpf   1.80         const_cast<MessageLoaderParms &>(msgParms));
426 karl    1.78     // Must be after MessageLoader::getMessage call
427 kumpf   1.80     tmp->contentLanguages = msgParms.contentlanguages;
428 karl    1.78     tmp->cimMessage = String::EMPTY;
429                  tmp->errors.appendArray(instances);
430                  tmp->code = code;
431                  tmp->file = "";
432                  tmp->line = 0;
433                  _rep = tmp;
434              }
435 kumpf   1.53 CIMException::CIMException(const CIMException & cimException)
436 kumpf   1.61     : Exception()
437 kumpf   1.53 {
438 kumpf   1.80     CIMExceptionRep* tmp = new CIMExceptionRep();
439                  CIMExceptionRep* rep;
440 kumpf   1.59     rep = reinterpret_cast<CIMExceptionRep*>(cimException._rep);
441                  tmp->message = rep->message;
442 kumpf   1.80     tmp->contentLanguages = rep->contentLanguages;
443                  tmp->cimMessage = rep->cimMessage;
444 kumpf   1.59     tmp->code = rep->code;
445                  tmp->file = rep->file;
446                  tmp->line = rep->line;
447 karl    1.78     tmp->errors = rep->errors;
448 kumpf   1.59     _rep = tmp;
449 mike    1.22 }
450              
451 kumpf   1.53 CIMException& CIMException::operator=(const CIMException & cimException)
452 mike    1.22 {
453 kumpf   1.72     if (&cimException != this)
454                  {
455                      CIMExceptionRep* left;
456                      CIMExceptionRep* right;
457                      left = reinterpret_cast<CIMExceptionRep*>(this->_rep);
458                      right = reinterpret_cast<CIMExceptionRep*>(cimException._rep);
459                      left->message = right->message;
460 kumpf   1.80         left->contentLanguages = right->contentLanguages;
461                      left->cimMessage = right->cimMessage;
462 kumpf   1.72         left->code = right->code;
463                      left->file = right->file;
464                      left->line = right->line;
465 kumpf   1.80         left->errors = right->errors;
466 kumpf   1.72     }
467 kumpf   1.53     return *this;
468 kumpf   1.32 }
469              
470 kumpf   1.53 CIMException::~CIMException()
471 kumpf   1.37 {
472              }
473              
474 karl    1.78 Uint32 CIMException::getErrorCount() const
475              {
476                  return reinterpret_cast<CIMExceptionRep*>(_rep)->errors.size();
477              }
478              /**************
479              CIMInstance CIMException::getError(Uint32 index)
480              {
481                  return reinterpret_cast<CIMExceptionRep*>(_rep)->errors[index];
482              }
483              ***************/
484              
485              CIMConstInstance CIMException::getError(Uint32 index) const
486              {
487                  return reinterpret_cast<CIMExceptionRep*>(_rep)->errors[index];
488              }
489              
490              void CIMException::addError(const CIMInstance& instance)
491              {
492 mike    1.79     reinterpret_cast<CIMExceptionRep*>(_rep)->errors.append(instance);
493 karl    1.78 }
494              
495 kumpf   1.53 CIMStatusCode CIMException::getCode() const
496 kumpf   1.37 {
497 kumpf   1.59     CIMExceptionRep* rep;
498                  rep = reinterpret_cast<CIMExceptionRep*>(_rep);
499                  return rep->code;
500 mike    1.22 }
501              
502              PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2