Sun WBEM SDK Developer's Guide

Deleting a Class

Use the CIMClient deleteClass method to delete a class. Deleting a class removes the class, its subclasses, and all instances of the class; it does not delete any associations that refer to the deleted class.

Example — Deleting a Class

The example in Example 4–23 uses the deleteClass method to delete a class in the default namespace root\cimv2. This program takes four required string arguments (host name, class name, username, and password). The user running this program must specify the username and password for an account that has write permission to the root\cimv2namespace.


Example 4–23 Deleting a Class (deleteClass)

 
		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 com.sun.wbem.cim.CIMException;
		import java.util.Enumeration;
	 /**
		* Deletes the class specified in the command line. Works in the default
		* namespace root\cimv2.
		*/
		public class DeleteClass {
	      public static void main(String args[]) throws CIMException {
			      CIMClient cc = null;
			      if(args.length != 4) {
	   		 	      System.out.println("Usage: 
                        DeleteClass host className username password"); 
	   		 	      System.exit(1);
				    }
				    try {
	   			      /**
	     		       * Creates a namespace object (cns), which stores the host 
	     		       * name.
					       */ 
						    CIMNameSpace cns = new CIMNameSpace(args[0]);
 
	   			     /** 
						    * Connects to the CIM Object Manager, and passes it the
						    * namespace object (cns) and the username and password
	     		      * command line arguments. 
	     		      */
						    cc = new CIMClient(cns, args[2], args[3]);
 
					      /** 
						     * Create an object (CIMObjectPath) that 
						     * contains the name of the class specified in args[1].
						     */
						    CIMObjectPath cop = new CIMObjectPath(args[1]);
 
						    /**
						     * Delete the class referenced by the CIM object path.
						     */
	  		  			    cc.deleteClass(cop);
					   } catch (Exception e) {
	 		  			    System.out.println("Exception: "+e);
					   }
					   if(cc != null) {
	    				    cc.close();
				     }
  	    }
}