Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » using @pre. operator. in the PostConditions
using @pre. operator. in the PostConditions [message #655746] Tue, 22 February 2011 14:42 Go to next message
Hussam  is currently offline Hussam Friend
Messages: 19
Registered: January 2011
Junior Member
Hello every experts ,

I am writing a program in Java,using Eclipse for providing the user by the ability to apply some operators on a per developed UML Model of any software. one of this operators is to add a new Operation into an interface , so that all the related elements that interface has to be updated.

I need to use the @pre in the post conditions as you see in the following short code.:

String test="Interface.allInstances()->select(getAppliedStereotypes().name- >includes('newAddOperationInterface')->forAll(intf:Interface|intf.ownedMember@pre->size()<intf.ownedMember->size())";

Constraint consTest=(Constraint)oclHelper.createInvariant(test); existsDepndency_AddPheno=ocl2.check(this.model, consTest);

if(existsDepndency_AddPheno)


The result is that : Not@pre may only used in an operation postcondition constraint
, so how can I use it. where exactly I could embed the code of post conditions in the Java program?
Re: using @pre. operator. in the PostConditions [message #655748 is a reply to message #655746] Tue, 22 February 2011 14:46 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Hussam,

ah, maybe I misread your first post. When you compile the expression, are you using the OCLHelper.createPostcondition(String) method?

Best,
-- Axel
Re: using @pre. operator. in the PostConditions [message #655760 is a reply to message #655748] Tue, 22 February 2011 15:07 Go to previous messageGo to next message
Hussam  is currently offline Hussam Friend
Messages: 19
Registered: January 2011
Junior Member
Hi Axel,

I did the .CreatePostcondition but it gives me : Notnull.

this is the result. Notnull.


regrads
Re: using @pre. operator. in the PostConditions [message #655761 is a reply to message #655748] Tue, 22 February 2011 15:07 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
The problem is probably caused by your use of the OCL Helper:

Constraint consTest=(Constraint)oclHelper.createInvariant(test); existsDepndency_AddPheno=ocl2.check(this.model, consTest);


Use

Constraint consTest=(Constraint)oclHelper.createPostcondition(test); existsDepndency_AddPheno=ocl2.check(this.model, consTest);

instead.

Best,
-- Axel
Re: using @pre. operator. in the PostConditions [message #655768 is a reply to message #655761] Tue, 22 February 2011 15:21 Go to previous messageGo to next message
Hussam  is currently offline Hussam Friend
Messages: 19
Registered: January 2011
Junior Member
Hi Axel,

Sorry for more questions,

I think I need to set the operationContext (Object , Object)

but I do not know how to use this operation.

Do you have an example?

Regards,.
Re: using @pre. operator. in the PostConditions [message #655793 is a reply to message #655746] Tue, 22 February 2011 16:26 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Use the Classifier representing your "Interface" class as the first argument, and the Operation representing the operation for which you want to define a postcondition as the second argument. You have to retrieve those from your UML model.

Best,
-- Axel
Re: using @pre. operator. in the PostConditions [message #655830 is a reply to message #655746] Tue, 22 February 2011 18:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Hussam
On 22/02/2011 14:42, Hussam wrote:
> The result is that :

I am afraid that you need to be much clearer

Is this "the result" of
evaluation
parsing
your thinking?

@pre should only be used in postconditions, though I'm not sure that the
3.0 editors enforce this, but thye don;y yewt work with UML anyway.

Currently Eclipse OCL only supports parsing of pre and postconditions.
As far as I am aware there is no mechanism to execute them.

With the advent of invocation delegates, it would now be possible to
have an execution option to check the pre and post conditions.

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

Regards

Ed Willink
Re: using @pre. operator. in the PostConditions [message #655916 is a reply to message #655830] Wed, 23 February 2011 09:54 Go to previous messageGo to next message
Hussam  is currently offline Hussam Friend
Messages: 19
Registered: January 2011
Junior Member
Thank you Edward,

The result is that : @pre may only used in an operation postcondition constraint ..


my problem is that I was using the @pre operator in an OCL expression which to be used in an invariant and not a post condition.

but I think in my situation to use the oclHelper.createPostcondition() it needs the OperationContext to be defined as i discussed above with Axel.. but in this case also I have a problem that the Operation that I need to use the pre and post conditions for it is a pure Java Method which uses any UML model to make some operation in it. I wich it is clear, I mean, my Operation is not coming from a UML model, but it will use some element from any UML model as an input to produce some outputs, my Postconditions has to check that this operation produces the correct results:

Example:

I have one of my operation:

public void connectTwoClasses(Dependency connection){
//the preconditions are to make sure that there is a dependency with Stereotype <<ConnectClasses>> and the ends of this dependency must be of type Class.

I made them by the oclHelper.createInvariant(String exp)

the context is the UML model ,any UML model which will contains this classes and the connection elements.

//the postconditions are to cheak whether the connection is made correctly by query the number of interfaces , the number of Association before and after , of course I need to use the @pre . So how to use the OperationContext in this case as the connectTwoClasses(Dependency connection) operation is not in the UML model which will be used as an input for this method?

}




best regards,

Re: using @pre. operator. in the PostConditions [message #655999 is a reply to message #655916] Wed, 23 February 2011 17:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I really do not understand your problem because you present only small
excerpts that you think are interesting.

> public void connectTwoClasses(Dependency connection){
> //the preconditions are to make sure that there is a dependency with
> Stereotype <<ConnectClasses>> and the ends of this dependency must be of
> type Class.

public void connectTwoClasses(Dependency connection)

is a Java declaration. It is not OCL, so I am unclear why you expect OCL
post conditions to be relevant.

Regards

Ed Willink

On 23/02/2011 09:54, Hussam wrote:
> Thank you Edward,
>
> The result is that : @pre may only used in an operation postcondition
> constraint ..
>
>
> my problem is that I was using the @pre operator in an OCL expression
> which to be used in an invariant and not a post condition.
> but I think in my situation to use the oclHelper.createPostcondition()
> it needs the OperationContext to be defined as i discussed above with
> Axel.. but in this case also I have a problem that the Operation that I
> need to use the pre and post conditions for it is a pure Java Method
> which uses any UML model to make some operation in it. I wich it is
> clear, I mean, my Operation is not coming from a UML model, but it will
> use some element from any UML model as an input to produce some outputs,
> my Postconditions has to check that this operation produces the correct
> results:
>
> Example:
>
> I have one of my operation:
>
> public void connectTwoClasses(Dependency connection){
> //the preconditions are to make sure that there is a dependency with
> Stereotype <<ConnectClasses>> and the ends of this dependency must be of
> type Class.
>
> I made them by the oclHelper.createInvariant(String exp)
>
> the context is the UML model ,any UML model which will contains this
> classes and the connection elements.
> //the postconditions are to cheak whether the connection is made
> correctly by query the number of interfaces , the number of Association
> before and after , of course I need to use the @pre . So how to use the
> OperationContext in this case as the connectTwoClasses(Dependency
> connection) operation is not in the UML model which will be used as an
> input for this method?
>
> }
>
>
>
>
> best regards,
>
>
Re: using @pre. operator. in the PostConditions [message #656006 is a reply to message #655916] Wed, 23 February 2011 17:31 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
I thnk I understand what the problem is. You have implemented some method in Java for which there is no corresponding operation in your UML model. Yet, you'd like to express a postcondition using OCL. Correct so far?

I guess this results in a major and a number of questions. The most important problem I see is that there most likely is no clean way to set the operation context if you're trying to constrain an non-modeled operation. There simply is no model element for the operation you want to constraint.

Which brings me to the questions. Why aren't you adding the operation that you'd like to add your postcondition for to the model? This would at least allow you to provide the OCLHelper with the appropriate Operation model element when setting the operation context.

My next question then relates to the lack of @pre implementation in the evaluator. What are you trying to achieve with the compiled OCL expression? Due to the lacking @pre support at evaluation time there unfortunately seems to be little use currently for such a compiled operation.

If it's just for checking if you got the OCL syntax right, I really recommend adding the operation to constrain to your UML model, then write the postcondition and check if it compiles.

Hope that helps,
-- Axel
Re: using @pre. operator. in the PostConditions [message #656124 is a reply to message #656006] Thu, 24 February 2011 10:06 Go to previous messageGo to next message
Hussam  is currently offline Hussam Friend
Messages: 19
Registered: January 2011
Junior Member
Hi Axel,

You are right ,that I have a java method which is not modeled , my program is not modeled .

to make it more clear:

I am writing a program , this program has to work with the UML models itself, I mean I need to for example add new Interface or Association or Class into the model not manually but automatically , my program will do that. So for adding a new Association between two classes , there are too many elements to be added , Like the interface represented that Association, The Dependencies between the classes and that new added Interface and so on.

my Java method will take the UML Model (Any UML model the user want to use my program to evolve it or to add some new elements ..) as an Input , some preconditions have to be checked before invoking the Java method and I need also to check some postconditions on that Model(The Input model). that means , if I want to model my method , I would have two models, one for my program, and the Input one that my program will evolve it.

So, if it is possible to use the Postconditions without modelling ,please tell me how? if not , is there any way to retrieve the number of elements of specified type in the input model pre and after the implementing of the method using OCL?

one more possibility of help:
Do you know a tool or plugin which coukld be used to generate a UML model for my Java program so that it would be used in Papyrus or like that.


Regards,
Re: using @pre. operator. in the PostConditions [message #656134 is a reply to message #656124] Thu, 24 February 2011 10:23 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It seems you are doing a model to model transformation, so rather than
'my Java method', I would suggest QVTo or ATL. These understand OCL so
you may find that you have the environment you want. You just need to
keep a clear head to avoid confusion between the OCL in the tooling and
the OCL in the generated code, where I would probably recommend
synthesizing a text string in an OpaqueExpression rather than an AST in
an ExpressionInOcl.

Papyrus is a steadily improving tool for UML, so I don't understand
why you want advice on a tool to produce UML for Papyrus.

Regards

Ed Willink


On 24/02/2011 10:06, Hussam wrote:
> Hi Axel,
>
> You are right ,that I have a java method which is not modeled , my
> program is not modeled .
>
> to make it more clear:
>
> I am writing a program , this program has to work with the UML models
> itself, I mean I need to for example add new Interface or Association or
> Class into the model not manually but automatically , my program will do
> that. So for adding a new Association between two classes , there are
> too many elements to be added , Like the interface represented that
> Association, The Dependencies between the classes and that new added
> Interface and so on.
>
> my Java method will take the UML Model (Any UML model the user want to
> use my program to evolve it or to add some new elements ..) as an Input
> , some preconditions have to be checked before invoking the Java method
> and I need also to check some postconditions on that Model(The Input
> model). that means , if I want to model my method , I would have two
> models, one for my program, and the Input one that my program will
> evolve it.
>
> So, if it is possible to use the Postconditions without modelling
> ,please tell me how? if not , is there any way to retrieve the number of
> elements of specified type in the input model pre and after the
> implementing of the method using OCL?
>
> one more possibility of help:
> Do you know a tool or plugin which coukld be used to generate a UML
> model for my Java program so that it would be used in Papyrus or like that.
>
>
> Regards,
>
Previous Topic:using @pre. operator.
Next Topic:Get best overlapping collections
Goto Forum:
  


Current Time: Fri Apr 19 08:24:28 GMT 2024

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

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

Back to the top