(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 karl    1.86.8.1 // EXP_PULL_BEGIN
288                  InvalidEnumerationContextException::InvalidEnumerationContextException()
289                      : Exception(MessageLoaderParms(
290                            "Common.Exception.INVALID_ENUMERATION_CONTEXT_EXCEPTION",
291                            "Invalid Enumeration Context, uninitilialized"))
292                  {
293                  }
294                  // EXP_PULL_END
295 chuck   1.64     
296 kumpf   1.54     SSLException::SSLException(const String& message)
297 kumpf   1.80         : Exception(MessageLoaderParms(
298                            "Common.Exception.SSL_EXCEPTION",
299                            "SSL Exception: $0" ,
300                            message))
301 chuck   1.64     {
302                  }
303                  
304 chuck   1.65     SSLException::SSLException(MessageLoaderParms& msgParms)
305 kumpf   1.80         : Exception(MessageLoaderParms(
306                            "Common.Exception.SSL_EXCEPTION",
307 marek   1.82               "SSL Exception: $0",
308                            MessageLoader::getMessage(msgParms)))
309 chuck   1.64     {
310                  }
311                  
312 kumpf   1.62     DateTimeOutOfRangeException::DateTimeOutOfRangeException(const String& message)
313 kumpf   1.80         : Exception(MessageLoaderParms(
314                            "Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
315                            "DateTime is out of range : $0" ,
316                            message))
317 kumpf   1.62     {
318                  }
319 kumpf   1.26     
320 kumpf   1.80     DateTimeOutOfRangeException::DateTimeOutOfRangeException(
321                      MessageLoaderParms& msgParms)
322                      : Exception(MessageLoaderParms(
323                            "Common.Exception.DATETIME_OUT_OF_RANGE_EXCEPTION",
324 marek   1.82               "DateTime is out of range : $0",
325                            MessageLoader::getMessage(msgParms)))
326 chuck   1.64     {
327                  }
328 chuck   1.65     
329 mike    1.22     ////////////////////////////////////////////////////////////////////////////////
330                  //
331                  // CIMException
332                  //
333                  ////////////////////////////////////////////////////////////////////////////////
334                  
335 chuck   1.64     // l10n - note - use this when you have an exception with no
336                  // detail message, or one with an untranslated detail message
337                  // The pegasus message associated with code will be translated.
338 kumpf   1.53     CIMException::CIMException(
339 kumpf   1.29         CIMStatusCode code,
340 kumpf   1.37         const String& message)
341 kumpf   1.61         : Exception()
342 kumpf   1.29     {
343 kumpf   1.59         CIMExceptionRep * tmp = new CIMExceptionRep ();
344                      tmp->message = message;
345                      tmp->code = code;
346                      tmp->file = "";
347                      tmp->line = 0;
348 kumpf   1.75         tmp->contentLanguages.clear();
349 karl    1.78         tmp->cimMessage = String::EMPTY;
350                      _rep = tmp;
351                  }
352                  
353                  
354 kumpf   1.80     // l10n - note - use this when you have an exception
355 karl    1.78     // an untranslated detail message and an attached CIM_Error
356                  // The pegasus message associated with code will be translated.
357                  CIMException::CIMException(
358                      CIMStatusCode code,
359                      const String& message,
360                      const CIMInstance& instance)
361                      : Exception()
362                  {
363                      CIMExceptionRep * tmp = new CIMExceptionRep ();
364                      tmp->message = message;
365                      tmp->code = code;
366                      tmp->file = "";
367                      tmp->errors.append(instance);
368                      tmp->line = 0;
369                      tmp->contentLanguages.clear();
370 kumpf   1.80         tmp->cimMessage = String::EMPTY;
371 chuck   1.64         _rep = tmp;
372                  }
373                  
374 kumpf   1.80     // l10n - note - use this when you have an exception
375 karl    1.78     // an untranslated detail message and an attached CIM_Error
376                  // array
377                  // The pegasus message associated with code will be translated.
378                  CIMException::CIMException(
379                      CIMStatusCode code,
380                      const String& message,
381                      const Array<CIMInstance>& instances)
382                      : Exception()
383                  {
384                      CIMExceptionRep * tmp = new CIMExceptionRep ();
385                      tmp->message = message;
386                      tmp->code = code;
387                      tmp->file = "";
388                      tmp->errors.appendArray(instances);
389                      tmp->line = 0;
390                      tmp->contentLanguages.clear();
391 kumpf   1.80         tmp->cimMessage = String::EMPTY;
392 karl    1.78         _rep = tmp;
393                  }
394 chuck   1.64     // l10n - note use this when you have an exception with a translated
395                  // detail message
396                  CIMException::CIMException(
397                      CIMStatusCode code,
398                      const MessageLoaderParms& msgParms)
399                      : Exception()
400                  {
401 kumpf   1.80         CIMExceptionRep* tmp = new CIMExceptionRep();
402 chuck   1.64         tmp->message = MessageLoader::getMessage(
403 kumpf   1.80             const_cast<MessageLoaderParms &>(msgParms));
404 chuck   1.64         // Must be after MessageLoader::getMessage call
405 karl    1.78         tmp->contentLanguages = msgParms.contentlanguages;
406                      tmp->cimMessage = String::EMPTY;
407                      tmp->code = code;
408                      tmp->file = "";
409                      tmp->line = 0;
410                      _rep = tmp;
411                  }
412                  
413                  CIMException::CIMException(
414                      CIMStatusCode code,
415                      const MessageLoaderParms& msgParms,
416                      const CIMInstance& instance)
417                      : Exception()
418                  {
419 kumpf   1.80         CIMExceptionRep* tmp = new CIMExceptionRep();
420 karl    1.78         tmp->message = MessageLoader::getMessage(
421 kumpf   1.80             const_cast<MessageLoaderParms &>(msgParms));
422 karl    1.78         // Must be after MessageLoader::getMessage call
423 kumpf   1.80         tmp->contentLanguages = msgParms.contentlanguages;
424 chuck   1.64         tmp->cimMessage = String::EMPTY;
425 karl    1.78         tmp->errors.append(instance);
426 chuck   1.64         tmp->code = code;
427                      tmp->file = "";
428                      tmp->line = 0;
429 kumpf   1.59         _rep = tmp;
430 kumpf   1.29     }
431                  
432 karl    1.78     CIMException::CIMException(
433                      CIMStatusCode code,
434                      const MessageLoaderParms& msgParms,
435                      const Array<CIMInstance>& instances)
436                      : Exception()
437                  {
438 kumpf   1.80         CIMExceptionRep* tmp = new CIMExceptionRep();
439 karl    1.78         tmp->message = MessageLoader::getMessage(
440 kumpf   1.80             const_cast<MessageLoaderParms &>(msgParms));
441 karl    1.78         // Must be after MessageLoader::getMessage call
442 kumpf   1.80         tmp->contentLanguages = msgParms.contentlanguages;
443 karl    1.78         tmp->cimMessage = String::EMPTY;
444                      tmp->errors.appendArray(instances);
445                      tmp->code = code;
446                      tmp->file = "";
447                      tmp->line = 0;
448                      _rep = tmp;
449                  }
450 kumpf   1.84     
451 kumpf   1.53     CIMException::CIMException(const CIMException & cimException)
452 kumpf   1.61         : Exception()
453 kumpf   1.53     {
454 kumpf   1.84         _rep = new CIMExceptionRep(
455                          *reinterpret_cast<CIMExceptionRep*>(cimException._rep));
456 mike    1.22     }
457                  
458 kumpf   1.53     CIMException& CIMException::operator=(const CIMException & cimException)
459 mike    1.22     {
460 kumpf   1.72         if (&cimException != this)
461                      {
462 kumpf   1.84             CIMExceptionRep* left = reinterpret_cast<CIMExceptionRep*>(this->_rep);
463                          CIMExceptionRep* right =
464                              reinterpret_cast<CIMExceptionRep*>(cimException._rep);
465                          *left = *right;
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