Referencing other Enumerations from other .ecore Model [message #986897] |
Thu, 22 November 2012 10:06 |
Tobias Lutz 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 |
Ed Willink 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 |
Tobias Lutz 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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 3.46135 seconds