WBEMfor Solaris on Sun Developer's Guide

Deleting an Instance

Use the deleteInstance method to delete an instance.

Example -- Deleting 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:


Example 6-5 Deleting an Instance (deleteInstance)

 
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();
    	}
		}
}