Solaris WBEM 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 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.