Solaris WBEM Developer's Guide

Writing an Associator Provider


Note –

The objectName argument in each of the association methods called by your client program. In other words, CIMObjectPath must be the object path of an instance, not a class.


Unless the CIMOM sees the object path of an instance, it assumes that the client wants to see the class definitions of the association in the CIM Object Manager Repository. The class definitions of the association includes the templates from which the association's member instances are derived. Therefore, the CIMOM will use the client API's association method and not the provider's association method.

The most important part of designing and coding an association is the association class. Your association will only be as complex as the contents of the association class. The number of members of the association equals the number of references in the association class. Roles can be used to model more complicated associations. The following examples show some sample association classes.

The following code sample implements the associators method. The CIMOM passes values for associatorNames, objectName, role, resultRole, includeQualifiers, includeClassOrigin, and propertyList to the association provider. In addition, the code prints the name of the CIM associator 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.


Example 6–3 CIMAssociator Provider

...

public CIMInstance[] associators(CCIMObjectPath assocName, CIMObjectPath 
                objectName, String resultClass, 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;
        }
        if ((resultRole != null)  && (!resultRole.equalsIgnoreCase
                                     ("taughtby"))) {
        // Teachers only result in taughtby 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;
        }
}