完全な関連付けプロバイダには、すべての AssociatorProvider メソッドを実装する必要があります。わかりやすくするために、次のコード例には、associators メソッドだけを実装しています。CIM Object Manager は、assocName、 objectName、 role、 resultRole、 includeQualifiers、 includeClassOrigin、 propertyList のそれぞれの値を関連付けプロバイダに渡します。
例 5–4 では、CIM 関連付けクラスの名前と、返される関連付けされたオブジェクトが属する CIM クラスまたはインスタンスを出力します。このプロバイダは、example_teacher クラスと example_student クラスのインスタンスを扱います。
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"))) { // teacher は teaches という役割だけを担う return v; } // teacher のアソシエータを取得する CIMProperty nameProp = (CIMProperty)objectName.getKeys().elementAt(0); String name = (String)nameProp.getValue().getValue(); // student クラスを取得する CIMObjectPath tempOp = new CIMObjectPath("example_student"); tempOp.setNameSpace(assocName.getNameSpace()); CIMClass cc = cimom.getClass(tempOp, false); // objectName によって渡されたインスタンス名をテストし、 // student クラスの関連付けされたインスタンスを返す if(name.equals("teacher1")) { // teacher1 の student (複数) を取得する 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; } }