Solaris WBEM Developer's Guide

Creating an Instance

Use the newInstance method to create an instance of an existing class. If the existing class has a key property, the application must set the key property to a unique value. As an option, an instance can define additional qualifiers that are not defined for the class. These qualifiers can be defined for the instance or for a particular property of the instance. The qualifiers do not need to appear in the class declaration.

Applications can use the getQualifiers method to get the set of qualifiers that are defined for a class.

Example 4–5 Creating an Instance

This example uses the newInstance method to create a Java class representing a CIM instance, for example, a Solaris package, from the Solaris_Package class.

/*Connect to the CIM Object Manager in the root\cimv2 
namespace on the local host. Specify the username and password of an 
account that has write permission to the objects in the 
root\cimv2 namespace. */
    UserPrincipal up = new UserPrincipal("root");
    PasswordCredential pc = new PasswordCredential("root-password"); 
    /* Connect to the namespace as root with the root password. */
    CIMClient cc = new CIMClient(cns, up, pc);
// Get the Solaris_Package class
cimclass = cc.getClass(new CIMObjectPath("Solaris_Package"),  
                                          true, true, true, null);
/* Create a new instance of the Solaris_Package 
 class populated with the default values for properties. If the provider
 for the class does not specify default values, the values of the 
 properties will be null and must be explicitly set. */
 CIMInstance ci = cc.createInstance (new CIMObjectPath("Solaris_Package"),