13 s.soni 1.1 //
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 // Author: <Subodh Soni> (<ssubodh@in.ibm.com>)
33 //
34 s.soni 1.1 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <stdio.h>
39 #include <iostream>
40 #include "ExceptionsTest.h"
41 #include <Pegasus/Common/InternalException.h>
42
43 PEGASUS_NAMESPACE_BEGIN
44 PEGASUS_USING_STD;
45 // The following macro is enabled/ disabled by defining in the Makefile.
46
47 #ifdef TEST_EXCEPTIONS
48 #define PEGASUS_EXCEPTION PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, \
49 "ExceptionsTest Exception")
50 #define CIM_EXCEPTION CIMException(CIM_ERR_FAILED, "Test Provider")
51 #else
52 #define PEGASUS_EXCEPTION
53 #define CIM_EXCEPTION
54 #endif
55 s.soni 1.1
56 // Update the value of the following macro for enabling/ disabling exceptions.
57 //
58 #define EXCEPTION_TYPE 1
59 #define CheckExceptionType(X) { \
60 cout <<" Exception Type " << X << endl;\
61 if (X == 1) throw PEGASUS_EXCEPTION; \
62 if (X == 2) throw CIM_EXCEPTION; \
63 }
64
65 ExceptionsTest::ExceptionsTest(void)
66 {
67 }
68
69 ExceptionsTest::~ExceptionsTest(void)
70 {
71 }
72
73 void ExceptionsTest::initialize(CIMOMHandle & cimom)
74 {
75
76 s.soni 1.1 cout <<" ExceptionsTest::initialize" << endl;
77
78 CheckExceptionType(EXCEPTION_TYPE);
79
80 // create default instances for FirstClass
81 CIMInstance instance1("FirstClass");
82 CIMObjectPath reference1("FirstClass.Id=1");
83
84 instance1.addProperty(CIMProperty("Id", Uint8(1))); // key
85 instance1.addProperty(CIMProperty("Message", String("Subodh.....")));
86
87 _instances.append(instance1);
88 _instanceNames.append(reference1);
89
90 CheckExceptionType(EXCEPTION_TYPE);
91
92 CIMInstance instance2("FirstClass");
93 CIMObjectPath reference2("FirstClass.Id=2");
94
95 instance2.addProperty(CIMProperty("Id", Uint8(2))); // key
96 instance2.addProperty(CIMProperty("Message", String("Soni....")));
97 s.soni 1.1
98 _instances.append(instance2);
99 _instanceNames.append(reference2);
100
101 CheckExceptionType(EXCEPTION_TYPE);
102
103 // create default instances for SecondClass
104 CIMInstance instance_1("SecondClass");
105 CIMObjectPath reference_1("SecondClass.Srno=11");
106
107 instance_1.addProperty(CIMProperty("Srno", Uint8(1))); // key
108 instance_1.addProperty(CIMProperty("Name", String("Class Two Instance 1.....")));
109
110 _instances_second.append(instance_1);
111 _instanceNames_second.append(reference_1);
112
113 CheckExceptionType(EXCEPTION_TYPE);
114
115 CIMInstance instance_2("SecondClass");
116 CIMObjectPath reference_2("SecondClass.Srno=2");
117
118 s.soni 1.1 instance_2.addProperty(CIMProperty("Srno", Uint8(2))); // key
119 instance_2.addProperty(CIMProperty("Name", String("Class Two Instance 2....")));
120
121 _instances_second.append(instance_2);
122 _instanceNames_second.append(reference_2);
123
124 CheckExceptionType(EXCEPTION_TYPE);
125 }
126
127 void ExceptionsTest::terminate(void)
128 {
129 }
130
131 void ExceptionsTest::getInstance(
132 const OperationContext & context,
133 const CIMObjectPath & instanceReference,
134 const Boolean includeQualifiers,
135 const Boolean includeClassOrigin,
136 const CIMPropertyList & propertyList,
137 InstanceResponseHandler & handler)
138 {
139 s.soni 1.1 // convert a potential fully qualified reference into a local reference
140 // (class name and keys only).
141 CIMObjectPath localReference = CIMObjectPath(
142 String(),
143 String(),
144 instanceReference.getClassName(),
145 instanceReference.getKeyBindings());
146
147 CIMName className = instanceReference.getClassName();
148
149 // begin processing the request
150 handler.processing();
151
152 cout <<"Calling Exception ExceptionsTest::getInstance 1" << endl;
153 CheckExceptionType(EXCEPTION_TYPE);
154
155 if (className == CIMName("FirstClass"))
156 {
157 // instance index corresponds to reference index
158 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
159 {
160 s.soni 1.1 if(localReference == _instanceNames[i])
161 {
162 // deliver requested instance
163 handler.deliver(_instances[i]);
164 break;
165 }
166 }
167 }
168 // complete processing the request
169 handler.complete();
170 cout <<"Calling Exception ExceptionsTest::getInstance 2" << endl;
171 CheckExceptionType(EXCEPTION_TYPE);
172 }
173
174 void ExceptionsTest::enumerateInstances(
175 const OperationContext & context,
176 const CIMObjectPath & classReference,
177 const Boolean includeQualifiers,
178 const Boolean includeClassOrigin,
179 const CIMPropertyList & propertyList,
180 InstanceResponseHandler & handler)
181 s.soni 1.1 {
182 cout <<"Calling Exception ExceptionsTest::enumerateInstances 1" << endl;
183 CheckExceptionType(EXCEPTION_TYPE);
184
185 CIMName clName = classReference.getClassName();
186 String className = clName.getString();
187
188 if (String::equalNoCase(className, "FirstClass"))
189 {
190 // announce operation processing.
191 handler.processing();
192 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
193 // deliver instance
194 handler.deliver(_instances[i]);
195 }
196 if (String::equalNoCase(className, "SecondClass"))
197 {
198 handler.processing();
199 for(Uint32 i = 0, n = _instances_second.size(); i < n; i++)
200 // deliver instance
201 handler.deliver(_instances_second[i]);
202 s.soni 1.1 }
203 if (String::equalNoCase(className, "ThirdClass"))
204 {
205 handler.processing();
206 for(Uint32 i = 0, n = _instances_third.size(); i < n; i++)
207 // deliver instance
208 handler.deliver(_instances_third[i]);
209 }
210 cout <<"Calling Exception ExceptionsTest::enumerateInstances 2" << endl;
211 CheckExceptionType(EXCEPTION_TYPE);
212
213 // complete processing the request
214 handler.complete();
215 }
216
217 void ExceptionsTest::enumerateInstanceNames(
218 const OperationContext & context,
219 const CIMObjectPath & classReference,
220 ObjectPathResponseHandler & handler)
221 {
222 // begin processing the request
223 s.soni 1.1 handler.processing();
224
225 cout <<"Calling Exception ExceptionsTest::enumerateInstanceNames 1" << endl;
226 CheckExceptionType(EXCEPTION_TYPE);
227 CIMName clName = classReference.getClassName();
228 String className = clName.getString();
229
230 if (className == "FirstClass")
231 {
232 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
233 // deliver reference
234 handler.deliver(_instanceNames[i]);
235 }
236 else if (className == "SecondClass")
237 {
238 for(Uint32 i = 0, n = _instances_second.size(); i < n; i++)
239 // deliver reference
240 handler.deliver(_instanceNames_second[i]);
241 }
242 else if (className == "ThirdClass")
243 {
244 s.soni 1.1 for(Uint32 i = 0, n = _instances_third.size(); i < n; i++)
245 // deliver reference
246 handler.deliver(_instanceNames_third[i]);
247
248 }
249 // complete processing the request
250 cout <<"Calling Exception ExceptionsTest::enumerateInstanceNames 2" << endl;
251 CheckExceptionType(EXCEPTION_TYPE);
252 handler.complete();
253 }
254
255 void ExceptionsTest::modifyInstance(
256 const OperationContext & context,
257 const CIMObjectPath & instanceReference,
258 const CIMInstance & instanceObject,
259 const Boolean includeQualifiers,
260 const CIMPropertyList & propertyList,
261 ResponseHandler & handler)
262 {
263 // convert a potential fully qualified reference into a local reference
264 // (class name and keys only).
265 s.soni 1.1 CIMObjectPath localReference = CIMObjectPath(
266 String(),
267 String(),
268 instanceReference.getClassName(),
269 instanceReference.getKeyBindings());
270
271 cout <<"Calling Exception ExceptionsTest::modifyInstance 1" << endl;
272 CheckExceptionType(EXCEPTION_TYPE);
273 // begin processing the request
274 handler.processing();
275
276 // instance index corresponds to reference index
277 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
278 {
279 if(localReference == _instanceNames[i])
280 {
281 // overwrite existing instance
282 _instances[i] = instanceObject;
283 break;
284 }
285 }
286 s.soni 1.1 // complete processing the request
287 handler.complete();
288 cout <<"Calling Exception ExceptionsTest::modifyInstance 2" << endl;
289 CheckExceptionType(EXCEPTION_TYPE);
290 }
291
292 void ExceptionsTest::createInstance(
293 const OperationContext & context,
294 const CIMObjectPath & instanceReference,
295 const CIMInstance & instanceObject,
296 ObjectPathResponseHandler & handler)
297 {
298 // convert a potential fully qualified reference into a local reference
299 // (class name and keys only).
300 CIMObjectPath localReference = CIMObjectPath(
301 String(),
302 String(),
303 instanceReference.getClassName(),
304 instanceReference.getKeyBindings());
305
306 cout <<"Calling Exception ExceptionsTest::createInstance 1" << endl;
307 s.soni 1.1 CheckExceptionType(EXCEPTION_TYPE);
308 // instance index corresponds to reference index
309 for(Uint32 i = 0, n = _instanceNames.size(); i < n; i++)
310 {
311 if(localReference == _instanceNames[i])
312 {
313 throw CIMObjectAlreadyExistsException(
314 localReference.toString());
315 }
316 }
317
318 // begin processing the request
319 handler.processing();
320
321 // add the new instance to the array
322 _instances.append(instanceObject);
323 _instanceNames.append(instanceReference);
324
325 cout <<"Calling Exception ExceptionsTest::createInstance 2" << endl;
326 CheckExceptionType(EXCEPTION_TYPE);
327 // deliver the new instance
328 s.soni 1.1 handler.deliver(_instanceNames[_instanceNames.size() - 1]);
329
330 // complete processing the request
331 handler.complete();
332 }
333
334 void ExceptionsTest::deleteInstance(
335 const OperationContext & context,
336 const CIMObjectPath & instanceReference,
337 ResponseHandler & handler)
338 {
339 // convert a potential fully qualified reference into a local reference
340 // (class name and keys only).
341 CIMObjectPath localReference = CIMObjectPath(
342 String(),
343 String(),
344 instanceReference.getClassName(),
345 instanceReference.getKeyBindings());
346
347 // begin processing the request
348 handler.processing();
349 s.soni 1.1
350 cout <<"Calling Exception ExceptionsTest::deleteInstance 1" << endl;
351 CheckExceptionType(EXCEPTION_TYPE);
352 // instance index corresponds to reference index
353 for(Uint32 i = 0, n = _instances.size(); i < n; i++)
354 {
355 if(localReference == _instanceNames[i])
356 {
357 // save the instance locally
358 CIMInstance cimInstance(_instances[i]);
359
360 // remove instance from the array
361 _instances.remove(i);
362 _instanceNames.remove(i);
363
364 // exit loop
365 break;
366 }
367 }
368
369 cout <<"Calling Exception ExceptionsTest::deleteInstance 2" << endl;
370 s.soni 1.1 CheckExceptionType(EXCEPTION_TYPE);
371 // complete processing the request
372 handler.complete();
373 }
374
375 PEGASUS_NAMESPACE_END
|