SZ
Administrator
Registered: Apr 2001
Location: New York
Posts: 492 |
AndroMDA and JMI
Thanks to Matthias Bohlen, founder of the AndroMDA project, for describing how this innovative, open-source MDA tool uses JMI. Matthias provided the following excellent overview:
********************************************
+ AndroMDA is based on Netbeans Metadata Repository (a.k.a. Netbeans MDR, see http://mdr.netbeans.org).
+ MDR is an implementation of the OMG's MetaObject Facility (MOF) standard (see http://www.omg.org/mof).
+ Basically, MDR is able to load arbitrary models based on arbitrary metamodels, provided that you load the metamodel into MDR before you load the model. Example: It can load UML 1.4 models because we load the UML 1.4 metamodel first.
+ MDR uses the MOF-to-Java mapping called JMI (Java Metadata Interface, see http://java.sun.com/products/jmi/index.jsp).
+ MDR reads metamodels as XMI and generates JMI interface bytecode for them.
+ Example: For UML, you get interfaces like UMLClass, Attribute, Operation, Association, etc. If you loaded a database metamodel instead, you would get interfaces like Table, Column, etc.
+ When loading a model, MDR creates an in-memory representation of the model, called an "abstract syntax tree" (AST). Each node in the AST is a Java object that implements one of the generated JMI interfaces.
+ AndroMDA traverses those AST objects, accesses them via their JMI interfaces and shields them with classes that hide the complexity of the UML (or another) metamodel. We call these classes "metamodel facades" or "metafacades" for short.
+ AndroMDA's templates generate source code and access the metafacades to get model information.
+ Example: Let's generate a private field for each attribute of a UML class:
code:
#foreach ($attr in $class.attributes)
private ${attr.type.name} ${attr.name};
#end
This would cause an access to a metafacade called UMLClassifierFacade which accesses a JMI interface called UMLClassifier. The method getAttributes() would be called and would return a Collection of AttributeFacades. On each one of those, the methods getType() and getName() would be called. At last, the above Velocity scriptlet would be equivalent to the following pseudo-Java code:
code:
foreach (attr in class.getAttributes()) {
generate(" private " + attr.getType().getName() +
" " + attr.getName() + ";");
}
That's it! JMI is used to access model information, facades are used to make that access easier and templates are used to make everything visible as text output (typically, the output is source code). This is similar to a three-tier application: JMI is like the database layer, facades are the business object layer, templates are like the GUI.
Report this post to a moderator | IP: Logged
|