Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsOCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205620/#msg_205620
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]]>Gary2008-09-17T09:42:32-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205658/#msg_205658
> 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]]>Alexander Shatalin2008-09-17T11:05:04-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205710/#msg_205710
Do you know how I could access(call for) the container of the node?]]>Gary2008-09-17T12:08:04-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205727/#msg_205727
Each "node" is an instance of EMF EObject, so you can call node.eContainer()
to get it.
-----------------
Alex Shatalin]]>Alexander Shatalin2008-09-17T12:35:08-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205746/#msg_205746
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]]>Gary2008-09-17T13:15:53-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205764/#msg_205764
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]]>Alexander Shatalin2008-09-17T14:07:09-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205796/#msg_205796
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]]>Gary2008-09-17T15:43:47-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205813/#msg_205813
> 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]]>Alexander Shatalin2008-09-17T15:55:51-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205891/#msg_205891
Gary2008-09-18T07:56:49-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205899/#msg_205899
> 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]]>Alexander Shatalin2008-09-18T09:37:44-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205907/#msg_205907
these changes?
Thank you,
Gary]]>Gary2008-09-18T09:40:28-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205921/#msg_205921
> 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.
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]]>Alexander Shatalin2008-09-18T09:48:12-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205928/#msg_205928
private static class JavaConstraints {
// 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?]]>Gary2008-09-18T10:22:17-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/205974/#msg_205974
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]]>Alexander Shatalin2008-09-18T11:21:58-00:00Re: OCL to Java Constraint
https://www.eclipse.org/forums/index.php/mv/msg/65370/206041/#msg_206041
I tested this solition with the following code!