Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » how to query xmi model-file
how to query xmi model-file [message #479173] Mon, 10 August 2009 02:26 Go to next message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
Hi,

I try to apply Jet on a very basic model containing orders with related
customers and attributes. How could I retrieve for a specific order(or for
all orders) the related customer (+ customer attributes) and the related
articles (+ article attributes). My xmi model and ecore meta-model are
included below. Any help would be very welcome.

kind regards
Aart

My xmi model is:
<?xml version="1.0" encoding="ASCII"?>
<OrderSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="www.acceleo.org/myDemo" xsi:schemaLocation="www.acceleo.org/myDemo
myDemo.ecore">
<orders id="XYZ001" customer="//@customers.0" articles="//@articles.0
//@articles.2 //@articles.3"/>
<orders id="XYZ002" customer="//@customers.2" articles="//@articles.2
//@articles.3"/>
<orders id="XYZ003" customer="//@customers.1" articles="//@articles.0
//@articles.3"/>
<orders id="XYZ004" customer="//@customers.0" articles="//@articles.2
//@articles.3 //@articles.1"/>
<customers name="customer 1" address="address of customer 1"/>
<customers name="customer 2" address="address of customer 2"/>
<customers name="customer 3" address="address of customer 3"/>
<articles description="article 1" price="25.0"/>
<articles description="article 2" price="12.5"/>
<articles description="article 3" price="35.0"/>
<articles description="article 4" price="49.95"/>
</OrderSystem>

My ecore model is:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myDemo"
nsURI="www.acceleo.org/myDemo" nsPrefix="">
<eClassifiers xsi:type="ecore:EClass" name="OrderSystem">
<eStructuralFeatures xsi:type="ecore:EReference" name="orders"
upperBound="-1"
eType="#//Order" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="customers"
upperBound="-1"
eType="#//Customer" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="articles"
upperBound="-1"
eType="#//Article" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Order">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="customer"
lowerBound="1"
eType="#//Customer"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="articles"
upperBound="-1"
eType="#//Article"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Customer">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="address"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Article">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="description"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="price"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
</eClassifiers>
</ecore:EPackage>
Re: how to query xmi model-file [message #479196 is a reply to message #479173] Mon, 10 August 2009 05:06 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1048
Registered: July 2009
Senior Member

Hi,

I'm not sure if this help you but here is a tutorial which uses an EMF
model, access different model elements and creates HTML as output.
Perhaps it gives you some hints for want you want to do.

http://www.vogella.de/articles/EclipseJET/article.html

Best regards, Lars

aart matsinger wrote:
> Hi,
>
> I try to apply Jet on a very basic model containing orders with related
> customers and attributes. How could I retrieve for a specific order(or
> for all orders) the related customer (+ customer attributes) and the
> related articles (+ article attributes). My xmi model and ecore
> meta-model are included below. Any help would be very welcome.
>
> kind regards
> Aart
>
> My xmi model is:
> <?xml version="1.0" encoding="ASCII"?>
> <OrderSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="www.acceleo.org/myDemo"
> xsi:schemaLocation="www.acceleo.org/myDemo myDemo.ecore">
> <orders id="XYZ001" customer="//@customers.0" articles="//@articles.0
> //@articles.2 //@articles.3"/>
> <orders id="XYZ002" customer="//@customers.2" articles="//@articles.2
> //@articles.3"/>
> <orders id="XYZ003" customer="//@customers.1" articles="//@articles.0
> //@articles.3"/>
> <orders id="XYZ004" customer="//@customers.0" articles="//@articles.2
> //@articles.3 //@articles.1"/>
> <customers name="customer 1" address="address of customer 1"/>
> <customers name="customer 2" address="address of customer 2"/>
> <customers name="customer 3" address="address of customer 3"/>
> <articles description="article 1" price="25.0"/>
> <articles description="article 2" price="12.5"/>
> <articles description="article 3" price="35.0"/>
> <articles description="article 4" price="49.95"/>
> </OrderSystem>
>
> My ecore model is: <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="myDemo"
> nsURI="www.acceleo.org/myDemo" nsPrefix="">
> <eClassifiers xsi:type="ecore:EClass" name="OrderSystem">
> <eStructuralFeatures xsi:type="ecore:EReference" name="orders"
> upperBound="-1"
> eType="#//Order" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="customers"
> upperBound="-1"
> eType="#//Customer" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="articles"
> upperBound="-1"
> eType="#//Article" containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Order">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="id"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="customer"
> lowerBound="1"
> eType="#//Customer"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="articles"
> upperBound="-1"
> eType="#//Article"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Customer">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="address"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Article">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="description"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="price"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
> </eClassifiers>
> </ecore:EPackage>
>




--
http://www.vogella.de/ - Eclipse plugin and Eclipse RCP Tutorials
http://www.twitter.com/vogella - vogella on Twitter
Re: how to query xmi model-file [message #479289 is a reply to message #479173] Mon, 10 August 2009 11:07 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Aart:

This has to be the #1 JET question, so I have finally put together a JET FAQ page, which hopefully explains it all:

http://wiki.eclipse.org/M2T-JET-FAQ/How_do_I_navigate_an_XMI _model_with_JET%3F

Paul
Re: how to query xmi model-file [message #479439 is a reply to message #479289] Tue, 11 August 2009 01:18 Go to previous messageGo to next message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
Paul,

Thanks for your clear explanantion. I think it is very helpful for new
users (like me) to find an example together with this level of explanation.
Although a well chosen example in itself is very valuable, in this form it
has maximal educational impact.

Aart
Re: how to query xmi model-file [message #479454 is a reply to message #479289] Tue, 11 August 2009 03:29 Go to previous messageGo to next message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
Paul,

When I execute the jet-file (first one since I have JET0.9.2) I get the
msg:
templates/orders.jet(6,26): <c:get select="$order/customer/@name">
Error: XPath expression returned no result
Moreover in the produced output the articles for the orders are missing,
so it seems that the iterate for order-articles yields nothing.
The order-id's are present in the output.
Does this mean that the model loader cannot find the ecore file?
I did create the ecore file in a different project. What is needed to let
the model loader find this ecore file ?

kind regards
Aart
Re: how to query xmi model-file [message #479574 is a reply to message #479454] Tue, 11 August 2009 11:34 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Aart:

This happens if you have not specified the org.eclipse.jet.emf model loader in plugin.xml. See:

http://wiki.eclipse.org/JET_FAQ_What_kind_of_input_model_can _JET_handle%3F#Model_loaders

Also, I have updated the FAQ page with complete JET transformations you can run (and dissect). Again, the link to the FAQ page is:

http://wiki.eclipse.org/M2T-JET-FAQ/How_do_I_navigate_an_XMI _model_with_JET%3F

If the time gods permit, I'll try to put together a short tutorial on this in the coming weeks. Your feed back is certainly appreciated.

Paul
Re: how to query xmi model-file [message #479750 is a reply to message #479574] Wed, 12 August 2009 07:00 Go to previous message
aart matsinger is currently offline aart matsinger
Messages: 12
Registered: July 2009
Junior Member
Paul,

The zip-example works well. I only needed to adapt the manifest file by
removing the bundle-version constraints since these caused a blocking
error msg.
I am looking forward to your tutorial.


kind regards
Aart
Previous Topic:[Announce] M2T XPAND 0.7.2 is available
Next Topic:resolving cross-references to imported model in xpand/xtend
Goto Forum:
  


Current Time: Thu Jul 24 23:45:30 EDT 2014

Powered by FUDForum. Page generated in 0.06609 seconds