Generator Development Walkthrough
this is a developing generator development guide
Preparing your Development Environment
Get the JARs from P4catfw.jar
in bin
modapi.jar
in bin
codegentk.jar
in bin
util.jar
in bin
Add the JARs to your CLASSPATH
Programming a Generator
Generators have to be derived from the Generator class from package de.tuhh.sts.cocoma.compiler.generators and have to provide a public constructor taking one string-valued argument. Apart from that there is no general rule how to program a generator. Still, this page will point you to the basic setup of a generator.
package ... ; ... public class
SomeGenerator ... /** }// constructor ... }// class SomeGenerator |
The most important function of a generator is generate(). When this method is invoked, a generator performs its actual task. Basically, the generate() method of generators often looks like the following:
package ... ; import de.tuhh.sts.cocoma.Symboltable ; public class
SomeGenerator ... /** }// constructor ... public
SymbolTable generate (IntermediateModel im, ...) //
create the symbol table to return
as the result of a generator run AssetClass
[] classes = im.getClasses () ; AssetClass cls = classes [i] ; //
do something with "cls" //
next, handle the attributes (or
only one kind of attributes, or all members) Attribute attrib = attribs [j] ; //
do something with "attrib" }// for j ... //
write result file }// for i ... //
return symbol table }// generate }// class SomeGenerator |
The lines shown in red are just examples of what could be done while generation. Here, Java code is generated using the Java code generation toolkit.
Other methods that have to be implemented are:
By calling getRequestedParameters() and getRequestedSymbolTables()the compiler framwork finds out which actual parameters the generate() method of a generator expects.
For the compiler framework to be able to schedule the generators these have to provide information on the return value of the generate() method on invocations of getProducedSymbolTable().
In certain adaptations of the compiler framework the domain modeller is informed about the state of the compilation process. The necessary information is gathered from generators by registering an observer, an implementation of the interface ProgressListener. An observer registers itself with a generator by calling addProgressListener(). When making progress the generator shall inform observers by invoking their changedState() method.
Configure the Compiler Framework
add generator to compiler configuration "my-cat.xml"<?xml version="1.0"?> <cat xmlns:util="http://www.sts.tu-harburg.de/2004/java/util/xmlconfigfile"> <scanner class="de.tuhh.sts.cocoma.compiler.ADLScanner"/> <parser class="de.tuhh.sts.cocoma.compiler.ADLParser"/> <dictionary class="de.tuhh.sts.cocoma.dictionary.FileDictionary"> <param name="directory">U:\Projects\my-project\model</param> </dictionary> <configuration name="myconfig"> <param name="outputDirBase">U:\Projects\my-project\src</param> <generator name="apigen" class="de.tuhh.sts.cocoma.compiler.generators.api.APIGenerator"> <param name="outputDir"><util:xpath path="../../../param[@name='outputDirBase']/text()"/>\classes</param> <param name="targetPackage">de.tuhh.sts</param> </generator> <generator name="mygen" class="de.tuhh.sts.cocoma.compiler.generators.myomy.MyGenerator"> <param name="output directory"><util:xpath path="../../../param[@name='outputDirBase']/text()"/>\classes</param> <param name="target package">de.tuhh.sts</param> </generator> </configuration> </cat> |
Running the Compiler
run the compiler using
java de.tuhh.sts.cocoma.compiler.CAT -configFile ...\etc\my-cat.xml -configuration myconfig .../model/my-model.ald
and check the results in U:\Projects\my-project\src\de\tuhh\sts\...
Configuring a Component
The following XML code shows a sample component configuration:
<?xml version="1.0"?> |
In this sample configuration file a component is configured to consist of a C-module ("base") and a ...
Running the Component
Java-Code um Komponente zu instantiieren:
// start component |
Dann Client-Code z.B.:
// get "Student" asset class // find all students named "Peter" // show all students found |
HWS