Previous Table of Contents Next


4.6 Instance Metamodel

   The Instance metamodel depends on the following package: org.omg::CWM::ObjectModel::Core

   In addition to the metadata normally interchanged with CWM, it is sometimes useful to interchange specific data instances as well. The ObjectModel’s Instance metamodel allows the inclusion of data instances with the metadata.

    The Instance metamodel is shown in Figure 4-7.

   Data values may be stored in one of two alternative ways. The Slot class is a generic container that can hold either DataValue or Object instances. One way of storing a data value is to create a Slot instance and place a DataValue instance “in? the Slot via the SlotValue association. The alternate way is to create an instance of DataSlot, storing the value into its dataValue attribute. The former method is more general while the latter creates fewer total objects. Both techniques are illustrated in the example in Figure 4-7.


   Slot

   


Instance

   value valueSlot

   






   





   feature



DataSlot


   DataValue Object

   






   


/ownedElement


   /namespace Extent

   




   Figure 4-7 Instance metamodel

   To aid understanding of the appropriate use of Instance metamodel classes and associations, a full example is presented in Figure 4-7 , showing how Instance metamodel objects are used to represent the model, shown in Figure 4-8 , and its instances.

   Marriage (MaritalStatus : String)

   


Person

   spouse





   Figure 4-8 Instance metamodel example model

   The example model describes people and their marital relationships to other people. Marital relationships are represented by the reflective Marriage association between two separate people. The Marriage association has two association ends named “person? and “spouse.? Notice that each instance of the Marriage association has a string-valued attribute describing the current status of the marital relationship it represents. Valid values for the MaritalStatus attribute are “Married,? “Divorced,? and “Widowed.? People who have never been married have no instances of the Marriage association.

    Figure 4-9 on page 4-59 shows how the example model is represented as instances of the CWM ObjectModel metaclasses Class, Attribute, DataType, Association, and AssociationEnd. In addition, Instance metamodel classes are used to capture two kinds of data values that might be exchange using the CWM DTDs: valid values of the MaritalStatus attribute, and the marital relationship between the people George and Martha Custis Washington. In the figure, instances of the Instance metamodel are shown with a shaded background and labeled with an uppercase letter near their upper right corner to facilitate discussion. Lines in the figure represent ObjectModel associations that capture relationships between instances and are labeled with the associations name.

   George is represented by Object A, and Martha, by Object B. These person objects own DataSlots C and D, respectively, that contain the names of the individuals.

   The valid values of the MaritalStatus attribute are recorded by DataValue instances I, J, and K.

   The marital relationship between George and Martha is represented, from George’s perspective, by Object F, which is an instance of the Marriage association. Object F owns Slots E, F, and G. Slot E holds the person association end and references Object A (George), whereas Slot G holds the spouse association end, referencing Object B (Martha). Slot H holds a DataValue instance describing the current value (“Married?) of the MaritalStatus attribute for Object F.




   Figure 4-9 Instance metamodel example instances