WBEMfor Solaris on Sun Developer's Guide

Example -- Creating a CIM Class

The example in Example 6-16 creates a new CIM class in the default namespace (/root/cimv2) on the local host. This class has two properties, one of which is the key property for the class. The example then uses the newInstance method to create an instance of the new class.


Example 6-16 Creating a CIM Class (CIMClass)

{
/* Connect to the /root/cimv2 namespace 
on the local host and create a new class called myclass */
// Connect to the default namespace on local host.
CIMClient cc = new CIMClient(); 
// Construct a new CIMClass object 
CIMClass cimclass = new CIMClass();
// Set CIM class name to myclass. 
cimclass.setName("myclass"); 
// Construct a new CIM property object
CIMProperty cp = new CIMProperty(); 
// Set property name
cp.setName("keyprop"); 
// Set property type
cp.setType(CIMDatatype.getpredefined(CIMDataType.STRING); 
// Construct a new CIM Qualifier object
CIMQualifier cq = new CIMQualifier(); 
// Set the qualifier name
cq.setName("key"); 
// Add the new key qualifier to the property
cp.addQualfiier(cq); 
/* Create an integer property initialized to 10 */
// Construct a new CIM property object
CIMProperty mp = new CIMProperty(); 
// Set property name to myprop
mp.setName("myprop"); 
// Set property type
mp.setType(CIMDatatype.getpredefined(CIMDataType.INTEGER); 
// Initialize myprop to 10 
mp.setValue(CIMValue.setValue(10));
 
/* Add the new properties to myclass and call the CIM Object Manager 
to create the class. */
// Add the key property to class object
cimclass.addProperty(cp); 
// Add the integer property to class object
cimclass.addProperty(mp); 
 
/* Connect to the CIM Object Manager and pass the new class */
cc.setClass(new CIMObjectPath(),cimclass); 
// Pass the new class to the CIM Object Manager
ci = cc.newInstance(); 
// Create a new CIM instance of myclass
// If the client connection is open, close it.
		if(cc != null) {
            cc.close();
}