Missing GenClass while using genmodel in JET Transformation Project [message #494900] |
Tue, 03 November 2009 07:50 |
Asheesh Arora Messages: 2 Registered: November 2009 Location: Pune |
Junior Member |
|
|
I have created ECore and GenModel using following steps:
1. Create My.ecore file
2. Set the package properties.
3. Create EClass Student with attributes: Name, Id
4. Create My.genmodel from My.ecore
5. Open My.ecore and add EClass Teacher with attribute: Name
As I have modified My.ecore after creating My.genmodel, it does not have GenClass tag corresponding to Teacher EClass.
My.genmodel file is:
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/test/src"
modelPluginID="test" modelName="My" importerID="test"
complianceLevel="6.0" copyrightFields="false">
<foreignModel>My.ecore</foreignModel>
<genPackages prefix="Mymodel" disposableProviderFactory="true" ecorePackage="My.ecore#/">
<genClasses ecoreClass="My.ecore#//Student">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute My.ecore#//Student/Name"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute My.ecore#//Student/ID"/>
</genClasses>
</genPackages>
</genmodel:GenModel>
If I open this genmodel file in EMF Generator Editor, I can see Teacher in the tree view. Also if I generate the model code, EMF generates classes for Teacher EClass.
I want to extend EMF Code Generation so I tried exnteding EMF Code Generator. From the GenPackage obejct, I am able to retrieve two GenClasses i.e Student and Teacher.
Now I am planinng to write my own code generation mechanism using JET Transformation Project. In My jet template I get only one GenClass instance for EClass Student.
I have set the modelLoader as org.eclipse.jet.emf for my transform extension.
My question is why GenClass instance for EClass Teacher is missing. What am I missing?
Below is my jet file:
<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<%@jet imports="org.eclipse.emf.ecore.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.jet.internal.xpath.*"%>
<%-- write to the JET execution console --%>
<c:log>
<c:setVariable var="genModel" select="/GenModel"/>
<%-- create derived attributes to contain genmodel methods JET Xpath cannot see --%>
<c:iterate select="$genModel/genPackages" var="genPackage">
<%GenPackage genPackage =(GenPackage)context.getVariable("genPackage");%>
<c:iterate select="$genPackage/genClasses" var="genClass">
<%GenClass genClass = (GenClass)context.getVariable("genClass");%>
<%=genClass.toString()%>
</c:iterate>
</c:iterate>
</c:log>
My console output is:
templates/emf2.jet:
org.eclipse.emf.codegen.ecore.genmodel.impl.GenClassImpl@1c31d43 (provider: Singleton, image: true, dynamic: false)
Successful execution with messages
It shows only one class whereas there should be two GenClasses.
I also tried loading My.genmodel programatically using EcoreResourceFactoryImpl. I am able to get both GenClasses. Below is my code for this:
ResourceSet set = new ResourceSetImpl();
EcoreResourceFactoryImpl fact = new EcoreResourceFactoryImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap(). put( "genmodel", new EcoreResourceFactoryImpl() );
GenModelPackage.eINSTANCE.eClass();
BMIDEPackage.eINSTANCE.eClass();
Resource res = set.getResource( URI.createFileURI( <FILE_PATH> ), true );
res.load( new HashMap() );
TreeIterator<EObject> list = res.getAllContents();
while ( list.hasNext() )
{
EObject obj = list.next();
if ( obj instanceof GenModel )
{
GenModel genModel = (GenModel) obj;
for ( GenClass genClass : genModel.getGenPackages().get( 0 ).getGenClasses() )
{
System.out.println(genClass.toString());
}
}
}
}
Result of this is:
org.eclipse.emf.codegen.ecore.genmodel.impl.GenClassImpl@1c23d65 (provider: Singleton, image: true, dynamic: false)
org.eclipse.emf.codegen.ecore.genmodel.impl.GenClassImpl@1c31d43 (provider: Singleton, image: true, dynamic: false)
Why I am not getting GenClass for EClass Teacher in JET Transformation Project?
Regards
Asheesh
[Updated on: Tue, 03 November 2009 07:51] Report message to a moderator
|
|
|
Re: Missing GenClass while using genmodel in JET Transformation Project [message #494986 is a reply to message #494900] |
Tue, 03 November 2009 13:29 |
Paul Elder Messages: 849 Registered: July 2009 |
Senior Member |
|
|
Asheesh Arora
Quote: |
I have created ECore and GenModel using following steps:
1. Create My.ecore file
2. Set the package properties.
3. Create EClass Student with attributes: Name, Id
4. Create My.genmodel from My.ecore
5. Open My.ecore and add EClass Teacher with attribute: Name
As I have modified My.ecore after creating My.genmodel, it does not have GenClass tag corresponding to Teacher EClass.
My.genmodel file is:
<< reference to Teacher missing >>
|
This appears to be a problem with the Genmodel editor (aka the EMF Generator). When it loads, it takes a look at the referenced .ecore file, and adds any Gen* classes that are missing from the Genmodel. However, when it makes such changes, it does not set the editor's dirty flag, so you do not know it has made those changes, and you cannot save them.
One way to fix this is to make a small change (so that the editor realizes it must save), and then save.
But, the most reliable way is to 'reload' the gen model after any .ecore file change. In the genmodel editor, click Generator > Reload. Or, from the package explorer, right click the .genmodel file and click Reload. In either case, follow the wizard. On completion, your missing genXXX elements will be there.
Paul
|
|
|
Powered by
FUDForum. Page generated in 0.03332 seconds