Home » Modeling » OCL » Navigate through a model
Navigate through a model [message #67457] |
Mon, 09 February 2009 20:00  |
Eclipse User |
|
|
|
Hi,
in the UML2Tools Classdiagram this ocl constraint is evaluated:
let result : Set(Type) = Set{} in
let pakkage : Package = self.getNearestPackage()
let siblings : Set(Type) = pakkage.ownedType in
let imports : Bag(Type) =
pakkage.elementImport->select(importedElement.oclIsKindOf(Type)
and (importedElement.oclIsKindOf(Class) implies not
importedElement.oclAsType(Class).isMetaclass())
)->collect(importedElement.oclAsType(Type)) in
result->union(siblings)->union(imports->asSet())
This gets the Elements in the actual Package.
The structure of my Model is always:
Model test
Package Classes
Package A
Package B
Package C
The constraint is evaluated in Package C but I want Elements from the
Package "Classes". Is this possible?
Thank you
Peter
|
|
|
Re: Navigate through a model [message #67518 is a reply to message #67457] |
Tue, 10 February 2009 09:53   |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Peter,
Why is this constraint only evaluated in the C package? What is the
context of this constraint? Is it Package or Classifier? It should be
evaluated on *every* instance of the context metaclass.
In any case, you have at least a few options to navigate from package C
to Classes:
- directly:
self.getModel().getNestedPackage('Classes')
- indirectly:
Package.allInstances->any(qualifiedName = 'test::Classes')
Or, you could define the constraint in the Package context and introduce
a condition on the package name:
context Package
inv:
if qualifiedName <> 'test::Classes' then Set{} else
let result : Set(Type) = Set{},
siblings : Set(Type) = self.ownedType,
imports : Bag(Type) =
elementImport->select(importedElement.oclIsKindOf(Type)
and (importedElement.oclIsKindOf(Class) implies not
importedElement.oclAsType(Class).isMetaclass())
)->collect(importedElement.oclAsType(Type))
in
result->union(siblings)->union(imports->asSet())
endif
Although, this isn't a boolean valued expression, so I'm assuming it is
some kind of operation body expression?
Incidentally, it could be expressed more straightforwardly to take
imports into account, thus:
self.member->iterate(e; result : Set(Type) = Set{} |
if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
e.oclAsType(Class).isMetaclass()) then
result->including(e.oclAsType(Type))
else
result
endif)
HTH,
Christian
Peter wrote:
> Hi,
> in the UML2Tools Classdiagram this ocl constraint is evaluated:
>
> let result : Set(Type) = Set{} in
> let pakkage : Package = self.getNearestPackage()
> let siblings : Set(Type) = pakkage.ownedType in
> let imports : Bag(Type) =
> pakkage.elementImport->select(importedElement.oclIsKindOf(Type)
> and (importedElement.oclIsKindOf(Class)
> implies not importedElement.oclAsType(Class).isMetaclass())
> )->collect(importedElement.oclAsType(Type)) in
> result->union(siblings)->union(imports->asSet())
>
> This gets the Elements in the actual Package.
> The structure of my Model is always:
> Model test
> Package Classes
> Package A
> Package B
> Package C
>
> The constraint is evaluated in Package C but I want Elements from the
> Package "Classes". Is this possible?
> Thank you
> Peter
>
|
|
| |
Re: Navigate through a model [message #67591 is a reply to message #67561] |
Tue, 10 February 2009 16:24   |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Peter,
See some comments in-line, below.
HTH,
Christian
Peter wrote:
> Hi Christian,
> first Thank you for your answer!
>
>> Why is this constraint only evaluated in the C package? What is the
>> context of this constraint? Is it Package or Classifier? It should
>> be evaluated on *every* instance of the context metaclass.
>
> Sorry I should explained that.
> This constraint get the Classifier Elements for a InstanceSpecification.
Ah! That'll be the root of your problem. More on that, below.
> When I set a name of a Instance Specification it`s also possible to set
> the Classifier with ": Classifier". The constraint gets the possible
> Classifiers.
> So its evaluated on a InstanceSpecification.
>
>
>> In any case, you have at least a few options to navigate from package
>> C to Classes:
>>
>> - directly:
>>
>> self.getModel().getNestedPackage('Classes')
>
> I already tried that. The OCL Console says
> Results:
> Cannot find operation (getNestedPackage(String)) for the type (Model)
Doh! Sorry, silly me. This is only a Java method produced by the UML2
code generator. Is has no correspondent in OCL. But, you could emulate
it with:
self.getModel().nestedPackage->any(name = 'Classes')
>> - indirectly:
>>
>> Package.allInstances()->any(qualifiedName = 'test::Classes')
>
> This works. But not when the actual Element is an InstanceSpecification?
The problem with instance specifications is that the OCL interpreter
supports evaluating OCL constraints and expressions on them that are
defined in the context of the instance's classifiers, to simulate their
evaluation in the run-time system. That is, since
InstanceSpecifications are (partial) models (at M1 level) of run-time
objects (the M0 level), we can evaluate the OCL constraints of their
classifiers on them. However, as they are nonetheless model elements,
one also wants to be able to treat InstanceSpecifications as M1
instances of the M2 InstanceSpecification metaclass, and evaluate
constraints defined at that level.
The default configuration of the OCL interpreter is to treat
InstanceSpecifications as like M0 objects (evaluating on them
expressions defined in the context of their classifiers) rather than M1
objects. This is a consequence of the
UMLEvaluationOptions::EVALUATION_MODE evaluation option, which is by
default EvaluationMode::ADAPTIVE.
To solve your problem, just set the evaluation-mode of your evaluation
environment to RUNTIME_OBJECTS (meaning that your instance
specifications are treated as an M0 instance of the
InstanceSpecification metaclass taken as an M1 element of the UML
metamodel).
EvaluationEnvironment<...> env = // get from your OCL or your Query
EvaluationOptions.setOption(
env,
UMLEvaluationOptions.EVALUATION_MODE,
EvaluationMode.RUNTIME_OBJECTS);
> When I evaluate this on a Instance Specification:
>
> Package.allInstances()->any(qualifiedName =
> self.getModel().name.concat('::Classes')).member->iterate(e; result :
> Set(Type) = Set{} |
> if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
> e.oclAsType(Class).isMetaclass()) then
> result->including(e.oclAsType(Type))
> else
> result
> endif)
>
> Results:
> OclInvalid
>
> When I evaluate it on a Class or a Package it gets the Classifier Elements.
>
> Any suggestion?
>
-----8<-----
|
|
|
Re: Navigate through a model [message #67633 is a reply to message #67591] |
Wed, 11 February 2009 09:04   |
Eclipse User |
|
|
|
Hi Christian,
I figured out that the Editor uses a Ecore OCL Instance and the
InstanceSpecifcations treated as EClasses.
I don`t know why my expressions before don`t work?
But this expression solved my problem.
self.getModel().nestedPackage->any(name='Classes').member->iterate(e;
result : Set(Type) = Set{} |
if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
e.oclAsType(Class).isMetaclass()) then
result->including(e.oclAsType(Type))
else
result
endif)
Thank you for your help and keep up the great work.
Peter
Christian W. Damus wrote:
> Hi, Peter,
>
> See some comments in-line, below.
>
> HTH,
>
> Christian
>
> Peter wrote:
>> Hi Christian,
>> first Thank you for your answer!
>>
>>> Why is this constraint only evaluated in the C package? What is the
>>> context of this constraint? Is it Package or Classifier? It should
>>> be evaluated on *every* instance of the context metaclass.
>>
>> Sorry I should explained that.
>> This constraint get the Classifier Elements for a InstanceSpecification.
>
> Ah! That'll be the root of your problem. More on that, below.
>
>
>> When I set a name of a Instance Specification it`s also possible to
>> set the Classifier with ": Classifier". The constraint gets the
>> possible Classifiers.
>> So its evaluated on a InstanceSpecification.
>>
>>
>>> In any case, you have at least a few options to navigate from package
>>> C to Classes:
>>>
>>> - directly:
>>>
>>> self.getModel().getNestedPackage('Classes')
>>
>> I already tried that. The OCL Console says
>> Results:
>> Cannot find operation (getNestedPackage(String)) for the type (Model)
>
> Doh! Sorry, silly me. This is only a Java method produced by the UML2
> code generator. Is has no correspondent in OCL. But, you could emulate
> it with:
>
> self.getModel().nestedPackage->any(name = 'Classes')
>
>
>>> - indirectly:
>>>
>>> Package.allInstances()->any(qualifiedName = 'test::Classes')
>>
>> This works. But not when the actual Element is an InstanceSpecification?
>
> The problem with instance specifications is that the OCL interpreter
> supports evaluating OCL constraints and expressions on them that are
> defined in the context of the instance's classifiers, to simulate their
> evaluation in the run-time system. That is, since
> InstanceSpecifications are (partial) models (at M1 level) of run-time
> objects (the M0 level), we can evaluate the OCL constraints of their
> classifiers on them. However, as they are nonetheless model elements,
> one also wants to be able to treat InstanceSpecifications as M1
> instances of the M2 InstanceSpecification metaclass, and evaluate
> constraints defined at that level.
>
> The default configuration of the OCL interpreter is to treat
> InstanceSpecifications as like M0 objects (evaluating on them
> expressions defined in the context of their classifiers) rather than M1
> objects. This is a consequence of the
> UMLEvaluationOptions::EVALUATION_MODE evaluation option, which is by
> default EvaluationMode::ADAPTIVE.
>
> To solve your problem, just set the evaluation-mode of your evaluation
> environment to RUNTIME_OBJECTS (meaning that your instance
> specifications are treated as an M0 instance of the
> InstanceSpecification metaclass taken as an M1 element of the UML
> metamodel).
>
> EvaluationEnvironment<...> env = // get from your OCL or your Query
> EvaluationOptions.setOption(
> env,
> UMLEvaluationOptions.EVALUATION_MODE,
> EvaluationMode.RUNTIME_OBJECTS);
>
>
>> When I evaluate this on a Instance Specification:
>>
>> Package.allInstances()->any(qualifiedName =
>> self.getModel().name.concat('::Classes')).member->iterate(e; result :
>> Set(Type) = Set{} |
>> if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
>> e.oclAsType(Class).isMetaclass()) then
>> result->including(e.oclAsType(Type))
>> else
>> result
>> endif)
>>
>> Results:
>> OclInvalid
>>
>> When I evaluate it on a Class or a Package it gets the Classifier
>> Elements.
>>
>> Any suggestion?
>>
>
> -----8<-----
|
|
|
Re: Navigate through a model [message #67654 is a reply to message #67633] |
Wed, 11 February 2009 17:15  |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Peter,
More comments in-line, below.
Cheers,
Christian
Peter wrote:
> Hi Christian,
> I figured out that the Editor uses a Ecore OCL Instance and the
> InstanceSpecifcations treated as EClasses.
Ah. Perplexing, indeed.
> I don`t know why my expressions before don`t work?
> But this expression solved my problem.
>
> self.getModel().nestedPackage->any(name='Classes').member->iterate(e;
> result : Set(Type) = Set{} |
> if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
> e.oclAsType(Class).isMetaclass()) then
> result->including(e.oclAsType(Type))
> else
> result
> endif)
Great! I'm glad that's working for you. Just, if you do ever find a
spare moment to reproduce the original problem, I would be interested to
know whether there isn't some bug that should be fixed in the OCL component.
> Thank you for your help and keep up the great work.
Thanks! for the vote of confidence. I appreciate it.
> Peter
>
> Christian W. Damus wrote:
>> Hi, Peter,
>>
>> See some comments in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>> Peter wrote:
>>> Hi Christian,
>>> first Thank you for your answer!
>>>
>>>> Why is this constraint only evaluated in the C package? What is the
>>>> context of this constraint? Is it Package or Classifier? It should
>>>> be evaluated on *every* instance of the context metaclass.
>>>
>>> Sorry I should explained that.
>>> This constraint get the Classifier Elements for a InstanceSpecification.
>>
>> Ah! That'll be the root of your problem. More on that, below.
>>
>>
>>> When I set a name of a Instance Specification it`s also possible to
>>> set the Classifier with ": Classifier". The constraint gets the
>>> possible Classifiers.
>>> So its evaluated on a InstanceSpecification.
>>>
>>>
>>>> In any case, you have at least a few options to navigate from
>>>> package C to Classes:
>>>>
>>>> - directly:
>>>>
>>>> self.getModel().getNestedPackage('Classes')
>>>
>>> I already tried that. The OCL Console says
>>> Results:
>>> Cannot find operation (getNestedPackage(String)) for the type (Model)
>>
>> Doh! Sorry, silly me. This is only a Java method produced by the
>> UML2 code generator. Is has no correspondent in OCL. But, you could
>> emulate it with:
>>
>> self.getModel().nestedPackage->any(name = 'Classes')
>>
>>
>>>> - indirectly:
>>>>
>>>> Package.allInstances()->any(qualifiedName = 'test::Classes')
>>>
>>> This works. But not when the actual Element is an InstanceSpecification?
>>
>> The problem with instance specifications is that the OCL interpreter
>> supports evaluating OCL constraints and expressions on them that are
>> defined in the context of the instance's classifiers, to simulate
>> their evaluation in the run-time system. That is, since
>> InstanceSpecifications are (partial) models (at M1 level) of run-time
>> objects (the M0 level), we can evaluate the OCL constraints of their
>> classifiers on them. However, as they are nonetheless model elements,
>> one also wants to be able to treat InstanceSpecifications as M1
>> instances of the M2 InstanceSpecification metaclass, and evaluate
>> constraints defined at that level.
>>
>> The default configuration of the OCL interpreter is to treat
>> InstanceSpecifications as like M0 objects (evaluating on them
>> expressions defined in the context of their classifiers) rather than
>> M1 objects. This is a consequence of the
>> UMLEvaluationOptions::EVALUATION_MODE evaluation option, which is by
>> default EvaluationMode::ADAPTIVE.
>>
>> To solve your problem, just set the evaluation-mode of your evaluation
>> environment to RUNTIME_OBJECTS (meaning that your instance
>> specifications are treated as an M0 instance of the
>> InstanceSpecification metaclass taken as an M1 element of the UML
>> metamodel).
>>
>> EvaluationEnvironment<...> env = // get from your OCL or your Query
>> EvaluationOptions.setOption(
>> env,
>> UMLEvaluationOptions.EVALUATION_MODE,
>> EvaluationMode.RUNTIME_OBJECTS);
>>
>>
>>> When I evaluate this on a Instance Specification:
>>>
>>> Package.allInstances()->any(qualifiedName =
>>> self.getModel().name.concat('::Classes')).member->iterate(e; result :
>>> Set(Type) = Set{} |
>>> if e.oclIsKindOf(Type) and not (e.oclIsKindOf(Class) and
>>> e.oclAsType(Class).isMetaclass()) then
>>> result->including(e.oclAsType(Type))
>>> else
>>> result
>>> endif)
>>>
>>> Results:
>>> OclInvalid
>>>
>>> When I evaluate it on a Class or a Package it gets the Classifier
>>> Elements.
>>>
>>> Any suggestion?
>>>
>>
>> -----8<-----
|
|
|
Goto Forum:
Current Time: Mon Apr 28 00:58:13 EDT 2025
Powered by FUDForum. Page generated in 0.03922 seconds
|