The following table describes the methods in the AssociatorProvider interface. For detailed information about the arguments these methods take, see The Association Methods.
Table 5–5 AssociatorProvider Interface Methods
Method |
Description |
---|---|
Vector associators(CIMObjectPath assocName, CIMObjectPath objectName, String role, String resultRole, boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList) |
Returns a vector of CIM instances that are associated to the instance specified by objectName. |
Vector associatorNames(CIMObjectPath assocName, CIMObjectPath objectName, String role, String resultRole) |
Returns a vector of the names of CIM instances that are associated to the CIM instance specified by objectName. |
Vector references(CIMObjectPath assocName, CIMObjectPath objectName, String role, boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList) |
Returns a vector of associations in which the CIM instance specified by objectName participates. |
Vector referenceNames(CIMObjectPath assocName, CIMObjectPath objectName, String role) |
Returns a vector of the names of associations in which the CIM instance specified by objectName participates. |
A complete association provider must implement all AssociatorProvider methods. For brevity, the code segment in the following example implements only the associators method. The CIM Object Manager passes values for assocName, objectName, role, resultRole, includeQualifiers, includeClassOrigin, and propertyList to the association provider.
Example 5–4 prints the name of a CIM association class and the CIM class or instance whose associated objects are to be returned. This provider handles instances of example_teacher and example_student classes.
public Vector associators(CIMObjectPath assocName, CIMObjectPath objectName, String role, String resultRole, boolean includeQualifiers, boolean includeClassOrigin, String propertyList[]) throws CIMException { System.out.println("Associators "+assocName+" "+objectName); if (objectName.getObjectName()equalsIgnoreCase("example_teacher")) { Vector v = new Vector(); if ((role != null) && (!role.equalsIgnoreCase("teaches"))) { // Teachers only play the teaches role. return v; } // Get the associators of a teacher CIMProperty nameProp = (CIMProperty)objectName.getKeys().elementAt(0); String name = (String)nameProp.getValue().getValue(); // Get the student class CIMObjectPath tempOp = new CIMObjectPath("example_student"); tempOp.setNameSpace(assocName.getNameSpace()); CIMClass cc = cimom.getClass(tempOp, false); // Test the instance name passed by objectName // and return the associated instances of the student class. if(name.equals("teacher1")) { // Get students for teacher1 CIMInstance ci = cc.newInstance(); ci.setProperty("name", new CIMValue("student1")); v.addElement(ci.filterProperties(propertyList, includeQualifiers, includeClassOrigin)); ci = cc.newInstance(); ci.setProperty("name", new CIMValue("student2")); v.addElement(ci.filterProperties(propertyList, includeQualifiers, includeClassOrigin)); return v; } }