Sun WBEM SDK Developer's Guide

Example — Deleting a Namespace

The sample program in Example 4–21, deletes the specified namespace on the specified host. The program takes five required string arguments (host name, parent namespace, child namespace, username, and password). The user running this program must specify the username and password for an account that has write permission to the namespace to be deleted.


Example 4–21 Deleting a Namespace (deleteNameSpace)

{
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;
 /**
 * This example program deletes the specified namespace on the
 * specified host. The user running this program must specify 
 * the username and password for a user account that has write
 * permission for the specified namespace.
 */
 public class DeleteNameSpace {
    public static void main(String args[]) throws CIMException {
        // Initialize an instance of the CIM Client class
				CIMClient cc = null;
        // Requires 5 command-line arguments. If not all entered,
        // prints command string.
				if(args.length != 5) {
	    		    System.out.println("Usage: DeleteNameSpace host parentNS 
					          childNS username password"); 
	    			  System.exit(1);
				}
				try {
		         /**
						 * Creates a namespace object (cns), which stores the host 
						 * name and parent namespace.
						 */ 
	      			 CIMNameSpace cns = new CIMNameSpace(args[0], args[1]);
	     			/** 
						 * 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[3], args[4]);
	   			  /**
						 * Creates another namespace object (cop), which stores the
						 * a null string for the host name and a string for the
						 * child namespace (from the command line arguments).
						 */
		   			 CIMNameSpace cop = new CIMNameSpace("",args[2]);
	 					/**
						 * Deletes the child name space under the parent namespace.
	     		   */ 
	    			   cc.deleteNameSpace(cop);
				} catch (Exception e) {
	    		    System.out.println("Exception: "+e);
				}
 				// Close the session
				if(cc != null) {
	   		    cc.close();
				}
   	 }
}