Method |
No args |
deep |
localOnly |
---|---|---|---|
enumerateClasses |
Returns the contents of the class specified in path. |
If true: Returns the contents of the subclasses of the specified class, but does not return the class. |
If true: Returns only noninherited properties and methods of the specified class. |
If false: Returns the contents of the direct subclasses of the specified class. |
If false: Returns all properties of the specified class. |
||
enumerateInstances |
Returns the instances of the class specified in path. |
If true: Returns the instances of the specified class and its subclasseses. |
If true: Returns only noninherited properties of the instances of the specified class. |
If false: Returns the instances of the specified class and its subclasses. The properties of the subclasses are filtered out. |
If false: Returns all properties of the instances of the specified class. |
||
enumerateClassNames |
Returns the names of the class specified in path. |
If true: Returns the names of all classes derived from the specified class. |
N/A |
If false: Returns only the names of the first-level children of the specified class. |
N/A |
||
enumerateInstanceNames |
Returns the names of the instances of the class specified in path. |
N/A |
N/A |
enumNameSpace |
Returns a list of the namespaces within the namespace specified in path |
If true: Returns the entire hierarchy of namespaces under the specified namespace. |
N/A |
If false: Returns only the first level children of the specified namespace. |
N/A |
The following example program returns the contents of a class and its subclasses.
... { /* Creates a CIMObjectPath object and initializes it with the name of the CIM class to be enumerated (myclass). */ CIMObjectPath cop = new CIMObjectPath(myclass); /* This enumeration contains the classes and subclasses in the enumerated class (deep=true). This enumeration returns only the noninherited methods and properties for each class and subclass (localOnly is true).*/ Enumeration e = cc.enumerateClasses(cop, true, true); } ...
The following example program performs a deep and shallow (deep=false) enumeration of classes and instances. The localOnly flag returns the contents of the classes and instances instead of the names of the classes and instances.
import java.rmi.*; import java.util.Enumeration; import javax.wbem.client.CIMClient; import javax.wbem.cim.CIMClass; import javax.wbem.cim.CIMException; import javax.wbem.cim.CIMInstance; import javax.wbem.cim.CIMNameSpace; import javax.wbem.cim.CIMObjectPath; import javax.wbem.client.UserPrincipal; import javax.wbem.client.PasswordCredential; /** * This example enumerates classes and instances. It does deep and * shallow enumerations on a class that is passed from the command line */ public class ClientEnum { public static void main(String args[]) throws CIMException { CIMClient cc = null; CIMObjectPath cop = null; if (args.length < 4) { System.out.println("Usage: ClientEnum host user passwd " + "classname"); System.exit(1); } try { CIMNameSpace cns = new CIMNameSpace(args[0]); UserPrincipal up = new UserPrincipal(args[1]); PasswordCredential pc = new PasswordCredential(args[2]); cc = new CIMClient(cns, up, pc); // Get the class name from the command line cop = new CIMObjectPath(args[3]); // Do a deep enumeration of the class Enumeration e = cc.enumerateClasses(cop, true, true, true, true); // Will print out all the subclasses of the class. while (e.hasMoreElements()) { System.out.println(e.nextElement()); } System.out.println("+++++"); // Do a shallow enumeration of the class e = cc.enumerateClasses(cop, false, true, true, true); // Will print out the first-level subclasses. while (e.hasMoreElements()) { System.out.println(e.nextElement()); } System.out.println("+++++"); // Do a deep enumeration of the instances of the class e = cc.enumerateInstances(cop, false, true, true, true, null); // Will print out all the instances of the class and its // subclasses. while (e.hasMoreElements()) { System.out.println(e.nextElement()); } System.out.println("+++++"); // Do a shallow enumeration of the instances of the class e = cc.enumerateInstances(cop, false, false, true, true, null); // Will print out all the instances of the class. while (e.hasMoreElements()) { System.out.println(e.nextElement()); } System.out.println("+++++"); e = cc.enumerateInstanceNames(cop); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } System.out.println("+++++"); e = cc.enumerateInstanceNames(cop); while (e.hasMoreElements()) { CIMObjectPath opInstance = (CIMObjectPath)e.nextElement(); CIMInstance ci = cc.getInstance(opInstance, false, true, true, null); System.out.println(ci); } System.out.println("+++++"); } catch (Exception e) { System.out.println("Exception: "+e); } // close session. if (cc != null) { cc.close(); } } }
The following example program returns a list of class names and subclass names.
... { /* Creates a CIMObjectPath object and initializes it with the name of the CIM class to be enumerated (myclass). */ CIMObjectPath cop = new CIMObjectPath(myclass); /* This enumeration contains the names of the classes and subclasses in the enumerated class. */ Enumeration e = cc.enumerateClassNames(cop, true); } ...
This example program uses the enumNameSpace method in the CIMClient class to print the name of the namespace and all the namespaces contained within the namespace.
import java.rmi.*; import java.util.Enumeration; import javax.wbem.cim.CIMClass; import javax.wbem.cim.CIMException; import javax.wbem.cim.CIMInstance; import javax.wbem.cim.CIMNameSpace; import javax.wbem.cim.CIMObjectPath; import javax.wbem.client.CIMClient; import javax.wbem.client.PasswordCredential; import javax.wbem.client.UserPrincipal; /** * */ public class EnumNameSpace { public static void main(String args[]) throws CIMException { CIMClient cc = null; // if not four arguments, show usage and exit if (args.length < 4) { System.out.println("Usage: EnumNameSpace host username " + "password namespace"); System.exit(1); } try { // args[0] contains the hostname. We create a CIMNameSpace // (cns) pointing to the specified namespace on the // specified host CIMNameSpace cns = new CIMNameSpace(args[0], ""); // args[1] and args[2] contain the username and password. // We create a UserPrincipal (up) using the username and // a PasswordCredential using the password. UserPrincipal up = new UserPrincipal(args[1]); PasswordCredential pc = new PasswordCredential(args[2]); // Connect to the CIM Object Manager and pass it the // CIMNameSpace, UserPrincipal and PasswordCredential objects // we created. cc = new CIMClient(cns, up, pc); // Use the namespace (args[3]) to create a CIMObjectPath CIMObjectPath cop = new CIMObjectPath("", args[3]); // Enumerate the namespace Enumeration e = cc.enumNameSpace(cop); while (e.hasMoreElements()) { System.out.println((CIMObjectPath)e.nextElement()); } // end while } catch (Exception e) { // is we have an exception, catch it and print it out. System.out.println("Exception: "+ e); } // end catch // close session. if (cc != null) { cc.close(); } } }