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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2