Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Referencing other Enumerations from other .ecore Model
Referencing other Enumerations from other .ecore Model [message #986897] Thu, 22 November 2012 10:06 Go to next message
Tobias Lutz is currently offline Tobias LutzFriend
Messages: 16
Registered: April 2012
Junior Member
Hi there,

I was just wondering if its possible to use an enumeration/element from another loaded model in an OCL invariant.

I got two meta-models (A and B) where B depends on A through a referenced element.
Model A got an enumeration with several types. So in model B is a class that got an attribute with a type of the enumeration in Model A.

I would like to validate the enumeration value in the element of model B with any enumeration type of the enumeration in model A.

For a concrete example:
if elementClassInModelB.enumerationAttribute = ModelA::EnumerationInModelA::type1 then true else false endif;


What I not know is the syntax to reference elements from another model for example the above mentioned enumeration.
I tried modelA::Enumeration::type1 but it didn't work.
I get the message : Unknown type ([modelA, Enumeration, value1]
Even 'NsUri'::Package::Enum::typeX didn't work.
Assuming that ecore::EClass works fine for example I though that this should work the same, but it doesn't.


These expressions got evaluated in the OCL Console and shall become invariants in the OCLinEcore editor later.

Edit: On the OCL Console it's been a misspelling but im facing a other problem:

After save the valid modelB.ecore file with the ocl editor and re-open it my expression got changed from modelAPackage::Enum::value1 to _'ModelA.ecore'::modelAPackage::Enum::value1 and the error says "unresolved Namespace"

If I change it to the namespace that is used for the attribute that references the other model element _'com.test.testmodelA' I can save the file again but when I re-open it other write constraints are modified and don't work anymore.

I'm using Xtext 2.3.1, Eclipse Juno SR 1 and OCL Examples and Editors 3.2.1

Here the real code that creates an error after re-opening:
ModelA:
package modelA : _'com.test.testmodelA' = 'http://www.testmodel/modelA'
{
    class ModelAElement;
    enum ModelAEnum { serializable }
    {
        literal value0;
        literal value1 = 1;
    }
}


Model B
import _'com.test.testmodelA' : '../../com.test.testmodel.testA/model/modelA.ecore#/';

package modelB : _'com.test.testmodelB' = '\'http://www.testmodel/modelB\''
{
    class ModelBElement
    {
        attribute modelType : _'com.test.testmodelA'::ModelAEnum[?] { ordered };
        invariant test: modelType = modelA::ModelAEnum::value0;
    }
}


Model B line 8 after re-open contains the Namespace that can't be resolved.
  invariant test: modelType = _'modelA.ecore'::modelA::ModelAEnum::value0


The workaround that I currently see is to check the string of the enum value to be equal to the string 'value'.
regards

[Updated on: Thu, 22 November 2012 14:21]

Report message to a moderator

Re: Referencing other Enumerations from other .ecore Model [message #986985 is a reply to message #986897] Thu, 22 November 2012 17:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This is not possible in OCL 2.x as specified, since there is no syntax
to reference external models.

It is possible in the new pivot-based Eclipse OCL that introduces an
nsURI alternative syntax for package names using string literals.

You will need to use at least the Juno release. (4.1 overall, 3.3 of the
pivot plugins).

I was originally unclear as to whether an import was of a model or a
package. I'm now clear that the nsURI refers to a package, so you should
find 'nsURI'::Enum::Literal works. Using completion assist
(Control+space may give some insight).

The target model needs to be on the classpath of your invoking application.

If you need more help, please post a zipped project demonstrating your
best attempt.

Regards

Ed Willink


On 22/11/2012 10:06, Tobias Lutz wrote:
> Hi there,
>
> I was just wondering if its possible to use an enumeration/element
> from another loaded model in an OCL invariant.
>
> I got two meta-models (A and B) where B depends on A through a
> referenced element.
> Model A got an enumeration with several types. So in model B is a
> class that got an attribute with a type of the enumeration in Model A.
> I would like to validate the enumeration value in the element of model
> B with any enumeration type of the enumeration in model A.
>
> For a concrete example:
>
> if elementClassInModelB.enumerationAttribute =
> ModelA::EnumerationInModelA::type1 then true else false endif;
>
> What I not know is the syntax to reference elements from another model
> for example the above mentioned enumeration.
> I tried modelA::Enumeration::type1 but it didn't work.
> I get the message : Unknown type ([modelA, Enumeration, value1]
> Even 'NsUri'::Package::Enum::typeX didn't work.
> Assuming that ecore::EClass works fine for example I though that this
> should work the same, but it doesn't.
>
>
> These expressions got evalueted in the OCL Console and shall become
> invariants in the OCLinEcore editor later.
>
> I hope you can help me.
>
> regards
>
>
Re: Referencing other Enumerations from other .ecore Model [message #987001 is a reply to message #986985] Thu, 22 November 2012 18:24 Go to previous messageGo to next message
Tobias Lutz is currently offline Tobias LutzFriend
Messages: 16
Registered: April 2012
Junior Member
Hello and thank you for your reply.

As I wrote above the current setting of my eclipse is:

Xtext 2.3.1
Eclipse Juno SR 1(4.1)
OCL Examples and Editors 3.2.1

so I guess this should fit and I am using pivot-based Eclipse OCL.

Here is the stept how you can reproduce the error:

1)Open "ModelB.ecore" in com.test.testmodel.testB with OCLinEcore Editor.
2)change invariant: "test: modelType = modelA::ModelAEnum::value1;" to "test: modelType = modelA::ModelAEnum::value0;" that you can save again.
3)Reopen the same "ModelB.ecore" file within the OCLinEcore Editor.
4)The Namespace invariant line was changed got a an error now.

Edit: Now the proper projects are in the attachement.
I tried it with the 'nsURI':: but without success with completion assist.

[Updated on: Thu, 22 November 2012 18:44]

Report message to a moderator

Re: Referencing other Enumerations from other .ecore Model [message #987018 is a reply to message #987001] Thu, 22 November 2012 22:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This was fixed by

commit 9e90359286377e38e33e7ee4e69613dbd6fa65a2
Author: Ed Willink <ed@xxxxxxxx.uk> 2012-08-30 12:50:42

[unrelated] Allow modeled navigation in import syntax

Since it involves a grammar change, it's dubious for a maintenance release.

The fix is in the M2 and M3 builds for Kepler, both of which should be
installable on Juno.

Regards

Ed Willink


On 22/11/2012 18:24, Tobias Lutz wrote:
> Hello and thank you for your reply.
>
> As I wrote above the current setting of my eclipse is:
>
> Xtext 2.3.1
> Eclipse Juno SR 1(4.1)
> OCL Examples and Editors 3.2.1
>
> so I guess this should fit and I am using pivot-based Eclipse OCL.
>
> Here is the stept how you can reproduce the error:
>
> 1)Open "ModelB.ecore" in com.test.testmodel.testB with OCLinEcore Editor.
> 2)change invariant: "test: modelType = modelA::ModelAEnum::value1;" to "test: modelType = modelA::ModelAEnum::value0;" that you can save again.
> 3)Reopen the same "ModelB.ecore" file within the OCLinEcore Editor.
> 4)The Namespace invariant line was changed got a an error now.
>
>
>
>
Re: Referencing other Enumerations from other .ecore Model [message #987054 is a reply to message #987018] Fri, 23 November 2012 08:24 Go to previous messageGo to next message
Tobias Lutz is currently offline Tobias LutzFriend
Messages: 16
Registered: April 2012
Junior Member
I installed OCL for Keppler M3 on eclipse juno and the errors are gone Smile
Thank you for your support.

regards
Re: Referencing other Enumerations from other .ecore Model [message #1067187 is a reply to message #987054] Sun, 07 July 2013 11:29 Go to previous messageGo to next message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
I know it is quit old to open this post again but i am new to ocl and trying to do the same of referencing another elements in another ecore metamodel. Forexample i have an association between an elements "feature" in metamodel-1 with another element "Task" in metamodel-2. So I'm adding some constrains using EAnnotation within metamodel-1 under 'feature'..

I tried the same as you suggested: 'nsURI'::Enum::Literal' but with Eclass, like this: 'nsURI'::Packagename::elementname'
'http//taskmodel/1' :: Tmodel::Task. However it didn't work with me ..!!

I am using juno with ocl interaction editor , and testing the constrain with the xmi file.

Re: Referencing other Enumerations from other .ecore Model [message #1067226 is a reply to message #1067187] Sun, 07 July 2013 18:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

You should read the original thread more carefully. You need to use the
Xtext OCL Console.

Regards

Ed Willink

On 07/07/2013 14:20, Salwa Alzahmi wrote:
> I know it is quit old to open this post again but i am new to ocl and
> trying to do the same of referencing another elements in another ecore
> metamodel. Forexample i have an association between an elements
> "feature" in metamodel-1 with another element "Task" in metamodel-2.
> So I'm adding some constrains using EAnnotation within metamodel-1
> under 'feature'..
>
> I tried the same as you suggested: 'nsURI'::Enum::Literal' but with
> Eclass, like this: 'nsURI'::Packagename::elementname'
> 'http//taskmodel/1' :: Tmodel::Task. However it didn't work with me ..!!
>
> I am using juno with ocl interaction editor , and testing the
> constrain with the xmi file.
>
>
Re: Referencing other Enumerations from other .ecore Model [message #1067230 is a reply to message #1067226] Sun, 07 July 2013 19:07 Go to previous message
Salwa Alzahmi is currently offline Salwa AlzahmiFriend
Messages: 37
Registered: June 2013
Member
Yeah , I tried it and it's working fine now ..
Thank you alot Very Happy

Previous Topic: Return OrderedSet{null} for many features
Next Topic:[OCLinEcore] Project specific settings not taken into account for code generation
Goto Forum:
  


Current Time: Fri Apr 19 17:01:56 GMT 2024

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

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

Back to the top