| Scott Finnie |
 |
Tuesday, July 03 2007 @ 09:14 AM CEST (Read 1225 times) |
|
|

User
Status: offline
Registered: 06/18/07
Posts: 18
|
Hi,
Just started my first oaw project and have a couple of basic questions. I've based my project on the uml2 example (oaw4.demo.emf.uml2.generator)
My first question relates to metamodel expressions in the xpand template. Which uml2 metamodel definition should I use for writing clauses? For example, I want to access associations in the model, so I tried the following:
«DEFINE Root FOR uml::Model»
«EXPAND PackageRoot FOREACH (List[uml::Package])ownedElement»
«ENDDEFINE»
«DEFINE PackageRoot FOR uml::Package»
«FILE name+".txt"»
«EXPAND AssociationRoot FOREACH (List[uml::Association])ownedAssociation»
«ENDFILE»
«ENDDEFINE»
...
However the editor gives an error on the second FOREACH clause. I'm assuming it's because either uml:Association or ownedAssociation isn't valid (they're based on nothing more than vague recollection of the uml metamodel). Should I use the uml metamodel from the omg website as a reference, or is there something better? (e.g. directly based on the eclipse uml2 definition?)
The second question is around type selection. I added some primitive types to the example model in the project, and when I run the workflow I get the following error:
1942 ERROR - No Definition 'PackageRoot for uml::PrimitiveType' found!
I'm not sure why I get this error. The model has primitive types in it, but none of my template selection clauses mention PrimitiveType. So I assumed xpand would quietly ignore them. That doesn't seem to be the case, or am I missing something?
Thanks in advance for any help.
- Scott.
|
| |
|
|
| Karsten Thoms |
 |
Tuesday, July 03 2007 @ 09:44 AM CEST |
|
|
 Status: online
Registered: 07/20/05
Posts: 1849
|
Hi Scott,
uml::Package does not define ownedAssociation, only an operation ownedAssociations which takes a Class instance as parameter. You could use this:
«DEFINE Root FOR uml::Model»
«EXPAND PackageRoot FOREACH ownedElement.typeSelect(Package)»
«ENDDEFINE»
«DEFINE PackageRoot FOR uml::Package»
«FILE name+".txt"»
«EXPAND AssociationRoot FOREACH packagedElement.typeSelect(Association)»
«ENDFILE»
«ENDFILE»
This template won't do recursion into package hierarchies. You probably want to do that. So you could Expand PackageRoot for all packagedElements of type Package.
I'm not sure why I get this error. The model has primitive types in it, but none of my template selection clauses mention PrimitiveType. So I assumed xpand would quietly ignore them. That doesn't seem to be the case, or am I missing something?
The association 'ownedElement' contains Package and PrimitiveType instances (and probably others as well). Xpand is statically typed and you need a definition for each possible type or reduce the sets to match your definitions, usually using typeSelect(). You should have the same error in your Xpand editor in the problems view.
HTH,
~Karsten
|
| |
|
|
| Scott Finnie |
 |
Tuesday, July 03 2007 @ 10:58 AM CEST |
|
|

User
Status: offline
Registered: 06/18/07
Posts: 18
|
Hi Karsten,
Thanks for the quick response.
Xpand is statically typed and you need a definition for each possible type or reduce the sets to match your definitions, usually using typeSelect().
OK, so if I understand correctly:
- FOREACH ownedElement.typeSelect(Package) will return only ownedElements of subtype package, but
- FOREACH (List[uml::Package])ownedElement will return all ownedElements irrespective of type.
If that's the case I'm not sure I understand what purpose the (List[uml::Package]) modifier fulfils? I assumed it served to restrict the collection in exactly the way your typeSelect() clause does. If not, what does it do? What advantage does it provide over FOREACH (List) ownedElement - or simply just FOREACH ownedElement?
One further question: what would you recommend as a reference for the uml2 metamodel? Thinking of class diagram(s) / xml schema / javadocs. Diagrams preferable, but accuracy more important.
Thanks again,
Scott.
|
| |
|
|
| Karsten Thoms |
 |
Tuesday, July 03 2007 @ 11:17 AM CEST |
|
|
 Status: online
Registered: 07/20/05
Posts: 1849
|
If that's the case I'm not sure I understand what purpose the (List[uml:Razzackage]) modifier fulfils? I assumed it served to restrict the collection in exactly the way your typeSelect() clause does. If not, what does it do? What advantage does it provide over FOREACH (List) ownedElement - or simply just FOREACH ownedElement?
It's just a hint. In case of EMF based models it is usually unnecessary, unless you really know that your collection will return only elements of the respective type. Then it is sufficient and slightly more performant, since it does not create a new list, while typeSelect() does. When working with JavaBeans based metamodels it is necessary, since Xpand does not know which elements are in a (untyped) collection.
One further question: what would you recommend as a reference for the uml2 metamodel? Thinking of class diagram(s) / xml schema / javadocs. Diagrams preferable, but accuracy more important.
Primary source is the UML2 superstructure. Further I look into the UML2 API reference, but usually less. Further you can refer to the UML2.ecore file, it is in the UML2 plugins.
HTH,
~Karsten
|
| |
|
|
| Scott Finnie |
 |
Tuesday, July 03 2007 @ 11:36 AM CEST |
|
|

User
Status: offline
Registered: 06/18/07
Posts: 18
|
Hi Karsten,
Thanks again for speedy response!
Regards,
Scott.
|
| |
|
|