|
[Previous] [Overview] [Next]
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 modelelements.
The figure below depicts the core package of the UML.

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, data type, 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.

UML 1.3 - Core Packages - 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.

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 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;
}
%> |
Of course not always things go the right way right away. If you have trouble getting things to work, please check out the troubleshooting section.
|