Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [JET]JETEmitter Problem when running workspace
[JET]JETEmitter Problem when running workspace [message #910485] Sun, 09 September 2012 20:29 Go to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hello experts,

I want to generate code from one xml based on EMF with JETEmitter in a new file wizard. I was able to generate helloWorld.txtjet after running the new wizard. But when I tried to generate the xml file information, I got blank file. One more thing, when I used the java generated code directly, it worked.

Here is my generate java code:

private void generate(DocumentRoot documentRoot, IProgressMonitor monitor) throws JETException{
String pluginId = "jet.project";
String base = Platform.getBundle(pluginId).getEntry("/").toString();
String relativeUri = "templates/generate.txtjet";
JETEmitter emitter = new JETEmitter(base + relativeUri, getClass().getClassLoader());

IProgressMonitor sub = new SubProgressMonitor(monitor, 1);
String result = emitter.generate(sub, new Object[] {documentRoot});
monitor.worked(1);
}

Has somebody any idea about it? It seems that it cannot load the documentRoot object after pressing the finish button.



Re: [JET]JETEmitter Problem when running workspace [message #910609 is a reply to message #910485] Mon, 10 September 2012 04:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 09/09/2012 10:29 PM, Yumin Zhou
wrote:<br>
</div>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">Hello
experts,
<br>
<br>
I want to generate code from one xml based on EMF with JETEmitter
in a new file wizard. I was able to generate helloWorld.txtjet
after running the new wizard. But when I tried to generate the xml
file information, I got blank file. One more thing, when I used
the java generated code directly, it worked. <br>
</blockquote>
So why are you doing it this way?<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">Here
is my generate java code:
<br>
<br>
private void generate(DocumentRoot documentRoot, IProgressMonitor
monitor) throws JETException{
<br>
    String pluginId = "jet.project";     <br>
</blockquote>
Is this bundle installed in your running Eclipse?  I.e., it's not a
project in the workspace is it?<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">   
String base =
Platform.getBundle(pluginId).getEntry("/").toString();        
String relativeUri = "templates/generate.txtjet";    <br>
</blockquote>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">    
JETEmitter emitter = new JETEmitter(base + relativeUri,</blockquote>
I suppose this is equivalent too
Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">getClass().getClassLoader());</blockquote>
Are you expecting this approach to be able to compile the template
dynamically or you're expecting it only to ever use the already
compiled template?  Note that EMF's generator uses<br>
<blockquote>  protected JETEmitter
createJETEmitter(JETEmitterDescriptor jetEmitterDescriptor)<br>
  {<br>
    JETEmitter jetEmitter = new JETEmitter(getTemplatePath(),
jetEmitterDescriptor.templatePathName,
getClass().getClassLoader());<br>
</blockquote>
And we set up the template path to point at the templates folder in
the loaded bundle.  You might want to set a breakpoint in
org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.createJETEmitter(JETEmitterDescriptor)
and see how the arguments are set up for EMF's use JETEmitter for
generating model code from Ecore/GenModel.<br>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">   
<br>
       IProgressMonitor sub = new SubProgressMonitor(monitor, 1); 
    String result = emitter.generate(sub, new Object[]
{documentRoot});
<br>
       monitor.worked(1);     }
<br>
<br>
Has somebody any idea about it? It seems that it cannot load the
documentRoot object after pressing the finish button. <br>
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #910839 is a reply to message #910609] Mon, 10 September 2012 13:29 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hello Ed,

thank you for your reply.
Because I have several templates. What I thought was that when I click on one template which displays in the last page of wizard like eclipse plugin templates, JETEmitter can generate what I have Chosen.

The attachments show three pages of my wizard. The second is to load a xml file and the third is to choose a template. After all the code will be written into the file which the first page created.

index.php/fa/11441/0/
index.php/fa/11442/0/
index.php/fa/11443/0/

That's why I think I cannot just use generated Java code, am I right?
Re: [JET]JETEmitter Problem when running workspace [message #910907 is a reply to message #910839] Mon, 10 September 2012 15:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Yumin,

I really don't understand these details and you didn't answer all of my
questions that I need answered to understand what you're doing.


On 10/09/2012 3:29 PM, Yumin Zhou wrote:
> Hello Ed,
>
> thank you for your reply.
> Because I have several templates. What I thought was that when I click on one template which displays in the last page of wizard like eclipse plugin templates, JETEmitter can generate what I have Chosen.
>
> The attachments show three pages of my wizard. The second is to load a xml file and the third is to choose a template. After all the code will be written into the file which the first page created.
>
>
>
>
>
> That's why I think I cannot just use generated Java code, am I right?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #911075 is a reply to message #910907] Mon, 10 September 2012 23:36 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Ed,

Thank you for replying so soon.

I thought the details might help me to explain the first question clearly.

<br>String pluginId = "jet.project"; <br>
</blockquote>
Is this bundle installed in your running Eclipse? I.e., it's not a project in the workspace is it?<br>

It is installed in running eclipse because I created the "Hello World" code after running. The "Hello World" template is in this project "jet.project", too.

<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">
String base = Platform.getBundle(pluginId).getEntry("/").toString();
String relativeUri = "templates/generate.txtjet"; <br>
</blockquote>
<blockquote cite="mid:k2iu87$mrj$1@xxxxxxxxe.org" type="cite">
JETEmitter emitter = new JETEmitter(base + relativeUri,</blockquote>
I suppose this is equivalent too
Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().<br>

I suppose, too. I think it is not the path problem, otherwise I wouldn't get the generated code "hello world", am I right?

What my problem seems that the generation doesn't get the object after running wizard.

YM
Re: [JET]JETEmitter Problem when running workspace [message #911137 is a reply to message #911075] Tue, 11 September 2012 03:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Yumin,

Comments below.

On 11/09/2012 1:36 AM, Yumin Zhou wrote:
> Ed,
>
> Thank you for replying so soon.
>
> I thought the details might help me to explain the first question
> clearly.
> <br>String pluginId = "jet.project"; <br>
> </blockquote>
> Is this bundle installed in your running Eclipse? I.e., it's not a
> project in the workspace is it?<br>
>
> It is installed in running eclipse because I created the "Hello World"
> code after running. The "Hello World" template is in this project
> "jet.project", too.
>
> <blockquote cite="mid:k2iu87$mrj$mailto:1@xxxxxxxx"
> type="cite"> String base =
> Platform.getBundle(pluginId).getEntry("/").toString(); String
> relativeUri = "templates/generate.txtjet"; <br>
> </blockquote>
> <blockquote cite="mid:k2iu87$mrj$mailto:1@xxxxxxxx"
> type="cite"> JETEmitter emitter = new JETEmitter(base +
> relativeUri,</blockquote>
> I suppose this is equivalent too
> Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().<br>
>
Be sure to actually try that call so you know it's actually finding that
entry in your bundle.
>
> I suppose, too. I think it is not the path problem, otherwise I
> wouldn't get the generated code "hello world", am I right?
I suppose so.
> What my problem seems that the generation doesn't get the object after
> running wizard.
Have you set a breakpoint to see what value of DocumentRoot is being
passed to the JETEmitter? In any case, if the templates are already
compiled and the resulting Java code for that are also compiled and
available in the installed IDE, and you aren't planning to support
dynamic templates (i.e., someone providing a modified version of the
template itself in the workspace), then you can use that compiled
template directly without the JETEmitter.

In the end, it's very hard to answer your question without all the
dynamic details, but if you set a breakpoint and trace through what
happens when you call generate on the emitter, you should be able to
track down what's going wrong.
>
> YM


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #911858 is a reply to message #911137] Wed, 12 September 2012 13:07 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

>Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().
I tried this method but got an error message "Invalid thread access".

>Have you set a breakpoint to see what value of DocumentRoot is being
passed to the JETEmitter?

I set a breakpoint at >String result = emitter.generate(sub, new Object[] {documentRoot});<. There is something in the documentRoot that has already loaded to my EMF but the result variable showed "null".

Now I'm considering if I should change the generation method to Xpand instead of JET. I really prefer you could give me some advice. Xpand or JET2Platform runtransformonobject?
Re: [JET]JETEmitter Problem when running workspace [message #911919 is a reply to message #911858] Wed, 12 September 2012 15:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Personally I'd use the latest version of Xtend. We've never really
gotten down to whether you actually need dynamic templates. My sense is
that you don't, so you don't really need to use JETEmitter at all, just
use the compiled templates.


On 12/09/2012 3:07 PM, Yumin Zhou wrote:
> Hi Ed,
>
>> Platform.getBundle(pluginId).getEntry("templates/generate.txtjet").toString().
>>
> I tried this method but got an error message "Invalid thread access".
>
>> Have you set a breakpoint to see what value of DocumentRoot is being
> passed to the JETEmitter?
>
> I set a breakpoint at >String result = emitter.generate(sub, new
> Object[] {documentRoot});<. There is something in the documentRoot
> that has already loaded to my EMF but the result variable showed "null".
>
> Now I'm considering if I should change the generation method to Xpand
> instead of JET. I really prefer you could give me some advice. Xpand
> or JET2Platform runtransformonobject?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #911959 is a reply to message #911919] Wed, 12 September 2012 16:47 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

finally I figured out what I need is called dynamic template. I'm so sorry for not explaining clearly at very beginning. That is why I cannot use the compiled templates. Now I'm starting Xpand and Xtend. Hope it goes well.

Thank you for your help
Re: [JET]JETEmitter Problem when running workspace [message #929916 is a reply to message #911959] Mon, 01 October 2012 22:07 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

I got another problem. It's fine when I run the plugin on the second workbench, but it fails to generate anything when I make an external wizard. Is there something necessary I forgot to patch into the plugin? Or JET doesn't support external wizard?

Best Regards
Yumin
Re: [JET]JETEmitter Problem when running workspace [message #930213 is a reply to message #929916] Tue, 02 October 2012 05:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Yumin,

I really can't guess from your comment about an "external wizard".
What's special about an external wizard? Dynamic templates to require a
workspace in which to generate the Java code and have JDT compile it to
create classes that can be loaded dynamically, so if by external wizard
you mean one that doesn't have a workspace, then no, dynamic templates
can't work in that case. Of course there's nothing stopping your
external wizard from having a workspace just for the purpose of
compiling JET templates...


On 02/10/2012 12:07 AM, Yumin Zhou wrote:
> Hi Ed,
>
> I got another problem. It's fine when I run the plugin on the second
> workbench, but it fails to generate anything when I make an external
> wizard. Is there something necessary I forgot to patch into the
> plugin? Or JET doesn't support external wizard?
>
> Best Regards
> Yumin


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #932815 is a reply to message #930213] Thu, 04 October 2012 13:04 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

I'm really sorry. I've made a mistake for explaining my problem, not "external wizard" but "export wizard". I exported my project as a custom plugin. After I installed it in the eclipse, the wizard worked but nothing generated.

Best, YMZ
Re: [JET]JETEmitter Problem when running workspace [message #932932 is a reply to message #932815] Thu, 04 October 2012 15:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
You'll need to use the debugger.

On 04/10/2012 3:04 PM, Yumin Zhou wrote:
> Hi Ed,
>
> I'm really sorry. I've made a mistake for explaining my problem, not
> "external wizard" but "export wizard". I exported my project as a
> custom plugin. After I installed it in the eclipse, the wizard worked
> but nothing generated.
>
> Best, YMZ


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #933212 is a reply to message #932932] Thu, 04 October 2012 21:04 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

I made debug and got the following error message:
org.eclipse.emf.codegen.jet.JETException: /templates/hello.txtjet
	at org.eclipse.emf.codegen.jet.JETEmitter$EclipseHelper.initialize(JETEmitter.java:883)
	at org.eclipse.emf.codegen.jet.JETEmitter.initialize(JETEmitter.java:397)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:459)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:447)
	at org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:438)
	at ip.xact.project.wizard.NewFileWizard$1.run(NewFileWizard.java:120)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: java.io.FileNotFoundException: /templates/hello.txtjet
	at org.eclipse.osgi.framework.internal.protocol.bundleentry.Handler.findBundleEntry(Handler.java:44)
	at org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:175)
	at java.net.URL.openConnection(URL.java:945)
	at java.net.URL.openStream(URL.java:1010)
	at org.eclipse.emf.codegen.jet.JETCompiler.openStream(JETCompiler.java:754)
	at org.eclipse.emf.codegen.jet.JETCompiler.<init>(JETCompiler.java:118)
	at org.eclipse.emf.codegen.jet.JETEmitter$MyBaseJETCompiler.<init>(JETEmitter.java:316)
	at org.eclipse.emf.codegen.jet.JETEmitter$EclipseHelper.initialize(JETEmitter.java:496)
	... 6 more

It seems an initializing problem. But after I added below variables, I still got this error message.
emitter.addVariable("EMF_CODEGEN", "org.eclipse.emf.codegen");
emitter.addVariable("EMF_COMMON", "org.eclipse.emf.common");
emitter.addVariable("EMF_CODEGEN_ECORE", "org.eclipse.emf.codegen.ecore");
emitter.addVariable("EMF_ECORE", "org.eclipse.emf.ecore");
Re: [JET]JETEmitter Problem when running workspace [message #933511 is a reply to message #933212] Fri, 05 October 2012 04:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Yumin,

It sounds like this folder is not ending up in your deployed bundle.
Did you specify it (templates/) in the bin.includes of your
build.properties?

On 04/10/2012 11:04 PM, Yumin Zhou wrote:
> Hi Ed,
>
> I made debug and got the following error message:
> org.eclipse.emf.codegen.jet.JETException: /templates/hello.txtjet
> at
> org.eclipse.emf.codegen.jet.JETEmitter$EclipseHelper.initialize(JETEmitter.java:883)
> at
> org.eclipse.emf.codegen.jet.JETEmitter.initialize(JETEmitter.java:397)
> at
> org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:459)
> at
> org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:447)
> at
> org.eclipse.emf.codegen.jet.JETEmitter.generate(JETEmitter.java:438)
> at ip.xact.project.wizard.NewFileWizard$1.run(NewFileWizard.java:120)
> at
> org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
> Caused by: java.io.FileNotFoundException: /templates/hello.txtjet
> at
> org.eclipse.osgi.framework.internal.protocol.bundleentry.Handler.findBundleEntry(Handler.java:44)
> at
> org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:175)
> at java.net.URL.openConnection(URL.java:945)
> at java.net.URL.openStream(URL.java:1010)
> at
> org.eclipse.emf.codegen.jet.JETCompiler.openStream(JETCompiler.java:754)
> at
> org.eclipse.emf.codegen.jet.JETCompiler.<init>(JETCompiler.java:118)
> at
> org.eclipse.emf.codegen.jet.JETEmitter$MyBaseJETCompiler.<init>(JETEmitter.java:316)
> at
> org.eclipse.emf.codegen.jet.JETEmitter$EclipseHelper.initialize(JETEmitter.java:496)
> ... 6 more
> It seems an initializing problem. But after I added below variables, I
> still got this error message.
> emitter.addVariable("EMF_CODEGEN", "org.eclipse.emf.codegen");
> emitter.addVariable("EMF_COMMON", "org.eclipse.emf.common");
> emitter.addVariable("EMF_CODEGEN_ECORE",
> "org.eclipse.emf.codegen.ecore");
> emitter.addVariable("EMF_ECORE", "org.eclipse.emf.ecore");


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [JET]JETEmitter Problem when running workspace [message #933760 is a reply to message #933511] Fri, 05 October 2012 10:14 Go to previous message
Yumin Zhou is currently offline Yumin ZhouFriend
Messages: 21
Registered: July 2012
Junior Member
Hi Ed,

yes, it was the problem what you said. After I added the \templates folder in build.properties, it worked.
Lots of thanks to you!

Best, YM
Previous Topic:EMF Ecore - EOpposite relation to self
Next Topic:[CDO] Validation problem markers
Goto Forum:
  


Current Time: Fri Mar 29 10:42:01 GMT 2024

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

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

Back to the top