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.
If CIMObjectpath is a class, the methods return the associated classes and the subclasses of each associated class.
If CIMObjectpath is an instance, the methods return the instances of the associated class and the subclasses of each associated class.
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 |
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.
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:
\\myserver\root\cimv2 is the default CIM name space on host myserver.
Solaris_ComputerSystem is the name of the class from which the instance is derived.
Name=mycomputer, CreationClassName=Solaris_ComputerSystem are two key properties in the format key property=value.
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.
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); ... }
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:
assocClass
resultClass
resultRole
role
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.