Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF and JET generating a new package.
EMF and JET generating a new package. [message #423393] Mon, 29 September 2008 19:43 Go to next message
Marc Gendron is currently offline Marc GendronFriend
Messages: 12
Registered: July 2009
Junior Member
Hi all,

I am currently experimenting with Jet and EMF. I want to generate another
package and other files with ecore and genmodel files. There is an example
of what I am trying to do :

///////////////////////////////////
ca.home.impl
HomeFactoryImpl.java
HomeImpl.java
HomePackageImpl.java
ca.home.util
HomeAdapterFactory.java
HomeSwitch.java
ca.home.proxy //this is the new package
HomeProxy.java //This is the new file
Home.java
HomeFactory.java
HomePackage.java
///////////////////////////////////

I can create a Proxy.javajet. I don't how exactly I can do this.


I tryed to create an Action that is place in the context menu of The
genmodel Editor. This is the code :
///////////////////////////////////
GenModel genModel = null;
GenClass gc = null;

if (s instanceof StructuredSelection)
{
StructuredSelection selection = (StructuredSelection)s;
Iterator<?> iterator = selection.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof GenModel)
genModel = (GenModel) obj;
else if (obj instanceof GenClass)
gc = (GenClass) obj;
}
}
if (genModel == null && gc==null)
return;

if (gc==null)
gc = genModel.createGenClass();


String uri ="platform:/plugin/mypluggin/templates/model/Proxy.javajet";
JETEmitter emitter = new JETEmitter( uri,getClass().getClassLoader() );


Object[] arg = {gc};

String result = "";
try {
result = emitter.generate( new NullProgressMonitor(), arg );
} catch (JETException e) {
e.printStackTrace();
}
System.out.println(result);
///////////////////////////////////

But It doesn't display anything because it Doesn't like the import in the
first line of Proxy.javajet. For now, the first line of Proxy.javajet is the
same as Class.javajet.


This is the Proxy.javajet :
//////////////////////////////////
<%@ jet package="org.eclipse.emf.codegen.ecore.templates.model"
imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.*" class="Class"
version="$Id: Class.javajet,v 1.75 2008/05/20 14:39:35 emerks Exp $" %>

Hello world.
//////////////////////////////////

Why if I remove the "org.eclipse.emf.codegen.ecore.genmodel.*" it print
"Hello world."? In my run configuration, I selected the
"org.eclipse.emf.codegen.ecore" plugin.

What is the best solution to create my Proxy package?


Thanks in adavance,

Marc
Re: EMF and JET generating a new package. [message #423395 is a reply to message #423393] Mon, 29 September 2008 20:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30819
Registered: July 2009
Senior Member
Marc,

Comments below.

Marc Gendron wrote:
> Hi all,
>
> I am currently experimenting with Jet and EMF. I want to generate another
> package and other files with ecore and genmodel files. There is an example
> of what I am trying to do :
>
You've looked at the Generator Extension example? You can create the
example project (File->New->Example...) your workspace if you have the
EMF SDK installed.
> ///////////////////////////////////
> ca.home.impl
> HomeFactoryImpl.java
> HomeImpl.java
> HomePackageImpl.java
> ca.home.util
> HomeAdapterFactory.java
> HomeSwitch.java
> ca.home.proxy //this is the new package
> HomeProxy.java //This is the new file
> Home.java
> HomeFactory.java
> HomePackage.java
> ///////////////////////////////////
>
> I can create a Proxy.javajet. I don't how exactly I can do this.
>
>
> I tryed to create an Action that is place in the context menu of The
> genmodel Editor. This is the code :
> ///////////////////////////////////
> GenModel genModel = null;
> GenClass gc = null;
>
> if (s instanceof StructuredSelection)
> {
> StructuredSelection selection = (StructuredSelection)s;
> Iterator<?> iterator = selection.iterator();
> while (iterator.hasNext()) {
> Object obj = iterator.next();
> if (obj instanceof GenModel)
> genModel = (GenModel) obj;
> else if (obj instanceof GenClass)
> gc = (GenClass) obj;
> }
> }
> if (genModel == null && gc==null)
> return;
>
> if (gc==null)
> gc = genModel.createGenClass();
>
>
> String uri ="platform:/plugin/mypluggin/templates/model/Proxy.javajet";
> JETEmitter emitter = new JETEmitter( uri,getClass().getClassLoader() );
>
>
> Object[] arg = {gc};
>
> String result = "";
> try {
> result = emitter.generate( new NullProgressMonitor(), arg );
> } catch (JETException e) {
> e.printStackTrace();
> }
> System.out.println(result);
> ///////////////////////////////////
>
> But It doesn't display anything because it Doesn't like the import in the
> first line of Proxy.javajet. For now, the first line of Proxy.javajet is the
> same as Class.javajet.
>
>
> This is the Proxy.javajet :
> //////////////////////////////////
> <%@ jet package="org.eclipse.emf.codegen.ecore.templates.model"
> imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.*" class="Class"
> version="$Id: Class.javajet,v 1.75 2008/05/20 14:39:35 emerks Exp $" %>
>
> Hello world.
> //////////////////////////////////
>
> Why if I remove the "org.eclipse.emf.codegen.ecore.genmodel.*" it print
> "Hello world."? In my run configuration, I selected the
> "org.eclipse.emf.codegen.ecore" plugin.
>
> What is the best solution to create my Proxy package?
>
>
> Thanks in adavance,
>
> Marc
>
>
>
Previous Topic:EMF + API Tools
Next Topic:Handling Resource moves in Workspace
Goto Forum:
  


Current Time: Sun Jan 26 20:13:38 GMT 2020

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

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

Back to the top