Use the deleteInstance method to delete an instance.
The example in Example 6-5 connects the client application to the CIM Object Manager and uses the following interfaces to delete all instances of a class:
CIMObjectPath to construct an object containing the CIM object path of the object to be deleted
enumInstance to get the instances and all instances of its subclasses
deleteInstance to delete each instance
import java.rmi.*;
import com.sun.wbem.client.CIMClient;
import com.sun.wbem.cim.CIMInstance;
import com.sun.wbem.cim.CIMValue;
import com.sun.wbem.cim.CIMProperty;
import com.sun.wbem.cim.CIMNameSpace;
import com.sun.wbem.cim.CIMObjectPath;
import com.sun.wbem.cim.CIMClass;
import java.util.Enumeration;
public class DeleteInstances {
public static void main(String args[]) throws CIMException {
CIMClient cc = null;
try {
/* Construct a namespace object containing the
command line arguments. */
CIMNameSpace cns = new CIMNameSpace(args[0]);
/* Pass the namespace object to the CIM Object Manager.*/
CIMClient cc = new CIMClient(cns);
/* Construct an object containing the CIM object
path of the object we want to delete. */
CIMObjectPath cop = new CIMObjectPath(args[1]);
/* Do a deep enumeration (deep is set to
CIMClient.DEEP) of the instances of the object. A deep
enumeration of the instances of a class returns the
class instances and all instances of its subclasses. */
Enumeration e = cc.enumInstances(cop, CIMClient.DEEP);
// Print the name of each object and delete the instance.
while(e.hasMoreElements()) {
CIMObjectPath op = (CIMObjectPath)e.nextElement();
System.out.println(op);
cc.deleteInstance(op);
}
}
catch (Exception e) {
System.out.println("Exception: "+e);
}
// If the client connection is open, close it.
if(cc != null) {
cc.close();
}
}
}
|