Sun WBEM SDK Developer's Guide

Retrieving Class Definitions

Use the getClass method to get a CIM class. When a class is created, it inherits the methods and properties of the class it is derived from and all parent classes in the class hierarchy. The getClass method takes the Boolean argument localOnly. If localOnlyis true, this method returns only non-inherited properties and methods. If localOnly is false, all properties in the class are returned.

Example — Retrieving a Class Definition

The code shown in Example 4–18, uses the following methods to retrieve a class definition:


Example 4–18 Retrieving a Class Definition (getClass)

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;
/**
 * Gets the class specified in the command line. Works in the default
 * namespace root\cimv2.
 */
public class GetClass {
    public static void main(String args[]) throws CIMException {
        CIMClient cc = null;
        try {
            CIMNameSpace cns = new CIMNameSpace(args[0]);
            cc = new CIMClient(cns);
            CIMObjectPath cop = new CIMObjectPath(args[1]);
						// Returns only the methods and properties that 
						// are local to the specified class (localOnly is true).
            cc.getClass(cop, cc.DEEP);
        } catch (Exception e) {
            System.out.println("Exception: "+e);
        }
        if(cc != null) {
            cc.close();
        }
    }
}