Solaris WBEM Developer's Guide

Deleting a Class

Use the CIMClient mothod, deleteClass, to delete a class. This method removes the class and throws a CIMException.

Note –

You must first remove any existing subclasses or instances before deleting a base class.

Example 4–18 Deleting a Class

This example uses the deleteClass method to delete a class in the default namespace root\cimv2. This program takes four required string arguments:

The user running this program must specify the username and the password for an account, which has write permission to the root\cimv2 namespace.

import javax.wbem.cim.CIMClass;
import javax.wbem.cim.CIMException;
import javax.wbem.cim.CIMNameSpace;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.client.CIMClient;
import javax.wbem.client.UserPrincipal;
import javax.wbem.client.PasswordCredential;

import java.rmi.*;
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 not four arguments, show usage and exit
       if (args.length != 4) {
           System.out.println("Usage: DeleteClass host className " +
                              "username password"); 
       try {
          // args[0] contains the hostname. We create a CIMNameSpace 
          // (cns) pointing to the default namespace on the specified host
          CIMNameSpace cns = new CIMNameSpace(args[0]);

          // args[2] and args[3] contain the username and password.
          // We create a UserPrincipal (up) using the username and
          // a PasswordCredential using the password.
          UserPrincipal up = new UserPrincipal(args[2]);
          PasswordCredential pc = new PasswordCredential(args[3]);

          cc = new CIMClient(cns, up, pc);

          // Get the class name (args[4]) and create a CIMObjectPath
          CIMObjectPath cop = new CIMObjectPath(args[1]);
          // delete the class
   catch (Exception e) {
          System.out.println("Exception: "+e);
   if (cc != null) {