The MetaModel

Although the IMetaModelFacade (documented in the iQgen API) offers many simple methods to access the actual model, sometimes you will find that you need more information than the facade has to offer. Then you will need to use the model directly. In order to do this successfully, you will have to learn about the relationships between different madel elements.

The figure below depicts the core package of the UML.

Figure 4.7. UML 1.3 - Core Package - Backbone

UML 1.3 - Core Package - Backbone

The centerpiece of this diagram is the class Classifier. A classifier is an element that describes behavioral and structural features; it comes in several specific forms, including Class, DataType, Interface, Component, and others that are defined in the classifier package. In the metamodel, a Classifier declares a collection of Features, such as Attributes, Methods, and Operations. It has a name, which is unique in the Namespace enclosing the Classifier.

Classifier is an abstract metaclass that is subclassed by concrete classes like Class and Interface as shown in the figure below.

Figure 4.8. UML 1.3 - Core Package - Classifiers

UML 1.3 - Core Package - Classifiers
In iQgen you can access elements of the metamodel through the method ru.novosoft.uml.MBase getElement(). The implementation of the model is based on a library by Novosoft. The figure below shows the interface hierarchy of Novosoft's core UML package ru.novosoft.uml.foundation.core.

Figure 4.9. Novosoft's UML Core Package

Novosoft's UML Core Package
You can cast the element you obtain with MBase getElement() to the appropriate interface type in order to access its methods. These are defined in the Novosoft API reference.

Let's say you want to access all parameters of a method or operation. The appropriate code looks like this:

<%@ page extends="com.innoq.generator.jsp.JspBase"
         import="java.util.*,ru.novosoft.uml.*,ru.novosoft.uml.foundation.core.*,
                 ru.novosoft.uml.foundation.data_types.MParameterDirectionKind" %>
<%!
public Collection getParameters(MBase m)  {
   Collection parameters  = Collections.EMPTY_LIST;
   MBase m = getElement();
   // a MBehavioralFeature includes both methods and operations
   // see class diagram above
   if (m instanceof MBehavioralFeature) {
      MBehavioralFeature bf = (MBehavioralFeature) m;
      parameters = new ArrayList();
      Iterator it = bf.getParameters().iterator();
      while (it.hasNext()) {
         MParameter par = (MParameter) it.next();
         // exclude the return parameter
         if  (par.getKind().getValue() != MParameterDirectionKind._RETURN) {
            parameters.add(par);

         }
      }
   }
   return parameters;
}
%>