Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Noob To OCL needs Help with XMI(Use OCL with XMI files)
Noob To OCL needs Help with XMI [message #1829249] Mon, 29 June 2020 15:48 Go to next message
gennaro esposito is currently offline gennaro espositoFriend
Messages: 2
Registered: June 2020
Junior Member
Hello! I'm new with OCL and I'm having some problems with it.
I have an xmi file from which I want to retrive some information using OCL. The thing is that when I create the OCL file from the xmi I have no reference to the xmi file or package (see screenshot).
Second problem is that my xmi file is structured in this way

<?xml version="1.0" encoding="ASCII"?>
<match:Root xmi:version="2.0" xmlns:xmi="" xmlns:match="">
<matches>
<metaclass href=""/>
<shapes href="Model\EditorSelector.xmi#//@contexts.0"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.1"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.2"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.3"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.4"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.5"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.6"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.7"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.8"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.9"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.10"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.11"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.12"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.13"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.14"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.15"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.16"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.17"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.18"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.19"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.20"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.21"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.22"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.23"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.24"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.25"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.26"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.27"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.28"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.29"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.30"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.31"/>
<shapes href="Model\EditorSelector.xmi#//@contexts.32"/>
</matches>


and I'm not able to count how many times a specific context(i.e. Context Image) occurs into my result.
When I use "self.matches.shapes" it returns me all the contexts found. Can anybody help me? Tnaks
Re: Noob To OCL needs Help with XMI [message #1829266 is a reply to message #1829249] Mon, 29 June 2020 20:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are right that OCL cannot access the XMI, since OCL like most modeling tools accesses models, which might come from an XMI file or a database or ....

Unfortunately OMG OCL has no ability to access metamodels. Eclipse OCL remedies this via an import tatement. Try adding import 'Model/editor.ecore'

You might also try following the tutorials that will show this to you and how to use the Xtext OCL Console to practice OCL expression evaluation.

Regards

Ed Willink
Re: Noob To OCL needs Help with XMI [message #1829290 is a reply to message #1829266] Tue, 30 June 2020 15:09 Go to previous messageGo to next message
gennaro esposito is currently offline gennaro espositoFriend
Messages: 2
Registered: June 2020
Junior Member
Thanks for your reply. Can I use OCL command line to make some sort of "query" to count the occurency of a certain name?
I was trying something like:

for each self.matches.shapes{
if self.matches.shapes.name='Metaclass'
then count +1
else count;
}
return count

is that possible into the OCL console?
Re: Noob To OCL needs Help with XMI [message #1829295 is a reply to message #1829290] Tue, 30 June 2020 20:25 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

I suggest you read the Warner and Kleppe book to find out about the power OCL. You are trying to write imperative Java which is impossible in a side effect free language.

Try something like.

self.matches.shapes->select(name='MetaClass')->count()

which you can of course practice in the OCL console.

Regards

Ed Willink
Previous Topic:eAllContents() or closure of eContents() in OCL
Next Topic:Looking for OCL Rules for BPMN
Goto Forum:
  


Current Time: Sun May 05 14:29:04 GMT 2024

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

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

Back to the top