Solaris WBEM SDK Developer's Guide

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 objects themselves.

Figure 3-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.

Figure 3–1 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 3-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 one required argument, CIMObjectPath, which is the name of a source CIM class or CIM instance whose associations, associated classes, or instances you want to return. If the CIM Object Manager does not find any associations, associated classes, or instances, it does not return anything.

Figure 3-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 Figure 3–2, 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 3-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 TeacherStudent association.

associators(MathTeacher, null, null, null, null,,false, false, null)

Student

Returns associated classes. Teacher is linked to Student by the TeacherStudent association. MathTeacher and ArtTeacher inherit the TeacherStudent association 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 TeacherStudentassociation.

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)

The name of the TeacherStudent class.

Returns the names of the associations in which Teacher participates.

referenceNames(Teacher, null, null)

The 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 because 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 namespace, 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. This model path:

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

Specifies the following:

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 3-14 Passing Instances

This example enumerates the instances in the op class and its subclasses, uses a while loop to cast each instance to a CIMObjectPath (op), and passes 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 assocClass, resultClass, role, and resultRole parameters 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 are included in the classes and instances that are returned.