Home » Modeling » OCL » Direct access to pre/post conditions of an context operation
Direct access to pre/post conditions of an context operation [message #68466] |
Thu, 05 March 2009 11:27  |
Eclipse User |
|
|
|
Hey all again,
is there the possibility to navigate directly to a pre/post condition of
an operation, defined in a ocl document. i want to handle only some
preconditions, which have specific name.
I was wondering, that there is no getPreconditions() metod for
operations. i know, inside the uml spec, every operation can define a
number of pre/postconditions directly. but how can i access the ast of
each precondition, if i haven't the possibility to access them?
and is there the possibility to serialize the generated ast (the ocl
metamodel instrance) for visualizing it with the emf editor?
thanks again. i hope after getting access to the pre/ostconditions, i
won't have so much questions any more. imho, in contrast to the uml
spec, the ocl spec is much more confusing and harder to understand.
Timothy
|
|
|
Re: Direct access to pre/post conditions of an context operation [message #68507 is a reply to message #68466] |
Fri, 06 March 2009 09:01   |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Timothy,
See some replies in-line, below.
HTH,
Christian
Timothy Marc wrote:
> Hey all again,
>
> is there the possibility to navigate directly to a pre/post condition of
> an operation, defined in a ocl document. i want to handle only some
> preconditions, which have specific name.
If you assign your constraints names (between the "pre" or "post"
keyword and the colon), then you will be able to find them again, after
parsing.
You can determine that a constraint is a pre- or post-condition of an
operation by checking that UMLReflection::getConstrainedElements(...)
includes your operation. Get the name of the constraint using
UMLReflection::getName(...).
> I was wondering, that there is no getPreconditions() metod for
> operations. i know, inside the uml spec, every operation can define a
> number of pre/postconditions directly. but how can i access the ast of
> each precondition, if i haven't the possibility to access them?
The OCL façade object through which you parsed the OCL constraints keeps
track of them. You can find them all using OCL::getConstraints().
These are the ASTs. Then, it's a matter of using the UMLReflection API
as I mentioned above to find the right constraint. There is potential,
here, for handy additions to the OCLUtil class ...
> and is there the possibility to serialize the generated ast (the ocl
> metamodel instrance) for visualizing it with the emf editor?
Yes. You can serialize the environment, which includes all of the
constraints that you parsed, additional operation/attribute definitions
("helpers"), demand-created collection types, etc. Just get the
Environment's resource, set a useful URI, and save it:
Environment<...> myEnv = /* ... */;
Resource res = myEnv.getTypeResolver().getResource();
// set res's URI and save it
> thanks again. i hope after getting access to the pre/ostconditions, i
> won't have so much questions any more. imho, in contrast to the uml
> spec, the ocl spec is much more confusing and harder to understand.
Well, the newsgroup is always here to answer. :-)
> Timothy
|
|
| | |
Re: Direct access to pre/post conditions of an context operation [message #68561 is a reply to message #68507] |
Fri, 06 March 2009 15:36   |
Eclipse User |
|
|
|
Christian,
so, it is me again for the (hopefully) last question today. I tried to
serialize the parsed ast, but i got a ClassNotFoundException, when i
open the xmi with the sample reflective edtitor.
The Class "ExpressionInOcl" could not be found. I think, the connection
to the ocl.uml metamodel is lost??? Is it so?
And by the way, how can the OCL AST View be used? I don't know how to
pass an ast to it, since it seems that there is no functionality
implemented.
Thx
Timothy
Christian W. Damus schrieb:
> Hi, Timothy,
>
> See some replies in-line, below.
>
> HTH,
>
> Christian
>
>
> Timothy Marc wrote:
>> Hey all again,
>>
>> is there the possibility to navigate directly to a pre/post condition
>> of an operation, defined in a ocl document. i want to handle only some
>> preconditions, which have specific name.
>
> If you assign your constraints names (between the "pre" or "post"
> keyword and the colon), then you will be able to find them again, after
> parsing.
>
> You can determine that a constraint is a pre- or post-condition of an
> operation by checking that UMLReflection::getConstrainedElements(...)
> includes your operation. Get the name of the constraint using
> UMLReflection::getName(...).
>
>
>> I was wondering, that there is no getPreconditions() metod for
>> operations. i know, inside the uml spec, every operation can define a
>> number of pre/postconditions directly. but how can i access the ast of
>> each precondition, if i haven't the possibility to access them?
>
> The OCL façade object through which you parsed the OCL constraints keeps
> track of them. You can find them all using OCL::getConstraints(). These
> are the ASTs. Then, it's a matter of using the UMLReflection API as I
> mentioned above to find the right constraint. There is potential, here,
> for handy additions to the OCLUtil class ...
>
>
>> and is there the possibility to serialize the generated ast (the ocl
>> metamodel instrance) for visualizing it with the emf editor?
>
> Yes. You can serialize the environment, which includes all of the
> constraints that you parsed, additional operation/attribute definitions
> ("helpers"), demand-created collection types, etc. Just get the
> Environment's resource, set a useful URI, and save it:
>
> Environment<...> myEnv = /* ... */;
> Resource res = myEnv.getTypeResolver().getResource();
> // set res's URI and save it
>
>
>> thanks again. i hope after getting access to the pre/ostconditions, i
>> won't have so much questions any more. imho, in contrast to the uml
>> spec, the ocl spec is much more confusing and harder to understand.
>
> Well, the newsgroup is always here to answer. :-)
>
>
>> Timothy
|
|
|
Re: Direct access to pre/post conditions of an context operation [message #68615 is a reply to message #68561] |
Wed, 11 March 2009 09:28  |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Timothy,
Is your code running in an Eclipse instance? If so, you should have no
trouble find this class because the OCL-UML metamodel is statically
registered. Otherwise, you would have to take care of the package
registrations, yourself. The org.eclipse.ocl.standalone.tests project
provides a complete example of how to do that: it runs the OCL JUnit
tests in an Eclipse-free context.
I don't know what condition the OCL AST View is in. It hasn't been
updated in years, as far as I know, so it may be out of touch with the
OCL API. Best to ask its authors about that.
HTH,
Christian
Timothy Marc wrote:
> Christian,
>
> so, it is me again for the (hopefully) last question today. I tried to
> serialize the parsed ast, but i got a ClassNotFoundException, when i
> open the xmi with the sample reflective edtitor.
>
> The Class "ExpressionInOcl" could not be found. I think, the connection
> to the ocl.uml metamodel is lost??? Is it so?
>
> And by the way, how can the OCL AST View be used? I don't know how to
> pass an ast to it, since it seems that there is no functionality
> implemented.
>
> Thx
> Timothy
>
> Christian W. Damus schrieb:
>> Hi, Timothy,
>>
>> See some replies in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Timothy Marc wrote:
>>> Hey all again,
>>>
>>> is there the possibility to navigate directly to a pre/post condition
>>> of an operation, defined in a ocl document. i want to handle only
>>> some preconditions, which have specific name.
>>
>> If you assign your constraints names (between the "pre" or "post"
>> keyword and the colon), then you will be able to find them again,
>> after parsing.
>>
>> You can determine that a constraint is a pre- or post-condition of an
>> operation by checking that UMLReflection::getConstrainedElements(...)
>> includes your operation. Get the name of the constraint using
>> UMLReflection::getName(...).
>>
>>
>>> I was wondering, that there is no getPreconditions() metod for
>>> operations. i know, inside the uml spec, every operation can define a
>>> number of pre/postconditions directly. but how can i access the ast
>>> of each precondition, if i haven't the possibility to access them?
>>
>> The OCL façade object through which you parsed the OCL constraints
>> keeps track of them. You can find them all using
>> OCL::getConstraints(). These are the ASTs. Then, it's a matter of
>> using the UMLReflection API as I mentioned above to find the right
>> constraint. There is potential, here, for handy additions to the
>> OCLUtil class ...
>>
>>
>>> and is there the possibility to serialize the generated ast (the ocl
>>> metamodel instrance) for visualizing it with the emf editor?
>>
>> Yes. You can serialize the environment, which includes all of the
>> constraints that you parsed, additional operation/attribute
>> definitions ("helpers"), demand-created collection types, etc. Just
>> get the Environment's resource, set a useful URI, and save it:
>>
>> Environment<...> myEnv = /* ... */;
>> Resource res = myEnv.getTypeResolver().getResource();
>> // set res's URI and save it
>>
>>
>>> thanks again. i hope after getting access to the pre/ostconditions, i
>>> won't have so much questions any more. imho, in contrast to the uml
>>> spec, the ocl spec is much more confusing and harder to understand.
>>
>> Well, the newsgroup is always here to answer. :-)
>>
>>
>>> Timothy
|
|
|
Goto Forum:
Current Time: Sat May 10 09:17:11 EDT 2025
Powered by FUDForum. Page generated in 0.03861 seconds
|