Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Creating an OCLExpression expensive?
Creating an OCLExpression expensive? [message #1058834] Wed, 15 May 2013 10:50 Go to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Hi there,

Here is my XML model:

<?xml version="1.0" encoding="UTF-8"?>
<Device xmlns="model" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="dd" comment="">
<HeadModule orderNumber="328061"/>
<Modules xsi:type="Module" number="1" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="2" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="3" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="4" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="5" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="6" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="7" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="8" deviceType="49157" orderNumber="328095"/>
<Modules xsi:type="Module" number="9" deviceType="15" orderNumber="328301"/>
<Modules xsi:type="Module" number="10" deviceType="15" orderNumber="328301"/>
<Modules xsi:type="NullModule" number="11"/>
<Modules xsi:type="NullModule" number="12"/>
<BackPlanes orderNumber="321702"/>
<BackPlanes orderNumber="321702"/>
<BackPlanes orderNumber="321702"/>
</Device>



I create an OCL query and execute that over an EObject called Device (above XML EObject).

Sample code:
// create OCL instance for Ecore
OCL ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);

// create OCL helper
OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper = ocl
.createOCLHelper();

// set OCL context classifier
helper.setContext(ModelPackage.Literals.DEVICE);
// helper.setInstanceContext(ModelPackage.Literals.DEVICE__MODULES);
helper.setInstanceContext(device);

// create query
OCLExpression<EClassifier> query = helper
.createQuery("self.Modules->select(m|m.number<>null)->size()");

// use the query expression parsed before to create a Query
Query eval = ocl.createQuery(query);
int result = (Integer) eval.evaluate(device);


This is working fine, but helper.createQuery() statement takes about 20 seconds.
Am I doing something wrong in this code? or Someone has a solution to this issue?


Thanks in advance.
Kosala
Re: Creating an OCLExpression expensive? [message #1059237 is a reply to message #1058834] Fri, 17 May 2013 12:50 Go to previous message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member

Updating the eclipse PDE class path with all dependent jars (jars required for OCL) solved the problem.

Thanks
Re: Creating an OCLExpression expensive? [message #1059272 is a reply to message #1058834] Wed, 15 May 2013 11:01 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4056
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi<br>
<br>
Further to my response to a less detailed question on the OCL
newsgroup.<br>
<br>
From the OCL documentation:<br>
<br>
<div class="titlepage">
<div>
<div>
<h2 style="clear: both;" class="title"><a name="Standalone"></a>Ecore/UML
Standalone Configuration</h2>
</div>
</div>
</div>
<p>If you use Eclipse OCL within Eclipse you should find that the
appropriate registrations are provided for you automatically by
the plugin registration mechanisms.</p>
<p>However if you use Eclipse OCL outside Eclipse, for instance in
JUnit tests, you must provide the corresponding registrations in
your code.</p>
<div class="section" title="Ecore">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a name="Ecore"></a>Ecore</h3>
</div>
</div>
</div>
<p>For the Ecore metamodel, the required registrations should be
provided by invoking <code class="code">org.eclipse.ocl.ecore.OCL.initialize(ResourceSet)</code>.</p>
</div>
---<br>
<br>
I see no use of <code class="code">OCL.initialize</code> so I
suspect that you are incurring Internet failures on unregistered
nsURIs.<br>
<br>
    Regards<br>
<br>
        Ed Willink<br>
<br>
    <br>
On 15/05/2013 11:50, Kosala Yapa wrote:
<blockquote cite="mid:kmvp9l$ul7$1@xxxxxxxxe.org" type="cite">Hi
there,
<br>
<br>
Here is my XML model:
<br>
<br>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<br>
&lt;Device xmlns="model" xmi:version="2.0"
xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a> name="dd"
comment=""&gt;
<br>
&lt;HeadModule orderNumber="328061"/&gt;
<br>
&lt;Modules xsi:type="Module" number="1" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="2" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="3" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="4" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="5" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="6" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="7" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="8" deviceType="49157"
orderNumber="328095"/&gt;
<br>
&lt;Modules xsi:type="Module" number="9" deviceType="15"
orderNumber="328301"/&gt;
<br>
&lt;Modules xsi:type="Module" number="10" deviceType="15"
orderNumber="328301"/&gt;
<br>
&lt;Modules xsi:type="NullModule" number="11"/&gt;
<br>
&lt;Modules xsi:type="NullModule" number="12"/&gt;
<br>
&lt;BackPlanes orderNumber="321702"/&gt;
<br>
&lt;BackPlanes orderNumber="321702"/&gt;
<br>
&lt;BackPlanes orderNumber="321702"/&gt;
<br>
&lt;/Device&gt;
<br>
<br>
<br>
<br>
I create an OCL query and execute that over an EObject called
Device (above XML EObject).
<br>
<br>
Sample code:
<br>
// create OCL instance for Ecore
<br>
OCL ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
<br>
<br>
// create OCL helper
<br>
OCLHelper&lt;EClassifier, EOperation, EStructuralFeature,
Constraint&gt; helper = ocl
<br>
createOCLHelper();
<br>
<br>
// set OCL context classifier
<br>
helper.setContext(ModelPackage.Literals.DEVICE);
<br>
//
helper.setInstanceContext(ModelPackage.Literals.DEVICE__MODULES);
<br>
helper.setInstanceContext(device);
<br>
<br>
// create query
<br>
OCLExpression&lt;EClassifier&gt; query = helper
<br>
createQuery("self.Modules-&gt;select(m|m.number&lt;&gt;null)-&gt;size()");
<br>
<br>
// use the query expression parsed before to create a Query
<br>
Query eval = ocl.createQuery(query);
<br>
int result = (Integer) eval.evaluate(device);
<br>
<br>
<br>
This is working fine, but helper.createQuery() statement takes
about 20 seconds. Am I doing something wrong in this code? or
Someone has a solution to this issue?
<br>
<br>
<br>
Thanks in advance.
<br>
Kosala
<br>
</blockquote>
<br>
</body>
</html>
Previous Topic:EMF Languge Pack do not work
Next Topic:[CDO] To know if a Resource is being modified by others
Goto Forum:
  


Current Time: Tue Sep 30 11:50:15 GMT 2014

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

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