Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » OCL to Java Constraint
OCL to Java Constraint [message #205620] Wed, 17 September 2008 09:42 Go to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi, could anyone help me solve this issue I am having?

I would like to do the following (without needing to add the
myContainerReference to the model)

myContainerReference.oclIsUndefined()

This would require me to Select the container of the current node then set
it to undefined!

Is this possible in Java??
Note: I am attempting this as a constraint for my node mapping!

Thank you in advance,
Gary
Re: OCL to Java Constraint [message #205658 is a reply to message #205620] Wed, 17 September 2008 11:05 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

> Is this possible in Java??
Sure. An this is a proper way to solve this issue. Add java constraint and
place appropriate code into .genmodel to let GMF generate proper body of
the method.

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205710 is a reply to message #205658] Wed, 17 September 2008 12:08 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Thanks Alex,

Do you know how I could access(call for) the container of the node?
Re: OCL to Java Constraint [message #205727 is a reply to message #205710] Wed, 17 September 2008 12:35 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

Each "node" is an instance of EMF EObject, so you can call node.eContainer()
to get it.

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205746 is a reply to message #205727] Wed, 17 September 2008 13:15 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Sorry Alex, I'm not too sure how I can make this work!
If I Replace OCL constraint:

myContainerReference.oclIsUndefined()

with Java constraint:
this.eContainer() = null;

Should this work? I kinda think I'm goin wrong, but I'm not sure where!

Thank you,
Gary
Re: OCL to Java Constraint [message #205764 is a reply to message #205746] Wed, 17 September 2008 14:07 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

Well, just try - you'll see the diff generated by GMF ant it's really not
so hard to understand what's going on..

AFAIR, body of the java constraint should be: "return domainElement.eContainer()
= null;"
And you have to modify .gmfgen model to set GenJavaExpressionProvider.injectExpressionBody
to "true".

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205796 is a reply to message #205764] Wed, 17 September 2008 15:43 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi Alex,

This is what I have for my constraint:
return domainElement.eContainer() = null;

However I hadn't done this:
And you have to modify .gmfgen model to set
GenJavaExpressionProvider.injectExpressionBody to "true".

(Because of this my diagram will not draw the nodes)

However there is no option available in my .gmfgen to set
GenJavaExpressionProvider.injectExpressionBody to "true".
Do you know why this is?

Thank you,
Gary
Re: OCL to Java Constraint [message #205813 is a reply to message #205796] Wed, 17 September 2008 15:55 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

> And you have to modify .gmfgen model to set
> GenJavaExpressionProvider.injectExpressionBody to "true".
Even without this option you can simply modify generated method and place
this java code there manually.

> However there is no option available in my .gmfgen to set
> GenJavaExpressionProvider.injectExpressionBody to "true". Do you know
> why this is?
Wich GMF version do you use?

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205891 is a reply to message #205813] Thu, 18 September 2008 07:56 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi Alex, I'm using GMF version 2.0.2 on eclipse europa
Re: OCL to Java Constraint [message #205899 is a reply to message #205891] Thu, 18 September 2008 09:37 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

> Hi Alex, I'm using GMF version 2.0.2 on eclipse europa
AFAIR this property was added to .gmfgen model only in GMF 2.1 release. In
older versions you have to specify any valid java method name as a "body"
of OCL constraint, generate code and then modify generated code by properly
implementing corresponding method.

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205907 is a reply to message #205899] Thu, 18 September 2008 09:40 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Ok, thanks, do you know in which generated class I would need to make
these changes?

Thank you,
Gary
Re: OCL to Java Constraint [message #205921 is a reply to message #205907] Thu, 18 September 2008 09:48 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

> Ok, thanks, do you know in which generated class I would need to make
I think it's VisualIdRegistry. You can generate code with and without these
constraints and compare results to see what was changed.
We are using Version control to store all models/generated code there, so
it's easy - you modify model, regenerate code and call "synchronize" to see
diff.

Another option - you can use one of existing diff tools: http://www.google.com/search?hl=ru&rls=com.microsoft%3Ar u-ru&q=diff+free&lr=

Actually, I think diff is very useful then you are generating the code because
from time to time you have to modify it or just see what was changed..

HTH
-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #205928 is a reply to message #205921] Thu, 18 September 2008 10:22 Go to previous messageGo to next message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Ok, thanks Alex, this has provided me with the new class:

private static class JavaConstraints {

private static java.lang.Boolean returnAdminDomaineContainernull(
AdminDomain self) {

// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT

throw new CIMLevelZeroAbstractExpression.NoImplException(
"No user java implementation provided in
'returnAdminDomaineContainernull' operation"); //$NON-NLS-1$
}
}

I now need to implement this method, do I simply return true! Or do i also
need to do the setting of the container to null here?
Re: OCL to Java Constraint [message #205974 is a reply to message #205928] Thu, 18 September 2008 11:21 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Gary,

You have to return "true" if passed attribute (self) is a valid domain model
element to be visualized as "AdminDomain". AFAIR your prev. requirements,
you have to type following line instead of "throw new CIMLevelZeroAbstractExpression.NoImplException("No
user java implementation provided in 'returnAdminDomaineContainernull' operation");":

return self.eContainer() == null;

-----------------
Alex Shatalin
Re: OCL to Java Constraint [message #206041 is a reply to message #205974] Thu, 18 September 2008 14:07 Go to previous message
Gary is currently offline GaryFriend
Messages: 125
Registered: July 2009
Senior Member
Hi Alex,
I tested this solition with the following code!

private static java.lang.Boolean returnAdminDomaineContainernull(
AdminDomain self) {

if (self == self) {
return true;
}

return self.eContainer() == null;
}

replacing 'if (self == self)' with 'if (self != self)' giving me both
possible outputs

RESULTS:

for (self == self) when initalizing a diagram only the container node is
shown(as before)!

for (self != self) when initalizing a diagram neather the contained or
container node is displayed!

Any Ideas why this could be the case?
Previous Topic:Is it possible to use GMF on a abstract semantic model ?
Next Topic:Tooltips
Goto Forum:
  


Current Time: Sun Jun 13 19:41:31 GMT 2021

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

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

Back to the top