Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem with Genmodel with multiple ecores
Problem with Genmodel with multiple ecores [message #417417] Mon, 10 March 2008 07:37 Go to next message
Eclipse UserFriend
Originally posted by: hkumar.agrawal.gmail.com

Hi,

We had a functionality where we had one ecore and we would generate the genModel from it (programatically) and it worked fine. (Note that the ecore was also generated programatically).
We now changed the functionality to generate multiple ecores and a new root package that would have references to all the ecores in its eStructuralFeatures. When we generate the genModel using the new ecore we find the the genModel does not have the ePackages for the individual ecores. It does have the ePackage for the root package. On calling generate for this genModel we get an exception related to the "Dependency helper" (because it is unable to find the ePackages). This is what we are doing:

 
URI ecoreURI = URI.createFileURI(filename.getFullPath().toString());
Resource resource = resourceSet.getResource(ecoreURI, true);
EPackage ePackage = (EPackage)resource.getContents().get(0);
IPath genModelPath = ecorePath.removeFileExtension().addFileExtension(
"genmodel");
URI genModelURI = URI.createFileURI(genModelPath.toString());

Resource genModelResource = Resource.Factory.Registry.INSTANCE
	.getFactory(genModelURI).createResource(genModelURI);
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();

genModelResource.getContents().add(genModel);
resourceSet.getResources().add(genModelResource);
genModel.setCopyrightText(COPYRIGHT);
genModel.setForceOverwrite(true);
genModel.setUpdateClasspath(false);
genModel.setModelDirectory('/' + projectName + '/' + Paths.GENSRC.makeRelative().toString());

genModel.initialize(Collections.singleton(ePackage));

GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
genModel.setModelName(genModelURI.trimFileExtension().lastSegment());
genPackage.setPrefix(businessLogicProject.getProjectName());
genModel.setModelPluginID(projectName);


// Create the file
try {
	genModelResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
	_LOGGER.debug("Error saving file: " + e);
}

genModel.setCanGenerate(true);


genModel.generate(new NullProgressMonitor());



If we programatically, add the required ePackages to the genModels instance in memory, it works fine !

Has anyone faced such an issue before ?
Any help is much appreciated.

Thanks in advance.
Regards
Hemant
Re: Problem with Genmodel with multiple ecores [message #417420 is a reply to message #417417] Mon, 10 March 2008 12:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050106010007070708070908
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hemant,

Comments below.

Hemant wrote:
> Hi,
>
> We had a functionality where we had one ecore and we would generate the genModel from it (programatically) and it worked fine. (Note that the ecore was also generated programatically).
> We now changed the functionality to generate multiple ecores and a new root package that would have references to all the ecores in its eStructuralFeatures.
By root package, you don't mean it actually contains the other packages
as subpackages but rather that it has a class with features that refer
to classifiers from the other packages, so it kind of ties them all
together.
> When we generate the genModel using the new ecore we find the the genModel does not have the ePackages for the individual ecores. It does have the ePackage for the root package. On calling generate for this genModel we get an exception related to the "Dependency helper" (because it is unable to find the ePackages). This is what we are doing:
>
>
 
> URI ecoreURI = URI.createFileURI(filename.getFullPath().toString());
> Resource resource = resourceSet.getResource(ecoreURI, true);
> EPackage ePackage = (EPackage)resource.getContents().get(0);
> IPath genModelPath = ecorePath.removeFileExtension().addFileExtension(
> "genmodel");
> URI genModelURI = URI.createFileURI(genModelPath.toString());
>
> Resource genModelResource = Resource.Factory.Registry.INSTANCE
> 	.getFactory(genModelURI).createResource(genModelURI);
> GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
>
> genModelResource.getContents().add(genModel);
> resourceSet.getResources().add(genModelResource);
> genModel.setCopyrightText(COPYRIGHT);
> genModel.setForceOverwrite(true);
> genModel.setUpdateClasspath(false);
> genModel.setModelDirectory('/' + projectName + '/' + Paths.GENSRC.makeRelative().toString());
>
> genModel.initialize(Collections.singleton(ePackage));
>
> GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
> genModel.setModelName(genModelURI.trimFileExtension().lastSegment());
> genPackage.setPrefix(businessLogicProject.getProjectName());
> genModel.setModelPluginID(projectName);
>
>
> // Create the file
> try {
> 	genModelResource.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
> 	_LOGGER.debug("Error saving file: " + e);
> }
>
> genModel.setCanGenerate(true);
>
>
> genModel.generate(new NullProgressMonitor());
>
> 

>
> If we programatically, add the required ePackages to the genModels instance in memory, it works fine !
>
What you really want to do is add the GenPackages for the the EPackages,
which are off in their own GenModels somewhere, to the usedGenPackages
of the GenModel for this "root EPackage". That's the step that happens
in the wizard in the tutorial for creating an extended model:

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/tutorials/slibmod/slibmod.html

> Has anyone faced such an issue before ?
> Any help is much appreciated.
>
An alternative is to include all packages in a single GenModel. In all
cases, every EPackage that's reachable from an EPackage in your GenModel
must be wrapped by a GenPackage which is either in the GenModel as a
genPackage or reachable as a usedGenPackage.
> Thanks in advance.
> Regards
> Hemant
>


--------------050106010007070708070908
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">
Hemant,<br>
<br>
Comments below.<br>
<br>
Hemant wrote:
<blockquote
cite="mid:2734525.35531205134717142.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">Hi,

We had a functionality where we had one ecore and we would generate the genModel from it (programatically) and it worked fine. (Note that the ecore was also generated programatically).
We now changed the functionality to generate multiple ecores and a new root package that would have references to all the ecores in its eStructuralFeatures. </pre>
</blockquote>
By root package, you don't mean it actually contains the other packages
as subpackages but rather that it has a class with features that refer
to classifiers from the other packages, so it kind of ties them all
together.<br>
<blockquote
cite="mid:2734525.35531205134717142.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">When we generate the genModel using the new ecore we find the the genModel does not have the ePackages for the individual ecores. It does have the ePackage for the root package. On calling generate for this genModel we get an exception related to the "Dependency helper" (because it is unable to find the ePackages). This is what we are doing:

 
URI ecoreURI = URI.createFileURI(filename.getFullPath().toString());
Resource resource = resourceSet.getResource(ecoreURI, true);
EPackage ePackage = (EPackage)resource.getContents().get(0);
IPath genModelPath = ecorePath.removeFileExtension().addFileExtension(
"genmodel");
URI genModelURI = URI.createFileURI(genModelPath.toString());

Resource genModelResource = Resource.Factory.Registry.INSTANCE
	.getFactory(genModelURI).createResource(genModelURI);
GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();

genModelResource.getContents().add(genModel);
resourceSet.getResources().add(genModelResource);
genModel.setCopyrightText(COPYRIGHT);
genModel.setForceOverwrite(true);
genModel.setUpdateClasspath(false);
genModel.setModelDirectory('/' + projectName + '/' + Paths.GENSRC.makeRelative().toString());

genModel.initialize(Collections.singleton(ePackage));

GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
genModel.setModelName(genModelURI.trimFileExtension().lastSegment());
genPackage.setPrefix(businessLogicProject.getProjectName());
genModel.setModelPluginID(projectName);


// Create the file
try {
	genModelResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
	_LOGGER.debug("Error saving file: " + e);
}

genModel.setCanGenerate(true);


genModel.generate(new NullProgressMonitor());



If we programatically, add the required ePackages to the genModels instance in memory, it works fine !
</pre>
</blockquote>
What you really want to do is add the GenPackages for the the
EPackages, which are off in their own GenModels somewhere, to the
usedGenPackages of the GenModel for this "root EPackage".&nbsp; That's the
step that happens in the wizard in the tutorial for creating an
extended model: <br>
<blockquote>&nbsp;<a
href=" http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/tutorials/slibmod/slibmod.html"> http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. emf.doc/tutorials/slibmod/slibmod.html</a><br>
</blockquote>
<blockquote
cite="mid:2734525.35531205134717142.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">
Has anyone faced such an issue before ?
Any help is much appreciated.
</pre>
</blockquote>
An alternative is to include all packages in a single GenModel.&nbsp; In all
cases, every EPackage that's reachable from an EPackage in your
GenModel must be wrapped by a GenPackage which is either in the
GenModel as a genPackage or reachable as a usedGenPackage.<br>
<blockquote
cite="mid:2734525.35531205134717142.JavaMail.root@cp1.dzone.com"
type="cite">
<pre wrap="">
Thanks in advance.
Regards
Hemant
</pre>
</blockquote>
<br>
</body>
</html>

--------------050106010007070708070908--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Problem with Genmodel with multiple ecores [message #417724 is a reply to message #417420] Tue, 25 March 2008 07:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hkumar.agrawal.gmail.com

Hi,

"<i>By root package, you don't mean it actually contains the other packages as subpackages but rather that it has a class with features that refer to classifiers from the other packages, so it kind of ties them all together.</i>"

-Thats correct

"<i>What you really want to do is add the GenPackages for the the EPackages, which are off in their own GenModels somewhere, to the usedGenPackages of the GenModel for this "root EPackage". That's the step that happens in the wizard in the tutorial for creating an extended model: </i>"

- We did this and it seemed to work, when we hit a <b>StackOverflowError</b>. This is happening at org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl.set ImportManager.
Seems like the functionality here is to set the importmanager to all the usedGenPackagaes recursively down the tree ! This would obviously lead to a stackoverflow if there are cyclic dependencies. I think a simple check of the importManager already being the instance passed can be used to prevent the stack overflow.


"<i>An alternative is to include all packages in a single GenModel. In all cases, every EPackage that's reachable from an EPackage in your GenModel must be wrapped by a GenPackage which is either in the GenModel as a genPackage or reachable as a usedGenPackage.</i>"

- Another post in the forum
<b>http://www.eclipsepowered.com/eclipse/forums/t85796.html</b> suggests that we have a common genmodel.
I realize that that would work, however, that is what we already had and we wanted to remove that. This is cos we wanted to have some performance improvements in our system.

Thanks
Hemant
Re: Problem with Genmodel with multiple ecores [message #417727 is a reply to message #417724] Tue, 25 March 2008 12:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Hemant,

We don't expect GenModels to have cycles. The tools themselves would
never create such a thing because the tools create them one and a time
and won't let you create one that doesn't have proper dependencies. So
it's sort of a chicken and egg problem... I'm not sure what performance
improvements you're looking for, but I don't see how separate GenModels
for mutually dependent packages would help with that.


Hemant wrote:
> Hi,
>
> "<i>By root package, you don't mean it actually contains the other packages as subpackages but rather that it has a class with features that refer to classifiers from the other packages, so it kind of ties them all together.</i>"
>
> -Thats correct
>
> "<i>What you really want to do is add the GenPackages for the the EPackages, which are off in their own GenModels somewhere, to the usedGenPackages of the GenModel for this "root EPackage". That's the step that happens in the wizard in the tutorial for creating an extended model: </i>"
>
> - We did this and it seemed to work, when we hit a <b>StackOverflowError</b>. This is happening at org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl.set ImportManager.
> Seems like the functionality here is to set the importmanager to all the usedGenPackagaes recursively down the tree ! This would obviously lead to a stackoverflow if there are cyclic dependencies. I think a simple check of the importManager already being the instance passed can be used to prevent the stack overflow.
>
>
> "<i>An alternative is to include all packages in a single GenModel. In all cases, every EPackage that's reachable from an EPackage in your GenModel must be wrapped by a GenPackage which is either in the GenModel as a genPackage or reachable as a usedGenPackage.</i>"
>
> - Another post in the forum
> <b>http://www.eclipsepowered.com/eclipse/forums/t85796.html</b> suggests that we have a common genmodel.
> I realize that that would work, however, that is what we already had and we wanted to remove that. This is cos we wanted to have some performance improvements in our system.
>
> Thanks
> Hemant
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Selection order in tree-based EMF editors
Next Topic:Cannot start ecore bundle
Goto Forum:
  


Current Time: Fri Apr 19 21:02:55 GMT 2024

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

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

Back to the top