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();
}
}
}