Example: Member Delegation with Filtering

Meta Data Services Programming

Meta Data Services Programming

Example: Member Delegation with Filtering

The repository stores information that determines whether a derived collection can be filtered for objects that support a certain target interface.

To filter a derived collection, you must create two derived collection definitions and a new relationship to connect them. One derived collection contains the target objects of interest (that is, the set of target objects, minus those that do not match your filter criteria). The second derived collection contains the origin object. You need a derived origin collection whenever you want to create a relationship that includes a derived destination collection. The new relationship type is used to match the collections.

Note  If the derived collections were connected by the relationship type as the base collections, there would be two collections on each side of the relationship type, and the matching of origin and destination collections would not be well defined.

The following table identifies the Repository Type Information (RTIM) objects that are used to create derived collections and shows the corresponding pointers that appear in the example code.

RTIM object Pointer
IInterfaceDef *pINewOrgIface, *pIDestIface, *pIIReposDispatch;
IClassDef *pIClassDef;
IPropertyDef *pIBaseProp, *pIDerivedProp;
IRelationshipDef *pINewRelshipDef
IRelshipColDef *pIBaseOrgCol, *pIDerivedOrgCol;
IRelshipColDef *pIBaseDstCol, *pIDerivedDstCol;
IReposTypeLib *pITypeLib;

In order to run this sample, you must create a type library and a class definition for a new interface. Also, the interface pIDestIface must exist, as well as a relationship from this interface with two collections, pIBaseOrgCol and pIBaseDstCol. The pointers pIDestIface, pIBaseOrgCol, and pIBaseDstCol are assumed to have been already set before running this example.

// Create interfaces for a given class:
pIClassDef->CreateInterfaceDef(CRepVariant(OBJID_INewOrgIface), 
CVariant("INewOrgIface"), CRepVariant(IID_INewOrgIface), 
IIReposDispatch, CVariant("Default"), &pINewOrgIface);

// Create a new relationship type:
/* Notice that CVariant is a wrapper of the VARIANT class defined
   in the header file "oleutil.h" */
pITypeLib->CreateRelationshipDef(CRepVariant(OBJID_NULL), 
CVariant("A_Relationship"), &pINewRelshipDef);

// Create an origin collection definition:
pINewOrgIface->CreateRelationshipColDef(CRepVariant(OBJID_Members), 
CVariant("Members"), DISPID_Members, TRUE, COLLECTION_NAMING, 
pINewRelshipDef, &pIDerivedOrgCol);

// Get the ServicedBy collection and add the base origin collection:
pIDerivedOrgCol->Interface("IInterfaceMember2")
                          .ServicedBy.Add(pIBaseOrgCol);

// Create the destination collection:
pIDestIface->CreateRelationshipColDef(CRepVariant(OBJID_NULL), 
CVariant("Parent"), DISPID_Parent, FALSE, NULL, pINewRelshipDef, 
pIDerivedDstCol);
// Get the ServicedBy collection and add the base destination collection:
pIDerivedDstCol->Interface("IInterfaceMember2")
                           .ServicedBy.Add(pIBaseDstCol);

In this example code, the derived origin collection will filter the objects that support the IDestIface interface. Note that a new relationship type is defined. The relationship instances, however, will not use this relationship type. All of the collections will continue to use the base relationship type instead. The new relationship type will be used to identify the matching collections in RTblRelColDefs.

See Also

Creating a Derived Member

Defining Inheritance

Example: Basic Member Delegation

Filtering Derived Collections