Sun WBEM SDK Developer's Guide

Overview

A Web-Based Enterprise Management (WBEM) application is a standard Java program that uses Sun WBEM SDK APIs to manipulate CIM objects. A client application typically uses the CIM API to construct an object (for example, a namespace, class, or instance) and then initialize that object. The application then uses the Client APIs to pass the object to the CIM Object Manager and request a WBEM operation, such as creating a CIM namespace, class, or instance.

Sequence of a Client Application

Sun WBEM SDK applications typically follow this sequence:

  1. Connect to the CIM Object Manager - (CIMClient).

    A client application contacts a CIM Object Manager to establish a connection each time it needs to perform a WBEM operation, such as creating a CIM Class or updating a CIM instance.

  2. Use one or more APIs to perform some programming tasks.

    Once a program connects to the CIM Object Manager, it uses the APIs to request operations.

  3. Close the client connection to the CIM Object Manager - (close).

    Applications should close the current client session when finished. Use the CIMClient interface to close the current client session and free any resources used by the client session.

Example — Typical Sun WBEM SDK Application

Example 4–1 is a simple application that connects to the CIM Object Manager, using all default values. The program gets a class and then enumerates and prints the instances in that class.


Example 4–1 Typical Sun WBEM SDK Application

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;
 
/**
 * Returns all instances of the specified class.
 * This method takes two arguments: hostname (args[0]) 
 * and name of class to list (args[1]). 
 */
public class WBEMsample {
    public static void main(String args[]) throws CIMException {
        CIMClient cc = null;
            try {
                /* args[0] contains the namespace. We create
                a CIM namespace (cns) pointing to the default
	              root\cimv2 namespace on the specified host. *	/
						   CIMNameSpace cns = new CIMNameSpace(args[0]);
						   /* Connect to the CIM Object manager and pass it 
							 the namespace object containing the namespace. */
						   cc = new CIMClient(cns, "root", "root_password");
						   /* Create a CIMObjectPath from the class name. */
						   CIMObjectPath cop = new CIMObjectPath(args[1]);
						   /* Get the class, including qualifiers, 
	              class origin, and properties. */
	              cc.getClass(cop, true, true, true, null);
                // Return all instances names belonging to the class.
                Enumeration e = cc.enumerateInstanceNames(cop);
                while(e.hasMoreElements()) {
                    CIMObjectPath op = (CIMObjectPath)e.nextElement();
                    System.out.println(op);
                  } // end while
	  	        } catch (Exception e) {
                System.out.println("Exception: "+e);
            }
            if(cc != null) {
               cc.close();
            } 
     } // end main
 } // end WBEMsample


Typical Programming Tasks

Once a client application connects to the CIM Object Manager, it uses the API to request operations. The program's feature set determines which operations it needs to request. The typical tasks that most programs perform are:

In addition, applications may occasionally perform the following tasks: