Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Need information to override the default validation function body
Need information to override the default validation function body [message #479006] Fri, 07 August 2009 23:25 Go to next message
Yigal Spinner is currently offline Yigal Spinner
Messages: 102
Registered: July 2009
Senior Member
I created an eCore and assigned annotation on the EClass to generate the
validation. (Example Class1 with Key=constrains, value=data)
The EMF generates the generic PackageValidator.java class and has a
method to validate the class for example:
validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
Map<Object, Object> context);

Is there a way to supply a generic implementation for the body of this
method? and not get the default implementation that does nothing.

I tried to use the generation example and merge this class with a class
I created that only have the method I want to supply the body for, but
it overrides all the other methods and attributes and remove them.

Can you direct me to a way I can generate the body during the EMF Model
generation?

Thanks Yigal.
Re: Need information to override the default validation function body [message #479072 is a reply to message #479006] Sat, 08 August 2009 20:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070908000603070301070306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Yigal,

Comments below.

Yigal Spinner wrote:
> I created an eCore and assigned annotation on the EClass to generate
> the validation. (Example Class1 with Key=constrains, value=data)
> The EMF generates the generic PackageValidator.java class and has a
> method to validate the class for example:
> validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
> Map<Object, Object> context);
>
> Is there a way to supply a generic implementation for the body of this
> method?
No.
> and not get the default implementation that does nothing.
No.
>
> I tried to use the generation example and merge this class with a
> class I created that only have the method I want to supply the body
> for, but it overrides all the other methods and attributes and remove
> them.
>
> Can you direct me to a way I can generate the body during the EMF
> Model generation?
There isn't currently a way to do that with a named constraint. You
must modify the generated validator class. There's work being done on
which might change the story:

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

>
> Thanks Yigal.

--------------070908000603070301070306
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Yigal,<br>
<br>
Comments below.<br>
<br>
Yigal Spinner wrote:
<blockquote cite="mid:h5id5h$lqr$1@build.eclipse.org" type="cite">I
created an eCore and assigned annotation on the EClass to generate the
&nbsp;validation. (Example Class1 with Key=constrains, value=data)
<br>
The EMF generates the generic PackageValidator.java class and has a
method to validate the class for example:
<br>
validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
Map&lt;Object, Object&gt; context);
<br>
<br>
Is there a way to supply a generic implementation for the body of this
method?</blockquote>
No.<br>
<blockquote cite="mid:h5id5h$lqr$1@build.eclipse.org" type="cite"> and
not get the default implementation that does nothing.
<br>
</blockquote>
No.<br>
<blockquote cite="mid:h5id5h$lqr$1@build.eclipse.org" type="cite"><br>
I tried to use the generation example and merge this class with a class
I created that only have the method I want to supply the body for, but
it overrides all the other methods and attributes and remove them.
<br>
<br>
Can you direct me to a way I can generate the body during the EMF Model
generation?
<br>
</blockquote>
There isn't currently a way to do that with a named constraint.&nbsp; You
must modify the generated validator class.&nbsp; There's work being done on
which might change the story:<br>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786">https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786</a><br>
</blockquote>
<blockquote cite="mid:h5id5h$lqr$1@build.eclipse.org" type="cite"><br>
Thanks Yigal.
<br>
</blockquote>
</body>
</html>

--------------070908000603070301070306--
Re: Need information to override the default validation function body [message #479122 is a reply to message #479072] Sun, 09 August 2009 15:30 Go to previous messageGo to next message
Yigal Spinner is currently offline Yigal Spinner
Messages: 102
Registered: July 2009
Senior Member
Hi Ed,
Thanks for the reply. I copied the ValidatorClass.javajet template and
add it to my simple plugin (I used the example to add validator
generation that comes with the product).
I modified the template with some changes and it built the java class.
When I run the EMF generation it does not pick the new Jet generation
from my plugin.
I changed in the genmodel the flag for dynamic generation to "true" and
put the my plugin templates directory, but that did not help either.
How can I override the ValidatorClass.java so I can get my code in?

Thanks
Yigal



Ed Merks wrote:
> Yigal,
>
> Comments below.
>
> Yigal Spinner wrote:
>> I created an eCore and assigned annotation on the EClass to generate
>> the validation. (Example Class1 with Key=constrains, value=data)
>> The EMF generates the generic PackageValidator.java class and has a
>> method to validate the class for example:
>> validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
>> Map<Object, Object> context);
>>
>> Is there a way to supply a generic implementation for the body of this
>> method?
> No.
>> and not get the default implementation that does nothing.
> No.
>>
>> I tried to use the generation example and merge this class with a
>> class I created that only have the method I want to supply the body
>> for, but it overrides all the other methods and attributes and remove
>> them.
>>
>> Can you direct me to a way I can generate the body during the EMF
>> Model generation?
> There isn't currently a way to do that with a named constraint. You
> must modify the generated validator class. There's work being done on
> which might change the story:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786
>
>>
>> Thanks Yigal.
Re: Need information to override the default validation function body [message #479123 is a reply to message #479122] Sun, 09 August 2009 15:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090709090801040904060604
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Yigal,

Did you do these steps?

http://wiki.eclipse.org/index.php/EMF/FAQ#What_are_Dynamic_T emplates.3F



Yigal Spinner wrote:
> Hi Ed,
> Thanks for the reply. I copied the ValidatorClass.javajet template
> and add it to my simple plugin (I used the example to add validator
> generation that comes with the product).
> I modified the template with some changes and it built the java class.
> When I run the EMF generation it does not pick the new Jet generation
> from my plugin.
> I changed in the genmodel the flag for dynamic generation to "true"
> and put the my plugin templates directory, but that did not help either.
> How can I override the ValidatorClass.java so I can get my code in?
>
> Thanks
> Yigal
>
>
>
> Ed Merks wrote:
>> Yigal,
>>
>> Comments below.
>>
>> Yigal Spinner wrote:
>>> I created an eCore and assigned annotation on the EClass to generate
>>> the validation. (Example Class1 with Key=constrains, value=data)
>>> The EMF generates the generic PackageValidator.java class and has a
>>> method to validate the class for example:
>>> validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
>>> Map<Object, Object> context);
>>>
>>> Is there a way to supply a generic implementation for the body of
>>> this method?
>> No.
>>> and not get the default implementation that does nothing.
>> No.
>>>
>>> I tried to use the generation example and merge this class with a
>>> class I created that only have the method I want to supply the body
>>> for, but it overrides all the other methods and attributes and
>>> remove them.
>>>
>>> Can you direct me to a way I can generate the body during the EMF
>>> Model generation?
>> There isn't currently a way to do that with a named constraint. You
>> must modify the generated validator class. There's work being done
>> on which might change the story:
>>
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786
>>
>>>
>>> Thanks Yigal.

--------------090709090801040904060604
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yigal,<br>
<br>
Did you do these steps?<br>
<blockquote><a
href=" http://wiki.eclipse.org/index.php/EMF/FAQ#What_are_Dynamic_T emplates.3F"> http://wiki.eclipse.org/index.php/EMF/FAQ#What_are_Dynamic_T emplates.3F</a><br>
</blockquote>
<br>
<br>
Yigal Spinner wrote:
<blockquote cite="mid:h5mq3p$bui$1@build.eclipse.org" type="cite">Hi
Ed,
<br>
Thanks for the reply.&nbsp; I copied the ValidatorClass.javajet template and
add it to my simple plugin (I used the example to add validator
generation that comes with the product).
<br>
I modified the template with some changes and it built the java class.
<br>
When I run the EMF generation it does not pick the new Jet generation
from my plugin.
<br>
I changed in the genmodel the flag for dynamic generation to "true" and
put the my plugin templates directory, but that did not help either.
<br>
How can I override the ValidatorClass.java so I can get my code in?
<br>
<br>
Thanks
<br>
Yigal
<br>
<br>
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Yigal,
<br>
<br>
Comments below.
<br>
<br>
Yigal Spinner wrote:
<br>
<blockquote type="cite">I created an eCore and assigned annotation
on the EClass to generate the&nbsp; validation. (Example Class1 with
Key=constrains, value=data)
<br>
The EMF generates the generic PackageValidator.java class and has a
method to validate the class for example:
<br>
validateClass1_data (Class1 class1, DiagnosticChain diagnostics,
Map&lt;Object, Object&gt; context);
<br>
<br>
Is there a way to supply a generic implementation for the body of this
method?
<br>
</blockquote>
No.
<br>
<blockquote type="cite">and not get the default implementation that
does nothing.
<br>
</blockquote>
No.
<br>
<blockquote type="cite"><br>
I tried to use the generation example and merge this class with a class
I created that only have the method I want to supply the body for, but
it overrides all the other methods and attributes and remove them.
<br>
<br>
Can you direct me to a way I can generate the body during the EMF Model
generation?
<br>
</blockquote>
There isn't currently a way to do that with a named constraint.&nbsp; You
must modify the generated validator class.&nbsp; There's work being done on
which might change the story:
<br>
<br>
&nbsp;&nbsp;&nbsp; <a class="moz-txt-link-freetext" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786">https://bugs.eclipse.org/bugs/show_bug.cgi?id=255786</a>
<br>
<br>
<blockquote type="cite"><br>
Thanks Yigal.
<br>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>

--------------090709090801040904060604--
Re: Need information to override the default validation function body [message #479632 is a reply to message #479123] Tue, 11 August 2009 19:00 Go to previous messageGo to next message
Yigal Spinner is currently offline Yigal Spinner
Messages: 102
Registered: July 2009
Senior Member
Hi Ed,
I followed the instruction on the page and I have 2 new issues.
1. The override template MUST be in the target project. I would like to
create a plugin that has the override templates and let the developer
point to the set of overrides to use.
2. My plugin that has the additional generation functionality (based on
the EMF example of generation validation) does not work any more because
the process tries to dynamically compile the templates but it can not find
them any where.
I stepped through the code and it uses URI in current project or the EMF
codegen plugin and my templates are in neither.

I think this is a bug, since the code should use the plugin ID to get the
bundle and find the file in the bundle and then the dynamic compile will
work.

Yigal
Re: Need information to override the default validation function body [message #479633 is a reply to message #479632] Tue, 11 August 2009 19:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
Yigal,

Comments below.

Yigal Spinner wrote:
> Hi Ed,
> I followed the instruction on the page and I have 2 new issues.
> 1. The override template MUST be in the target project. I would like
> to create a plugin that has the override templates and let the
> developer point to the set of overrides to use.
If the path contains a ":" it will be treated as a URI, so one could use
platform:/plugin/<plugin-id>/templates.... if the templates are in that
binary plugin. If I recall correctly, we even look for compiled
versions (.classes) of the templates in that case...
> 2. My plugin that has the additional generation functionality (based
> on the EMF example of generation validation) does not work any more
> because the process tries to dynamically compile the templates but it
> can not find them any where.
> I stepped through the code and it uses URI in current project or the
> EMF codegen plugin and my templates are in neither.
Maybe you need to set the Template Plugin Variables for the dependencies
your templates drag in?
>
> I think this is a bug, since the code should use the plugin ID to get
> the bundle and find the file in the bundle and then the dynamic
> compile will work.
I'm not sure what you're referring to here...
>
> Yigal
>
Re: Need information to override the default validation function body [message #480066 is a reply to message #479633] Thu, 13 August 2009 16:27 Go to previous messageGo to next message
Yigal Spinner is currently offline Yigal Spinner
Messages: 102
Registered: July 2009
Senior Member
Hi Ed,
Thanks for the information it was very helpful. I was able to override
the EMF templates and run my own templates.
I found out that the best configuration is to put the ENF override
templates in a separate directory then my templates.
I'm glade the newsgroup works so well to get answers, otherwise there no
other source.

In you answer you indicated that the dynamic architecture uses the
*.class. But while debugging the code I did not find any evidence for it
and the architecture recompiles the templates every time. It recompiles
my generation templates as well even if they are in a separate directory.
This is fine except it increases the generation time.

Thanks
Yigal.
Re: Need information to override the default validation function body [message #480068 is a reply to message #480066] Thu, 13 August 2009 16:47 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
Yigal,

Yes, I'm trying to remember where that stuff is...

In JETEmitter's EclipseHelper.initialize method there's logic for

else if (templateURI.isPlatformPlugin())
{

So if the template path is a URI of the form
platform:/plugin/<plugin-id>/ then it will use the templates target java
class/file name to look up the .class in that bundle. So if you compile
the templates in a project with a JET nature then you (your clients)
will be able to load those precompiled templates.


Yigal Spinner wrote:
> Hi Ed,
> Thanks for the information it was very helpful. I was able to
> override the EMF templates and run my own templates.
> I found out that the best configuration is to put the ENF override
> templates in a separate directory then my templates.
> I'm glade the newsgroup works so well to get answers, otherwise there
> no other source.
>
> In you answer you indicated that the dynamic architecture uses the
> *.class. But while debugging the code I did not find any evidence for
> it and the architecture recompiles the templates every time. It
> recompiles my generation templates as well even if they are in a
> separate directory.
> This is fine except it increases the generation time.
>
> Thanks
> Yigal.
>
Previous Topic:CDO and client/server approach
Next Topic:How to apply profile to activity diagram
Goto Forum:
  


Current Time: Tue Sep 16 15:38:13 GMT 2014

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

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