Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » how to call a user defined operation.
how to call a user defined operation. [message #34391] Fri, 27 July 2007 15:44 Go to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

Hello,

I am stuck in my problem. I defined a operation (with defineOperation) on a
stereotype. I would like to call it "programmaticaly".

I have obviously defined my ocl and oclhelper, my operation accepts one
parameter, and I use something like that:

ocl.getEvaluationEnvironment().callOperation(operation, -1, element, new Object[]{argument});

At this stage it is unclear to me what should be the operation code and whether the
parameter source (here element) is the same as the one used to do a simple
ocl.evaluate(context, query).


If I run this code, it triggers a null expression:

org.eclipse.ocl.uml.UMLEvaluationEnvironment
- >getJavaMethodFor
// here container/receiver are correct (non null)
EClassifier eclassifier = getEClassifier(container, receiver);
// but eclassifier is null
java.lang.Class<?> containerClass = eclassifier.getInstanceClass();


does any help could help me...

--
F. Lagarde
Re: how to call a user defined operation. [message #34459 is a reply to message #34391] Fri, 27 July 2007 17:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

The EvaluationEnvironment::callOperation(...) method isn't really intended
for clients to use in this way. Why not just evaluate an OCL expression
that includes a call to your custom operation?

Anyways, the operation code is only used for OCL's pre-defined operations.
-1 is appropriate for your case.

The "element" parameter is the target of the operation call. Because you
have defined this operation on a stereotype, the "element" must be an
instance of that stereotype.

The default implementation of the evaluation environment looks for a Java
method that it can invoke reflectively. It won't be able to find any
method for your additional operation. Your custom evaluation environment
implementation will have to trap invocations of your additional operation
and figure out what to do.

For an example, see the "Customizing the Environment" topic in the OCL
Developer Guide. It has example of the addition of a "regexMatch"
operation to the String type. There's a working instance of this example
in the org.eclipse.ocl.(ecore|uml).tests plug-in.

HTH,

Christian

François Lagarde wrote:

> Hello,
>
> I am stuck in my problem. I defined a operation (with defineOperation) on
> a stereotype. I would like to call it "programmaticaly".
>
> I have obviously defined my ocl and oclhelper, my operation accepts one
> parameter, and I use something like that:
>
> ocl.getEvaluationEnvironment().callOperation(operation, -1, element, new
> Object[]{argument});
>
> At this stage it is unclear to me what should be the operation code and
> whether the
> parameter source (here element) is the same as the one used to do a
> simple ocl.evaluate(context, query).
>
>
> If I run this code, it triggers a null expression:
>
> org.eclipse.ocl.uml.UMLEvaluationEnvironment
> - >getJavaMethodFor
> // here container/receiver are correct (non null)
> EClassifier eclassifier = getEClassifier(container, receiver);
> // but eclassifier is null
> java.lang.Class<?> containerClass = eclassifier.getInstanceClass();
>
>
> does any help could help me...
>
Re: how to call a user defined operation. [message #34527 is a reply to message #34459] Fri, 27 July 2007 18:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: firstname.name.gmail.com

In the last post, on 07/27 about 07h, "Christian" (Christian W Damus) wrote:

Christian> Why not just evaluate an OCL expression that includes a call
Christian> to your custom operation?

it is what I wanted to do at first. But, the parameter of this operation is a
sequence of Classifier (given by an additional variable which makes a call to
getAllExtendedMetaclasses), and I do not know how to call it in "a raw text".

Maybe a solution would to bind the value of this variable to the parameter of the
function. But I am not sure how to deal with it. Does it make sens to do
something like.

1. create a variable called myParameter,
2. assign the value of the variable to my already predefined variable,
3. evaluate an expression "myOperation(myParameter)"
4. enjoy the result.

Christian> The "element" parameter is the target of the operation call.
Christian> Because you have defined this operation on a stereotype, the
Christian> "element" must be an instance of that stereotype.

up to this point it is what I did...

Christian> [...] Your custom evaluation environment implementation will have to
Christian> trap invocations of your additional operation and figure out
Christian> what to do.

it seems to be not really so simple...

Christian> For an example, see the "Customizing the Environment" topic in
Christian> the OCL Developer Guide. [...]
Christian> org.eclipse.ocl.(ecore|uml).tests plug-in.

I already read it and I also found a lot of good "snippets" in the ocl.tests..

thanks for your precious help/advices.

--
F. Lagarde
Re: how to call a user defined operation. [message #34627 is a reply to message #34527] Fri, 27 July 2007 19:15 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, François,

See some comments in-line, below.

Cheers,

Christian


François Lagarde wrote:

> In the last post, on 07/27 about 07h, "Christian" (Christian W Damus)
> wrote:
>
> Christian> Why not just evaluate an OCL expression that includes a
> call Christian> to your custom operation?
>
> it is what I wanted to do at first. But, the parameter of this operation
> is a sequence of Classifier (given by an additional variable which makes a
> call to getAllExtendedMetaclasses), and I do not know how to call it in "a
> raw text".

Ah, indeed. That's tricky.


> Maybe a solution would to bind the value of this variable to the parameter
> of the function. But I am not sure how to deal with it. Does it make sens
> to do something like.
>
> 1. create a variable called myParameter,
> 2. assign the value of the variable to my already predefined variable,
> 3. evaluate an expression "myOperation(myParameter)"
> 4. enjoy the result.

Yes, exactly. Maybe have a beer with the result, too ;-)

Seriously, this looks very much like the first example in the "Customizing
the Environment" help topic, in which a "global variable" nameed app$ is
defined and its value bound in the evaluation environment when evaluating
an expression.

> Christian> The "element" parameter is the target of the operation
> call. Christian> Because you have defined this operation on a
> stereotype, the Christian> "element" must be an instance of that
> stereotype.
>
> up to this point it is what I did...
>
> Christian> [...] Your custom evaluation environment implementation
> will have to Christian> trap invocations of your additional
> operation and figure out Christian> what to do.
>
> it seems to be not really so simple...

No, it isn't, really. If you have ideas for simplifying the API or perhaps
defining wrappers/facades/utilities around it, they would be most welcome!


> Christian> For an example, see the "Customizing the Environment"
> topic in Christian> the OCL Developer Guide. [...]
> Christian> org.eclipse.ocl.(ecore|uml).tests plug-in.
>
> I already read it and I also found a lot of good "snippets" in the
> ocl.tests..
>
> thanks for your precious help/advices.

It's my pleasure!
Previous Topic:OCL with Java importer
Next Topic:How to get a descreasing ordered sequence?
Goto Forum:
  


Current Time: Thu Apr 25 04:08:05 GMT 2024

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

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

Back to the top