Example 6-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.
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 (args[1]). Gets the * instances of the class in the namespace specified in the command * line (args[0]). */ 1 public class WBEMsample { 2 public static void main(String args[]) throws CIMException { 3 CIMClient cc = null; 4 try { 5 /* args[0] contains the namespace. We create 6 a namespace object (cns) to store the namespace. */ 7 CIMNameSpace cns = new CIMNameSpace(args[0]); 8 /* Connect to the CIM Object manager and pass it 9 the namespace object containing the namespace. */ 10 cc = new CIMClient(cns); 11 /* args[1] contains the class name. We create a 12 CIM Object Path that references the specified 13 class in the current namespace. */ 14 CIMObjectPath cop = new CIMObjectPath(args[1]); 15 /* Get the class object referenced by the CIM Object 16 Path. */ 17 cc.getClass(cop); 18 //Deep enumeration of the class and all its subclasses 19 Enumeration e = cc.enumInstances(cop, true); 20 while(e.hasMoreElements()) { 21 CIMObjectPath op = (CIMObjectPath)e.nextElement(); 22 System.out.println(op); 23 } 24 catch (Exception e) { 25 System.out.println("Exception: "+e); 26 } 27 if(cc != null) { 28 cc.close(); 29 } 30 } 31 } |