Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Customizing OCL Environment...
Customizing OCL Environment... [message #46177] Mon, 10 December 2007 00:22 Go to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,
I folowed the example in the "OCL Developer Guide-> Programmer's Guide->
Advanced Topics-> Customizing the Environment->Defining Helper Operation in
Java" topic.
I added two operations, the example works perfectly (I can parse constraints
using my two new operations)
Now I want to use the same process, but to customize UMLEnvironment not
Ecore one.
I changed all classes used in this example: for example:
class MyEnvironment extends UMLEnvironment instead of class
MyEnvironment extends EcoreEnvironment
class MyEvaluationEnvironment extends UMLEvaluationEnvironment instead
of class MyEvaluationEnvironment extends EcoreEvaluationEnvironment....
I changed also method signature to use UML parameter instead of Ecore one.
for example I canged the operation type in the method callOperation().
public Object callOperation(org.eclipse.uml2.uml.Operation operation, int
opcode, Object source, Object[] args) //not EOperation.

When I parse the constraint that contains my operation (regexMach), I get
this error: : Cannot call operation (regexMatch) because it is not a query.

the instruction addOperation(getOCLStandardLibrary().getString(),
regexMatch); was passed (without error)

so I think that problem comes from MyEvaluationEnvironment and not
MyEnvironment class. (problem in call operation and not in
definecustomsoperations())

Could some one help me?

thanks!
Re: Customizing OCL Environment... [message #46327 is a reply to message #46177] Mon, 10 December 2007 13:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

The UML Operation that your custom UMLEnvironment creates must be designated
as a "query" operation in order to OCL to guarantee that a constraint
evaluation will not have side-effects in the modeled system.

Before invoking addOperation(...) simply set your operation as a query using
Operation::setIsQuery(boolean) method.

Cheers,

Christian


charfi asma wrote:

> Hi,
> I folowed the example in the "OCL Developer Guide-> Programmer's Guide->
> Advanced Topics-> Customizing the Environment->Defining Helper Operation
> in Java" topic.
> I added two operations, the example works perfectly (I can parse
> constraints using my two new operations)
> Now I want to use the same process, but to customize UMLEnvironment not
> Ecore one.
> I changed all classes used in this example: for example:
> class MyEnvironment extends UMLEnvironment instead of class
> MyEnvironment extends EcoreEnvironment
> class MyEvaluationEnvironment extends UMLEvaluationEnvironment
> instead
> of class MyEvaluationEnvironment extends
> EcoreEvaluationEnvironment.... I changed also method signature to use UML
> parameter instead of Ecore one. for example I canged the operation type in
> the method callOperation(). public Object
> callOperation(org.eclipse.uml2.uml.Operation operation, int
> opcode, Object source, Object[] args) //not EOperation.
>
> When I parse the constraint that contains my operation (regexMach), I get
> this error: : Cannot call operation (regexMatch) because it is not a
> query.
>
> the instruction addOperation(getOCLStandardLibrary().getString(),
> regexMatch); was passed (without error)
>
> so I think that problem comes from MyEvaluationEnvironment and not
> MyEnvironment class. (problem in call operation and not in
> definecustomsoperations())
>
> Could some one help me?
>
> thanks!
Re: Customizing OCL Environment... [message #46420 is a reply to message #46327] Thu, 13 December 2007 00:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi christian,
thank you very much, it works but I still have problem with callOperation
method.
My operatoion is added to String. when I evaluate it on s it return
OclInvalid. although in the method code I only put return true

public Object callOperation(Operation operation, int opcode, Object source,
Object[] args)

{

return true;

}



[OCL] Evaluate: s

[OCL] Result : ((1,2),(1,3))

[OCL] Evaluate: '^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\))*\)$'

[OCL] Result : ^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\))*\)$

[OCL] Evaluate:
s.regexMatch('^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\)) *\)$')

[OCL] Result : OclInvalid

[OCL] Evaluate: true

[OCL] Result : true

[OCL] Evaluate:
s.regexMatch('^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\)) *\)$').=(true)

[OCL] Result : false

It seems like the new operation is not recongnized.

is the annotation of the operation has an impact? in fact when I change all
Ecore concept to UML one, I did not change EAnotation.

I don't know the equivalent of EAnnotation in UML so I keep this code in my
defineCustomOperations method

EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();

annotation.setSource("MyEnvironment");

regexMatch.getEAnnotations().add(annotation);

Can you help me?

thank you very much

"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: Customizing OCL Environment... [message #46635 is a reply to message #46420] Thu, 13 December 2007 14:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

I'd suggest putting a breakpoint at the top of the

EvaluationVisitorImpl::visitCallOperationExp(...)

method to see where an exception is occurring (which would result in
OclInvalid) or where OclInvalid is being returned for some other reason.

I don't have any suggestion off-hand for why this wouldn't work.

Cheers,

Christian

charfi asma wrote:

> Hi christian,
> thank you very much, it works but I still have problem with callOperation
> method.
> My operatoion is added to String. when I evaluate it on s it return
> OclInvalid. although in the method code I only put return true
>
> public Object callOperation(Operation operation, int opcode, Object
> source, Object[] args)
>
> {
>
> return true;
>
> }
>
>
>
> [OCL] Evaluate: s
>
> [OCL] Result : ((1,2),(1,3))
>
> [OCL] Evaluate: '^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\))*\)$'
>
> [OCL] Result : ^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\))*\)$
>
> [OCL] Evaluate:
> s.regexMatch('^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\)) *\)$')
>
> [OCL] Result : OclInvalid
>
> [OCL] Evaluate: true
>
> [OCL] Result : true
>
> [OCL] Evaluate:
> s.regexMatch('^\(\([0-9]+(,[0-9]+)*\)(,\([0-9]+(,[0-9]+)*\)) *\)$').=(true)
>
> [OCL] Result : false
>
> It seems like the new operation is not recongnized.
>
> is the annotation of the operation has an impact? in fact when I change
> all Ecore concept to UML one, I did not change EAnotation.
>
> I don't know the equivalent of EAnnotation in UML so I keep this code in
> my
> defineCustomOperations method
>
> EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
>
> annotation.setSource("MyEnvironment");
>
> regexMatch.getEAnnotations().add(annotation);
>
> Can you help me?
>
> thank you very much
>
> "Christian W. Damus" <cdamus@ca.ibm.com> a �rit dans le message de news:
> fjjed9$nge$3@build.eclipse.org...
>> Hi, Asma,
>>
>> The UML Operation that your custom UMLEnvironment creates must be
>> designated
>> as a "query" operation in order to OCL to guarantee that a constraint
>> evaluation will not have side-effects in the modeled system.
>>
>> Before invoking addOperation(...) simply set your operation as a query
>> using
>> Operation::setIsQuery(boolean) method.
>>
>> Cheers,
>>
>> Christian
>>
>>
>> charfi asma wrote:
>>
>>> Hi,
>>> I folowed the example in the "OCL Developer Guide-> Programmer's Guide->
>>> Advanced Topics-> Customizing the Environment->Defining Helper Operation
>>> in Java" topic.
>>> I added two operations, the example works perfectly (I can parse
>>> constraints using my two new operations)
>>> Now I want to use the same process, but to customize UMLEnvironment not
>>> Ecore one.
>>> I changed all classes used in this example: for example:
>>> class MyEnvironment extends UMLEnvironment instead of class
>>> MyEnvironment extends EcoreEnvironment
>>> class MyEvaluationEnvironment extends UMLEvaluationEnvironment
>>> instead
>>> of class MyEvaluationEnvironment extends
>>> EcoreEvaluationEnvironment.... I changed also method signature to use
>>> UML parameter instead of Ecore one. for example I canged the operation
>>> type in
>>> the method callOperation(). public Object
>>> callOperation(org.eclipse.uml2.uml.Operation operation, int
>>> opcode, Object source, Object[] args) //not EOperation.
>>>
>>> When I parse the constraint that contains my operation (regexMach), I
>>> get this error: : Cannot call operation (regexMatch) because it is not a
>>> query.
>>>
>>> the instruction addOperation(getOCLStandardLibrary().getString(),
>>> regexMatch); was passed (without error)
>>>
>>> so I think that problem comes from MyEvaluationEnvironment and not
>>> MyEnvironment class. (problem in call operation and not in
>>> definecustomsoperations())
>>>
>>> Could some one help me?
>>>
>>> thanks!
>>
Re: Customizing OCL Environment... [message #46727 is a reply to message #46635] Fri, 14 December 2007 02:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,
when I import plugin org.eclipse.emf.ocl to open
org.eclipse.emf.ocl.expressions.impl.EvaluationVisitorImpl class I did not
get source (only .class)
I can not add brakpoint to this method. I got this error (org.eclipse.ocl)
does not exist when I check it out from cvs.
how can I do :-(
thank you
asma
"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: Customizing OCL Environment... [message #46759 is a reply to message #46727] Thu, 13 December 2007 17:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

I mean the org.eclipse.ocl.internal.evaluation.EvaluationVisitorImpl class.
The other is only involved in parsing and evaluation using the deprecated
1.0 version of the API.

In general, if you want to check out a consistent set of OCL plug-ins, you
can use the "Team -> Load Map Projects" context-menu action on the
org.eclipse.ocl.releng/maps/ocl.map file. This will load the CVS tags of
all of the OCL projects that were released together, comprising a
consistent baseline.

Or, if you just want to get all of the OCL code from HEAD, you can use the
"Import Project Set..." context-menu action on either of the *.psf files in
the org.eclipse.ocl.releng/psf folder.

HTH,

Christian


charfi asma wrote:

> Hi,
> when I import plugin org.eclipse.emf.ocl to open
> org.eclipse.emf.ocl.expressions.impl.EvaluationVisitorImpl class I did
> not get source (only .class)
> I can not add brakpoint to this method. I got this error (org.eclipse.ocl)
> does not exist when I check it out from cvs.
> how can I do :-(
> thank you
> asma

-----8<-----
Re: Customizing OCL Environment... [message #46781 is a reply to message #46759] Fri, 14 December 2007 04:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi,
when I choose "ImportProjectSet" menu on ocl-all.psf I get a window that
require a password!
I put anonymous as username but the import did not succed.
concerning the other way "Team -> Load Map Projects" context-menu action on
the
> org.eclipse.ocl.releng/maps/ocl.map file", I can not find Load Map Project
> in Team.

any way, I did not get the same error now.

In fact My problem was in MyEnvironmentEvaluation. which was not considered
when I run my plugin.
the callOperation was not executed. so I modify the method that create this
class: public MyEvaluationEnvironment createEvaluationEnvironment()
before I put two methods:
public EvaluationEnvironment<Classifier,Operation,Property,Class,EObject >
createEvaluationEnvironment(MyEnvironmentFactory factory)

{return new MyEvaluationEnvironment(factory);}

public MyEvaluationEnvironment
createEvaluationEnvironment(EvaluationEnvironment<Classifier,Operation,Property,Class,EObject >
parent)

{return new MyEvaluationEnvironment(parent);}

and there for I used two constructors in my MyEvaluationEnvironment().

I find in the UMLEnvironmentFactory 3 methods to
createEvaluationEnvironment() so I use the third one which did not have
parameter. but in MyEvaluationEnvironment I can not put constructor without
parameter (cause it extends UMLEvaluationEnvironment)

so to add a constructor without param (public MyEvaluationEnvironment()
{super(); }) as it is specified in EcoreEvaluationEnvironment, I implement
the interface EvaluationEnvironment instead of extending
UMLEvaluationEnvironment.

when I put all this changes it works! now the calloperation is executed and
it return true if I put return true and false if I put return false. but I
have neu problem in the evaluation method: self =null! (parsing did not
raise error)
--------------------------------------parsing--------------- --------------------------------------------
[OCL] variableExpCS: Variable Expression: self

[OCL] variableExpCS: Variable Expression: self

[OCL] stringLiteralExpCS: String: 'Gaspard::Tiler'

[OCL] operationCallExpCS: getAppliedStereotype

[OCL] stringLiteralExpCS: String: 'fitting'

[OCL] operationCallExpCS: getValue

[OCL] operationCallExpCS: oclAsType

[OCL] variableDeclarationCS: adding variable declaration for s

[OCL] variableExpCS: Variable Expression: s

[OCL] stringLiteralExpCS: String:
'^\{\{[0-9]+(,[0-9]+)*\}(,\{[0-9]+(,[0-9]+)*\})*\}$'

[OCL] operationCallExpCS: regexMatch

[OCL] booleanLiteralExpCS: Boolean: true

[OCL] operationCallExpCS: =

--------------------------------------evaluation------------ --------------------------------------------
[OCL] Evaluate: self

[OCL] Result : null

[OCL] Evaluate: self

[OCL] Result : null

[OCL] Evaluate: 'Gaspard::Tiler'

[OCL] Result : Gaspard::Tiler

[OCL] Evaluate: self

[OCL] Result : null

[OCL] Evaluate: self.getAppliedStereotype('Gaspard::Tiler')

[OCL] Result : OclInvalid

[OCL] Evaluate: 'fitting'

[OCL] Result : fitting

[OCL] Evaluate: self

[OCL] Result : null

[OCL] Evaluate: self.getValue(self.getAppliedStereotype('Gaspard::Tiler'),
'fitting')

[OCL] Result : OclInvalid

[OCL] Evaluate: self.getValue(self.getAppliedStereotype('Gaspard::Tiler'),
'fitting').oclAsType(oclstdlib::String)

[OCL] Result : OclInvalid

[OCL] Evaluate: s : String =
self.getValue(self.getAppliedStereotype('Gaspard::Tiler'),
'fitting').oclAsType(oclstdlib::String)

[OCL] Result : s

[OCL] Evaluate: s

[OCL] Result : null

[OCL] Evaluate: '^\{\{[0-9]+(,[0-9]+)*\}(,\{[0-9]+(,[0-9]+)*\})*\}$'

[OCL] Result : ^\{\{[0-9]+(,[0-9]+)*\}(,\{[0-9]+(,[0-9]+)*\})*\}$

[OCL] Evaluate:
s.regexMatch('^\{\{[0-9]+(,[0-9]+)*\}(,\{[0-9]+(,[0-9]+)*\}) *\}$')

[OCL] Result : false // cause I put in callOperation return false when I
put return true it is evaluated true.

----------------------------------------------------------

Did you suggest any modifications?



thank you asma




"Christian W. Damus" <cdamus@ca.ibm.com> a
Re: Customizing OCL Environment... [message #46842 is a reply to message #46781] Fri, 14 December 2007 15:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Asma,

See some comments in-line, below.

HTH,

Christian


charfi asma wrote:

> Hi,
> when I choose "ImportProjectSet" menu on ocl-all.psf I get a window that
> require a password!

If you're not an Eclipse committer, then you will need to search-and-replace
the occurrences of "extssh" in the PSF file with "pserver"


> I put anonymous as username but the import did not succed.

Only the pserver protocol supports anonymous access.


> concerning the other way "Team -> Load Map Projects" context-menu action
> on the
>> org.eclipse.ocl.releng/maps/ocl.map file", I can not find Load Map
>> Project in Team.

Ah. I guess that is provided by the Eclipse Releng Tools plug-in (available
at the bottom of the Eclipse Platform download pages).


> any way, I did not get the same error now.
>
> In fact My problem was in MyEnvironmentEvaluation. which was not
> considered when I run my plugin.
> the callOperation was not executed. so I modify the method that create
> this class: public MyEvaluationEnvironment createEvaluationEnvironment()
> before I put two methods:
> public EvaluationEnvironment<Classifier,Operation,Property,Class,EObject >
> createEvaluationEnvironment(MyEnvironmentFactory factory)
>
> {return new MyEvaluationEnvironment(factory);}
>
> public MyEvaluationEnvironment
>
createEvaluationEnvironment(EvaluationEnvironment<Classifier,Operation,Property,Class,EObject >
> parent)
>
> {return new MyEvaluationEnvironment(parent);}
>
> and there for I used two constructors in my MyEvaluationEnvironment().
>
> I find in the UMLEnvironmentFactory 3 methods to
> createEvaluationEnvironment() so I use the third one which did not have
> parameter. but in MyEvaluationEnvironment I can not put constructor
> without parameter (cause it extends UMLEvaluationEnvironment)

But, the UMLEnvironmentFactory only has two methods for creating evaluation
environments, same as the EcoreEnvironmentFactory. One creates a root
evaluation environment and the other creates a nested evaluation
environment (given some parent).


> so to add a constructor without param (public MyEvaluationEnvironment()
> {super(); }) as it is specified in EcoreEvaluationEnvironment, I implement
> the interface EvaluationEnvironment instead of extending
> UMLEvaluationEnvironment.

That should work. But, why not extend UMLEvaluationEnvironment? You only
have to provide a constructor that accepts the UMLEnvironmentFactory and
calls super, and another that accepts a parent environment and also calls
super. If you do this, then you won't have to re-implement all of the
EvaluationEnvironment interface. You will only have to provide the
overrides for your custom operation(s).

Or, at least extend the AbstractEvaluationEnvironment class which provides
an implementation of the variable-value bindings and the evaluation options
map.


> when I put all this changes it works! now the calloperation is executed
> and it return true if I put return true and false if I put return false.
> but I have neu problem in the evaluation method: self =null! (parsing did
> not raise error)

This should only happen if your client application doesn't provide a value
for "self" when it evaluates an OCL expression, or if your
EvaluationEnvironment implementation didn't implement the
add()/getValueOf()/replace()/remove() methods for manipulating the
variable-value bindings.


-----8<-----
Re: Customizing OCL Environment... [message #46930 is a reply to message #46842] Tue, 18 December 2007 00:56 Go to previous message
Eclipse UserFriend
Originally posted by: asma.charfi.com

Hi Christian,
I find the error:-))))
it deals with calloperation method
I did not put
if (operation.getEAnnotation("MyEnvironment") == null) {

System.out.println("il va apeler l'operation de super");

return super.callOperation(operation, opcode, source, args);}

so when OCL want to evaluate self or getAppliedStereotype()...it did not
find super.callOperation() that's why OCL only recognize my new operation
and not other (the default one)

now, I succed in customizing an UMLEnvironment! thank you a lot for your
help!

asma

"Christian W. Damus" <cdamus@ca.ibm.com> a
Previous Topic:[Announce] MDT OCL 1.2.0M4 is available
Next Topic:left-hand-side evaluation of OCL expression: request for advice
Goto Forum:
  


Current Time: Sat Nov 22 21:31:18 GMT 2014

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

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