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.
The code shown in Example 4–18, uses the following methods to retrieve a class definition:
CIMNameSpace – to create a new namespace
CIMClient – to create a new client connection to the CIM Object Manager
CIMObjectPath – to create an object path, an object to contain the name of the class to retrieve
getClass – to retrieve the class from the CIM Object Manager
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(); } } }