Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » JET: navigating to references for EMF-models
JET: navigating to references for EMF-models [message #61221] Wed, 13 May 2009 11:11 Go to next message
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009
Member
hi,

in
http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse. jet.doc/tasks/usingJetWithEMF.xhtml
it says:
"Each EReference feature on an object is mapped to an element with the
same name. If $class refers to an EObject with an EReference
ownedAttributes, then $class/ownedAttributes will return all the elements
in that collection. "

I want to do that. I did add "modelLoader="org.eclipse.jet.emf" the
plugin.xml.

My model (file-name: My.carpool) is:
<?xml version="1.0" encoding="UTF-8"?>
<carpool:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:carpool="http://de/tuberlin/swt/car.ecore">
<car name="TrabbiNew" price="2500" basedOn="//@car.1"
wheels="//@wheel.0"/>
<car name="TrabbiOld" price="600" wheels="//@wheel.1"/>
<wheel name="GoodWheel" price="300"/>
<wheel name="BadWheel" price="400"/>
</carpool:Model>

In my template, that works: <c:get select="//car[1]/@name" /> .

But that does not work:
- <c:get select="//car[2]/wheels[1]/@name" />

So how can I navigate to instances, which are references by EReference in
the metamodel? Do I maybe have to let JET know the .ecore metamodel
somehow? Or is there no easy way to navigate and I misunderstood the
tutorial?


thank you
Re: JET: navigating to references for EMF-models [message #61292 is a reply to message #61221] Fri, 15 May 2009 13:32 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Usul wrote:
> snip...

> In my template, that works: <c:get select="//car[1]/@name" /> .
>
> But that does not work: - <c:get select="//car[2]/wheels[1]/@name" />
>
> So how can I navigate to instances, which are references by EReference
> in the metamodel? Do I maybe have to let JET know the .ecore metamodel
> somehow? Or is there no easy way to navigate and I misunderstood the
> tutorial?
>

My guess is that JET did not find your .ecore model. When JET attempts
to load an EMF model, it uses the file extension to search in the EMF
Resource.Factory.Registry.INSTANCE to find a resource factory. Factories
specify to individual file extensions can be registered via the
org.eclipse.emf.ecore.extension_parser extension point.

But, for ECore models serialized as XMI (such as yours), this is often
unnecessary. If a extension specific factory is not found, JET will use
a generic XMI resource factory.

The generic XMI resource factory looks that the namespace URI in your
model, and attempts to find it in the EPackage.Registry.INSTANCE. If
you have generated Java code form your .ecore model (and that plug-in is
installed), your package is registered.

But, if your .ecore model is 'under development', and lives in your
workspace along with your JET transformation, then EMF will not find the
namespace URI in the Package registry. In that case, EMF make use of XSI
schema location information in the root element in the document.

<carpool:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:carpool="http://de/tuberlin/swt/car.ecore"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://de/tuberlin/swt/car.ecore
your-location-for-car.ecore"
>

Failing all this, I think EMF may just treat the XMI as a plan XML document.

What happens if you evaluate:
<c:get select="//car[2]/@wheels" />

If you are getting a result, then that's an indication that the .ecore
package information wasn't found.

Hope this helps,

Paul
Re: JET: navigating to references for EMF-models [message #62410 is a reply to message #61292] Tue, 09 June 2009 15:42 Go to previous message
Miguel Angel Garcia de Dios is currently offline Miguel Angel Garcia de DiosFriend
Messages: 22
Registered: July 2009
Junior Member
Hi everyone,
I am try to apply your solution, I mean, I have my gui.ecore model and,
after de classical process of generating code automatically and
launching it as an Eclipse Application, I also have generated my
bank.gui model (which is an instance of my gui.ecore built sing the
generated editor). Now, in that Eclipse aplication launched from my
original Eclipse. When i launch the JET Transformation, I set bank.gui
as transformation input and I receive this message:
"Error: Feature 'version' not found.
(platform:/resource/jet.example/models/bank.gui, 2, 146)"

The XMI file of my model instance is this:
<?xml version="1.0" encoding="UTF-8"?>
<gui:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gui="http://gui/1.0">
<allWidgets xsi:type="gui:Window" label="MainMenuWindow"
widgetActions="//@allGActions.0" contained="//@allWidgets.2
//@allWidgets.3 //@allWidgets.1"/>
<allWidgets xsi:type="gui:Button" label="UserMenuMainMenuButton"
widgetEvents="//@allEvents.0" container="//@allWidgets.0"/>
<allWidgets xsi:type="gui:Button" label="AccountMenuMainMenuButton"
widgetEvents="//@allEvents.1" container="//@allWidgets.0"/>
<allWidgets xsi:type="gui:Button" label="ExitMainMenuButton"
widgetEvents="//@allEvents.2" container="//@allWidgets.0"/>
<allWidgets xsi:type="gui:Window" label="UserMenuWindow"
widgetActions="//@allGActions.1 //@allGActions.2"
contained="//@allWidgets.8 //@allWidgets.5 //@allWidgets.7
//@allWidgets.6"/>
<allWidgets xsi:type="gui:Button" label="CreateUserUserMenuButton"
widgetEvents="//@allEvents.3" container="//@allWidgets.4"/>
<allWidgets xsi:type="gui:Button" label="EditUserUserMenuButton"
widgetEvents="//@allEvents.4" container="//@allWidgets.4"/>
<allWidgets xsi:type="gui:Button" label="DeleteUserUserMenuButton"
widgetEvents="//@allEvents.5" container="//@allWidgets.4"/>
<allWidgets xsi:type="gui:Button" label="BackUserMenuButton"
widgetEvents="//@allEvents.6" container="//@allWidgets.4"/>
<allWidgets xsi:type="gui:Window" label="CreateUserWindow"
widgetActions="//@allGActions.3 //@allGActions.4"
contained="//@allWidgets.12 //@allWidgets.10 //@allWidgets.11"/>
<allWidgets xsi:type="gui:Button"
label="CreateCashierCreateUserButton" widgetEvents="//@allEvents.7"
container="//@allWidgets.9"/>
<allWidgets xsi:type="gui:Button"
label="CreateClientCreateUserButton" widgetEvents="//@allEvents.8"
container="//@allWidgets.9"/>
<allWidgets xsi:type="gui:Button" label="BackCreateUserButton"
widgetEvents="//@allEvents.9" container="//@allWidgets.9"/>
<allWidgets xsi:type="gui:Window" label="CreateCashierWindow"
widgetActions="//@allGActions.9 //@allGActions.10"
contained="//@allWidgets.17 //@allWidgets.16 //@allWidgets.14
//@allWidgets.15"/>
....

Thank you
Paul Elder wrote:
>
>
> Usul wrote:
>> snip...
>
>> In my template, that works: <c:get select="//car[1]/@name" /> .
>>
>> But that does not work: - <c:get select="//car[2]/wheels[1]/@name" />
>>
>> So how can I navigate to instances, which are references by EReference
>> in the metamodel? Do I maybe have to let JET know the .ecore
>> metamodel somehow? Or is there no easy way to navigate and I
>> misunderstood the tutorial?
>>
>
> My guess is that JET did not find your .ecore model. When JET attempts
> to load an EMF model, it uses the file extension to search in the EMF
> Resource.Factory.Registry.INSTANCE to find a resource factory. Factories
> specify to individual file extensions can be registered via the
> org.eclipse.emf.ecore.extension_parser extension point.
>
> But, for ECore models serialized as XMI (such as yours), this is often
> unnecessary. If a extension specific factory is not found, JET will use
> a generic XMI resource factory.
>
> The generic XMI resource factory looks that the namespace URI in your
> model, and attempts to find it in the EPackage.Registry.INSTANCE. If
> you have generated Java code form your .ecore model (and that plug-in is
> installed), your package is registered.
>
> But, if your .ecore model is 'under development', and lives in your
> workspace along with your JET transformation, then EMF will not find the
> namespace URI in the Package registry. In that case, EMF make use of XSI
> schema location information in the root element in the document.
>
> <carpool:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:carpool="http://de/tuberlin/swt/car.ecore"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://de/tuberlin/swt/car.ecore
> your-location-for-car.ecore"
> >
>
> Failing all this, I think EMF may just treat the XMI as a plan XML
> document.
>
> What happens if you evaluate:
> <c:get select="//car[2]/@wheels" />
>
> If you are getting a result, then that's an indication that the .ecore
> package information wasn't found.
>
> Hope this helps,
>
> Paul
Previous Topic:[M2T] How to achieve a general goal
Next Topic:[Announce] M2T XPAND 0.7.0RC4 is available
Goto Forum:
  


Current Time: Sat Nov 22 17:03:05 GMT 2014

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

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