Getting and Setting Instances
Client applications commonly use the getInstance method to retrieve CIM instances from the CIM Object Manager. When an instance of a class is created, it inherits the properties of the class it is derived from and all parent classes in its class hierarchy. The getInstance method takes the Boolean argument localOnly.
If localOnly is true, getInstance returns only the non-inherited properties in the specified instance. The non-inherited properties are those defined in the instance itself.
If localOnly is false, all properties in the class are returned; those defined in the instance, and all properties inherited from all parent classes in its class hierarchy.
Use the setInstance method to update an existing instance.
Example 3-7 Getting and Setting Instances
The following example gets instances of an object path in an enumeration, updates the property value of b to 10 in each instance, and passes the updated instances to the CIM Object Manager.
... { // Create an object path, an object that contains the CIM name for // "myclass" CIMObjectPath cop = new CIMObjectPath("myclass"); /* Get instances for each instance object path in an enumeration, update the property value of b to 10 in each instance, and pass the updated instance to the CIM Object Manager. */ while(e.hasMoreElements()) { CIMInstance ci = cc.getInstance((CIMObjectPath)(e.nextElement ()),true, true, true, null); ci.setProperty("b", new CIMValue(new Integer(10))); cc.setInstance(new CIMObjectPath(),ci); } } ... |
Getting and Setting Properties
A CIM property is a value that describes the characteristic of a CIM class. Properties can be thought of as a pair of functions, one that gets the property value and one that sets the property value.
Example 3-8 Getting a Property
The following example uses enumerateInstanceNames to return the names of all instances of the Solaris processor, getProperty to get the value of the current clockspeed for each instance, and println to print the current clockspeed values.
... { /* Create an object (CIMObjectPath) to store the name of the Solaris_Processor class. */ CIMObjectPath cop = new CIMObjectPath("Solaris_Processor"); /* The CIM Object Manager returns an enumeration containing the names of instances of the Solaris_Processor class. */ Enumeration e = cc.enumerateInstanceNames(cop); /* Iterate through the enumeration of instance object paths. Use the getProperty method to get the current clockspeed value for each Solaris processor. */ while(e.hasMoreElements()) { CIMValue cv = cc.getProperty(e.nextElement(CIMObjectPath), "CurrentClockSpeed"); System.out.println(cv); } ... } |
Example 3-9 Setting a Property
The following example sets the initial shell value for all Solaris_UserTemplate instances. This code segment uses enumerateInstanceNames to get the names of all instances of the Solaris_User Template, and setProperty to set the value of the initial shell for each instance.
... { /* Create an object (CIMObjectPath) to store the name of the Solaris_Processor class. */ CIMObjectPath cop = new CIMObjectPath("Solaris_UserTemplate"); /* The CIM Object Manager returns an enumeration containing the names of instances of the Solaris_UserTemplate class and all its subclasses. */ Enumeration e = cc.enumerateInstanceNames(cop); /* Iterate through the enumeration of instance object paths. Use the setProperty method to set the initial shell value to /usr/bin/sh for each Solaris_UserTemplate instance. */ for (; e.hasMoreElements(); cc.setProperty(e.nextElement(), "/usr/bin/sh", new CIMValue(new Integer(500)))); ... } |
Enumerating Objects
An enumeration is a collection of objects that can be retrieved one at a time. You can enumerate classes, class names, instances, instance names, and namespaces. The results of an enumeration depend on the method and the arguments used, as shown in the following table.
Enumerating Objects
Table 3-1 Enumerating Objects
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 itself. | If true: Returns only non-inherited 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 non-inherited 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 |
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 |
Example 3-10 Enumerating Classes
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 non-inherited methods and properties for each class and subclass (localOnly is true).*/ Enumeration e = cc.enumerateClasses(cop, true, true); } ... |
Example 3-11 Enumerating Classes and Instances