JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Solaris WBEM Developer's Guide
search filter icon
search icon

Document Information

Preface

1.  Overview of Solaris Web-Based Enterprise Management

2.  Using the CIM Object Manager

3.  Using the Sample Programs

4.  Writing a Client Program

Client API Overview

Sequence of a Client Application

Opening and Closing a Client Connection

About Name Spaces

Opening a Client Connection

Closing a Client Connection

Performing Basic Client Operations

Creating an Instance

Deleting an Instance

Getting and Setting Instances

Getting and Setting Properties

Enumerating Objects

Enumerating Objects

Creating Associations

About the Association Methods

Passing a Class to the Association Methods

Passing Instances to the Association Methods

Using Optional Arguments With the Association Methods

Calling Methods

Retrieving Class Definitions

Handling Exceptions

Creating a Name Space

Deleting a Name Space

Creating a Base Class

Deleting a Class

Setting Access Control

Solaris_UserAcl Class

To Set Access Control for a User

Solaris_NamespaceAcl Class

To Set Access Control for a Name Space

Working With Qualifiers and Qualifier Types

Getting and Setting CIM Qualifiers

Batching Client Requests

Handling CIM Events

About Indications

About Subscriptions

To Create a Subscription

Adding a CIM Listener

Creating an Event Filter

To Create an Event Filter

Creating an Event Handler

Binding an Event Filter to an Event Handler

Reading and Writing Log Messages

About Log Files

5.  Writing WBEM Queries

6.  Writing a Provider Program

7.  Creating JavaBeans Components Using the MOF Compiler

8.  Administering Security

9.  Troubleshooting

A.  Solaris Platform Schema

Index

Performing Basic Client Operations

This section describes how to use the javax.wbem.client APIs to request operations and to perform common programming tasks.

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 software package, from the Solaris_Package class.

...
{ 
/*Connect to the CIM Object Manager in the root\cimv2 
name space on the local host. Specify the username and password of an 
account that has write permission to the objects in the 
root\cimv2 name space. */
 
 UserPrincipal up = new UserPrincipal("root");
 PasswordCredential pc = new PasswordCredential("root-password"); 
 /* Connect to the name space 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"), 
 ci);
 }
 ... 

Deleting an Instance

Use the deleteInstance method to delete an instance.

Example 4-6 Deleting Instances

The example does the following:

 
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;

/** 
 * Returns all instances of the specified class.
 * This example takes five arguments: hostname (args[0]), username
 * (args[1]), password (args[2]) name space (args[3] and classname (args[4])
 * It will delete all instances of the specified classname.  The specified 
 * username must have write permissions to the specified name space  
 */
public class DeleteInstances {
    public static void main(String args[]) throws CIMException {
        CIMClient cc = null;
        // if not five arguments, show usage and exit
        if (args.length != 5) {
           System.out.println("Usage: DeleteInstances host username " +
                              "password namespace classname ");
           System.exit(1);
        }
        try {
            // args[0] contains the hostname and args[3] contains the 
            // name space.  We create a CIMNameSpace (cns) pointing to 
            // the specified name space on the specified host
            CIMNameSpace cns = new CIMNameSpace(args[0], args[3]);

            // 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);

            // Get the class name (args[4]) and create a CIMObjectPath
            CIMObjectPath cop = new CIMObjectPath(args[4]);

            // Get an enumeration of all the instance object paths of the
            // class and all subclasses of the class.  An instance object 
            // path is a reference used by the CIM object manager to 
            // locate the instance
            Enumeration e = cc.enumerateInstanceNames(cop);

            // Iterate through the instance object paths in the enumeration.
            // Construct an object to store the object path of each 
            // enumerated instance, print the instance and then delete it 
            while (e.hasMoreElements()) {
                CIMObjectPath  op = (CIMObjectPath)e.nextElement();
                System.out.println(op);
                cc.deleteInstance(op);
            } // end while 
        } catch (Exception e) {
        // if we have an exception, catch it and print it out.
        System.out.println("Exception: "+e);
        } // end catch

        // close session.
        if (cc != null) {
            cc.close();
        }
    }
}

Getting and Setting Instances

Client applications commonly use the getInstance method to retrieve CIM instances from the CIMOM. When an instance of a class is created, the class inherits the properties of all the parent classes in its class hierarchy. The getInstance method takes the Boolean argument localOnly.

Use the setInstance method to update an existing instance.

Example 4-7 Getting and Setting Instances

This example does the following:

...
{
    // 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 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 platform 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))));
}

Enumerating Objects

An enumeration is a collection of objects that can be retrieved one object at a time. You can enumerate classes, class names, instances, instance names, and name spaces. The results of an enumeration depend on the method and the arguments used, as shown in the following table.

Enumerating Objects

Table 4-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.
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 name spaces within the name space specified in path.
If true: Returns the entire hierarchy of name spaces under the specified name space.
N/A
If false: Returns only the first level children of the specified name space.
N/A

Example 4-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 noninherited methods and properties 
    for each class and subclass (localOnly is true).*/
 
    Enumeration e = cc.enumerateClasses(cop, true, true);  
}
...

Example 4-11 Enumerating Classes and Instances

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();
       }
    }
}

Example 4-12 Enumerating Class Names

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);
}
... 

Example 4-13 Enumerating Name Spaces

This example program uses the enumNameSpace method in the CIMClient class to print the name of the name space and all the name spaces contained within the name space.

 
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 name space 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 name space (args[3]) to create a CIMObjectPath
            CIMObjectPath cop = new CIMObjectPath("", args[3]);

            // Enumerate the name space
            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();
        }
    }
}

Creating Associations

An association describes a relationship between two or more managed resources such as a computer and its hard disk. This relationship is abstracted in an association class, which is a special type of class that contains an association qualifier. You can add or change an association class without affecting the actual objects.

Figure 4-1 TeacherStudent Association 1

Diagram shows that in TeacherStudent Association 1, the Teacher Teaches the Student and that the Student is Taught By the Teacher.

The preceding figure shows two classes, Teacher and Student. Both classes are linked by the TeacherStudent association. The TeacherStudent association has two references:

About the Association Methods

The association methods in CIMClient return information about the relationships between classes and instances. These methods are described in the following table.

Table 4-2 Association Methods

Method
Description
associators
Gets the CIM classes or instances that are associated with the specified CIM class or instance
associatorNames
Gets the names of the CIM classes or instances that are associated with the specified CIM class or instance
references
Gets the association classes or instances that refer to the specified CIM class or instance, respectively
referenceNames
Gets the names of the association classes or instances that refer to the specified CIM classes or instances, respectively

These methods take a single required argument, CIMObjectPath. CIMObjectPath is the name of a source CIM class or CIM instance whose associations, associated classes, or instances you want to return. If the CIMOM does not find any associations, associated classes, or instances, the CIMOM does not return anything.

Figure 4-2 TeacherStudent Association 2

Diagram shows that Math Teacher and Art Teacher are subclasses of Teacher, and that Teacher 1, Teacher 2, and Student 1 are class instances.

In the preceding figure, the associators and associatorNames methods return information about the classes associated with the Teacher and Student classes. The references and referenceNames methods return information about the associations between the Teacher and Student classes.

Table 4-3 TeacherStudent Methods

Example
Output
Description
associators(Teacher, null, null, null, null, false, false, null)
Student class
Returns associated classes. Student is linked to Teacher by the TeacherStudentassociation
associators(MathTeacher, null, null, null, null,false, false, null)
Student
Returns associated classes. Teacher is linked to Student by the TeacherStudentassociation. MathTeacher and ArtTeacher inherit the TeacherStudentassociation from Teacher
associatorNames(Teacher, null, null, null, null)
Name of the Student class
Returns the names of the associated classes. Student is linked to Teacher by the TeacherStudent association
references(Student, null, null, false, false, null)
TeacherStudent
Returns the associations in which Student participates
references(Teacher, null, null, false, false, null)
TeacherStudent
Returns the associations in which Teacher participates
references(Teacher, null, null, false, false, null)
TeacherStudent
Returns the associations in which Teacher participates
referenceNames(Teacher, null, null)
Name of the TeacherStudent class
Returns the names of the associations in which Teacher participates
referenceNames(Teacher, null, null)
Name of the TeacherStudent class
Returns the names of the associations in which Teacher participates

Note - The associatorNames and referenceNames methods do not take the arguments includeQualifiers, includeClassOrigin, and propertyList. These arguments are irrelevant to a method that returns only the names of instances or classes, not their entire contents.


Passing a Class to the Association Methods

To specify the name of a class, you specify its model path. The model path includes the class's name space, class name, and keys. A key is a property or set of properties that uniquely identify managed resource. Key properties are marked with the key qualifier. The following example shows a sample model path:

\\myserver\\root\cimv2\Solaris_ComputerSystem.Name= mycomputer: CreationClassName=Solaris_ComputerSystem

This model path specifies the following values:

Passing Instances to the Association Methods

You use the enumerateInstances method to return all instances of a given class, and a loop structure to iterate through the instances. In the loop, you can pass each instance to an association method.

Example 4-14 Passing Instances

This example enumerates the instances in the op class and its subclasses. The example uses a while loop to cast each instance to a CIMObjectPath (op), and to pass each instance as the first argument to the associators method.

 {
    ...
    Enumeration e = cc.enumerateInstances(op, true);
    while (e.hasMoreElements()) {
        op = (CIMObjectPath)e.nextElement();
        Enumeration e1 = cc.associators(op, null, null, 
                null, null, false, false, null);
    ...
    }           
Using Optional Arguments With the Association Methods

You can use the optional arguments with the association methods to filter the classes and instances that are returned. Each optional parameter value passes its results to the next parameter for filtering until all parameters have been processed.

You can pass values for any one or a combination of the optional parameters. You must enter a value or null for each parameter. The first four parameters are used to filter the classes and instances that are returned:

Only the classes and instances that match the values specified for these parameters are returned. The includeQualifiers, includeClassOrigin, and propertyList parameters filter the information that is included in the classes and instances that are returned.

Calling Methods

You use the invokeMethod interface to call a method in a class supported by a provider. To retrieve the signature of a method, an application must first get the definition of the class to which the method belongs. The invokeMethod method returns a CIMValue. The return value is null when the method that you invoke does not define a return value.

The invokeMethod interface takes four arguments, as described in the following table.

Table 4-4 invokeMethod Parameters

Parameter
Data Type
Description
name
CIMObjectPath
The name of the instance on which the method must be invoked
methodName
String
The name of the method to call
inParams
Vector
Input parameters to pass to the method
outParams
Vector
Output parameters to get from the method

Example 4-15 Calling a Method

This example gets the instances of the CIM_Service class, which represent services that manage device or software features. The example uses the invokeMethod method to stop each service.

{
    ...
    /* Pass the CIM Object Path of the CIM_Service class 
    to the CIM Object Manager. We want to invoke a method defined in
    this class. */ 
     
    CIMObjectPath op = new CIMObjectPath("CIM_Service"); 
     
    /* The CIM Object Manager returns an enumeration of instance
    object paths, the names of instances of the CIM_Service 
    class. */
     
    Enumeration e = cc.enumerateInstanceNames (op, true); 
     
    /* Iterate through the enumeration of instance object paths */
     
    while(e.hasMoreElements()) {
                // Get the instance
                CIMObjectPath op = (CIMObjectPath) e.nextElement();
                //Invoke the Stop Service method to stop the CIM services.
                cc.invokeMethod("StopService", null, null);
              }
}
 

Retrieving Class Definitions

The getClass method gets a CIM class. When a class is created, the class inherits the methods and properties of all parent classes in the class hierarchy. The getClass method takes the localOnly Boolean argument.

Example 4-16 Retrieving a Class Definition

This example uses the following methods to retrieve a class definition:

import java.rmi.*;
import javax.wbem.client.CIMClient;
import javax.wbem.cim.CIMInstance;
import javax.wbem.cim.CIMValue;
import javax.wbem.cim.CIMProperty;
import javax.wbem.cim.CIMNameSpace;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.cim.CIMClass;
import javax.wbem.cim.CIMException;
import java.util.Enumeration;
/**
 * Gets the class specified in the command line. Works in the default
 * name space root\cimv2.
 */
public class GetClass {
    public static void main(String args[]) throws CIMException {
        CIMClient cc = null;
        try {
           CIMNameSpace cns = new CIMNameSpace(args[0]);
           UserPrincipal up = new UserPrincipal("root");
           PasswordCredential pc = new PasswordCredential("root_password");
           cc = new CIMClient(cns);
           CIMObjectPath cop = new CIMObjectPath(args[1]);
           // Returns only the methods and properties that 
           // are local to the specified class (localOnly is true).
           cc.getClass(cop, true);
        } catch (Exception e) {
            System.out.println("Exception: "+e);
        }
        if(cc != null) {
            cc.close();
        }
    }
}

Handling Exceptions

Each CIMClient method throws a CIMException, or error condition. The CIMOM creates a hierarchy of WBEM-specific exceptions by using Java exception handling. The CIMException class is the base class for CIM exceptions. All other CIM exception classes extend from the CIMException class.

Each class of CIM exceptions defines a particular type of error condition that the API code handles. CIMException has methods to retrieve error codes and parameters that relate to the exception. Refer to file:/usr/sadm/lib/wbem/doc/index.html for more information on the CIMException class.

Creating a Name Space

The Solaris OS installation compiles the standard CIM Managed Object Format (MOF) files into the default name space. If you create a new name space, you must compile the appropriate CIM .mof files into the new name space before you create objects in that name space. For example, if you plan to create classes that use the standard CIM elements, compile the CIM Core schema into the name space. If you plan to create classes that extend the CIM Application schema, compile the CIM Application into the name space.

Example 4-17 Creating a Name Space

This example uses a two-step process to create a name space within an existing name space:

  1. When the name space is created, the CIMNameSpace method constructs a name space object that contains the parameters to be passed to the CIM Object Manager.

  2. The CIMClient class connects to the CIM Object Manager and passes the name space object. The CIM Object Manager creates the name space, using the parameters contained in the name space object.

{
    ...
    /* Creates a name space object on the client, which stores parameters 
    passed to it from the command line. args[0] contains the host 
    name (for example, myhost); args[1] contains the 
    parent name space (for example, the toplevel directory.) */
     
    CIMNameSpace cns = new CIMNameSpace (args[0], args[1]); 

    UserPrincipal up = new UserPrincipal("root");
    PasswordCredential pc = new PasswordCredential("root_password"); 
     
    /* Connects to the CIM Object Manager and passes it three parameters:
    the name space object (cns), which contains the host name (args[0]) and
    parent name space name (args[1]), a user name string (args[3]), and a
    password string (args[4]). */
     
    CIMClient cc = new CIMClient (cns, up, pc);
     
    /* Passes to the CIM Object Manager another name space object that 
    contains a null string (host name) and args[2], the name of a 
    child name space (for example, secondlevel). */
     
    CIMNameSpace cop = new CIMNameSpace("", args[2]);
    
    /* Creates a new name space by the name passed in as args[2] under the
    toplevel name space on myhost./*
     
    cc.createNameSpace(cop);
    ...
} 

Deleting a Name Space

Use the deleteNameSpace method to delete a name space.

Creating a Base Class


Note - You can also create a base class using the MOF language. If you are familiar with MOF syntax, use a text editor to create a MOF file. Then use the MOF compiler to compile the file into Java classes. See Chapter 7, Creating JavaBeans Components Using the MOF Compiler.


Use the CIMClass class to create a Java class representing a CIM class. To declare the most basic class, you need only specify the class name and a key property or an abstract qualifier. However, most classes include properties that describe the data of the class. To declare a property, include the property's data type, name, and an optional default value. The property data type must be an instance of CIMDataType.

A property can have a key qualifier, which identifies the property as a key property. A key property uniquely defines the instances of the class. Only keyed classes can have instances. Therefore, if you do not define a key property in a class, the class can only be used as an abstract class. If you define a key property in a class in a new name space, you must first compile the core MOF files into the name space. The core MOF files contain the declarations of the standard CIM qualifiers, such as the key qualifier.

Class definitions can be more complicated, including such features as aliases, qualifiers, and qualifier flavors.

Deleting a Class

Use the CIMClient method, deleteClass, to delete a class. This method removes the class and throws a CIMException.


Note - You must first remove any existing subclasses or instances before deleting a base class.


Example 4-18 Deleting a Class

This example uses the deleteClass method to delete a class in the default name space root\cimv2. This program takes four required string arguments:

The user running this program must specify the username and the password for an account, which has write permission to the root\cimv2 name space.

 
import javax.wbem.cim.CIMClass;
import javax.wbem.cim.CIMException;
import javax.wbem.cim.CIMNameSpace;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.client.CIMClient;
import javax.wbem.client.UserPrincipal;
import javax.wbem.client.PasswordCredential;

import java.rmi.*;
import java.util.Enumeration;

/**
 * Deletes the class specified in the command line. Works in the default
 * name space root\cimv2.
 */
public class DeleteClass {
    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: DeleteClass host className " +
                              "username password"); 
            System.exit(1);
        }
        try {
            // args[0] contains the hostname. We create a CIMNameSpace
            // pointing to the default name space on the specified host
            CIMNameSpace cns = new CIMNameSpace(args[0]);

            // args[2] and args[3] contain the username and password.
            // We create a UserPrincipal (up) using the username and
            // a PasswordCredential using the password.
            UserPrincipal up = new UserPrincipal(args[2]);
            PasswordCredential pc = new PasswordCredential(args[3]);

            cc = new CIMClient(cns, up, pc);

            // Get the class name (args[4]) and create a CIMObjectPath
            CIMObjectPath cop = new CIMObjectPath(args[1]);
            // delete the class
            cc.deleteClass(cop);
        }
        catch (Exception e) {
            System.out.println("Exception: "+e);
        }
        if (cc != null) {
            cc.close();
        }
    }
}