Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ?
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #25647] Tue, 10 July 2007 12:25 Go to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Nicolas,

I'll redirect your question to the M2T newsgroup (it's on the "to" list
of the reply, so you don't have to repost) since your syntax implies to
me you are using JET2 syntax.


Nicolas Toublanc wrote:
> Hi,
>
> I'm trying to transform a RSA model using standard Eclipse
> transformation.
>
> With an ecore model (.emf) generated from a RSA model (.emx), that's
> working:
>
> "package mypackage;
> <%-- import the ecore namespace --%>
> <%@jet imports="org.eclipse.emf.ecore.*"%>
>
> <%-- import model helpers --%>
> <%@jet imports="mypackage.util.JavaJetUtil"%>
> /**
> * DTO that represents '<c:get select="$currentClass/@name" />' entity.
> *
> */
> public class <c:get select="$currentClass/@name" /> ..."
>
>
>
> What should I do to make it work directly with my .emx model?
>
>
>
> Regards,
>
> Nicolas
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #25986 is a reply to message #25647] Wed, 11 July 2007 15:43 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Nicolas:

Rational Software Architect .emx files are Ecore-based models. So, yes, JET
can read .emx (and for that matter .uml/.uml2) models. Here are some tips
for doing it...

1) Open plugin.xml on your JET transformation, switch the the Extensions
tab, expand 'org.eclipse.jet.transform', click '(transform)', and set the
modelLoader field to 'org.eclipse.jet.emf'.

2) The UML2 meta model is very large, and I find must users are not
intimately familiar with the navigation features. JET has a special XPath
enhancement to make life a little easier. An XPath step such as $parent/foo
is interpreted as "the contents of the EReference named 'foo' on the object
identified by $parent". But, if there is not 'foo' feature, JET will then
attempt to find a contained class of $parent (i.e. something in eContents())
whose eClass name is 'foo'. So, the following are equivalent:

/contents/nestedPackages/ownedTypes[@name =
'Person']/ownedAttributes[@name = 'address']/type/@name

/Model/Package/Class[@name = 'Person']/Property[@name =
'address']/type/@name

3) JET doesn't cannot access stereotypes or steroetype properties. If you
need, custom XPath functions could be created to access these.

But, one word of caution. Our (IBMs) best practices on code generation
recommends against writing code generators directly against UML models. The
reasons:
* Code generators (at least JET-based code generators) work best with models
tuned to the structure of the output (you could call this an Intermediate
Model). Things like 'flattened' package structures, and simplifications of
UML constructs (have you ever looked at how UML handles documentation of an
Element) are common.
* Often, an Intermediate Model is developed 'bottom up' from the artifacts
that need to be generated. In our experience, all but the most UML literate
have trouble mapping code generation requirements directly to UML. Indeed,
there are often multiple validate representations.

To turn this around, this is the best practice we recommend:
1) Separate the concerns of code generation from the concern of representing
the code generation abstractions to the user.
2) Create a code generator specific 'Intermediate Model' that represents
concepts needed to produce the desired artifacts.
3) Build a JET transformation that consumes this model. Once done, you have
a code generator that can be validated, and an abstraction of the code
generator concepts (the intermediate model). For many users, this is enough!
4) (If necessary) Establish a UI representation of the code generator
abstractions (as expressed in the intermediate model). Since you are
thinking UML, this would be a mapping from UML constructs to the
intermediate model. But, UML is not the only possibility. The ambious might
choose to implement a domain specific language (DSL) using GMF. Or, a wizard
might be the right tool.
5) Implement a mapping transformation from the UI representation to the
intermediate model, and then chain in the JET transformation as the last
step (so that user's do not have to see, or be aware of the JET
transformation).

Paul

P.S. I've created a few FAQ articles for posterity:
http://wiki.eclipse.org/JET_FAQ_Should_I_write_my_JET_code_g enerator_directly_against_UML2%3F
http://wiki.eclipse.org/JET_FAQ_What_kind_of_input_model_can _JET_handle%3F
http://wiki.eclipse.org/JET_FAQ_Can_JET_handle_UML_models_as _input%3F

> Nicolas Toublanc wrote:
>> Hi,
>>
>> I'm trying to transform a RSA model using standard Eclipse
>> transformation.
>>
>> With an ecore model (.emf) generated from a RSA model (.emx), that's
>> working:
>>
>> "package mypackage;
>> <%-- import the ecore namespace --%>
>> <%@jet imports="org.eclipse.emf.ecore.*"%>
>>
>> <%-- import model helpers --%>
>> <%@jet imports="mypackage.util.JavaJetUtil"%>
>> /**
>> * DTO that represents '<c:get select="$currentClass/@name" />' entity.
>> *
>> */
>> public class <c:get select="$currentClass/@name" /> ..."
>>
>>
>>
>> What should I do to make it work directly with my .emx model?
>>
>>
>>
>> Regards,
>>
>> Nicolas
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #26112 is a reply to message #25986] Thu, 12 July 2007 06:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: n.toublanc.laposte.net

Thank you Paul for such a interesting answer.

So, what about the intermediate model format ? I think it could be .emf
or .xml?

Actually I'm able to generate the .emf model from my .emx file doing:
[new] > "EMF Model" > [Next] > Import from IBM Rational Software Modeler
model...

But, how can I chain that transformation (UML2 to EMF) with the final
transformation (EMF to Java) ?
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #26236 is a reply to message #26112] Thu, 12 July 2007 12:06 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Nicolas:

Some answers, clarifications and suggestions:

Yes, you can use EMF or XML as an intermediate model. It will depend on what
technology you use for the UML-to-intermediate-model mapping. Often, EMF is
a good fit, as it can generate a Java API for the model, and has a rich
meta-model.

The EMF Model import from a RSA/RSM model lets you design you ECore model in
UML (as an alternative to using Rose, XSD, annotated Java). There is a
optional RSM UML profile (called ECore, I think) that contains stereotypes
to let you refine things. But, at the most basic, a UML Class becomes an
EClass, a UML Package becomes an EPackage, etc.

[Apologies to the non IBM community, the rest of this message is specific to
IBM product.]

The Rational tools include components for creating such transformation
chains. First, ensure that you have the optional 'Transformation Authoring'
component installed.

For creating JET transformations, there is a new project wizard "EMFT JET
Project with Exemplar Authoring". If you have the 7.0.0.2 or later
maintenance release, there is a tutorial in the Tutorial Gallery, under
Watch and Learn called "Create model-to-text transformations with JET".

For a 'mapping' transformation, there is a new project wizard "Model to
Model Mapping Transformation Project". This starts the plug-in project
wizard, to actually create a mapping transformation project, you must get to
the third panel of the wizard (Templates), select "Plug-in with
Transformation Mapping", and click Next. Mapping transformations use a
graphical editor to specify the mapping. I'm not aware of a tutorial yet.

Paul


"Nicolas Toublanc" <n.toublanc@laposte.net> wrote in message
news:f74jel$q2i$1@build.eclipse.org...
> Thank you Paul for such a interesting answer.
>
> So, what about the intermediate model format ? I think it could be .emf or
> .xml?
>
> Actually I'm able to generate the .emf model from my .emx file doing:
> [new] > "EMF Model" > [Next] > Import from IBM Rational Software Modeler
> model...
>
> But, how can I chain that transformation (UML2 to EMF) with the final
> transformation (EMF to Java) ?
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #26276 is a reply to message #26236] Thu, 12 July 2007 12:27 Go to previous messageGo to next message
Joe Toomey is currently offline Joe ToomeyFriend
Messages: 79
Registered: July 2009
Member
Paul Elder wrote:
>
> For creating JET transformations, there is a new project wizard "EMFT JET
> Project with Exemplar Authoring". If you have the 7.0.0.2 or later
> maintenance release, there is a tutorial in the Tutorial Gallery, under
> Watch and Learn called "Create model-to-text transformations with JET".

If you use the Rational tools and you do Jet template authoring, you owe
it to yourself to try this feature. I have used it to author a couple
of complicated patterns (after having written some by hand in the past),
and it easily saved me a factor of 10 in time and effort. This feature
rocks. Nice work Paul, Chris and the rest of your team!

--Joe
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #29262 is a reply to message #26276] Thu, 26 July 2007 15:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: n.toublanc.laposte.net

Hi,

Thanks again for your precious responses.

I was some busy with others projects, so I'm just coming back to JET.

I better understand the code generation philosophy, and I did some tries
with RSA plug-ins. However, I have some troubles with them:

-1- MODEL TO CODE generation (e.g. ".emf" to ".java" or ".xml" to
".java") (second step of generation chain)

I tried the RSA plug-in "EMFT JET Project with Exemplar Authoring",
using the tutorial. It's really interesting, because you can generate
complex jet template from ".java" target, enabling ".java" (in this
example) files generation from a XML model file.

Now, I would like to do the same using EMF model instead of XML one. I'm
not sure to really understand what is ".ecore" file. I can generate one
form my ".xsd" file. So, if ".ecore" is the equivalent of ".xsd", what
about the implementation (equivalent of ".xml" file) : ".ecore" too? How
to use it with authoring?

-2- MODEL TO MODEL generation (e.g. ".emx" to ".emf" or ".emx" to
".xml") (first step of generation chain)

Now that I've my expected intermediate model, I would like to generate
it from my UML model.

I tried to create a "Model to Model Mapping Transformation Project". The
visual user interface looks powerful, so I would like to generate my
intermediate model with this tool. But, how to use ".emx" in input
model? Then, how to test or run this plug-in?



Nicolas
Re: [JET] [RSA] How can I transform a Rational Software Architect model (.emx) using JET ? [message #30346 is a reply to message #29262] Tue, 07 August 2007 16:09 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Nicolas:

Sorry for the slow response. A special project and summer vacation mean I
have less time for the list this month.

Answers below:

> -1- MODEL TO CODE generation (e.g. ".emf" to ".java" or ".xml" to ".java")
> (second step of generation chain)
>
> Now, I would like to do the same using EMF model instead of XML one. I'm
> not sure to really understand what is ".ecore" file. I can generate one
> form my ".xsd" file. So, if ".ecore" is the equivalent of ".xsd", what
> about the implementation (equivalent of ".xml" file) : ".ecore" too? How
> to use it with authoring?
>

The file type bound to an Ecore model is controlled by .genmodel file
associated with the .ecore file when you create a an EMF project. Each
EPackage has a property All > Prefix. The associated file extension is the
lower case of this value.

Also, once you have generated the Model code, you can change (or add
additional file extension assosicates) by opening plugin.xml in the EMF
project, and modifying the org.eclipse.emf.ecore.extension_parser

<extension point="org.eclipse.emf.ecore.extension_parser">
<parser
type="fileExtensionYouWant"
class="a.value.you.should.not.change" />
</extension>

You can have multiple <parser> elements, if you like.

> -2- MODEL TO MODEL generation (e.g. ".emx" to ".emf" or ".emx" to ".xml")
> (first step of generation chain)
>
> Now that I've my expected intermediate model, I would like to generate it
> from my UML model.
>
> I tried to create a "Model to Model Mapping Transformation Project". The
> visual user interface looks powerful, so I would like to generate my
> intermediate model with this tool. But, how to use ".emx" in input model?
> Then, how to test or run this plug-in?

The labels on the New Transformation Mapping page are a little misleading.
While the buttons say "Add Model", the really mean "Add Meta-Model". An .emx
file confirms to the UML2 meta-model. If you click the Add Model button
(beside the Input Models box), then click "Browse Registered Packages", and
type *uml2 (to filter the list), you will see
http://www.eclipse.org/uml2/2.0.0/UML - select that.

Also, if your UML model uses profiles, you can select, those, too.

Finally, for more information on the Rational products, you might consider
looking that the IBM Rational forums, and web pages:

http://www.ibm.com/developerworks/forums/dw_forum.jsp?forum= 787&cat=24

and the web page:

http://www.ibm.com/developerworks/rational/products/patterns olutions/assets.html?S_TACT=105AGX15&S_CMP=LP

Paul
Previous Topic:Installing JET plugins in a separate directory
Next Topic:Getting Double Quotes in a string
Goto Forum:
  


Current Time: Wed Apr 24 23:58:46 GMT 2024

Powered by FUDForum. Page generated in 0.03261 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top