Home » Modeling » OCL » Evaluate OCL constraints in an UML model programmatically
| |
Re: Evaluate OCL constraints in an UML model programmatically [message #1733502 is a reply to message #1733497] |
Sat, 28 May 2016 21:56 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 #1733913 is a reply to message #1733793] |
Thu, 02 June 2016 08:01 |
Ed Willink Messages: 7670 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 #1735922 is a reply to message #1734161] |
Thu, 23 June 2016 16:06 |
Chung-Ling Lin 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 319 times) -
Attachment: TestOCL0621.zip
(Size: 100.49KB, Downloaded 284 times) -
Attachment: MyProf.png
(Size: 15.46KB, Downloaded 377 times)
[Updated on: Thu, 23 June 2016 16:14] Report message to a moderator
|
|
| |
Re: Evaluate OCL constraints in an UML model programmatically [message #1735936 is a reply to message #1735929] |
Thu, 23 June 2016 18:53 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 |
Chung-Ling Lin 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 |
Ed Willink Messages: 7670 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 #1737281 is a reply to message #1736827] |
Wed, 06 July 2016 20:41 |
Chung-Ling Lin 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 288 times)
|
|
|
Re: Evaluate OCL constraints in an UML model programmatically [message #1737291 is a reply to message #1737281] |
Thu, 07 July 2016 03:01 |
Ed Willink Messages: 7670 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 #1737542 is a reply to message #1736116] |
Sat, 09 July 2016 17:00 |
Chung-Ling Lin 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.
Fig 1
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.
Fig 3
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.
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
|
|
|
Goto Forum:
Current Time: Sun Sep 22 14:08:26 GMT 2024
Powered by FUDForum. Page generated in 0.05596 seconds
|