BUG#: 5840
[tpot/pegasus/.git] / src / Pegasus / Common / Exception.h
1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // 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 // 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 // 
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
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 // 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 // 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 #ifndef Pegasus_Exception_h
35 #define Pegasus_Exception_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/String.h>
39 #include <Pegasus/Common/CIMStatusCode.h>
40 #include <Pegasus/Common/Linkage.h>
41 #include <Pegasus/Common/ContentLanguageList.h>
42 #include <Pegasus/Common/Array.h>
43
44 #ifdef PEGASUS_INTERNALONLY
45 # include <Pegasus/Common/MessageLoader.h>
46 #endif
47
48 PEGASUS_NAMESPACE_BEGIN
49 class ExceptionRep;
50 class CIMInstance;
51 class CIMConstInstance;
52
53
54 /**
55 <p>The <tt>Exception</tt> class is the parent class for all
56 exceptions that can be generated by any component of the
57 Pegasus infrastructure. It includes not only the CIM exceptions
58 that are defined by the DMTF, but also various exceptions that
59 may occur during the processing of functions called by clients
60 and providers.</p>
61 */
62 class PEGASUS_COMMON_LINKAGE Exception
63 {
64 public:
65
66     ///
67     Exception(const String& message);
68
69     ///
70     Exception(const Exception& exception);
71
72 #ifdef PEGASUS_INTERNALONLY
73     Exception(const MessageLoaderParms& msgParms);
74 #endif
75
76     ///
77     virtual ~Exception();
78
79     ///
80     virtual const String& getMessage() const;
81
82 #ifdef PEGASUS_INTERNALONLY
83     // Note: Not virtual to preserve binary compatibility.
84     const ContentLanguageList& getContentLanguages() const;
85
86     // Not virtual to preserve binary compatibility.
87     void setContentLanguages(const ContentLanguageList& langs);
88 #endif
89
90 protected:
91
92     Exception();
93
94     ExceptionRep * _rep;
95 };
96
97 ///
98 class PEGASUS_COMMON_LINKAGE IndexOutOfBoundsException : public Exception
99 {
100 public:
101     ///
102     IndexOutOfBoundsException();
103 };
104
105 ///
106 class PEGASUS_COMMON_LINKAGE AlreadyExistsException : public Exception
107 {
108 public:
109     ///
110     AlreadyExistsException(const String& message);
111
112 #ifdef PEGASUS_INTERNALONLY
113     AlreadyExistsException(MessageLoaderParms& msgParms);
114 #endif
115 };
116
117 ///
118 class PEGASUS_COMMON_LINKAGE InvalidNameException : public Exception
119 {
120 public:
121     ///
122     InvalidNameException(const String& name);
123
124 #ifdef PEGASUS_INTERNALONLY
125     InvalidNameException(MessageLoaderParms& msgParms);
126 #endif
127 };
128
129 ///
130 class PEGASUS_COMMON_LINKAGE InvalidNamespaceNameException : public Exception
131 {
132 public:
133     ///
134     InvalidNamespaceNameException(const String& name);
135
136 #ifdef PEGASUS_INTERNALONLY
137     InvalidNamespaceNameException(MessageLoaderParms& msgParms);
138 #endif
139 };
140
141 ///
142 class PEGASUS_COMMON_LINKAGE UninitializedObjectException : public Exception
143 {
144 public:
145     ///
146     UninitializedObjectException();
147 };
148
149 ///
150 class PEGASUS_COMMON_LINKAGE TypeMismatchException : public Exception
151 {
152 public:
153     ///
154     TypeMismatchException();
155     TypeMismatchException(const String& message);
156
157 #ifdef PEGASUS_INTERNALONLY
158     TypeMismatchException(MessageLoaderParms& msgParms);
159 #endif
160
161 };
162
163 ///
164 class PEGASUS_COMMON_LINKAGE DynamicCastFailedException : public Exception
165 {
166 public:
167     ///
168     DynamicCastFailedException();
169 };
170
171 ///
172 class PEGASUS_COMMON_LINKAGE InvalidDateTimeFormatException : public Exception
173 {
174 public:
175     ///
176     InvalidDateTimeFormatException();
177 };
178
179 ///
180 class PEGASUS_COMMON_LINKAGE MalformedObjectNameException : public Exception
181 {
182 public:
183     ///
184     MalformedObjectNameException(const String& objectName);
185
186 #ifdef PEGASUS_INTERNALONLY
187     MalformedObjectNameException(MessageLoaderParms& msgParms);
188 #endif
189 };
190
191 ///
192 class PEGASUS_COMMON_LINKAGE BindFailedException : public Exception
193 {
194 public:
195     ///
196     BindFailedException(const String& message);
197
198 #ifdef PEGASUS_INTERNALONLY
199     BindFailedException(MessageLoaderParms& msgParms);
200 #endif
201 };
202
203 ///
204 class PEGASUS_COMMON_LINKAGE InvalidLocatorException : public Exception
205 {
206 public:
207     ///
208     InvalidLocatorException(const String& locator);
209
210 #ifdef PEGASUS_INTERNALONLY
211     InvalidLocatorException(MessageLoaderParms& msgParms);
212 #endif
213 };
214
215 ///
216 class PEGASUS_COMMON_LINKAGE CannotCreateSocketException : public Exception
217 {
218 public:
219     ///
220     CannotCreateSocketException();
221 };
222
223 ///
224 class PEGASUS_COMMON_LINKAGE CannotConnectException : public Exception
225 {
226 public:
227     ///
228     CannotConnectException(const String& message);
229
230 #ifdef PEGASUS_INTERNALONLY
231     CannotConnectException(MessageLoaderParms& msgParms);
232 #endif
233 };
234
235 ///
236 class PEGASUS_COMMON_LINKAGE AlreadyConnectedException: public Exception
237 {
238 public:
239     ///
240     AlreadyConnectedException();
241 };
242
243 ///
244 class PEGASUS_COMMON_LINKAGE NotConnectedException: public Exception
245 {
246 public:
247     ///
248     NotConnectedException();
249 };
250
251 ///
252 class PEGASUS_COMMON_LINKAGE ConnectionTimeoutException: public Exception
253 {
254 public:
255     ///
256     ConnectionTimeoutException();
257 };
258
259 ///
260 class PEGASUS_COMMON_LINKAGE SSLException: public Exception
261 {
262 public:
263     ///
264     SSLException(const String& message);
265
266 #ifdef PEGASUS_INTERNALONLY
267     SSLException(MessageLoaderParms& msgParms);
268 #endif
269 };
270
271 ///
272 class PEGASUS_COMMON_LINKAGE DateTimeOutOfRangeException : public Exception
273 {
274 public:
275     ///
276     DateTimeOutOfRangeException(const String& message);
277
278 #ifdef PEGASUS_INTERNALONLY
279     DateTimeOutOfRangeException(MessageLoaderParms& msgParms);
280 #endif
281 };
282
283 /** The CIMException defines the CIM exceptions that are formally defined in
284     the CIM Operations over HTTP specification.
285 */
286 class PEGASUS_COMMON_LINKAGE CIMException : public Exception
287 {
288 public:
289
290     /**  Construct a CIMException with status code and Error description
291          message.
292          @param code CIMStatus code defining the error
293          @param message String defining the message text
294          @param instance CIMInstance containing the CIM_Error
295          instance
296     */
297     CIMException(
298         CIMStatusCode code = CIM_ERR_SUCCESS,
299         const String& message = String::EMPTY);
300
301     /**  Construct a CIMException with status code, message
302          and a CIM_Error instance attached to the exception. Note that
303          this allows the CIMStatusCode and Description in the CIMError
304          to be different than those attached to the call.
305          @param code CIMStatus code defining the error
306          @param message String defining the message text
307          @param instance CIMInstance containing the CIM_Error
308          instance.
309     */
310     CIMException(
311         CIMStatusCode code,
312         const String& message,
313         const CIMInstance& instance);
314
315     /**  Construct a CIMException with status code, message
316          and an Array of CIM_Error instances attached to the exception.
317          Note that this allows the CIMStatusCode and Description in the
318          CIMErrors to be different than those attached to the call.
319          @param code CIMStatus code defining the error
320          @param message String defining the message text
321          @param instances Array<CIMInstance> containing  CIM_Error
322          instances.
323     */
324
325     CIMException(
326         CIMStatusCode code,
327         const String& message,
328         const Array<CIMInstance>& instances);
329
330 #ifdef PEGASUS_INTERNALONLY
331     CIMException(
332         CIMStatusCode code,
333         const MessageLoaderParms& msgParms);
334
335     CIMException(
336         CIMStatusCode code,
337         const MessageLoaderParms& msgParms,
338         const CIMInstance& instance);
339     CIMException(
340         CIMStatusCode code,
341         const MessageLoaderParms& msgParms,
342         const Array<CIMInstance>& instances);
343 #endif
344
345     ///
346     CIMException(const CIMException & cimException);
347
348     ///
349     CIMException& operator=(const CIMException & cimException);
350
351     ///
352     virtual ~CIMException();
353
354     /** gets the CIMStatusCode for the current CIMException. This is the
355         code that defines the ERROR that was executed and transmitted
356         to the Client.
357         @return a single CIMStatusCode
358         @SeeAlso CIMStatusCode
359         EXAMPLE
360             try
361             { .. Execute CIM Operation
362             }
363             catch (CIMExcepton e)
364             {
365                 if (e.getCode() == CIM_ERR_ACCESS_DENIED )
366                     ....
367             }
368      */
369      CIMStatusCode getCode() const;
370
371 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
372
373     /* get the count of CIM_Error instances attached to the CIMException.
374        Normally this method is used by the client to determine if any
375        CIM_Error instances are attached to a CIMException and as the
376        end test if the user decides to get the exception instances.
377        @return Uint32 count of CIM_Error instances attached to a CIMException.
378        0 indicates that there are no instances attached.
379     */
380     Uint32 getErrorCount() const;
381
382     /* get a single CIM_Error instance that is attached to a CIMException.
383        @param Uint32 index that defines the index to a particular CIMInstance
384        attached to the CIMException. The index must be less than the value of
385        the return from getErrorCount()
386        Return CIMInstance the instance defined by the index.
387        exception: returns out-of-range exception if the index is outside the
388        range of the array of CIM_Instances attached to the CIMExcepton.
389        EXAMPLE
390             try
391             { .. Execute CIM Operation
392             }
393             catch (CIMExcepton e)
394             {
395                 if (e.getErrorCount() > 0 )
396                 {
397                     for (Uint32 i = 0 ; i < getErrorCount() ; i++)
398                        ... get and process each CIM_Error instance
399                 }
400             }
401     */
402
403     CIMConstInstance getError(Uint32 index) const;
404
405     //CIMInstance getError(Uint32 index);
406
407     /* Adds a single error instance to a CIMException
408        @param instance CIMInstance is the instance of CIM_Error
409        that is to be added to the CIMException. This instance is
410        NOT checked by the infrastructure for correct type.
411     */
412     void addError(const CIMInstance& instance);
413
414 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
415 };
416
417
418 PEGASUS_NAMESPACE_END
419
420 #endif /* Pegasus_Exception_h */