TRIMM Core

Trimm-Core TRIMM Core is the foundation on which all other TRIMM modules are built.
You rarely need to work with TrimmCore alone, but it can be good to understand the TRIMM MetaModel which you can use when creating your own extensions to TrimmJava, TrimmJpa, TrimmGroovy/Grails or TrimmWebservice.

MetaModel

TRIMM Core defines the MetaModel, which is an in-memory model that can reflect the contents of structural class models, such as a UML 2 Class model instance.

The MetaModel is based on the composite design pattern, where everything is a MetaType (or a specialization thereof) and each MetaType instance can contain multiple children which are all instances of MetaType.

TRIMM Core MetaModel Pattern

TRIMM Core MetaModel Pattern


MetaType Hierarchy

MetaType Hierarchy


The good thing about using the Composite pattern is processing of a MetaModel can be handled purely recursively. Even though a composite model which is built on MetaType with MetaType’s as children can contain any combination, there are method defined on each MetaType specialization which allows filtering children to support reasoning about classic Class structural models while allowing the flexibility of having a composite model that is easy to process (recursively).
The picture below shows the typical usage of the MetaModel:

MetaModel typical usage pattern

MetaModel typical usage pattern

Here’s an example of a Groovy (model-preprocessing) script that swaps a MetaType’s (or a subclass thereof) name property out with the value of the alias property (if it is set):

metaModel.each {  metaType ->
    // Swap Alias and Name in case there's an alias defined for a MetaType
    if (metaType.alias != null) {
	    def old = metaType.name
	    metaType.name = metaType.alias
	    metaType.alias = old
    }
}

MetaModel layer

The OMG Meta-Object Facility (MOF) defines 4 layers for Models:

  • M3 – The Meta Meta Model
  • M2 – The Meta Model
  • M1 – The Model
  • M0 – The usage instances of a Model
TRIMM Core MetaModel level

TRIMM Core MetaModel level

Beware of Meta Model confusion

The fact that TRIMM Core calls it’s object representation of a UML Class model, which is a M1 layer model, for MetaModel should not be confused with MOF’s definition of a Meta Model, which is a M2 layer model.

Just think of the TRIMM Core MetaModel as a representation of your UML Class model.

The reason why we’ve chosen to call it MetaModel is because, to us, it forms the Meta definition for the resulting model (such as a Java model or a WebService model) it is transformed into.
The relationship between the UML Model (M1) and the TRIMM Core MetaModel instance (M1) is depicted below:

UML Model instance example

UML Model instance example


TRIMM Core MetaModel instance example

TRIMM Core MetaModel instance example

Reading a UML Model using TRIMM Core

Just having a MetaModel class library doesn’t help much if you don’t have anything to populate it with.
The easiest way to create a new model is to do it using a UML tool such as Enterprise Architect or MagicDraw (the two currently supported UML tools) using the XmiReader abstraction.
TRIMM supports reading from both a File and a URL (e.g. loading from classpath using Class.class.getResource("file-on-classpath.xml"))

Enterprise Architect

TRIMM supports Enterprise Architect version 8.x, 9.x and 10.x using the EAXmiReader class.
TRIMM can read XMI 2.1 model exports from Enterprise Architect – Please see this guide

 
import dk.tigerteam.trimm.mdsd.uml2.xmi.ea.EAXmiReader;
import dk.tigerteam.trimm.mdsd.meta.MetaModel;
...

MetaModel metaModel = new EAXmiReader().read(new File("EA-XMI-2.1-Export.xml")); 

MagicDraw

TRIMM supports MagicDraw version version 16.x and 17.x using two different MagicDrawXmiReader subclasses
TRIMM can read both MagicDraw’s .mdxml file format and the .mdzip file format (which basically is an mdxml file zipped).

MagicDraw version 16.x

 
import dk.tigerteam.trimm.mdsd.uml2.xmi.magicdraw.MagicDraw16XmiReader;
import dk.tigerteam.trimm.mdsd.meta.MetaModel;
...

MetaModel metaModel = new MagicDraw16XmiReader().read(new File("MagicDrawXmiFile.mdxml")); 

MagicDraw version 17.x

 
import dk.tigerteam.trimm.mdsd.uml2.xmi.magicdraw.MagicDraw17XmiReader;
import dk.tigerteam.trimm.mdsd.meta.MetaModel;
...

MetaModel metaModel = new MagicDraw17XmiReader().read(new File("MagicDrawXmiFile.mdxml"));