1 //%2006////////////////////////////////////////////////////////////////////////
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.
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:
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.
30 //==============================================================================
32 // Author: Mark Hamzy, IBM (hamzy@us.ibm.com)
34 // Modified By: Mark Hamzy, IBM (hamzy@us.ibm.com)
36 //%/////////////////////////////////////////////////////////////////////////////
37 package org.pegasus.jmpi.tests.Indication;
39 import java.util.Vector;
40 import org.pegasus.jmpi.CIMClass;
41 import org.pegasus.jmpi.CIMDataType;
42 import org.pegasus.jmpi.CIMException;
43 import org.pegasus.jmpi.CIMInstance;
44 import org.pegasus.jmpi.CIMOMHandle;
45 import org.pegasus.jmpi.CIMObjectPath;
46 import org.pegasus.jmpi.CIMProperty;
47 import org.pegasus.jmpi.CIMValue;
48 import org.pegasus.jmpi.EventProvider2;
49 import org.pegasus.jmpi.InstanceProvider2;
50 import org.pegasus.jmpi.MethodProvider2;
51 import org.pegasus.jmpi.OperationContext;
52 import org.pegasus.jmpi.SelectExp;
53 import org.pegasus.jmpi.SelectList;
54 import org.pegasus.jmpi.NonJoinExp;
55 import org.pegasus.jmpi.QueryExp;
56 import org.pegasus.jmpi.UnsignedInt32;
57 import org.pegasus.jmpi.UnsignedInt64;
59 public class JMPI_IndicationProvider
60 implements InstanceProvider2,
64 private static String CLASSNAME = "TestIndication";
65 private static String NAMESPACE = "test/static";
66 private CIMOMHandle ch = null;
67 private Vector paths = new Vector ();
68 private Vector instances = new Vector ();
70 public void initialize (CIMOMHandle ch)
73 System.out.println ("JMPI_IndicationProvider::initialize: ch = " + ch);
78 public void cleanup ()
81 System.out.println ("JMPI_IndicationProvider::cleanup");
88 public CIMObjectPath createInstance (OperationContext oc,
90 CIMInstance cimInstance)
93 System.out.println ("JMPI_IndicationProvider::createInstance: oc = " + oc);
94 System.out.println ("JMPI_IndicationProvider::createInstance: cop = " + cop);
96 String nameSpaceCop = cop.getNameSpace ();
97 cop = new CIMObjectPath (cimInstance.getClassName (),
98 cimInstance.getKeyValuePairs ());
99 cop.setNameSpace (nameSpaceCop);
100 System.out.println ("JMPI_IndicationProvider::createInstance: cop = " + cop);
101 System.out.println ("JMPI_IndicationProvider::createInstance: cimInstance = " + cimInstance);
103 // Ensure the Namespace is valid
104 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
105 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
107 // Ensure the class existing in the specified namespace
108 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
109 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
111 // Ensure that all of the properties exists in the instance
112 if ( cimInstance.getProperty ("InstanceId") == null
113 || cimInstance.getProperty ("PropertyString") == null
115 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
117 // Ensure that all of the key properties exists in the object path
118 if (cop.getKeyValue ("InstanceId") == null)
119 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
121 // Ensure the requested object do not exist
122 if (findObjectPath (cop) >= 0)
123 throw new CIMException (CIMException.CIM_ERR_ALREADY_EXISTS);
125 paths.addElement (cop);
126 instances.addElement (cimInstance);
131 public CIMInstance getInstance (OperationContext oc,
134 boolean includeQualifiers,
135 boolean includeClassOrigin,
136 String propertyList[])
139 System.out.println ("JMPI_IndicationProvider::getInstance: oc = " + oc);
140 System.out.println ("JMPI_IndicationProvider::getInstance: cop = " + cop);
141 System.out.println ("JMPI_IndicationProvider::getInstance: cimClass = " + cimClass);
142 System.out.println ("JMPI_IndicationProvider::getInstance: includeQualifiers = " + includeQualifiers);
143 System.out.println ("JMPI_IndicationProvider::getInstance: includeClassOrigin = " + includeClassOrigin);
144 System.out.println ("JMPI_IndicationProvider::getInstance: propertyList = " + propertyList);
146 // ensure the InstanceId key is valid
147 Vector keys = cop.getKeys ();
151 i < keys.size () && ! ((CIMProperty)keys.elementAt (i)).getName ().equalsIgnoreCase ("InstanceId");
156 if (i == keys.size ())
157 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
159 // ensure the Namespace is valid
160 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
161 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
163 // ensure the class existing in the specified namespace
164 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
165 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
167 // ensure the request object exists
168 int index = findObjectPath (cop);
171 throw new CIMException (CIMException.CIM_ERR_NOT_FOUND);
173 return (CIMInstance)instances.elementAt (index);
176 public void setInstance (OperationContext oc,
178 CIMInstance cimInstance)
181 System.out.println ("JMPI_IndicationProvider::setInstance: oc = " + oc);
182 System.out.println ("JMPI_IndicationProvider::setInstance: cop = " + cop);
183 System.out.println ("JMPI_IndicationProvider::setInstance: cimInstance = " + cimInstance);
185 // ensure the Namespace is valid
186 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
187 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
189 // ensure the class existing in the specified namespace
190 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
191 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
193 // ensure the request object exists
194 int index = findObjectPath (cop);
197 throw new CIMException (CIMException.CIM_ERR_NOT_FOUND);
200 public void deleteInstance (OperationContext oc,
204 System.out.println ("JMPI_IndicationProvider::deleteInstance: oc = " + oc);
205 System.out.println ("JMPI_IndicationProvider::deleteInstance: cop = " + cop);
207 // ensure the Namespace is valid
208 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
209 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
211 // ensure the class existing in the specified namespace
212 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
213 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
215 // ensure the request object exists
216 int index = findObjectPath (cop);
219 throw new CIMException (CIMException.CIM_ERR_NOT_FOUND);
222 public Vector enumerateInstanceNames (OperationContext oc,
227 System.out.println ("JMPI_IndicationProvider::enumerateInstanceNames: oc = " + oc);
228 System.out.println ("JMPI_IndicationProvider::enumerateInstanceNames: cop = " + cop);
229 System.out.println ("JMPI_IndicationProvider::enumerateInstanceNames: cimClass = " + cimClass);
231 // ensure the Namespace is valid
232 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
233 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
235 // ensure the class existing in the specified namespace
236 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
237 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
242 public Vector enumerateInstances (OperationContext oc,
245 boolean includeQualifiers,
246 boolean includeClassOrigin,
247 String propertyList[])
250 System.out.println ("JMPI_IndicationProvider::enumerateInstances: oc = " + oc);
251 System.out.println ("JMPI_IndicationProvider::enumerateInstances: cop = " + cop);
252 System.out.println ("JMPI_IndicationProvider::enumerateInstances: cimClass = " + cimClass);
253 System.out.println ("JMPI_IndicationProvider::enumerateInstances: includeQualifiers = " + includeQualifiers);
254 System.out.println ("JMPI_IndicationProvider::enumerateInstances: includeClassOrigin = " + includeClassOrigin);
255 System.out.println ("JMPI_IndicationProvider::enumerateInstances: propertyList = " + propertyList);
257 // ensure the Namespace is valid
258 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
259 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
261 // ensure the class existing in the specified namespace
262 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
263 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
268 public Vector execQuery (OperationContext oc,
271 String queryStatement,
272 String queryLanguage)
275 System.out.println ("JMPI_IndicationProvider::execQuery: oc = " + oc);
276 System.out.println ("JMPI_IndicationProvider::execQuery: cop = " + cop);
277 System.out.println ("JMPI_IndicationProvider::execQuery: cimClass = " + cimClass);
278 System.out.println ("JMPI_IndicationProvider::execQuery: queryStatement = " + queryStatement);
279 System.out.println ("JMPI_IndicationProvider::execQuery: queryLanguage = " + queryLanguage);
281 if (!queryLanguage.equals ("WQL"))
283 throw new CIMException (CIMException.CIM_ERR_NOT_SUPPORTED);
286 SelectExp q = new SelectExp (queryStatement);
287 SelectList attrs = q.getSelectList ();
288 NonJoinExp from = (NonJoinExp)q.getFromClause ();
289 QueryExp where = q.getWhereClause ();
290 Vector instances = enumerateInstances (oc,
296 Vector ret = new Vector ();
298 // filter the instances
299 for (int i = 0; i < instances.size (); i++)
302 || where.apply ((CIMInstance)instances.elementAt (i))
305 ret.addElement (attrs.apply ((CIMInstance)instances.elementAt (i)));
312 public CIMValue invokeMethod (OperationContext oc,
319 System.out.println ("JMPI_IndicationProvider::invokeMethod: oc = " + oc);
320 System.out.println ("JMPI_IndicationProvider::invokeMethod: cop = " + cop);
321 System.out.println ("JMPI_IndicationProvider::invokeMethod: methodName = " + methodName);
322 System.out.println ("JMPI_IndicationProvider::invokeMethod: inArgs = " + inArgs);
323 System.out.println ("JMPI_IndicationProvider::invokeMethod: outArgs = " + outArgs);
325 // ensure the Namespace is valid
326 if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))
328 throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);
331 // ensure the class existing in the specified namespace
332 if (!cop.getObjectName ().equalsIgnoreCase (CLASSNAME))
334 throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);
337 if (methodName.equalsIgnoreCase ("SendTestIndicationNormal"))
341 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
343 else if (inArgs.size () != 1)
345 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
348 CIMProperty cp = (CIMProperty)inArgs.elementAt (0);
350 if (!cp.getName ().equalsIgnoreCase ("indicationSendCount"))
352 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
354 else if (cp.getType ().getType () != CIMDataType.UINT64)
356 throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);
359 CIMValue cvIndicationSendCount = cp.getValue ();
360 UnsignedInt64 uiIndicationSendCount = (UnsignedInt64)cvIndicationSendCount.getValue ();
362 System.out.println ("JMPI_IndicationProvider::invokeMethod: uiIndicationSendCount = " + uiIndicationSendCount);
364 CIMClass ccIndication;
365 CIMInstance ciIndication;
366 CIMObjectPath copIndication;
368 ccIndication = ch.getClass (cop,
373 ciIndication = ccIndication.newInstance ();
375 ciIndication.setProperty ("InstanceId", new CIMValue (uiIndicationSendCount));
376 ciIndication.setProperty ("PropertyString", new CIMValue ("Hello"));
378 copIndication = createInstance (oc,
382 System.out.println ("JMPI_IndicationProvider::invokeMethod: deliverEvent: copIndication = " + copIndication);
383 System.out.println ("JMPI_IndicationProvider::invokeMethod: deliverEvent: ciIndication = " + ciIndication);
385 ch.deliverEvent (copIndication.getNameSpace (),
388 return new CIMValue (new UnsignedInt32 ("0"));
392 throw new CIMException (CIMException.CIM_ERR_METHOD_NOT_AVAILABLE);
396 public void authorizeFilter (OperationContext oc,
399 CIMObjectPath classPath,
403 System.out.println ("JMPI_IndicationProvider::authorizeFilter: oc = " + oc);
404 System.out.println ("JMPI_IndicationProvider::authorizeFilter: filter = " + filter);
405 System.out.println ("JMPI_IndicationProvider::authorizeFilter: eventType = " + eventType);
406 System.out.println ("JMPI_IndicationProvider::authorizeFilter: classPath = " + classPath);
407 System.out.println ("JMPI_IndicationProvider::authorizeFilter: owner = " + owner);
411 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectString () = " + filter.getSelectString ());
412 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getWhereClause () = " + filter.getWhereClause ());
413 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectList () = " + filter.getSelectList ());
414 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getFromClause () = " + filter.getFromClause ());
418 public boolean mustPoll (OperationContext oc,
421 CIMObjectPath classPath)
424 System.out.println ("JMPI_IndicationProvider::mustPoll: oc = " + oc);
425 System.out.println ("JMPI_IndicationProvider::mustPoll: filter = " + filter);
426 System.out.println ("JMPI_IndicationProvider::mustPoll: eventType = " + eventType);
427 System.out.println ("JMPI_IndicationProvider::mustPoll: classPath = " + classPath);
431 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectString () = " + filter.getSelectString ());
432 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getWhereClause () = " + filter.getWhereClause ());
433 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectList () = " + filter.getSelectList ());
434 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getFromClause () = " + filter.getFromClause ());
440 public void activateFilter (OperationContext oc,
443 CIMObjectPath classPath,
444 boolean firstActivation)
447 System.out.println ("JMPI_IndicationProvider::activateFilter: oc = " + oc);
448 System.out.println ("JMPI_IndicationProvider::activateFilter: filter = " + filter);
449 System.out.println ("JMPI_IndicationProvider::activateFilter: eventType = " + eventType);
450 System.out.println ("JMPI_IndicationProvider::activateFilter: classPath = " + classPath);
451 System.out.println ("JMPI_IndicationProvider::activateFilter: firstActivation = " + firstActivation);
455 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectString () = " + filter.getSelectString ());
456 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getWhereClause () = " + filter.getWhereClause ());
457 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectList () = " + filter.getSelectList ());
458 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getFromClause () = " + filter.getFromClause ());
462 public void deActivateFilter (OperationContext oc,
465 CIMObjectPath classPath,
466 boolean lastActivation)
469 System.out.println ("JMPI_IndicationProvider::deActivateFilter: oc = " + oc);
470 System.out.println ("JMPI_IndicationProvider::deActivateFilter: filter = " + filter);
471 System.out.println ("JMPI_IndicationProvider::deActivateFilter: eventType = " + eventType);
472 System.out.println ("JMPI_IndicationProvider::deActivateFilter: classPath = " + classPath);
473 System.out.println ("JMPI_IndicationProvider::deActivateFilter: lastActivation = " + lastActivation);
477 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectString () = " + filter.getSelectString ());
478 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getWhereClause () = " + filter.getWhereClause ());
479 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getSelectList () = " + filter.getSelectList ());
480 System.out.println ("JMPI_IndicationProvider::activateFilter: filter.getFromClause () = " + filter.getFromClause ());
484 private int findObjectPath (CIMObjectPath path)
486 String p = path.toString ();
488 for (int i = 0; i < paths.size (); i++)
490 System.out.println ("testing " + paths.elementAt (i) + " against " + path);
492 if (((CIMObjectPath)paths.elementAt (i)).toString ().equalsIgnoreCase (p))