3D PLM Enterprise Architecture

Middleware Abstraction - Object Modeler

Creating a Component Factory

Enabling component instantiation without be tied to the component implementation
Use Case

Abstract

This article shows how to create a factory for a CAA V5 component.


What You Will Learn With This Use Case

This use case is intended to show you how to create a factory for a CAA V5 components [1], that is, how to bundle several C++ classes that each implements one or several interfaces [2] and make that this set of classes acts and behaves as a single application object. This article focusses on how to create a factory for such components.

[Top]

The CAASysGeoModelImpl Use Case

CAASysGeoModelImpl is a use case of the CAASystem.edu framework that illustrates the System framework capabilities.

[Top]

What Does CAASysGeoModelImpl Do

This use case includes the code for a set of components that stand for geometric objects. The circle is taken as an example.

The circle component is made of the CAASysCircle main class, and of the CAAESysCreateInstanceForCircle, CAAESysCircle, CAAESysCircleCenterProperties, and CAAESysColorProperties extension classes. CAAESysCreateInstanceForCircle implements the CATICreateInstance interface to enable the component creation. CAAESysCircle implements the CAAISysCircle interface that is the circle type interface. CAAESysCircleCenterProperties implements the CAAISysCircleCenterProperties interface to manage the marker used to represent the circle center. CAAESysColorProperties implements the CAAISysColorProperties interface to manage the circle color. CAAESysCircle and CAAISysCircleCenterProperties are extension classes of the CAASysCircle class only, while CAAESysColorProperties is shared with other geometric components, such as the line, the polyline, and the ellipse. Refer to sharing extensions in [1].

In addition, the factory for the circle component is also described. The CAASysGeomCont main class that represents a container for geometric objects implements the CAAISysGeomFactory interface through a code extension class named CAAESysGeomFactoryForGeomCont.

Note: Extension links are shown as dashed arrows, and implementation to interface links are shown using the realization link symbol, made of a dash line ended using a triangle on the interface side.

[Top]

How to Launch CAASysGeoModelImpl

You first need to build CAASysGeoModelImpl. To do this, you will need to set up the build time environment, then compile CAASysGeoModelImpl along with its prerequisites as described in [4]. You cannot launch CAASysGeoModelImpl itself. CAASysGeoModelImpl is simply used by the CAASysUsingComp [3] use case.

[Top]

Where to Find the CAASysGeoModelImpl Code

The CAASysGeoModelImpl use case is made of several classes located in the CAASysGeoModelComp.m for the component main classes, and CAASysGeoModelImpl.m module for the extension classes. These modules belong to the CAASystem.edu framework:

Windows InstallRootDirectory\CAASystem.edu\
Unix InstallRootDirectory/CAASystem.edu/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed. The header files of shared classes are located in the PrivateInterfaces directory of CAASystem.edu.

[Top]

Step-by-Step

To create a component factory, such as the factory for CAASysCircle, there are three main steps:

# Step Where
1 Create the CAASysCircle component factory main class header file CAAESysGeomFactoryForGeomCont.h file
2 Create the CAASysCircle component factory main class source file CAAESysGeomFactoryForGeomCont.cpp file
3 Update the interface dictionary CAASystem.edu.dico file

[Top]

Creating the CAASysCircle Component Factory Class Header File

#include "CATBaseUnknown.h"
#include "CAAISysGeomFactory.h" // Implemented interface

class CAAESysGeomFactoryForGeomCont : public CATBaseUnknown
{
  // Used in conjunction with CATImplementClass in the .cpp file
  CATDeclareClass;

  public:
    CAAESysGeomFactoryForGeomCont();
    virtual ~CAAESysGeomFactoryForGeomCont();

    virtual HRESULT Create (const CAAISysGeomFactory::GeomObject iObjectType, 
                            const IID                           &iRequestedInterfaceIID,          
                            CATBaseUnknown                     **oCreatedObj) const;
  private:
    CAAESysGeomFactoryForGeomCont(const CAAESysGeomFactoryForGeomCont&iObjectToCopy);
};

The CAAESysGeomFactoryForGeomCont class derives from CATBaseUnknown. The CATDeclareClass macro declares that the class CAAESysGeomFactoryForGeomCont belongs to a component. Note that the copy constructor is set as private. The class has a constructor and a destructor, and declares the single Create methods of the CAAISysGeomFactory interface.

[Top]

Creating the CAASysCircle Component Factory Class Source File

#include "CAAESysGeomFactoryForGeomCont.h"
#include "CATInstantiateComponent.h"

#include "TIE_CAAISysGeomFactory.h"
TIE_CAAISysGeomFactory(CAAESysGeomFactoryForGeomCont);

CATImplementClass(CAAESysGeomFactoryForGeomCont,DataExtension,CATBaseUnknown,CAASysGeomCont);

CAAESysGeomFactoryForGeomCont::CAAESysGeomFactoryForGeomCont() {}

CAAESysGeomFactoryForGeomCont::CAAESysGeomFactoryForGeomCont() {}

HRESULT CAAESysGeomFactoryForGeomCont::Create(const CAAISysGeomFactory::GeomObject iObjectType, 
                                              const IID                           &iIID,          
                                              CATBaseUnknown                     **oCreatedObj) const
{
  if ( NULL == oCreatedObj ) return E_FAIL;

  HRESULT rc = E_FAIL;
  
  switch (iObjectType)
  {
    ...
    case CAAISysGeomFactory::Circle : 
      rc = ::CATInstantiateComponent("CAASysCircle",
                                     iIID,
                                     (void**)oCreatedObj);
      break;
    ...
  }
  return rc;
}

The CAAESysGeomFactoryForGeomCont class states that it implements the CAAISysGeomFactory interface thanks to the TIE_CAAISysGeomFactory macro. The CATImplementClass macro declares that the CAAESysGeomFactoryForGeomCont class is a data extension, thanks to the DataExtension keyword, that extends CAASysGeomCont. The third argument must always be set as CATBaseUnknown or CATNull for any kind of extension. The Create method of CAAISysGeomFactory can create several geometric objects using a switch that takes the object type passed as input parameter. Create simply instantiate the CAASysCircle component main class using the CAAInstantiateComponent global function [5] that returns a pointer to the requested interface thanks to the IID [6] passed as its second parameter.

[Top]

Updating the Interface Dictionary

...
CAASysGeomCont CAAISysGeomFactory libCAASysGeoModelImpl
...

The interface dictionary declares that the CAASysGeomCont component implements the CAAISysGeomFactory interface, and that the code to load into memory to use this interface is located in the libCAASysGeoModelImpl shared library or DLL. Note that the component main class name is used to refer to the component in the interface dictionary, and never the extension class names. Note also that the shared library or DLL to associate with the component/interface pair is the one that contains the code created by the call to the TIE macro (This is generally the same library than the one that contains the interface implementation code, since the TIE macro is usually included in the extension class source file.) This is because when a client asks a component for an interface pointer, the TIE class is instantiated first, and it either retrieves the existing instance of the appropriate extension class, or otherwise instantiates it.

[Top]


In Short

This use case shows how to create a factory for components using the extension class CAAESysGeomFactoryForGeomCont of the component main class CAASysGeomCont. The main class declares the component inheritance and must C++-derive and OM-derive from CATBaseUnknown or from another component main class. Extension classes must directly or indirectly C++-derive from CATBaseUnknown, while OM-inheritance makes no sense for them. A component factory is a component that implements an interface providing a single method to create the component it deals with, and that instantiates the component main class using the CATInstantiateComponent global function. An extension class can be dedicated to a component or shared by several components. The interface dictionary declares the correspondence between the component, the interfaces it implements, and the shared library or DLL to load for each interface.

[Top]


References

[1] Creating Components
[2] Creating Interfaces
[3] Using Components
[4] Building and Launching a CAA V5 Use Case
[5] Creating Components
[6] What Is HRESULT?
[Top]

History

Version: 1 [Aug 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.