Login | Register
My pages Projects Community openCollabNet

2020-03-13: This site is going to be decommissioned and shut down very soon. Please copy and archive any data you wish to keep ASAP

If you were registered and logged in, you could join this project.

Summary A JMI-compliant template-based code generator.
Categories libraries, design
License BSD License
Owner(s) sunye


Bosco is a code generator tool: it generates the underlying model (also called repository) for any modeling language expressed in MOF. In other words, it reads XMI files and generates the corresponding source code, in different object-oriented languages (Java, Eiffel, Python, C++). In the case of Java, the generated code implements the JMI interfaces.

Bosco is written in Python and uses Cheetah, a template engine. More precisely, the code generation is driven by template files, which merges source code with Cheetah statements (#for, #if, etc.). Thanks to this, the generation is highly configurable: one can add new features to generated code without writting a single line of Python.


Small example

XMI Element

The element below commes from the UML 1.5 specification. It describles the metaclass Class, and its only attribute, isActive:

<Model:Class annotation="" isAbstract="false" isLeaf="false" isRoot="false" isSingleton="false" 
name="Class" supertypes="a32989FB2023D" visibility="public_vis" xmi.id="a3298A02900FE">
<Model:Attribute annotation="" isChangeable="true" isDerived="false" name="isActive"
scope="instance_level" type="a33DD6F650276" visibility="public_vis" xmi.id="a33F24B5A0190">
<Model:MultiplicityType is_ordered="false" is_unique="false" lower="1" upper="1"/>


A Cheetah template files merges text with simple statements (#set, #if #else, #for) and some Python code. The following template is a simplified version of the one that generates Java interfaces for MOF classes.

package $(class.container.idl_prefix).$(class.container.name);
#set $hasparents = $len($class.supertypes)    > 0 
#set $parents_str = ', '.join(map(lambda x: x.container.idl_prefix+'.'+x.container.name+'.'+x.name,$class.supertypes))

#if $hasparents
public interface $(class.name) extends $parents_str {
public interface $(class.name) extends javax.jmi.reflect.RefObject {
#end if

// Attributes:

#for attrs in $class.attributes()
#set $aux = $attrs.name.capitalize()
$(attrs.type.name) get${aux}() throws javax.jmi.reflect.JmiException;

}; // end of interface $(class.name)Class

Generated Java code

package org.omg.uml.Foundation.Core;
public interface Class extends org.omg.uml.Foundation.Core.Classifier {
// Attributes:
public void setActive(boolean aisActive) throws javax.jmi.reflect.JmiException; public boolean isActive() throws javax.jmi.reflect.JmiException;
}; // end of interface Class


Related projects