Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Using OCL with EMF Profiles(Evaluate OCL constraints on a Stereotyped Ecore Model with EMF Profiles)
Using OCL with EMF Profiles [message #1702208] Mon, 20 July 2015 16:09 Go to next message
Daria Giacinto is currently offline Daria GiacintoFriend
Messages: 7
Registered: July 2015
Junior Member
Hello,

I am trying to evaluate programmatically OCL constraints on models defined by an own Ecore meta model that is extended by EMF profiles . I implemented it regarding the Eclipse OCL documentation in Eclipse Mars Modeling Tools. It works in the restriced context of the stereotype application and the extended class when I set :

OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper = ocl.createOCLHelper();
helper.setInstanceContext(stereotypeApplication); 
or
helper.setContext(stereotypeApplication.getExtension().getTarget());


However, I cannot navigate from the StereotypeApplication to the extended Class.

E.g.: Defining a constraint:
invariant = helper.createInvariant('self.appliedTo.entityName');
or
invariant = helper.createInvariant('self.extension.target.entityName');

(appliedTo is the reference to the EObject and extension.target is the reference to the extended class)
Query constraintEvaluation = ocl.createQuery(invariant);


Check constraint:
constraintEvaluation.check(stereotypeApplication);


returns an Unrecognized variable: entityName

I was looking at customizing the environment and the pivot programmers guide but I am unsure how I can achieve that the stereotypes are included in the OCL constraint validation. Do I have to register the profiles? Or do I have to extend specific OCL classes? I would appreciate some hints in which direction I should go as I am not experienced in OCL programming.

Thank you,

Daria

Re: Using OCL with EMF Profiles [message #1702249 is a reply to message #1702208] Tue, 21 July 2015 04:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

What is an EMF Profile? Certainly not part of Ecore. I presume it is
something that you or a new project have added/are adding.

Profiles and Stereotypes are very underspecified for OCL and so the
implementation relies on implementation magic.

The Classic OCL approach of using Ecore/UML specialization with long
template argument lists is almost certainly going to need revision to
offer UML-like facilities not available with Ecore.

The new Pivot OCL approach has a shared pivot that supports profiles and
stereotypes, so you just need to extend the Ecore2AS loader to recognize
whatever Ecore extensions are in use to represent profiles.

So long as EMF profiles are not part of Ecore, the extension will have
to be an optional extension to Ecore, so that OCL continues to work with
Ecore alone.

In principle a variant of the extension point that makes UML optional
should enable some *.ecore++ support:

<extension point="org.eclipse.ocl.pivot.as_resource_factory">
<factory
class="org.eclipse.ocl.pivot.uml.internal.resource.UMLASResourceFactory"
extension="uml" contentType="org.eclipse.ocl.oclas.uml"
externalPriority="200"
resourceClass="org.eclipse.uml2.uml.resource.UMLResource"/>
</extension>

In practice, there will almost certaonly need to be some care with
meta-namespaces.

Ecore is coherent. http://www.eclipse.org/emf/2002/Ecore for Ecore and
http://www.eclipse.org/emf/2002/Ecore for its metamodel.

OMG UML is coherent. http://www.omg.org/spec/... for UML and
http://www.omg.org/spec/... for its metamodel.

Pivot OCL is coherent. http://www.eclipse.org/ocl/2015/Pivot for OCL and
http://www.eclipse.org/ocl/2015/Pivot for its metamodel.

However since stereotypes constraints are written against the metamodel
Eclipse UML2 requires special handling to accommodate:
http://www.eclipse.org/uml2/5.0.0/UML for UML but
{http://www.eclipse.org/emf/2002/Ecore,
http://www.eclipse.org/uml2/5.0.0/UML, http://www.omg.org/spec/...}

You may need similar special handling to accommodate a dual metamodel,
but this should at least be easier than a triple metamodel.

Regards

Ed Willink


On 20/07/2015 19:37, Daria Giacinto wrote:
> Hello,
>
> I am trying to evaluate programmatically OCL constraints on models
> defined by an own Ecore meta model that is extended by EMF profiles . I
> implemented it regarding the Eclipse OCL documentation in Eclipse Mars
> Modeling Tools. It works in the restriced context of the stereotype
> application and the extended class when I set :
>
> OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint>
> helper = ocl.createOCLHelper();
> helper.setInstanceContext(stereotypeApplication); or
> helper.setContext(stereotypeApplication.getExtension().getTarget());
>
> However, I cannot navigate from the StereotypeApplication to the
> extended Class.
> E.g.: Defining a constraint: invariant =
> helper.createInvariant('self.appliedTo.entityName'); or
> invariant = helper.createInvariant('self.extension.target.entityName');
> (appliedTo is the reference to the EObject and extension.target is the
> reference to the extended class)
> Query constraintEvaluation = ocl.createQuery(invariant);
>
> Check constraint:
> constraintEvaluation.check(stereotypeApplication);
>
> returns an Unrecognized variable: entityName
>
> I was looking at customizing the environment and the pivot programmers
> guide but I am unsure how I can achieve that the stereotypes are
> included in the OCL constraint validation. Do I have to register the
> profiles? Or do I have to extend specific OCL classes? I would
> appreciate some hints in which direction I should go as I am not
> experienced in OCL programming.
>
> Thank you,
>
> Daria
>
>
Re: Using OCL with EMF Profiles [message #1702916 is a reply to message #1702249] Mon, 27 July 2015 11:16 Go to previous messageGo to next message
Daria Giacinto is currently offline Daria GiacintoFriend
Messages: 7
Registered: July 2015
Junior Member
Thanks for your answer.

EMF profiles provide a meta model to extend an own ecore-based meta model. So, you can define profiles with stereotypes that extend a particular class of our meta-model. Afterwards, you can annotate a model element with such stereotype, i.e., a stereotype application is created that has a reference to this model element. When I set the context of the OCL helper to the stereotype application, I can only access properties of the applied model element by the use of an explicit type cast (oclAsType(appliedModelElement) . However, I also want to check whether a model element has a particular StereotypeApplication but currently they are not recognized, e.g., when I use oclIsTypeOf(StereotypeApplication).

Quote:
The new Pivot OCL approach has a shared pivot that supports profiles and
stereotypes, so you just need to extend the Ecore2AS loader to recognize
whatever Ecore extensions are in use to represent profiles.


What do I have to extend specifically from the Ecore2AS class in order that the stereotypes can be recognized? Are there examples available?

Or do I have to provide a metamodel binding, i.e., implement interfaces like Environment, EnvironmentFactory, EvaluationEnvironment as explained in the OCL Eclipse documentation (Classic Ecore Programmers Guide - Creating Metamodels Binding)?

My other idea is to customize the EcoreEnvironment and add a helper operation in Java to check whether a stereotype is applied. Would you recommend this approach?

Best regards

Daria
Re: Using OCL with EMF Profiles [message #1702921 is a reply to message #1702916] Mon, 27 July 2015 11:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

You seem to be a user hoping that something might work. You need the
OCL/EMF Profiles developers to do their job properly.

It would appear that EMF Profiles has given no consideration to OCL and
so you are in trouble.

Conversely EMF Profiles is not an Eclipse project and so Eclipse OCL has
no support.

You need to get the EMF Profiles developers to consider how they can
contribute to the larger Eclipse eco-system.

Regards

Ed Willink


On 27/07/2015 12:16, Daria Giacinto wrote:
> Thanks for your answer.
>
> EMF profiles provide a meta model to extend an own ecore-based meta
> model. So, you can define profiles with stereotypes that extend a
> particular class of our meta-model. Afterwards, you can annotate a
> model element with such stereotype, i.e., a stereotype application is
> created that has a reference to this model element. When I set the
> context of the OCL helper to the stereotype application, I can only
> access properties of the applied model element by the use of an
> explicit type cast (oclAsType(appliedModelElement) . However, I also
> want to check whether a model element has a particular
> StereotypeApplication but currently they are not recognized, e.g.,
> when I use oclIsTypeOf(StereotypeApplication).
> Quote:
>> The new Pivot OCL approach has a shared pivot that supports profiles
>> and stereotypes, so you just need to extend the Ecore2AS loader to
>> recognize whatever Ecore extensions are in use to represent profiles.
>
>
> What do I have to extend specifically from the Ecore2AS class in order
> that the stereotypes can be recognized? Are there examples available?
> Or do I have to provide a metamodel binding, i.e., implement
> interfaces like Environment, EnvironmentFactory, EvaluationEnvironment
> as explained in the OCL Eclipse documentation (Classic Ecore
> Programmers Guide - Creating Metamodels Binding)?
>
> My other idea is to customize the EcoreEnvironment and add a helper
> operation in Java to check whether a stereotype is applied. Would you
> recommend this approach?
>
> Best regards
> Daria
Re: Using OCL with EMF Profiles [message #1703046 is a reply to message #1702921] Tue, 28 July 2015 09:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

After googling EMF Profiles, it appears that

EMF Profiles has moved from EclipseLabs (deprecated) to GitHub (good)
EMF Profiles has had no commits for 2 years (worrying)
EMF Profiles installs and appears to run on Mars (good)
EMF Profiles provides no examples/tests demonstrating the EAnnotations (bad)

The tests demonstrating Profiles show an extension Ecore model strangely
embedded within a diagram.

Since there is a new model, it cannot be supported within Eclipse OCL.
But EMF Profiles already has a dependency on Eclipse OCL, so there
should be no problem in providing the required add-on functionality
within EMF Profiles.

Without any examples, I cannot be sure, but it is probably sufficient to
define a higher priority variant of

<extension point="org.eclipse.ocl.pivot.as_resource_factory">
<factory
class="org.eclipse.ocl.pivot.internal.ecore.EcoreASResourceFactory"
extension="ecore" contentType="org.eclipse.ocl.oclas.ecore"
externalPriority="100"/>
</extension>

that inspects the *.,ecore to see whether the EMF Profile overload of
org.eclipse.ocl.pivot.internal.ecore.EcoreASResourceFactory is needed to
redirect the Ecore2AS conversion to the EMF Profile overload of
org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2AS and friends.

The overloads need to ensure that EMF Profole's Stereotype etc are
converted to org.eclipse.ocl.pivot.Stereotype etc.

Regards

Ed Willink

On 27/07/2015 12:48, Ed Willink wrote:
> Hi
>
> You seem to be a user hoping that something might work. You need the
> OCL/EMF Profiles developers to do their job properly.
>
> It would appear that EMF Profiles has given no consideration to OCL
> and so you are in trouble.
>
> Conversely EMF Profiles is not an Eclipse project and so Eclipse OCL
> has no support.
>
> You need to get the EMF Profiles developers to consider how they can
> contribute to the larger Eclipse eco-system.
>
> Regards
>
> Ed Willink
>
>
> On 27/07/2015 12:16, Daria Giacinto wrote:
>> Thanks for your answer.
>>
>> EMF profiles provide a meta model to extend an own ecore-based meta
>> model. So, you can define profiles with stereotypes that extend a
>> particular class of our meta-model. Afterwards, you can annotate a
>> model element with such stereotype, i.e., a stereotype application is
>> created that has a reference to this model element. When I set the
>> context of the OCL helper to the stereotype application, I can only
>> access properties of the applied model element by the use of an
>> explicit type cast (oclAsType(appliedModelElement) . However, I also
>> want to check whether a model element has a particular
>> StereotypeApplication but currently they are not recognized, e.g.,
>> when I use oclIsTypeOf(StereotypeApplication).
>> Quote:
>>> The new Pivot OCL approach has a shared pivot that supports profiles
>>> and stereotypes, so you just need to extend the Ecore2AS loader to
>>> recognize whatever Ecore extensions are in use to represent profiles.
>>
>>
>> What do I have to extend specifically from the Ecore2AS class in
>> order that the stereotypes can be recognized? Are there examples
>> available?
>> Or do I have to provide a metamodel binding, i.e., implement
>> interfaces like Environment, EnvironmentFactory,
>> EvaluationEnvironment as explained in the OCL Eclipse documentation
>> (Classic Ecore Programmers Guide - Creating Metamodels Binding)?
>>
>> My other idea is to customize the EcoreEnvironment and add a helper
>> operation in Java to check whether a stereotype is applied. Would you
>> recommend this approach?
>>
>> Best regards
>> Daria
>
Re: Using OCL with EMF Profiles [message #1707098 is a reply to message #1703046] Wed, 02 September 2015 10:13 Go to previous messageGo to next message
Daria Giacinto is currently offline Daria GiacintoFriend
Messages: 7
Registered: July 2015
Junior Member
Hi,

I tried to follow your advice, but currently I am struggling to get my own ASResourceFactory called that is defined in the extension point. My ASResourceFactory extends AbstractASResourceFactory. I set the priority higher but the only message I get is "Both 'myPlugin' and 'org.eclipse.ocl.pivot' register an ASResourceFactory for 'org.eclipse.ocl.oclas.ecore'". Did I understand the 'content type' wrong and I have to provide something else? Or is the problem that I cannot extend the EcoreASResourceFactory because it is final?

Best regards

Daria
Re: Using OCL with EMF Profiles [message #1707110 is a reply to message #1707098] Wed, 02 September 2015 12:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

You need a distinct content type for a distinct content (additional EMF
Profile content).

(You are doing something new so it is possible that restrictions need to
be reviewed.)

Regards

Ed Willink


On 02/09/2015 11:13, Daria Giacinto wrote:
> Hi,
>
> I tried to follow your advice, but currently I am struggling to get my
> own ASResourceFactory called that is defined in the extension point.
> My ASResourceFactory extends AbstractASResourceFactory. I set the
> priority higher but the only message I get is "Both 'myPlugin' and
> 'org.eclipse.ocl.pivot' register an ASResourceFactory for
> 'org.eclipse.ocl.oclas.ecore'". Did I understand the 'content type'
> wrong and I have to provide something else? Or is the problem that I
> cannot extend the EcoreASResourceFactory because it is final?
>
> Best regards
> Daria
Re: Using OCL with EMF Profiles [message #1710069 is a reply to message #1707110] Sat, 03 October 2015 17:09 Go to previous messageGo to next message
Daria Giacinto is currently offline Daria GiacintoFriend
Messages: 7
Registered: July 2015
Junior Member
Hi,

regarding the content type: Can I choose the String arbitrary or are there any constraints? Up to now, I defined an arbitrary String in the plugin.xml.

Furthermore, I figured out that the ASResourceFactoryRegistryReader class reads the priority attribute from the extensions but it uses "priority" and not "externalPriority". I guess this is a bug? I changed it in my plugin.xml and now my ASResourceFactory is called.

I copied the methods from EcoreASResourceFactory to see how it works. However, no method of my ASResourceFactory is called, although it has the highest priority. I expected that the createResource method will be called like in the case of EcoreASResourceFactory and my extension of Ecore2AS . Instead, EcoreASResourceFactory and Ecore2AS are used. What are the reasons for this?

Best regards

Daria
Re: Using OCL with EMF Profiles [message #1710070 is a reply to message #1710069] Sat, 03 October 2015 17:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
https://wiki.eclipse.org/OCL/ForumNetiquette

On 03/10/2015 13:09, Daria Giacinto wrote:
> Hi,
>
> regarding the content type: Can I choose the String arbitrary or are
> there any constraints? Up to now, I defined an arbitrary String in the
> plugin.xml.
>
> Furthermore, I figured out that the ASResourceFactoryRegistryReader
> class reads the priority attribute from the extensions but it uses
> "priority" and not "externalPriority". I guess this is a bug? I changed
> it in my plugin.xml and now my ASResourceFactory is called.
>
> I copied the methods from EcoreASResourceFactory to see how it works.
> However, no method of my ASResourceFactory is called, although it has
> the highest priority. I expected that the createResource method will be
> called like in the case of EcoreASResourceFactory and my extension of
> Ecore2AS . Instead, EcoreASResourceFactory and Ecore2AS are used. What
> are the reasons for this?
>
> Best regards
>
> Daria
Re: Using OCL with EMF Profiles [message #1711306 is a reply to message #1710070] Wed, 14 October 2015 19:22 Go to previous messageGo to next message
Daria Giacinto is currently offline Daria GiacintoFriend
Messages: 7
Registered: July 2015
Junior Member
Hi,

I attached an example to show the different behavior on my own ASResourceFactory depending on using "priority" and "externalPriority" when using the extension point. I included a ReadMe to describe how to initiate the example plugin.

Best regards

Daria
Re: Using OCL with EMF Profiles [message #1711357 is a reply to message #1711306] Thu, 15 October 2015 09:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

Good repro. I see the same phenomenon in my workspace.

[Using JUnit rather than a nested command as the basis for a repro can
avoid the need for two Eclipse's and the second Eclipse startup time.]

Regards

Ed Willink


On 14/10/2015 20:22, Daria Giacinto wrote:
> Hi,
>
> I attached an example to show the different behavior on my own ASResourceFactory depending on using "priority" and "externalPriority" when using the extension point. I included a ReadMe to describe how to initiate the example plugin.
>
> Best regards
>
> Daria
Re: Using OCL with EMF Profiles [message #1711358 is a reply to message #1711357] Thu, 15 October 2015 09:57 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
On 15/10/2015 10:48, Ed Willink wrote:
> I see the same phenomenon in my workspace.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479841 raised.

Oops: the schema defines "externalPriority", but the code uses "priority".

Regards

Ed Willink
Re: Using OCL with EMF Profiles [message #1711409 is a reply to message #1711358] Thu, 15 October 2015 17:03 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5581
Registered: July 2009
Senior Member
Hi

After fixing the immediate bug in my workspace, your example hits an
assertion failure.

Unfortunately the notionally extensible design isn't.

"Re-useable code is not re-useable until has been re-used".

I've raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=479880 for you
but it's only an extension and I'm incredibly busy so no promises any
time soon.

If you want to investigate a patch yourself, I am not averse to removing
the "final" on classes that make extension impossible today.

Regards

Ed Willink


On 15/10/2015 10:57, Ed Willink wrote:
> On 15/10/2015 10:48, Ed Willink wrote:
>> I see the same phenomenon in my workspace.
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=479841 raised.
>
> Oops: the schema defines "externalPriority", but the code uses
> "priority".
>
> Regards
>
> Ed Willink
Previous Topic:Announce: Additional Luna maintenance release
Next Topic:Let statements for collection of collections
Goto Forum:
  


Current Time: Fri Jan 19 23:40:56 GMT 2018

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

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