Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Evaluate OCL constraints in an UML model programmatically
Evaluate OCL constraints in an UML model programmatically [message #1733473] Fri, 27 May 2016 21:42 Go to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

I am trying to write a standalone program to evaluate the OCL constraints in UML model. In my project, I use Papyrus to create a profile and an UML model. In my profile, I generate an OCL constraint in stereotype Artifact to enforce that each instance of Artifact should have ID attribute and the type is String
self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')


But when I run my program to evaluate my UML model, I got the error message shown as below.

Quote:
Exception in thread "main" org.eclipse.ocl.pivot.values.InvalidValueException: Failed to evaluate 'UML::Class::ownedAttribute' for 'RootElement::System' and 'self.base_Class.ownedAttribute'
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.evaluatePropertyCallExp(OCLEvaluationVisitor.java:176)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitPropertyCallExp(OCLEvaluationVisitor.java:776)
at org.eclipse.ocl.pivot.internal.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:413)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitIteratorExp(OCLEvaluationVisitor.java:529)
at org.eclipse.ocl.pivot.internal.IteratorExpImpl.accept(IteratorExpImpl.java:1781)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.safeVisit(OCLEvaluationVisitor.java:196)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitExpressionInOCL(OCLEvaluationVisitor.java:400)
at org.eclipse.ocl.pivot.internal.ExpressionInOCLImpl.accept(ExpressionInOCLImpl.java:517)
at org.eclipse.ocl.pivot.utilities.OCL.evaluate(OCL.java:380)
at Mypackage.Ocltest.main(Ocltest.java:150)
Caused by: java.lang.NullPointerException
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDerivedStructuralFeatureID(BasicEObjectImpl.java:1497)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1238)
at org.eclipse.ocl.pivot.internal.library.ExplicitNavigationProperty.evaluate(ExplicitNavigationProperty.java:51)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.evaluatePropertyCallExp(OCLEvaluationVisitor.java:168)
... 9 more


It seems that the evaluate method can't get the "ownedAttribute" EStructuralFeature of the UML class, but I am not sure what is the cause of this program. I also try to generate the profile and UML model using Rational Software Architect (RSA) and export the models to uml format, but I still get the same error message running my program. Here I attached my project in my post for your reference and thank you very much for your help.

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733497 is a reply to message #1733473] Sat, 28 May 2016 19:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

[Your MANIFEST.MF has been corrupted. Somehow you've inserted a
org.eclipse.qvtd.build.etl
after the BREE. Easily fixed and chnaged to Java 8.]

You are working much too hard.

If you use the Xtext OCL Console with the UML Model Editor on MyModelTest.uml. Select System as the contact object then evaluation of a similar constraint succeeds.

Evaluating:
self.extension_Artifact.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')
Results:
true

You should not need to use the Pivot representations; stick to the UML objects; the pivot should be hidden.

(If you do use the pivot objects then you would need ocl::Class::ownedProperties rather than uml::Class::ownedAttribute.)

Regards

Ed Willink
Re: Evaluate OCL constraints in an UML model programmatically [message #1733502 is a reply to message #1733497] Sat, 28 May 2016 21:56 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi Ed,

Thank you for your information. I fixed the execution environments in the MANIFEST.MF to JavaSE-1.8 but I still get the same error.

I didn't use the Pivot representation of the OCL constraint. In my profile, the constraint I wrote is
self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')

If I open MyModelTest.uml with UML model editor, right click on the RootElement and select OCL->Validate, I can get the evaluation results correctly. (A validation problem is reported since class "Hazard" does not have ID attribute)

In the program, I load the uml constraint from my profile, then I get the Pivot constraint via
asConstraint = ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Constraint.class, constraint);
and the result is: Quote:
Pivot constraint: context Artifact invariant ID Attribute: self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')


After that, I get the Pivot ExpressionInOCL via
asExpression = ocl.getSpecification(asConstraint);
and the expression I get is Quote:
Pivot constraint Expression:self.base_Class.ownedAttribute->one(p : UML::Property[?] | p.name.=('ID').and(p.type.name.=('String')))


But when I evaluate the "asExpression", I get the error message shown in my original post and I am not sure what the problem is...

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733513 is a reply to message #1733502] Sun, 29 May 2016 10:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

The problem is that your 'self'/'context' object is a Pivot object
rather than a UML object. If you want to use pivot objects you must
speak 'pivot' and so use ocl::Class::ownedProperties, which is
inconvenient and unnecessary when embedding in UML. Use a UML object
just as you do in the Console.

Regards

Ed Willink


On 28/05/2016 22:56, Chung-Ling Lin wrote:
> Hi Ed,
>
> Thank you for your information. I fixed the execution environments in
> the MANIFEST.MF to JavaSE-1.8 but I still get the same error.
>
> I didn't use the Pivot representation of the OCL constraint. In my
> profile, the constraint I wrote is
> self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and
> p.type.name='String')
> If I open MyModelTest.uml with UML model editor, right click on the
> RootElement and select OCL->Validate, I can get the evaluation results
> correctly. (A validation problem is reported since class "Hazard" does
> not have ID attribute)
>
> In the program, I load the uml constraint from my profile, then I get
> the Pivot constraint via asConstraint =
> ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Constraint.class,
> constraint); and the result is: Quote:
>> Pivot constraint: context Artifact invariant ID Attribute:
>> self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and
>> p.type.name='String')
>
>
> After that, I get the Pivot ExpressionInOCL via asExpression =
> ocl.getSpecification(asConstraint); and the expression I get is Quote:
>> Pivot constraint Expression:self.base_Class.ownedAttribute->one(p :
>> UML::Property[?] | p.name.=('ID').and(p.type.name.=('String')))
>
>
> But when I evaluate the "asExpression", I get the error message shown
> in my original post and I am not sure what the problem is...
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733538 is a reply to message #1733513] Mon, 30 May 2016 00:50 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi Ed,

Thank you for your help, I understand my problem now. But I still have question about using the APIs to get the result.

I try to modify the evaluate method as below, where "oe" is an uml element (In this example, the class "system") and "asExpression" is org.eclipse.ocl.pivot.ExpressionInOCL.
 ocl.evaluate(oe, asExpression);

But I get the error message below:
Quote:
Exception in thread "main" org.eclipse.ocl.pivot.values.InvalidValueException: Null source for $uml$::Class::ownedAttribute
at org.eclipse.ocl.pivot.utilities.ValueUtil.asNavigableObject(ValueUtil.java:237)
at org.eclipse.ocl.pivot.internal.library.ExplicitNavigationProperty.evaluate(ExplicitNavigationProperty.java:43)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.evaluatePropertyCallExp(OCLEvaluationVisitor.java:168)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitPropertyCallExp(OCLEvaluationVisitor.java:776)
at org.eclipse.ocl.pivot.internal.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:413)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitIteratorExp(OCLEvaluationVisitor.java:529)
at org.eclipse.ocl.pivot.internal.IteratorExpImpl.accept(IteratorExpImpl.java:1781)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.safeVisit(OCLEvaluationVisitor.java:196)
at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitExpressionInOCL(OCLEvaluationVisitor.java:400)
at org.eclipse.ocl.pivot.internal.ExpressionInOCLImpl.accept(ExpressionInOCLImpl.java:517)
at org.eclipse.ocl.pivot.utilities.OCL.evaluate(OCL.java:380)
at Mypackage.Ocltest.main(Ocltest.java:154)


I guess that org.eclipse.ocl.pivot.ExpressionInOCL may not applicable for the uml object, so I try the codes below:
UMLEnvironmentFactory uf = new UMLEnvironmentFactory(rs); //type of "rs" is ResourceSet
org.eclipse.ocl.uml.OCL ocl2 = org.eclipse.ocl.uml.OCL.newInstance(uf);
ocl2.check(oe, constraint); // type of "constraint" is org.eclipse.uml2.uml.Constraint

But it gives me the NULLPointerException error
Quote:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.ocl.OCL.check(OCL.java:498)
at Mypackage.Ocltest.main(Ocltest.java:145)


I am not sure how to convert the uml constraint to OCLExpression, so I also try to follow the tutorial to create the OCLExpression manually via OCLHelper, but I still get the error message.
org.eclipse.ocl.uml.OCL.Helper helper = ocl2.createOCLHelper();
helper.setContext(OCLUMLUtil.getMetaclass(oe) );
org.eclipse.ocl.uml.OCLExpression expr = null;
try {
	expr = (org.eclipse.ocl.uml.OCLExpression) helper.createInvariant("self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')");	
									
} catch (org.eclipse.ocl.ParserException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
System.out.println("newOCL validation result:" + ocl2.evaluate(oe, expr));


Quote:
org.eclipse.ocl.ParserException
at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:398)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:213)
at org.eclipse.ocl.uml.OCLHelperImpl.createInvariant(OCLHelperImpl.java:70)
at org.eclipse.ocl.uml.OCLHelperImpl.createInvariant(OCLHelperImpl.java:1)
at Mypackage.Ocltest.main(Ocltest.java:152)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.uml.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:147)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.getTupleType(OCLStandardLibraryUtil.java:2281)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.createCollectionOperations(OCLStandardLibraryUtil.java:1788)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.createSetOperations(OCLStandardLibraryUtil.java:1826)
at org.eclipse.ocl.uml.internal.OCLStandardLibraryImpl.createCollectionTypeOperations(OCLStandardLibraryImpl.java:499)
at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:155)
at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:1)
at org.eclipse.ocl.util.TypeUtil.resolveCollectionType(TypeUtil.java:697)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4542)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4514)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionSourceExpression(AbstractOCLAnalyzer.java:3521)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.iteratorExpCS(AbstractOCLAnalyzer.java:3549)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.loopExpCS(AbstractOCLAnalyzer.java:3465)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.propertyCallExpCS(AbstractOCLAnalyzer.java:3439)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.oclExpressionCS(AbstractOCLAnalyzer.java:1963)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invCS(AbstractOCLAnalyzer.java:1424)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invOrDefCS(AbstractOCLAnalyzer.java:1404)
at org.eclipse.ocl.parser.OCLAnalyzer.parseInvOrDefCS(OCLAnalyzer.java:260)
at org.eclipse.ocl.internal.helper.HelperUtil.parseInvariant(HelperUtil.java:200)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:210)
... 3 more
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.ocl.internal.helper.HelperUtil.getConstraintContext(HelperUtil.java:481)
at org.eclipse.ocl.OCL.evaluate(OCL.java:432)
at Mypackage.Ocltest.main(Ocltest.java:158)


Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733552 is a reply to message #1733538] Mon, 30 May 2016 06:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

Thank you for the repro projects; it avoids a lot of confusions and I
see your problem quite quickly.

You have made an 'interesting' mistake that I'll have to think about
trying to provide better diagnosis for.

When I wrote "Use a UML object just as you do in the Console.", I meant
use an org.eclipse.uml.* element, not use an org.eclipse.ocl.uml.* element.

org.eclipse.uml.* is the Eclipse UML2 model.
org.eclipse.ocl.ecore.* is the old/classic Ecore-specific OCL support
involving long parameter lists and ...
org.eclipse.ocl.uml.* is the old/classic UML-specific OCL support
involving long parameter lists and ...
org.eclipse.ocl.pivot.* is the new unified/pivot OCL with much simpler
APIs, Xtext editors, extensible modeled library, ...
(org.eclipse.ocl.pivot.uml.* is the largely hidden UML-specific aspect
of the pivot OCL).

In your code you should only use
org.eclipse.uml.* and org.eclipse.ocl.pivot.*

If you need more of org.eclipse.ocl.pivot.uml.* than
org.eclipse.ocl.pivot.uml.UMLStandaloneSetup please raise a Bugzilla for
a missing API. Currently you have much more initialization than is
necessary. OCL.newInstance now does most other initializations other
than Xtext/parsing and UML automatically

You should only use
org.eclipse.ocl.ecore.* or org.eclipse.ocl.uml.*
if you are deliberately using the old API and taking extreme care to
avoid Classic/Pivot confusions.

I see no errors in the Pivot-only parts of your example.

Regards

Ed Willink


On 30/05/2016 01:50, Chung-Ling Lin wrote:
> Hi Ed,
>
> Thank you for your help, I understand my problem now. But I still have question about using the APIs to get the result.
>
> I try to modify the evaluate method as below, where "oe" is an uml element (In this example, the class "system") and "asExpression" is org.eclipse.ocl.pivot.ExpressionInOCL. ocl.evaluate(oe, asExpression);
> But I get the error message below:
> Quote:
>> Exception in thread "main" org.eclipse.ocl.pivot.values.InvalidValueException: Null source for $uml$::Class::ownedAttribute
>> at org.eclipse.ocl.pivot.utilities.ValueUtil.asNavigableObject(ValueUtil.java:237)
>> at org.eclipse.ocl.pivot.internal.library.ExplicitNavigationProperty.evaluate(ExplicitNavigationProperty.java:43)
>> at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.evaluatePropertyCallExp(OCLEvaluationVisitor.java:168)
>> at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitPropertyCallExp(OCLEvaluationVisitor.java:776)
>> at org.eclipse.ocl.pivot.internal.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:413)
>> at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitIteratorExp(OCLEvaluationVisitor.java:529)
>> at org.eclipse.ocl.pivot.internal.IteratorExpImpl.accept(IteratorExpImpl.java:1781)
>> at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.safeVisit(OCLEvaluationVisitor.java:196)
>> at org.eclipse.ocl.pivot.internal.evaluation.OCLEvaluationVisitor.visitExpressionInOCL(OCLEvaluationVisitor.java:400)
>> at org.eclipse.ocl.pivot.internal.ExpressionInOCLImpl.accept(ExpressionInOCLImpl.java:517)
>> at org.eclipse.ocl.pivot.utilities.OCL.evaluate(OCL.java:380)
>> at Mypackage.Ocltest.main(Ocltest.java:154)
>
> I guess that org.eclipse.ocl.pivot.ExpressionInOCL may not applicable for the uml object, so I try the codes below:
> UMLEnvironmentFactory uf = new UMLEnvironmentFactory(rs); //type of "rs" is ResourceSet
> org.eclipse.ocl.uml.OCL ocl2 = org.eclipse.ocl.uml.OCL.newInstance(uf);
> ocl2.check(oe, constraint); // type of "constraint" is org.eclipse.uml2.uml.Constraint
> But it gives me the NULLPointerException error
> Quote:
>> Exception in thread "main" java.lang.NullPointerException
>> at org.eclipse.ocl.OCL.check(OCL.java:498)
>> at Mypackage.Ocltest.main(Ocltest.java:145)
>
> I am not sure how to convert the uml constraint to OCLExpression, so I also try to follow the tutorial to create the OCLExpression manually via OCLHelper, but I still get the error message.
> org.eclipse.ocl.uml.OCL.Helper helper = ocl2.createOCLHelper();
> helper.setContext(OCLUMLUtil.getMetaclass(oe) );
> org.eclipse.ocl.uml.OCLExpression expr = null;
> try {
> expr = (org.eclipse.ocl.uml.OCLExpression) helper.createInvariant("self.base_Class.ownedAttribute->one(p:Property|p.name='ID' and p.type.name='String')");
>
> } catch (org.eclipse.ocl.ParserException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> System.out.println("newOCL validation result:" + ocl2.evaluate(oe, expr));
>
> Quote:
>> org.eclipse.ocl.ParserException
>> at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:398)
>> at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:213)
>> at org.eclipse.ocl.uml.OCLHelperImpl.createInvariant(OCLHelperImpl.java:70)
>> at org.eclipse.ocl.uml.OCLHelperImpl.createInvariant(OCLHelperImpl.java:1)
>> at Mypackage.Ocltest.main(Ocltest.java:152)
>> Caused by: java.lang.NullPointerException
>> at org.eclipse.ocl.uml.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:147)
>> at org.eclipse.ocl.util.OCLStandardLibraryUtil.getTupleType(OCLStandardLibraryUtil.java:2281)
>> at org.eclipse.ocl.util.OCLStandardLibraryUtil.createCollectionOperations(OCLStandardLibraryUtil.java:1788)
>> at org.eclipse.ocl.util.OCLStandardLibraryUtil.createSetOperations(OCLStandardLibraryUtil.java:1826)
>> at org.eclipse.ocl.uml.internal.OCLStandardLibraryImpl.createCollectionTypeOperations(OCLStandardLibraryImpl.java:499)
>> at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:155)
>> at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:1)
>> at org.eclipse.ocl.util.TypeUtil.resolveCollectionType(TypeUtil.java:697)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4542)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4514)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionSourceExpression(AbstractOCLAnalyzer.java:3521)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.iteratorExpCS(AbstractOCLAnalyzer.java:3549)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.loopExpCS(AbstractOCLAnalyzer.java:3465)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.propertyCallExpCS(AbstractOCLAnalyzer.java:3439)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.oclExpressionCS(AbstractOCLAnalyzer.java:1963)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invCS(AbstractOCLAnalyzer.java:1424)
>> at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invOrDefCS(AbstractOCLAnalyzer.java:1404)
>> at org.eclipse.ocl.parser.OCLAnalyzer.parseInvOrDefCS(OCLAnalyzer.java:260)
>> at org.eclipse.ocl.internal.helper.HelperUtil.parseInvariant(HelperUtil.java:200)
>> at org.eclipse.ocl.internal.helper.OCLHelperImpl.createInvariant(OCLHelperImpl.java:210)
>> ... 3 more
>> Exception in thread "main" java.lang.NullPointerException
>> at org.eclipse.ocl.internal.helper.HelperUtil.getConstraintContext(HelperUtil.java:481)
>> at org.eclipse.ocl.OCL.evaluate(OCL.java:432)
>> at Mypackage.Ocltest.main(Ocltest.java:158)
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733659 is a reply to message #1733552] Mon, 30 May 2016 18:39 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi

Thank you for your help, but I still feel confuse. You mentioned that the Pivot parts of my example has no error, but I am not able to make the evaluate method work.
ocl.evaluate(oe, asExpression);


In this case, "oe" is org.eclipse.uml2.uml.Element, it is not an an org.eclipse.ocl.uml.* element. And the "asExpression" is an org.eclipse.ocl.pivot.ExpressionInOCL since the method takes an org.eclipse.ocl.pivot.ExpressionInOCL as parameter but not an org.eclipse.uml2.uml.Constraint

I try the org.eclipse.ocl.uml.OCL because I want to check if I can make the evaluate method work for the UML constraint. But if the Pivot part can work, then maybe I don't need to use the classic one since the OCL document says that the Pivot binding is preferred.

Best Regards,
Chung-Ling Lin

[Updated on: Mon, 30 May 2016 18:59]

Report message to a moderator

Re: Evaluate OCL constraints in an UML model programmatically [message #1733691 is a reply to message #1733659] Tue, 31 May 2016 06:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

You have a constraint body that is applicable to a Stereotype instance,
but you invoke it on a Class instance. (UML does not have first class
stereotype instances, hence when I tested it I added an
extension_Artifact navigation.)

Evaluating:
self.extension_Artifact.base_Class.ownedAttribute->one(p:Property|p.name='ID'
and p.type.name='String')
Results:
true

When you invoke base_Class it returns null indicating that the
navigation was not available and so you get a null failure later.

Regards

Ed Willink



On 30/05/2016 19:39, Chung-Ling Lin wrote:
> Hi
>
> Thank you for your help, but I still feel confuse. You mentioned that
> the Pivot parts of my example has no error, but I am not able to make
> the evaluate method work. ocl.evaluate(oe, asExpression);
>
> In this case, "oe" is org.eclipse.uml2.uml.Element, it is not an an
> org.eclipse.ocl.uml.* element. And the "asExpression" is an
> org.eclipse.ocl.pivot.ExpressionInOCL since the method takes an
> org.eclipse.ocl.pivot.ExpressionInOCL as parameter but not an
> org.eclipse.uml2.uml.Constraint
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1733793 is a reply to message #1733691] Tue, 31 May 2016 23:19 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi

Thank you very much for your help. It works after I add the "extension_Artifact" in my OCL constraint. But I got different error when I try to evaluate the OCL constraints on different stereotypes.

For example, I add another stereotype "MyModel" in the profile extends UML Metaclass::Model which enforces the target UML model contains an instance of Artifact, and it works in the Xtext OCL console

Quote:
Evaluating:
self.extension_MyModel.base_Model.allOwnedElements()->exists(e|e.oclIsTypeOf(UML::Class) and not e.getAppliedStereotype('MyRoot::Artifact').oclIsUndefined())
Results:
true


But when I run my program, I got the error message as below. And the error happens because I am fail to create an pivot.ExpressionInOCL from the OCL constraint defined in the profile. Quote:
org.eclipse.ocl.pivot.utilities.SemanticException: The 'MyModel::Artifact must exist' constraint is invalid: 'self.extension_MyModel.base_Model.allOwnedElements()->exists(e|e.oclIsTypeOf(UML::Class) and not e.getAppliedStereotype('MyRoot::Artifact').oclIsUndefined())'
1: Unresolved Property 'MyRoot::MyModel::extension_MyModel'
1: Unresolved Operation 'OclInvalid::getAppliedStereotype('MyRoot::Artifact')'
at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:144)
at org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:154)
at org.eclipse.ocl.pivot.internal.manager.PivotMetamodelManager.parseSpecification(PivotMetamodelManager.java:2151)
at org.eclipse.ocl.pivot.utilities.OCL.getSpecification(OCL.java:496)
at Mypackage.Ocltest.main(Ocltest.java:128)
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createEvaluationVisitor(AbstractEnvironmentFactory.java:256)
at org.eclipse.ocl.pivot.utilities.OCL.createEvaluationVisitor(OCL.java:253)
at org.eclipse.ocl.pivot.utilities.OCL.evaluate(OCL.java:379)
at Mypackage.Ocltest.main(Ocltest.java:139)


I also notice similar problem in the Papyrus profile. When I create an constraint and type "self.", only the stereotypes extends Metaclass:Class appear in the list, and the above constraint is invalid in the Papyrus profile.

And the same problem happened for the constraint applied to the stereotype extends Metaclass::Association or Metaclass::Property.

Should I only use the "extension_" for the stereotype extends Metaclass::Class and use other keywords for the stereotype extends different type of Metaclasses? If so, where can I find the information?

Thank you again for your help.

Best Regards,
Chung-Ling Lin

Re: Evaluate OCL constraints in an UML model programmatically [message #1733913 is a reply to message #1733793] Thu, 02 June 2016 08:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

You must use consistent 'self' object and type.

In the Console using a selection from the UML Model Editor, you can
select the "System" Class to which the Artifact stereotype has been
applied. This selects an instance of a Class as self and defines Class
as its type. You therefore need self.extension_Artifact to navigate from
the instance of Class to the instance of Artifact. This is necessary
since the instance of Artifact is not a conventional UML model element
and so you are not able to select it in the UML Model Editor. If you
look at the XMI of your model you will find some strange XMI for the
Artifact:

<MyRoot:Artifact xmi:id="_YkL-8Cd6Eeai4dhMexQnLA"
base_Class="_f8yiECQ2Eea58IaVhZ-4yw"/>

When your Artifact Constraint is validated, the Constraint is defined
for an Artifact, and so the 'self' object is the Artifact instance. It
is therefore an error, as you discovered, to attempt to navigate from
the Artifact using self.extension_Artifact.

My suggestion to use self.extension_Artifact in the Console was
therefore a mechanism to enable you to practice the Artifact constraint
while selecting a Class instance. It was not an instruction to chnage
the definition of the Artifact constraint.

Regards

Ed Willink



On 01/06/2016 00:19, Chung-Ling Lin wrote:
> Hi
>
> Thank you very much for your help. It works after I add the "extension_Artifact" in my OCL constraint. But I got different error when I try to evaluate the OCL constraints on different stereotypes.
>
> For example, I add another stereotype "MyModel" in the profile extends UML Metaclass::Model which enforces the target UML model contains an instance of Artifact, and it works in the Xtext OCL console
>
> Quote:
>> Evaluating:
>> self.extension_MyModel.base_Model.allOwnedElements()->exists(e|e.oclIsTypeOf(UML::Class) and not e.getAppliedStereotype('MyRoot::Artifact').oclIsUndefined())
>> Results:
>> true
>
>
> But when I run my program, I got the error message as below. And the error happens because I am fail to create an pivot.ExpressionInOCL from the OCL constraint defined in the profile. Quote:
>> org.eclipse.ocl.pivot.utilities.SemanticException: The 'MyModel::Artifact must exist' constraint is invalid: 'self.extension_MyModel.base_Model.allOwnedElements()->exists(e|e.oclIsTypeOf(UML::Class) and not e.getAppliedStereotype('MyRoot::Artifact').oclIsUndefined())'
>> 1: Unresolved Property 'MyRoot::MyModel::extension_MyModel'
>> 1: Unresolved Operation 'OclInvalid::getAppliedStereotype('MyRoot::Artifact')'
>> at org.eclipse.ocl.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:144)
>> at org.eclipse.ocl.pivot.internal.context.AbstractParserContext.parse(AbstractParserContext.java:154)
>> at org.eclipse.ocl.pivot.internal.manager.PivotMetamodelManager.parseSpecification(PivotMetamodelManager.java:2151)
>> at org.eclipse.ocl.pivot.utilities.OCL.getSpecification(OCL.java:496)
>> at Mypackage.Ocltest.main(Ocltest.java:128)
>> Exception in thread "main" java.lang.NullPointerException
>> at org.eclipse.ocl.pivot.utilities.AbstractEnvironmentFactory.createEvaluationVisitor(AbstractEnvironmentFactory.java:256)
>> at org.eclipse.ocl.pivot.utilities.OCL.createEvaluationVisitor(OCL.java:253)
>> at org.eclipse.ocl.pivot.utilities.OCL.evaluate(OCL.java:379)
>> at Mypackage.Ocltest.main(Ocltest.java:139)
>
>
> I also notice similar problem in the Papyrus profile. When I create an constraint and type "self.", only the stereotypes extends Metaclass:Class appear in the list, and the above constraint is invalid in the Papyrus profile.
>
> And the same problem happened for the constraint applied to the stereotype extends Metaclass::Association or Metaclass::Property.
>
> Should I only use the "extension_" for the stereotype extends Metaclass::Class and use other keywords for the stereotype extends different type of Metaclasses? If so, where can I find the information?
>
> Thank you again for your help.
>
> Best Regards,
> Chung-Ling Lin
>
>
Re: Evaluate OCL constraints in an UML model programmatically [message #1734138 is a reply to message #1733913] Sat, 04 June 2016 22:49 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi

The pivot model has the ElementExtension which contains both the pivot model element and its applied stereotype. Therefore, when working with the pivot model element, I just pass an instance of ElementExtension to evaluate the constraint. I understand that I can not just evaluate the constraint for an uml class instance based on your explanation. But I can't find the corresponding interface in eclipse uml2. Would you please direct me what type of UML object I should use in my program to evaluate the constraint?

Thank you again for your help.

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1734161 is a reply to message #1734138] Sun, 05 June 2016 14:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

Why do you want to evaluate the constraint yourself?

Normally Constraint evaluation occurs automatically as a result of
validation, typically by the Diagnostician.

If you really want to do it yourself, use the debugger to see how the
Diagnostian does it and replicate those calls that are relevant tio your
code.

org.eclipse.ocl.examples.pivot.tests.UMLValidateTest in
GIT\org.eclipse.ocl\tests\org.eclipse.ocl.examples.xtext.tests has a
variety of UML validation calls.

Regards

Ed Willink

On 04/06/2016 23:49, Chung-Ling Lin wrote:
> Hi
>
> The pivot model has the ElementExtension which contains both the pivot
> model element and its applied stereotype. Therefore, when working with
> the pivot model element, I just pass an instance of ElementExtension
> to evaluate the constraint. I understand that I can not just evaluate
> the constraint for an uml class instance based on your explanation.
> But I can't find the corresponding interface in eclipse uml2. Would
> you please direct me what type of UML object I should use in my
> program to evaluate the constraint?
> Thank you again for your help.
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1735219 is a reply to message #1733497] Thu, 16 June 2016 11:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

https://bugs.eclipse.org/bugs/show_bug.cgi?id=496251

It seems that the OCL Facade / OCLHelper / ParserContext API is not as
tolerant of UML elements as I thought. For now, you do need to manually
convert the UML type to a Pivot type before using it as the self-type
for a parse. Currently only Ecore types are auto-converted. Fixed in my
workspace....

Regards

Ed Willink

On 28/05/2016 20:52, Ed Willink wrote:
> Hi
>
> [Your MANIFEST.MF has been corrupted. Somehow you've inserted a
> org.eclipse.qvtd.build.etl
> after the BREE. Easily fixed and chnaged to Java 8.]
>
> You are working much too hard.
>
> If you use the Xtext OCL Console with the UML Model Editor on
> MyModelTest.uml. Select System as the contact object then evaluation
> of a similar constraint succeeds.
>
> Evaluating:
> self.extension_Artifact.base_Class.ownedAttribute->one(p:Property|p.name='ID'
> and p.type.name='String')
> Results:
> true
>
> You should not need to use the Pivot representations; stick to the UML
> objects; the pivot should be hidden.
>
> (If you do use the pivot objects then you would need
> ocl::Class::ownedProperties rather than uml::Class::ownedAttribute.)
>
> Regards
>
> Ed Willink
>
Re: Evaluate OCL constraints in an UML model programmatically [message #1735535 is a reply to message #1735219] Mon, 20 June 2016 22:33 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi

Thank you for your information and the program seems work now. Instead of evaluate the UML element, I find the corresponding EObject from the resource and the OCL evaluate result looks good.
I also try to use diagnostician in my example, but the diagnostician only works for the ecore model but not the uml model.

Quote:
An exception occurred while delegating evaluation of the 'IDAttribute' invariant on 'org.eclipse.emf.ecore.impl.DynamicEObjectImpl/http:///schemas/MyRoot/_OvmU8CREEea58IaVhZ-4yw/6#Artifact@77c7ed8e{file:/C:/Users/calot/workspaceMars/TestValidation/NewModels/MyModelTest.uml#_f9NeMCRJEea58IaVhZ-4yw}': java.lang.IllegalStateException: No 'http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot' ValidationDelegate for 'org.eclipse.emf.ecore.impl.DynamicEObjectImpl/http:///schemas/MyRoot/_OvmU8CREEea58IaVhZ-4yw/6#Artifact@77c7ed8e{file:/C:/Users/calot/workspaceMars/TestValidation/NewModels/MyModelTest.uml#_f9NeMCRJEea58IaVhZ-4yw}'


Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1735922 is a reply to message #1734161] Thu, 23 June 2016 16:06 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

I got another problem in my new example. In this example, I would like to ensure an association connects the instances of stereotype "MyActivity" and "MyArtifact". Therefore, I have another stereotype "Generates" extends UML Association with constraint: Quote:
self.base_Association.memberEnd->collect(p:Property|p.class)->select(c:Class|c.oclIsKindOf(MyProfile::MyActivity))->size()=1

To simplify my question, I just remove the second part of statement from the constraint to check the other end of the association is an instance of "MyArtifact" or not. And I export my profile as image file in the attachment "myprof.png".

In my UML model, I have an instance of stereotype "HazardAnalysis" an instance of stereotype "HazaardReport", and an association between them(see myModel.png).
When I use the Xtext OCL console and evaluate the constraint using my program, I got "false" in both results.
Quote:
Evaluating:
self.extension_Generates.base_Association.memberEnd->collect(p:Property|p.class)->select(c:Class|c.oclIsKindOf(MyProfile::MyActivity))->size()=1
Results:
false

Quote:
Pivot constraint: context Generates invariant Activity generates Artifact: self.base_Association.memberEnd->collect(p:Property|p.class)->select(c:Class|c.oclIsKindOf(MyProfile::MyActivity))->size()=1
Target class: org.eclipse.uml2.uml.internal.impl.AssociationImpl@3015db78 (name: analysis hazards, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isDerived: false)
Validation result: false


To identify what the problem is, I wrote a simple constraint in my stereotype "HazardAnalysis" to check weather this stereotype is a subtype of "Activity". But this time I got different results in OCL Xtext console and my program. In the xtext tool, I still got "false" but the validation result of my program is "true"
Quote:
Evaluating:
self
Results:
Domain::MyHazardAnalysis

Evaluating:
self.oclIsKindOf(MyProfile::MyActivity)
Results:
false

Quote:
Pivot constraint: context HazardAnalysis invariant Hazard analysis is kind of Activity: self.oclIsKindOf(MyProfile::MyActivity)
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@31da6b2e (name: MyHazardAnalysis, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: true


I look into the implementation of class OclAnyOclIsKindOfOperation and found that the type of "sourceVal" is "ClassImpl" and sourceType is UML::Class when I evaluate my first constraint. But when I evaluate my second constraint "self.oclIsKindOf(MyProfile::MyActivity)", the type of "sourceVal" is "DynamicEObjectImpl" and sourceType is "MyProfile::HazardAnalysis" and then the evaluate result is "true".

I have couple questions about the results of my example:
1) Why I get different results for my second constraint using Xtext console and running the program?
2) It seems that I can only check weather an EObject is a subtype of a stereotype or not, but I can't check if an UML element is a subtype of a stereotype. Is this a restriction of OCL language?

P.S. I execute my examples using Eclipse Mars with OCL 5.1 and Eclipse Neon with OCL 6.1, and the results are the same.

Best Regards,
Chung-Ling Lin
  • Attachment: myModel.png
    (Size: 12.80KB, Downloaded 110 times)
  • Attachment: TestOCL0621.zip
    (Size: 100.49KB, Downloaded 64 times)
  • Attachment: MyProf.png
    (Size: 15.46KB, Downloaded 107 times)

[Updated on: Thu, 23 June 2016 16:14]

Report message to a moderator

Re: Evaluate OCL constraints in an UML model programmatically [message #1735929 is a reply to message #1735922] Thu, 23 June 2016 16:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

A UML element is never a subtype of a Stereotype, unless it is also a
Stereotype.

A UML element may be stereotyped, in which case it has a corresponding
extension.

umlElement.extension_MyActivity <> null

Regards

Ed Willink

On 23/06/2016 17:06, Chung-Ling Lin wrote:
> 2) It seems that I can only check weather an EObject is a subtype of a
> stereotype or not, but I can't check if an UML element is a subtype of
> a stereotype. Is this an restriction of OCL language?
Re: Evaluate OCL constraints in an UML model programmatically [message #1735936 is a reply to message #1735929] Thu, 23 June 2016 18:53 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Thank you for your help. I check the following statement and I get the result as I expected.Quote:
Evaluating:
self
Results:
Domain::MyHazardAnalysis

Evaluating:
self.extension_HazardAnalysis.oclIsKindOf(MyProfile::MyActivity)
Results:
true


But if I select the stereotype in the profile and check the following statement, I got the result "false" Quote:
Evaluating:
self
Results:
MyProfile::HazardAnalysis

Evaluating:
self.oclIsKindOf(MyProfile::MyActivity)
Results:
false


In this example, I think the "self" is a stereotype, but the OclIsKindOf(Stereotype) doesn't work.

When you say: Quote:
A UML element is never a subtype of a Stereotype, unless it is also a Stereotype.
Do you mean "unless it is an instance of Stereotype"?
So if I want to make my constraint in the previous post work, I should get the instance of the stereotype, not the uml element right? Please correct me if I am wrong, thanks.

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1735982 is a reply to message #1735936] Fri, 24 June 2016 08:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

When you select a stereotyped element you select an M1 element.

When you select a stereotype definition you select an M2 element which
is an instance of an M3 UML type and of course not an instance of your
M2 class definition. As I explained before, UML (and Eclipse UML2)
provides only indirect access to stereotype instances.

> A UML element is never a subtype of a Stereotype, unless it is also a
> Stereotype.
i.e a stereotype definition, direct or derived.

Regards

Ed Willink


On 23/06/2016 19:53, Chung-Ling Lin wrote:
> Hi,
>
> Thank you for your help. I check the following statement and I get the
> result as I expected.Quote:
>> Evaluating:
>> self
>> Results:
>> Domain::MyHazardAnalysis
>>
>> Evaluating:
>> self.extension_HazardAnalysis.oclIsKindOf(MyProfile::MyActivity)
>> Results:
>> true
>
>
> But if I select the stereotype in the profile and check the following
> statement, I got the result "false" Quote:
>> Evaluating:
>> self
>> Results:
>> MyProfile::HazardAnalysis
>>
>> Evaluating:
>> self.oclIsKindOf(MyProfile::MyActivity)
>> Results:
>> false
>
>
> In this example, I think the "self" is a stereotype, but the
> OclIsKindOf(Stereotype) doesn't work.
>
> When you say: Quote:
>> A UML element is never a subtype of a Stereotype, unless it is also a
>> Stereotype.
> Do you mean "unless it is an instance of Stereotype"? So if I want to
> make my constraint in the previous post work, I should get the
> instance of the stereotype, not the uml element right? Please correct
> me if I am wrong, thanks.
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736112 is a reply to message #1735982] Sun, 26 June 2016 16:40 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

I am confused about the type of a stereotyped element. Consider an OCL expression source.oclIsKindOf(Type), when source is a stereotyped element, the source's types should be UML metaclass and stereotype definition . But when I try the following ocl expression, I get confused about the execution results of my program. In the following examples, I can always get the same source element, MySystem, which is an instance of UML::Class and also an instance of stereotype definition MyArtifact.

The following OCL expressions has the same context, stereotype definition MyArtifact; and the evaluated element is my M1 model class MySystem.

1) Expression: MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
Result: true
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: true


2) Expression: MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
Result: false
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: false


3) Expression: UML::Class.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
Result: false
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : UML::Class.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: false


4) Expression: UML::Class.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
Result: true
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : UML::Class.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: true


5) Expression: self.oclIsKindOf(MyProfile::MyArtifact)
Result: true
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : self.oclIsKindOf(MyProfile::MyArtifact)
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: true


6) Expression: self.oclIsKindOf(UML::Class)
Result: false
Quote:
Pivot constraint: context MyArtifact invariant test type of self and p : self.oclIsKindOf(UML::Class)
Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081 (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
Validation result: false


In my test 1) and 2) p.oclIsKindOf(MyProfile::MyArtifact) is true but p.oclIsKindOf(UML::Class) is false. It seems that the type of p is my stereotype definition but not UML::Class

In my test 3) and 4) p.oclIsKindOf(MyProfile::MyArtifact) is false but p.oclIsKindOf(UML::Class) is true. In this case, it seems that the type of p is UML::Class but not my stereotype definition.

In my test 5) and 6) self.oclIsKindOf(MyProfile::MyArtifact) is true but self.oclIsKindOf(UML::Class) is false. The type of self is my stereotype definition but not UML::Class

Based on my test result, when an M1 element is a stereotyped element, I can only get one type of this element (either UML metaclass or stereotype definition).
My questions are:
1) Why I didn't get both types of a stereotyped element in the same time?
2) In what kind of situation, the type of a stereotyped element is UML metaclass? And in what kind of situation, the type of a stereotyped element is stereotype definition?

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736116 is a reply to message #1736112] Sun, 26 June 2016 17:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

You are working somewhat beyond the UML specification. There are gaping
chasms between the UML and OCL specifications in respect of Constraints
and Stereotypes. Remarkably, the OCL specification has exactly zero to
say about Stereotypes. UML 2.5 provides some clues via Fig 12.15. But
UML is really only concerned with the type system not the run-time
instances. In Eclipse OCL, I have been trying to make sense of these
clues so that navigation using base_XXX and extension_YYY provides type
safe OCL navigation. This avoids the need for oclAsType's to remedy the
type-less getValue / getAppliedStereotype etc from Eclipse UML2's Java
API that transformation tools such as ATL and QVTo resort to.

Therefore when you define a stereotyped element <<YYY>>XXX at M1, you
define a compound type of XXX (also defined at M1) and YYY (defined in a
profile at M2). However the instance of this compound at M0 is an
instance of XXX with navigation relationships base_XXX/extension_YYY to
an instance of an instance of YYY. UML neglects to reify the
intermediate instance and so when serialized to UML it requires XMI
trickery. The Pivot OCL reifies the intermediate so that if you navigate
using Pivot AS objects rather than UML objects you find that the
instance of ocl::Class namedXXX has navigation relationships base_XXX
and extension_YYY to an instance of ocl::ElementExtension which is an
ocl::Class and an 'instance' of ocl::Stereotype named YYY.

However converting models from UML to Pivot AS incurs a cost which is
now avoided. Only metametamodels are necessarily converted by the Pivot
support. If you evaluate using UML objects the missing
instance-of-Stereotype UML model element is provided by
org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.

The important point is that instances of the compound type are instances
of the stereotyped type with extensions that are instances of instances
of the stereotyping type. Consequently evaluation using the Pivot OCL
uses just Classes and Properties since all Associations (Extensions),
AssociationClasses and Stereotypes are converted to a simpler regular form.

Support for Stereotype::allInstances() is a relatively recent bug fix.

NB. Since stereotypes are dynamically applicable, a run-time approach
that treats the compound type as a single type is not really practical.

Regards

Ed Willink




On 26/06/2016 17:40, Chung-Ling Lin wrote:
> Hi,
> I am confused about the type of a stereotyped element. Consider an OCL
> expression source.oclIsKindOf(Type), when source is a stereotyped
> element, the source's types should be UML metaclass and stereotype
> definition . But when I try the following ocl expression, I get
> confused about the execution results of my program. In the following
> examples, I can always get the same source element, MySystem, which is
> an instance of UML::Class and also an instance of stereotype
> definition MyArtifact.
>
> The following OCL expressions has the same context, stereotype
> definition MyArtifact; and the evaluated element is my M1 model class
> MySystem.
> 1) Expression:
> MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
> Result: true
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p :
>> MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: true
>
>
> 2) Expression:
> MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
> Result: false
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p :
>> MyProfile::MyArtifact.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: false
>
>
> 3) Expression:
> UML::Class.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
> Result: false
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p :
>> UML::Class.allInstances()->exists(p|p.oclIsKindOf(MyProfile::MyArtifact))
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: false
>
>
> 4) Expression:
> UML::Class.allInstances()->exists(p|p.oclIsKindOf(UML::Class)) Result:
> true
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p : UML::Class.allInstances()->exists(p|p.oclIsKindOf(UML::Class))
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: true
>
>
> 5) Expression: self.oclIsKindOf(MyProfile::MyArtifact) Result: true
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p : self.oclIsKindOf(MyProfile::MyArtifact)
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: true
>
>
> 6) Expression: self.oclIsKindOf(UML::Class) Result: false
> Quote:
>> Pivot constraint: context MyArtifact invariant test type of self and
>> p : self.oclIsKindOf(UML::Class)
>> Target class: org.eclipse.uml2.uml.internal.impl.ClassImpl@70e02081
>> (name: MySystem, visibility: <unset>) (isLeaf: false, isAbstract:
>> false, isFinalSpecialization: false) (isActive: false)
>> Validation result: false
>
>
> In my test 1) and 2) p.oclIsKindOf(MyProfile::MyArtifact) is true but
> p.oclIsKindOf(UML::Class) is false. It seems that the type of p is my
> stereotype definition but not UML::Class
>
> In my test 3) and 4) p.oclIsKindOf(MyProfile::MyArtifact) is false but
> p.oclIsKindOf(UML::Class) is true. In this case, it seems that the
> type of p is UML::Class but not my stereotype definition.
>
> In my test 5) and 6) self.oclIsKindOf(MyProfile::MyArtifact) is true
> but self.oclIsKindOf(UML::Class) is false. The type of self is my
> stereotype definition but not UML::Class
>
> Based on my test result, when an M1 element is a stereotyped element,
> I can only get one type of this element (either UML metaclass or
> stereotype definition). My questions are:
> 1) Why I didn't get both types of a stereotyped element in the same time?
> 2) In what kind of situation, the type of a stereotyped element is UML
> metaclass? And in what kind of situation, the type of a stereotyped
> element is stereotype definition?
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736368 is a reply to message #1736116] Tue, 28 June 2016 23:25 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Thank you again for your help, but I have question about the UMLElementExtension as you mentioned in the post.

>If you evaluate using UML objects the missing
>instance-of-Stereotype UML model element is provided by
>org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.

I rewrite my program as below using the UMLElementExtension. In my codes, oe is an uml element and ce is a stereotype. And I can get the expected evaluation results running the program.
org.eclipse.ocl.pivot.Stereotype asStereotype = null;
try {
	asStereotype = ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Stereotype.class, ce);
} catch (ParserException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
Object uee = org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.getUMLElementExtension(asStereotype, oe);
System.out.println("Validation result: "+ocl.evaluate(uee, asExpression));

If we consider the example from UML 2.5 Fig.12.29, and assume that I have an OCL expression whose context is stereotype Clock. When executing my program, the ce is stereotype Clock, and oe is StopWatch, which is an instance of UML::Class. And the evaluated element is the instance of Clock, which is provided by the UMLElementExtension uee.

Based on your explaination about the UMLElementExtension and the execution results of my program, I expect that I should be able to find the the instance of stereotype from the members of UMLElementExtension. But when I read the description and the implementation of this class, I only found the umlElement, which is class StopWatch in this example. And the umlStaticStereotype, which is stereotype Clock in this example. Where is the instance of Clock in the UMLElementExtension?

And in a correct instance of UMLElementExtension, should umlStaticStereotype and umlDynamicStereotype always the same?

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736582 is a reply to message #1736368] Thu, 30 June 2016 12:53 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

If you want me to look at this, please provide a repro project that
clearly demonstrates your achievements / failures.

Regards

Ed Willink


On 29/06/2016 00:25, Chung-Ling Lin wrote:
> Hi,
>
> Thank you again for your help, but I have question about the
> UMLElementExtension as you mentioned in the post.
>> If you evaluate using UML objects the missing instance-of-Stereotype
>> UML model element is provided by
>> org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.
>
> I rewrite my program as below using the UMLElementExtension. In my
> codes, oe is an uml element and ce is a stereotype. And I can get the
> expected evaluation results running the program.
> org.eclipse.ocl.pivot.Stereotype asStereotype = null;
> try {
> asStereotype =
> ocl.getMetamodelManager().getASOf(org.eclipse.ocl.pivot.Stereotype.class,
> ce);
> } catch (ParserException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> Object uee =
> org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.getUMLElementExtension(asStereotype,
> oe);
> System.out.println("Validation result: "+ocl.evaluate(uee,
> asExpression));
> If we consider the example from UML 2.5 Fig.12.29, and assume that I
> have an OCL expression whose context is stereotype Clock. When
> executing my program, the ce is stereotype Clock, and oe is StopWatch,
> which is an instance of UML::Class. And the evaluated element is the
> instance of Clock, which is provided by the UMLElementExtension uee.
>
> Based on your explaination about the UMLElementExtension and the
> execution results of my program, I expect that I should be able to
> find the the instance of stereotype from the members of
> UMLElementExtension. But when I read the description and the
> implementation of this class, I only found the umlElement, which is
> class StopWatch in this example. And the umlStaticStereotype, which is
> stereotype Clock in this example. Where is the instance of Clock in
> the UMLElementExtension?
>
> And in a correct instance of UMLElementExtension, should
> umlStaticStereotype and umlDynamicStereotype always the same?
>
> Best Regards,
> Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736595 is a reply to message #1736582] Thu, 30 June 2016 14:06 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Sorry I forgot to attach my project. In my example, the context of my OCL expression is stereotype Clock, so I should evaluate the constraint on an instance of Clock, which is provided by the UMLElementExtension uee. And the evaluation result is correct.

I just curios that when I check the UMLElementExtension, I can only see the instance of UML::Class from attribute umlElement and the stereotype from attribute umlStaticStereotype and umlDynamicStereotype. But where is the instance of Clock in the UMLElementExtension?

And should the umlStaticStereotype and umlDynamicStereotype always the same in an UMLElementExtension?

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1736827 is a reply to message #1736595] Sat, 02 July 2016 12:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi<br>
<br>
As I wrote before<br>
<br>
<i>If you evaluate using UML objects the missing
instance-of-Stereotype UML model element is provided by
org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.<br>
<br>
</i>UMLElementExtension, like your Clock is an M1 class. Its
instances only exist at M0. You might ask where is the instance of
Clock anywhere else in your UML model. It's not there unless you
use InstanceSpecifications.<br>
<br>
UMLElementExtension.umlStaticStereotype is the declared
stereotype.<br>
<br>
UMLElementExtension.umlDynamicStereotype may be a derivation of
umlStaticStereotype if umlElement.getAppliedStereotypes() provides
them.<br>
<br>
    Regards<br>
<br>
        Ed Willink<br>
<br>
<br>
On 30/06/2016 15:06, Chung-Ling Lin wrote:<br>
</div>
<blockquote cite="mid:nl390l$43f$1@xxxxxxxxe.org" type="cite">
<pre wrap="">Hi,

Sorry I forgot to attach my project. In my example, the context of my OCL expression is stereotype Clock, so I should evaluate the constraint on an instance of Clock, which is provided by the UMLElementExtension uee. And the evaluation result is correct.

I just curios that when I check the UMLElementExtension, I can only see the instance of UML::Class from attribute umlElement and the stereotype from attribute umlStaticStereotype and umlDynamicStereotype. But where is the instance of Clock in the UMLElementExtension?

And should the umlStaticStereotype and umlDynamicStereotype always the same in an UMLElementExtension?

Best Regards,
Chung-Ling Lin
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>
Re: Evaluate OCL constraints in an UML model programmatically [message #1737281 is a reply to message #1736827] Wed, 06 July 2016 20:41 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Sorry I didn't describe my question clearly and mix different level of elements in my description. So I summarize the models I have and the run time snapshots of my program in the attached slides for your reference.

Based on what you wrote "If you evaluate using UML objects the missing
instance-of-Stereotype UML model element is provided by org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.", what I think is an instance of UMLElementExtension should look like a wrapper contains the instance of a stereotype. So I can evaluate the OCL constraint on an instance of UMLElementExtension when the context of the OCL constraint is a stereotype.

But when I setup a break point in P.4 line 10, the value of the umlStaticStereotype and umlDynamicStereotype of the UMLElementExtension instance uee is stereotype Clock, and the umlElement is class StopWatch, which is an instance of UML metaclass Class. I can't find the instance of Clock in uee. Therefore, I got confuse about the role of UMLElementExtension. When you say the missing instance of stereotype is provided by UMLElementExtension, do you consider the instance of UMLElementExtension as a wrapper that contains the instance of a stereotype in it, or the instance of a stereotype is replaced by the instance of UMLElementExtension when evaluating an OCL constraint? If the second case is true, is that means the actual instance of a stereotype is not necessary in the implementation when evaluating a constraint?

I also test different examples using my program and I observed that I always have the same umlStaticStereotype and umlDynamicStereotype in an instance of UMLElementExtension. Would you please tell me how the umlStaticStereotype and umlDynamicStereotype are set via any M1/M2 model? In what kind of situation, the umlStaticStereotype and umlDynamicStereotype will be different in an instance of UMLElementExtension?

Thank you very much for your help.

Best Regards,
Chung-Ling Lin
  • Attachment: example.pptx
    (Size: 111.45KB, Downloaded 112 times)
Re: Evaluate OCL constraints in an UML model programmatically [message #1737291 is a reply to message #1737281] Thu, 07 July 2016 03:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

If you want me to look at this provide something executable, probably a
JUnit test that fails at the point where your expectation is not satisfied.

Partial and erroneous fragments of pseudo-code in a proprietary file
format are not helpful.

Regards

ed Willink


On 06/07/2016 22:41, Chung-Ling Lin wrote:
> Hi,
>
> Sorry I didn't describe my question clearly and mix different level of elements in my description. So I summarize the models I have and the run time snapshots of my program in the attached slides for your reference.
>
> Based on what you wrote "If you evaluate using UML objects the missing
> instance-of-Stereotype UML model element is provided by org.eclipse.ocl.pivot.uml.internal.library.UMLElementExtension.", what I think is an instance of UMLElementExtension should look like a wrapper contains the instance of a stereotype. So I can evaluate the OCL constraint on an instance of UMLElementExtension when the context of the OCL constraint is a stereotype.
>
> But when I setup a break point in P.4 line 10, the value of the umlStaticStereotype and umlDynamicStereotype of the UMLElementExtension instance uee is stereotype Clock, and the umlElement is class StopWatch, which is an instance of UML metaclass Class. I can't find the instance of Clock in uee. Therefore, I got confuse about the role of UMLElementExtension. When you say the missing instance of stereotype is provided by UMLElementExtension, do you consider the instance of UMLElementExtension as a wrapper that contains the instance of a stereotype in it, or the instance of a stereotype is replaced by the instance of UMLElementExtension when evaluating an OCL constraint? If the second case is true, is that means the actual instance of a stereotype is not necessary in the implementation when evaluating a constraint?
>
> I also test different examples using my program and I observed that I always have the same umlStaticStereotype and umlDynamicStereotype in an instance of UMLElementExtension. Would you please tell me how the umlStaticStereotype and umlDynamicStereotype are set via any M1/M2 model? In what kind of situation, the umlStaticStereotype and umlDynamicStereotype will be different in an instance of UMLElementExtension?
>
> Thank you very much for your help.
>
> Best Regards,
> Chung-Ling Lin
>


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Evaluate OCL constraints in an UML model programmatically [message #1737357 is a reply to message #1737291] Thu, 07 July 2016 14:20 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

The attached project is the same as the file I attached few days ago. And the corresponding break point of my slides p.4 line 10 is line 273 of the attached program.

I don't have the failure result of my project, I just want to clarify after I generate an instance of UMLElementExtension uee via the UMLElementExtension.getUMLElementExtension method at line 272, where is the instance of stereotype Clock in the generated instance of UMLElementExtension uee?


Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1737360 is a reply to message #1737357] Thu, 07 July 2016 14:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi<br>
<br>
At line 273 I see:<br>
<br>
<img src="https://www.eclipse.org/forums/index.php?t=getfile&amp;id=26417" alt=""><br>
<br>
showing that uee is a "StopWatch«Clock»"; i.e. an instance of the
Clock Stereotype applied to a StopWatch.<br>
<br>
uee.umlElement is StopWatch<br>
uee.umlDynamicStereotype is Clock<br>
uee.umlElement.eAdapters-&gt;includes(uee)  -- eAdapters is
magically cached within eStorage<br>
<br>
What is not there?<br>
<br>
    Regards<br>
<br>
        Ed Willink<br>
<br>
On 07/07/2016 16:20, Chung-Ling Lin wrote:<br>
</div>
<blockquote cite="mid:nllof4$6i0$1@xxxxxxxxe.org" type="cite">
<pre wrap="">Hi,

The attached project is the same as the file I attached few days ago. And the corresponding break point of my slides p.4 line 10 is line 273 of the attached program.

I don't have the failure result of my project, I just want to clarify after I generate an instance of UMLElementExtension uee via the UMLElementExtension.getUMLElementExtension method at line 272, where is the instance of stereotype Clock in the generated instance of UMLElementExtension uee?


Best Regards,
Chung-Ling Lin
</pre>
</blockquote>
<p><br>
</p>

<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
This email has been checked for viruses by Avast antivirus software.
<br><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>
Re: Evaluate OCL constraints in an UML model programmatically [message #1737381 is a reply to message #1737360] Thu, 07 July 2016 16:39 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Thank you for the information. So the instance of UMLElementExtension itself is considered as an instance of a stereotype. And the implementation of the OCL evaluation does not provide a direct access to the instance of stereotype UML element in the M1 model.

And the UMLElementExtension has two fields of stereotype, the umlStaticStereotype and umlDynamicStereotype. In what kind of situation, an instance of UMLElementExtension will have different values in these two fields? If an instance of UMLElementExtension has different umlStaticStereotype and umlDynamicStereotype, which stereotype the OCL constraint will be evaluated on?

Best Regards,
Chung-Ling Lin
Re: Evaluate OCL constraints in an UML model programmatically [message #1737393 is a reply to message #1737381] Thu, 07 July 2016 17:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

I have already answered both of these questions.

OMG UML (and so Eclipse UML2) provides no Stereotype instance; just a
bit of XMI magic.

A dynamic stereotype is distinct when one has been applied.

Regards

Ed Willink


On 07/07/2016 18:39, Chung-Ling Lin wrote:
> Hi,
>
> Thank you for the information. So the instance of UMLElementExtension
> itself is considered as an instance of a stereotype. And the
> implementation of the OCL evaluation does not provide a direct access
> to the instance of stereotype UML element in the M1 model.
>
> And the UMLElementExtension has two fields of stereotype, the
> umlStaticStereotype and umlDynamicStereotype. In what kind of
> situation, an instance of UMLElementExtension will have different
> values in these two fields? If an instance of UMLElementExtension has
> different umlStaticStereotype and umlDynamicStereotype, which
> stereotype the OCL constraint will be evaluated on?
>
> Best Regards,
> Chung-Ling Lin



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Evaluate OCL constraints in an UML model programmatically [message #1737491 is a reply to message #1737393] Fri, 08 July 2016 15:55 Go to previous messageGo to next message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Thank you for your information. I am still learning the OMG UML now and eager to learn more detail of UML. Would you please tell me which section of the UML spec I should read to get the detail information about what you said "OMG UML (and so Eclipse UML2) provides no Stereotype instance;"

Thank you for your help.

Best Regards,
Chung-Ling Lin

[Updated on: Fri, 08 July 2016 15:56]

Report message to a moderator

Re: Evaluate OCL constraints in an UML model programmatically [message #1737519 is a reply to message #1737491] Fri, 08 July 2016 23:18 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

Once again, I have already answered this (26-June).

I consider this thread closed.

Regards

Ed Willink

On 08/07/2016 17:55, Chung-Ling Lin wrote:
> Hi,
> Thank you for your information. I am still learning the OMG UML now
> and eager to learn more about the detail of UML. Would you please tell
> me which section of the UML spec I should read to get the detail
> information about what you said "OMG UML (and so Eclipse UML2)
> provides no Stereotype instance;"
> Thank you for your help.
>
> Best Regards,
> Chung-Ling Lin



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Evaluate OCL constraints in an UML model programmatically [message #1737542 is a reply to message #1736116] Sat, 09 July 2016 17:00 Go to previous message
Chung-Ling Lin is currently offline Chung-Ling LinFriend
Messages: 39
Registered: December 2011
Member
Hi,

Thank you again for the help. I read your explanation on 26-June again, but I am not understand about "However the instance of this compound at M0 is an instance of XXX with navigation relationships base_XXX/extension_YYY to an instance of an instance of YYY."
Therefore, I draw the models below to illustrate my understanding of the UML spec and your explanation.

http://i.imgur.com/zGhPIFh.png
Fig 1
http://i.imgur.com/X9Jd8oZ.png
Fig 2

Consider that we have a stereotype Clock extends metaclass Class, based on the UML spec, the notation of the extends relationship is represented as figure 1, and figure 2 shows that the extends relationship is an association between Class and Clock.

http://i.imgur.com/3aYjT7m.png
Fig 3
http://i.imgur.com/yL23qtt.png
Fig 4

Therefore, if I define a stereotyped element <<Clock>>StopWatch, the corresponding class diagram is shown in figure 3. If I use instance diagram notation to represent this M1 model as figure 4, the Extension between the Stereotype and the metaclass Class results in a link between the instance of Stereotype Clock and StopWatch.

http://i.imgur.com/WzBaaKv.png
Fig 5
Based on my understanding of your explanation, I draw the M0 diagram shown as figure 5. Therefore, the instance of this compound type, MyWatch, is an instance of StopWatch with navigation relationships base_Class/extension_Clock to an instance of an instance of Clock.

But what I don't understand is, since the extends relationship is defined as an association in M2, I understand that we have a link between the StopWatch and the instance of Clock in M1. Since MyWatch:StopWatch is an instance of StopWatch in M0, why this object still have a link to navigate the instance of instance of Clock?

Best Regards,
Chung-Ling Lin



Previous Topic:Clone Dict
Next Topic:How to write OCL in a file and use it in a state machine?
Goto Forum:
  


Current Time: Fri Sep 21 04:57:38 GMT 2018

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

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

Back to the top