Solaris WBEM Developer's Guide

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 function gets the property value and one function sets the property value.


Example 4–8 Getting a Property

The following example uses enumerateInstanceNames to return the names of all instances of the Solaris processor. This example uses getProperty to get the value of the current clock speed 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 4–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. This code segment uses 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))));
 
...
}