Home > Model Transformation > Model-to-Text (M2T) > OOMEGA oAW
OOMEGA oAW is a little adapter for the well-known generator openArchitectureWare. You can use that third-party generator and its template language Xpand to post-process models that were designed with OOMEGA.
We do not provide detailed documentation for the product openArchitectureWare as there are already good sources available in the internet. Please consult the respective websites. However we will explain here how to use openArchitectureWare on top of OOMEGA.
Please notice first of all that there is a working example. The Model-to-Text demo project (org.oomega.demo.m2t) demonstrates code generation with openArchitectureWare. The chapter Demo Projects explains how to setup and run this demo project. The source code of that project is probably a good starting point for you.
Start openArchitectureWare with Ant
First of all you need to include a task definition for the standard openArchitectureWare workflow task. It is important to set the classpath correctly. The required oAW libraries are shipped with OOMEGA's distribution - you can find them in the OOMEGA-Libraries project after installing the demo projects. Additionally you need to reference oomega-core.jar and potentially oomega-network-client.jar.
<path id="oaw"> <fileset dir="${oomega.home}/lib" includes="oomega-core.jar, oomega-network-client.jar" /> <fileset dir="${oomega.home}/lib/oaw" includes="*.jar" /> </path> <taskdef name="workflow" classpathref="oaw" classname="org.openarchitectureware.workflow.ant.WorkflowAntTask" />
When you finally want to execute the generator you will use the previously defined workflow task. Please ensure the following:
- The file attribute of the workflow task references a workflow document. See below for more information regarding the contents of a workflow document.
- The workflow tag contains the attribute fork="true".
- You need to set the classpath correctly again.
- Reference the previously defined path oaw. That contains all required oAW libraries, oomega-core.jar and potentially oomega-network-client.jar.
- Include paths of the directories containing workflow.oaw, property files and Xpand templates, i.e. *.xpt files.
- Include the automatically generated library of your specific metamodel that you have designed with OOMEGA.
<workflow file="src/openArchitectureWare/workflow.oaw" fork="true"> <classpath> <path refid="oaw" /> <pathelement path="src/openArchitectureWare" /> <pathelement path="src/openArchitectureWare/xpt" /> <fileset dir="build/output/lib" includes="m2t-demo.jar" /> </classpath> </workflow>
Design the Workflow document
The workflow document uses some properties that are defined within a dedicated property file, namely workflow.properties.
modelFile = build/output/traffic-light/TrafficLight.sdf modelHost = localhost modelPort = 8181 srcGenPath = build/output/traffic-light_openArchitectureWare
OOMEGA offers specific workflow components so that you can instantiate models that were designed with OOMEGA.
- FileEOCWorkflowComponent loads the contents of a SDF or SDML file. The <filename> tag is needed.
<component class="org.oomega.m2t.oaw.FileEOCWorkflowComponent"> <filename value="${modelFile}" /> <modelSlot value="model" /> </component>
- NetworkEOCWorkflowComponent can connect to a model in a remote model repository. The <host> and <port> tags are needed.
<component class="org.oomega.m2t.oaw.NetworkEOCWorkflowComponent"> <host value="${modelHost}" /> <port value="${modelPort}" /> <modelSlot value="model" /> </component>
The generator component is actually using the standard oAW JavaMetaModel with the JavaBeansStrategy. The previously prepared model slot model will be referenced within the <expand> tag.
Here's the whole content of the workflow.oaw file. The example uses the FileEOCWorkflowComponent.
<workflow> <property file="workflow.properties"/> <!-- component is used to instantiate the model. The model is put in the modelSlot 'model'. --> <component class="org.oomega.m2t.oaw.FileEOCWorkflowComponent"> <filename value="${modelFile}" /> <modelSlot value="model" /> </component> <!-- run the generator --> <component id="generator" class="org.openarchitectureware.xpand2.Generator" skipOnErrors="true"> <!-- the metamodel is JavaBeans based --> <metaModel class="org.openarchitectureware.type.impl.java.JavaMetaModel"> <typeStrategy class="org.openarchitectureware.type.impl.java.beans.JavaBeansStrategy"/> </metaModel> <fileEncoding value="UTF-8" /> <!-- call Define Root in template Root.xpt for our model put in the modelslot 'model' --> <expand value="Root::Root FOR model" /> <outlet path="${srcGenPath}" /> </component> </workflow>
Code Xpand templates
When you finally code your Xpand templates, please ensure that you include the correct import statements.
- The packages org.oomega.base and org.oomega.m2t.oaw are always needed.
- Additionally you need to import the packages of your custom metamodel, e.g. org.oomega.demo.m2t.statemachine.
«IMPORT org::oomega::base» «IMPORT org::oomega::m2t::oaw» «IMPORT org::oomega::demo::m2t::statemachine»
FileEOCWorkflowComponent and NetworkEOCWorkflowComponent inject an instance of the class org.oomega.m2t.oaw.OOMEGAModel to the model slot. OOMEGAModel provides a property entities that will return all EntityObjects of the model repository. Therefore you need to include the following lines after the import statements.
«DEFINE Root FOR OOMEGAModel» «EXPAND Root FOREACH entities» «ENDDEFINE»
Here's the whole content of the Root.xpt template that is used within the demo project org.oomega.demo.m2t.
«IMPORT org::oomega::m2t::oaw» «IMPORT org::oomega::base» «IMPORT org::oomega::demo::m2t::statemachine» «DEFINE Root FOR OOMEGAModel» «EXPAND Root FOREACH entities» «ENDDEFINE» «DEFINE Root FOR Automaton» «FILE "html/"+name+"Automaton.html"» <html> <head> <title>OOMEGA Demo - Automaton «name»</title> </head> <body> <span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:11pt"> <h3>Automaton «name»:</h3> <p> <b>a. Containing states:</b> <ul>«EXPAND Root FOREACH states» </ul> </p> <p> <b>b. Existing transitions:</b> <ul>«EXPAND Root FOREACH allTransitions» </ul> </p> </span> </body> </html> «ENDFILE» «ENDDEFINE» «DEFINE Root FOR State» <li>State «name»«IF initial» [initial state]«ENDIF»</li>«ENDDEFINE» «DEFINE Root FOR Transition» <li>Transition «from.name» --> «to.name»</li>«ENDDEFINE» «DEFINE Root FOR EntityObject» «ENDDEFINE»
Next chapter: Model-to-Model (M2M)