Home » Modeling » M2T (model-to-text transformation) » JET beginner question
JET beginner question [message #46232] |
Thu, 22 May 2008 06:01  |
Eclipse User |
|
|
|
Hi all,
I'm new to JET but familiar with the UML Superstructure, I think. I have
to generate a little Swing application from a UML UseCase diagram, in
which the Use Cases should appear as the application's menu structure.
I've researched a lot about JET, but I found so many different
approaches like JET1, JET2 or the programmatically conversion fromt he
UML model into a intermediate model, which should be passed to the JET
engine.
Before running in the wrong direction, I wanted to ask all of the
advanced JET guys here for the best way. Does anybody can give me a hint?
Thx a lot
tm
|
|
|
Re: JET beginner question [message #46257 is a reply to message #46232] |
Thu, 22 May 2008 09:12   |
Eclipse User |
|
|
|
Timothy:
Let me summarize the approaches you mention.
1) JET1. You access your model using embedded Java, so you must have
familiarity with the UML APIs. In addition, JET1 provides no support for
writing files, so you need to know how to create Eclipse plug-ins and how
to use the Eclipse workspace APIs to save your results.
2) JET2 directly against a UML2 model. Again, you need to understand the
UML meta-model/APIs. Also, JET2 doesn't have built-in capabilities to
access Stereotype applications - you'd have to write XPath functions to
get access. I know of at least one user who wrote custom JET tags to
access the model via OCL. Key for success here: familiarity with UML2
3) JET2 against a simplified intermediate model chained with a
UML2-to-intermediate model transformation. This is the approach I
generally recommend because I believe it provides a good separation of
concerns:
* hide the complexities of UML from the code generator/templates
* an opporutunity to "de-normalize" the UML representation to simplify
code generation (as a motivator take a look at how UML2 represents
documentation on a model element).
* isolate the code generator from changes in representation. In my
experience, the UML representation is a much more challenging thing for
many people to build (many don't even know what the UML superstructure
is). It is not uncommon for that representation to evolve as experience is
gained.
As a downside, there is added complexity in introducing a model-to-model
transformation.
If you happen to be using my employer's products (IBM Rational), there is
a recently published 'Redbook' that covers this topic in some detail. If
you're interested, go directly to part 4.
http://www.redbooks.ibm.com/redpieces/abstracts/sg247529.htm l?Open
Paul
|
|
|
Re: JET beginner question [message #46313 is a reply to message #46257] |
Thu, 22 May 2008 10:32   |
Eclipse User |
|
|
|
Dear Paul,
thanks for your suggestions. The intermediate model, that only focusses
the generation-relevant information is a good way i think, even if it is
a bit of redundant work, because every information one need for the
generation is found in the UML meta-model.
However, I was wondering about that you said, that JET is not able to
create files. Another need for the university is to create all the code
from an UML class model, so i have to write a lot of different files,
classes, interfaces, abstract classes, enumerations, etc. I think you
know what i mean.
My first idea was:
1. Create the intermediate model and store all elements, which are
commonly created in separate files (classes, interfaces, etc.)in a vector.
2. Define several templates for classes, interfaces, enumerations
3. Pass the elements in the to-generated-vector to the templates,
depending on their kind. Write the generated string programmatically to
files.
Is the complettly non-sense or even undoable with JET? I don't want to
create a plugin but a standalone java/swing-application.
Thx again.
--tm
Paul Elder schrieb:
> Timothy:
>
> Let me summarize the approaches you mention.
>
> 1) JET1. You access your model using embedded Java, so you must have
> familiarity with the UML APIs. In addition, JET1 provides no support for
> writing files, so you need to know how to create Eclipse plug-ins and
> how to use the Eclipse workspace APIs to save your results.
>
> 2) JET2 directly against a UML2 model. Again, you need to understand the
> UML meta-model/APIs. Also, JET2 doesn't have built-in capabilities to
> access Stereotype applications - you'd have to write XPath functions to
> get access. I know of at least one user who wrote custom JET tags to
> access the model via OCL. Key for success here: familiarity with UML2
>
> 3) JET2 against a simplified intermediate model chained with a
> UML2-to-intermediate model transformation. This is the approach I
> generally recommend because I believe it provides a good separation of
> concerns:
> * hide the complexities of UML from the code generator/templates
> * an opporutunity to "de-normalize" the UML representation to simplify
> code generation (as a motivator take a look at how UML2 represents
> documentation on a model element).
> * isolate the code generator from changes in representation. In my
> experience, the UML representation is a much more challenging thing for
> many people to build (many don't even know what the UML superstructure
> is). It is not uncommon for that representation to evolve as experience
> is gained.
>
> As a downside, there is added complexity in introducing a model-to-model
> transformation.
>
> If you happen to be using my employer's products (IBM Rational), there
> is a recently published 'Redbook' that covers this topic in some detail.
> If you're interested, go directly to part 4.
>
> http://www.redbooks.ibm.com/redpieces/abstracts/sg247529.htm l?Open
>
> Paul
>
|
|
| |
Re: JET beginner question [message #46463 is a reply to message #46373] |
Wed, 28 May 2008 08:44   |
Eclipse User |
|
|
|
Dear Felix,
i've done it the way you've described and it works fine.
I'm curious about the JET2 template project. I think i will go on with this
version, because the template editor for JET1 projects are as useful as
notepad :) The jet2 project also seems to be not as fragile as the former
version.
Do you prefer JET2? IMHO, the xpath dependation is a kind a overhead
production, i think? But JET2 can iterate over any Ecore mm, right?
Cheers
timothy
"Felix Dorner" <felix_do@web.de> schrieb im Newsbeitrag
news:g14246$cp8$1@build.eclipse.org...
> Hi Timothy, we share the same boat. I have written a _very_ basic jet
> transformation directly against uml class models.
>
> What I did to make a direct transformation is to make extensive use of
> jet's ability to _annotate_ the model elements with additional variables.
> The general pattern is very well documented in the main.jet template which
> is automatically created when you start a new jet project.
>
> For the annotations, I give you an example:
>
> For mapping uml operations to method signatures, you'd need to do:
>
> for each parameter of the operation
> check out its multiplicity
> check out its type
> check out if it's a return or an argument.
>
> Doing all this directly in the output template makes it very hard to read.
> So I do an initial iteration over the model, and attach this data as ready
> to eat meatballs to every "operation" element.
|
|
| |
Re: JET beginner question [message #46782 is a reply to message #46664] |
Tue, 03 June 2008 04:32   |
Eclipse User |
|
|
|
Dear Paul,
what is the way to navigate through a UML Class diagramm, for example, with
JET2? May i have to browse the related XMI representation?
Thx
Timothy
"Paul Elder" <pelder@ca.ibm.com> schrieb im Newsbeitrag
news:g1mt78$93k$1@build.eclipse.org...
>
> "Timothy Marc" <timothymarc@freenet.de> wrote in message
> news:g1jk42$73u$1@build.eclipse.org...
>> Do you prefer JET2? IMHO, the xpath dependation is a kind a overhead
>> production, i think? But JET2 can iterate over any Ecore mm, right?
>
> Well, I prefer JET2, but I'm biased :-)
>
> But JET does read Ecore mm.
>
> I won't argue that XPath adds overhead. I'm sure it does. But the trade
> off is that templates can be written w/o Java code (not everyone who wants
> to write templates knows Java).
>
> If you want to write Java code in your templates, you can. All JET
> variables are accessible via
> context.getVariable("name-without-initial-$").
>
> You can import Java classes into a template with <%@jet imports="..." %>
> Remember to add appropriate depencies to MANIFEST.MF.
>
> Paul
>
|
|
| | |
Re: JET beginner question [message #46900 is a reply to message #46870] |
Wed, 04 June 2008 09:38  |
Eclipse User |
|
|
|
Timothy:
JET can traverse a UML2 model, and not by reading the XMI.
JET uses XPath, but the XPath engine is not bound to XML!
Here's how it works:
1) If a UML2 model is provided as the input for a JET2 transformation,
JET2 will find an EMF ResourceFactory to load the document. The end result
is an EMF Resource and a network of objects UML2 objects.
2) XPath expressions are applied against the in-memory UML2 objects using
the EMF reflective APIs as follows:
* an initial XPath / corresponds to the EMF Resource object
* the direct contents of the resource can be accessed by the special
expression:
/contents
typically, this would return a Model or Package instance
* You can also match the root contents of the loaded model my using the
EMF type you expect. For example:
/Model
will match a Model instance.
* Assuming you have matched some element in the model, you can use an
XPath step to match the following:
* a 'child' step will match EReference features of an object (whether
containment or not). So, if $class was Class instance, then:
$class/ownedAttributes
would return a colleciton of Property objects. You could also use the
following expression:
$class/Property
which would match all the instances of Property in the eContents of $class
An example of following a non-containment feature:
$class/ownedAttributes[@name = 'foo']/type/@name
Here, the 'type' step matches a non-containment feature for Property.
* an 'attribute' step will match EAttribute features of an object.
Other tricks:
* You can used self:: steps to filter types:
$package/packagedElements[self::Class]
will return all the Class instances contained by a package.
The only limitation on JET2s access of UML is that it cannot access
stereotype information. There have been other posts on this group about
how XPath functions can be created that would provide this information.
Paul
|
|
|
Goto Forum:
Current Time: Wed May 07 22:17:27 EDT 2025
Powered by FUDForum. Page generated in 0.03856 seconds
|