Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Multiple EMF meta-models in a single plugin
Multiple EMF meta-models in a single plugin [message #478932] Fri, 07 August 2009 14:37 Go to next message
drew frantz is currently offline drew frantzFriend
Messages: 340
Registered: July 2009
Senior Member
I have 2 different EMF meta-models I am using in the app I am building. The
EMF models were constructed from existing .xsd schemas that were used on
other projects. It seems during resource loading something does not work
correctly since once I load a model of one type, then models of the other
type cannot be loaded (Error: I get a PackageNotFoundException: e.g.,
"Package with uri.....". I read the section in the EMF faq about loading emf
meta-mdelsl from an standaloine java applicatyion, and the error I get is .
Part of the problem is that all the existing xsd used the same
xmlns=http://www.foo.bar" and therefore when I open a file of a different
type with a different extension , the Resource loader tries to create an EMF
of the wrong type. I guess what I want is an ability to make sure the
resource registry is by file extension only and nothing else, since the file
extension are indeed unique.

Is there way for the EMF resource loader to ignore the URIS and only use
file extensions?

Here is the code I use to load the model and I am manually init the
registries.


void loadFile(File file)
{
initRegistry();
ResourceSet myResourceSet = new ResourceSetImpl();
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
URI.createURI(file.getAbsolutePath());
Resource resource = myResourceSet.getResource(uri, true);
EcoreUtil.resolveAll(resource);
}

protected void initRegistry()
{
CcpPackage ccp = CcpPackage.eINSTANCE;
CcePackage cce = CcePackage.eINSTANCE;
Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
Map<String, Object> extensionsMap = registry.getExtensionToFactoryMap();
extensionsMap.put(CCP_EXT, new CcpResourceFactoryImpl());
extensionsMap.put(CCE_EXT, new CceResourceFactoryImpl());

}
Re: Multiple EMF meta-models in a single plugin [message #478934 is a reply to message #478932] Fri, 07 August 2009 14:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Drew,

Comments below.

drew wrote:
> I have 2 different EMF meta-models I am using in the app I am building. The
> EMF models were constructed from existing .xsd schemas that were used on
> other projects. It seems during resource loading something does not work
> correctly since once I load a model of one type, then models of the other
> type cannot be loaded (Error: I get a PackageNotFoundException: e.g.,
> "Package with uri.....". I read the section in the EMF faq about loading emf
> meta-mdelsl from an standaloine java applicatyion, and the error I get is .
> Part of the problem is that all the existing xsd used the same
> xmlns=http://www.foo.bar" and therefore when I open a file of a different
> type with a different extension , the Resource loader tries to create an EMF
> of the wrong type.
If both schemas are using a common schema that common schema should be
generated as a separate package and plugin that's reused by the other
two schemas.
> I guess what I want is an ability to make sure the
> resource registry is by file extension only and nothing else, since the file
> extension are indeed unique.
>
It sounds like the problem is with having more than one package for the
same URI.
> Is there way for the EMF resource loader to ignore the URIS and only use
> file extensions?
>
That's generally the default already but doesn't sound like your problem.

Do you have more than one registration like this:

<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="http://www.example.com/Library"
class="com.example.library.LibraryPackage"
genModel="model/Library.genmodel"/>
</extension>

for http://www.foo.bar?
> Here is the code I use to load the model and I am manually init the
> registries.
>
>
> void loadFile(File file)
> {
> initRegistry();
> ResourceSet myResourceSet = new ResourceSetImpl();
> URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
> URI.createURI(file.getAbsolutePath());
> Resource resource = myResourceSet.getResource(uri, true);
> EcoreUtil.resolveAll(resource);
> }
>
> protected void initRegistry()
> {
> CcpPackage ccp = CcpPackage.eINSTANCE;
> CcePackage cce = CcePackage.eINSTANCE;
> Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> extensionsMap = registry.getExtensionToFactoryMap();
> extensionsMap.put(CCP_EXT, new CcpResourceFactoryImpl());
> extensionsMap.put(CCE_EXT, new CceResourceFactoryImpl());
>
Now also that each resource set has it's own local resource factory
registry so you can register things there rather than globally to avoid
conflicts (not that I think this is your problem though).
> }
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple EMF meta-models in a single plugin [message #478937 is a reply to message #478934] Fri, 07 August 2009 15:03 Go to previous messageGo to next message
drew frantz is currently offline drew frantzFriend
Messages: 340
Registered: July 2009
Senior Member
"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:h5heg0$tp3$1@build.eclipse.org...
> Drew,
>
> Comments below.
>
> drew wrote:
>> I have 2 different EMF meta-models I am using in the app I am building.
>> The EMF models were constructed from existing .xsd schemas that were used
>> on other projects. It seems during resource loading something does not
>> work correctly since once I load a model of one type, then models of the
>> other type cannot be loaded (Error: I get a PackageNotFoundException:
>> e.g., "Package with uri.....". I read the section in the EMF faq about
>> loading emf meta-mdelsl from an standaloine java applicatyion, and the
>> error I get is . Part of the problem is that all the existing xsd used
>> the same xmlns=http://www.foo.bar" and therefore when I open a file of a
>> different type with a different extension , the Resource loader tries to
>> create an EMF of the wrong type.
> If both schemas are using a common schema that common schema should be
> generated as a separate package and plugin that's reused by the other two
> schemas.
>> I guess what I want is an ability to make sure the resource registry is
>> by file extension only and nothing else, since the file extension are
>> indeed unique.
>>
> It sounds like the problem is with having more than one package for the
> same URI.
>> Is there way for the EMF resource loader to ignore the URIS and only use
>> file extensions?
>>


> That's generally the default already but doesn't sound like your problem.
>
> Do you have more than one registration like this:
>
> <extension point="org.eclipse.emf.ecore.generated_package">
> <package
> uri="http://www.example.com/Library"
> class="com.example.library.LibraryPackage"
> genModel="model/Library.genmodel"/>
> </extension>
df> I removed those entries from plugin.xml and got same result.
df> i also tried to use the local registry on the ResourceSet
df> The only thing that seemed to work was chnaging the NS URI parameter on
the ecore model and then regenerating, unfortunealy this breaks backward
compatibility of the existing files, which I am trying to support.

>
> for http://www.foo.bar?
>> Here is the code I use to load the model and I am manually init the
>> registries.
>>
>>
>> void loadFile(File file)
>> {
>> initRegistry();
>> ResourceSet myResourceSet = new ResourceSetImpl();
>> URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
>> URI.createURI(file.getAbsolutePath());
>> Resource resource = myResourceSet.getResource(uri, true);
>> EcoreUtil.resolveAll(resource);
>> }
>>
>> protected void initRegistry()
>> {
>> CcpPackage ccp = CcpPackage.eINSTANCE;
>> CcePackage cce = CcePackage.eINSTANCE;
>> Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
>> Map<String, Object> extensionsMap = registry.getExtensionToFactoryMap();
>> extensionsMap.put(CCP_EXT, new CcpResourceFactoryImpl());
>> extensionsMap.put(CCE_EXT, new CceResourceFactoryImpl());
>>
> Now also that each resource set has it's own local resource factory
> registry so you can register things there rather than globally to avoid
> conflicts (not that I think this is your problem though).
>> }
>>
>>
Re: Multiple EMF meta-models in a single plugin [message #478942 is a reply to message #478937] Fri, 07 August 2009 15:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050505070605040806070500
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Drew,

Comments below.

drew wrote:
> "Ed Merks" <Ed.Merks@gmail.com> wrote in message
> news:h5heg0$tp3$1@build.eclipse.org...
>
>> Drew,
>>
>> Comments below.
>>
>> drew wrote:
>>
>>> I have 2 different EMF meta-models I am using in the app I am building.
>>> The EMF models were constructed from existing .xsd schemas that were used
>>> on other projects. It seems during resource loading something does not
>>> work correctly since once I load a model of one type, then models of the
>>> other type cannot be loaded (Error: I get a PackageNotFoundException:
>>> e.g., "Package with uri.....". I read the section in the EMF faq about
>>> loading emf meta-mdelsl from an standaloine java applicatyion, and the
>>> error I get is . Part of the problem is that all the existing xsd used
>>> the same xmlns=http://www.foo.bar" and therefore when I open a file of a
>>> different type with a different extension , the Resource loader tries to
>>> create an EMF of the wrong type.
>>>
>> If both schemas are using a common schema that common schema should be
>> generated as a separate package and plugin that's reused by the other two
>> schemas.
>>
>>> I guess what I want is an ability to make sure the resource registry is
>>> by file extension only and nothing else, since the file extension are
>>> indeed unique.
>>>
>>>
>> It sounds like the problem is with having more than one package for the
>> same URI.
>>
>>> Is there way for the EMF resource loader to ignore the URIS and only use
>>> file extensions?
>>>
>>>
>
>
>
>> That's generally the default already but doesn't sound like your problem.
>>
>> Do you have more than one registration like this:
>>
>> <extension point="org.eclipse.emf.ecore.generated_package">
>> <package
>> uri="http://www.example.com/Library"
>> class="com.example.library.LibraryPackage"
>> genModel="model/Library.genmodel"/>
>> </extension>
>>
> df> I removed those entries from plugin.xml and got same result.
>
This is just one of the symptoms of the problem. Getting rid of them
will not cure the problems.
> df> i also tried to use the local registry on the ResourceSet
> df> The only thing that seemed to work was chnaging the NS URI parameter on
> the ecore model and then regenerating, unfortunealy this breaks backward
> compatibility of the existing files, which I am trying to support.
>
There needs to be a single generated package for the shared schema as I
mentioned in the first comment. It's the only proper solution. So
generate a model for the schema first, and then when generating the
models for the other schemas, be sure to use the last page of the wizard
to refer to that shared model.
>
>> for http://www.foo.bar?
>>
>>> Here is the code I use to load the model and I am manually init the
>>> registries.
>>>
>>>
>>> void loadFile(File file)
>>> {
>>> initRegistry();
>>> ResourceSet myResourceSet = new ResourceSetImpl();
>>> URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
>>> URI.createURI(file.getAbsolutePath());
>>> Resource resource = myResourceSet.getResource(uri, true);
>>> EcoreUtil.resolveAll(resource);
>>> }
>>>
>>> protected void initRegistry()
>>> {
>>> CcpPackage ccp = CcpPackage.eINSTANCE;
>>> CcePackage cce = CcePackage.eINSTANCE;
>>> Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
>>> Map<String, Object> extensionsMap = registry.getExtensionToFactoryMap();
>>> extensionsMap.put(CCP_EXT, new CcpResourceFactoryImpl());
>>> extensionsMap.put(CCE_EXT, new CceResourceFactoryImpl());
>>>
>>>
>> Now also that each resource set has it's own local resource factory
>> registry so you can register things there rather than globally to avoid
>> conflicts (not that I think this is your problem though).
>>
>>> }
>>>
>>>
>>>
>
>
>

--------------050505070605040806070500
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">
Drew,<br>
<br>
Comments below.<br>
<br>
drew wrote:
<blockquote cite="mid:h5hfn9$5b2$1@build.eclipse.org" type="cite">
<pre wrap="">"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:h5heg0$tp3$1@build.eclipse.org">news:h5heg0$tp3$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Drew,

Comments below.

drew wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I have 2 different EMF meta-models I am using in the app I am building.
The EMF models were constructed from existing .xsd schemas that were used
on other projects. It seems during resource loading something does not
work correctly since once I load a model of one type, then models of the
other type cannot be loaded (Error: I get a PackageNotFoundException:
e.g., "Package with uri.....". I read the section in the EMF faq about
loading emf meta-mdelsl from an standaloine java applicatyion, and the
error I get is . Part of the problem is that all the existing xsd used
the same xmlns=<a class="moz-txt-link-freetext" href="http://www.foo.bar">http://www.foo.bar</a>" and therefore when I open a file of a
different type with a different extension , the Resource loader tries to
create an EMF of the wrong type.
</pre>
</blockquote>
<pre wrap="">If both schemas are using a common schema that common schema should be
generated as a separate package and plugin that's reused by the other two
schemas.
</pre>
<blockquote type="cite">
<pre wrap="">I guess what I want is an ability to make sure the resource registry is
by file extension only and nothing else, since the file extension are
indeed unique.

</pre>
</blockquote>
<pre wrap="">It sounds like the problem is with having more than one package for the
same URI.
</pre>
<blockquote type="cite">
<pre wrap="">Is there way for the EMF resource loader to ignore the URIS and only use
file extensions?

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
<blockquote type="cite">
<pre wrap="">That's generally the default already but doesn't sound like your problem.

Do you have more than one registration like this:

&lt;extension point="org.eclipse.emf.ecore.generated_package"&gt;
&lt;package
uri=<a class="moz-txt-link-rfc2396E" href="http://www.example.com/Library">"http://www.example.com/Library"</a>
class="com.example.library.LibraryPackage"
genModel="model/Library.genmodel"/&gt;
&lt;/extension&gt;
</pre>
</blockquote>
<pre wrap=""><!---->df&gt; I removed those entries from plugin.xml and got same result.
</pre>
</blockquote>
This is just one of the symptoms of the problem.&nbsp; Getting rid of them
will not cure the problems.<br>
<blockquote cite="mid:h5hfn9$5b2$1@build.eclipse.org" type="cite">
<pre wrap="">df&gt; i also tried to use the local registry on the ResourceSet
df&gt; The only thing that seemed to work was chnaging the NS URI parameter on
the ecore model and then regenerating, unfortunealy this breaks backward
compatibility of the existing files, which I am trying to support.
</pre>
</blockquote>
There needs to be a single generated package for the shared schema as I
mentioned in the first comment.&nbsp; It's the only proper solution.&nbsp; So
generate a model for the schema first, and then when generating the
models for the other schemas, be sure to use the last page of the
wizard to refer to that shared model.<br>
<blockquote cite="mid:h5hfn9$5b2$1@build.eclipse.org" type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">for <a class="moz-txt-link-freetext" href="http://www.foo.bar">http://www.foo.bar</a>?
</pre>
<blockquote type="cite">
<pre wrap="">Here is the code I use to load the model and I am manually init the
registries.


void loadFile(File file)
{
initRegistry();
ResourceSet myResourceSet = new ResourceSetImpl();
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()):
URI.createURI(file.getAbsolutePath());
Resource resource = myResourceSet.getResource(uri, true);
EcoreUtil.resolveAll(resource);
}

protected void initRegistry()
{
CcpPackage ccp = CcpPackage.eINSTANCE;
CcePackage cce = CcePackage.eINSTANCE;
Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
Map&lt;String, Object&gt; extensionsMap = registry.getExtensionToFactoryMap();
extensionsMap.put(CCP_EXT, new CcpResourceFactoryImpl());
extensionsMap.put(CCE_EXT, new CceResourceFactoryImpl());

</pre>
</blockquote>
<pre wrap="">Now also that each resource set has it's own local resource factory
registry so you can register things there rather than globally to avoid
conflicts (not that I think this is your problem though).
</pre>
<blockquote type="cite">
<pre wrap="">}


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------050505070605040806070500--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF and final filed initialization
Next Topic:Validation fails on required EAttribute (EEnum) with default literal value.
Goto Forum:
  


Current Time: Fri Apr 19 16:38:52 GMT 2024

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

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

Back to the top