Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Getting the Resource.Factory from the EPackage
Getting the Resource.Factory from the EPackage [message #417069] Mon, 25 February 2008 19:58 Go to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I have multiple models being managed in the same ResourceSet. When a
resource is going to be created, I know from the URI which model I am
dealing with, but currently only by an EPackage reference.

Is there a way to get the generated Resource.Factory from the EPackage?
Or do I need to map the URI to the Resource.Factory separately.

Thanks,
Will
Re: Getting the Resource.Factory from the EPackage [message #417070 is a reply to message #417069] Mon, 25 February 2008 19:59 Go to previous messageGo to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I should add that the resources are XML files and all have the same
".xml" extension.

Will Horn wrote:
> I have multiple models being managed in the same ResourceSet. When a
> resource is going to be created, I know from the URI which model I am
> dealing with, but currently only by an EPackage reference.
>
> Is there a way to get the generated Resource.Factory from the EPackage?
> Or do I need to map the URI to the Resource.Factory separately.
>
> Thanks,
> Will
Re: Getting the Resource.Factory from the EPackage [message #417073 is a reply to message #417070] Mon, 25 February 2008 20:29 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.
--------------060908000706030105040802
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Will,

It's quite possible for a given package's instance to be serialized in
multiple different ways. For example, an Ecore EPackage can be
serialized as a *.ecore the normal way, or using EMOF syntax in a *.emof
file that uses EMOFResourceFactoryImpl. So generally there is no way to
map from a package to a resource factory to be used for that package.
With the advent of content types in EMF 2.4, it will be possible to
register in a more flexible way. For example, in the xmi plugin we
register any resource ending with *.ecore or *.xmi that contains a root
element form the Ecore namespace to be considered to be of type
"org.eclipse.emf.ecore"

<extension
point="org.eclipse.core.runtime.contentTypes">
<content-type
base-type="org.eclipse.core.runtime.xml"
file-extensions="ecore,xmi"
id="org.eclipse.emf.ecore"
name="%_UI_Ecore_content_type"
priority="normal">
<describer

class=" org.eclipse.emf.ecore.xmi.impl.RootXMLContentHandlerImpl$Des criber ">
<parameter
name="namespace"
value="http://www.eclipse.org/emf/2002/Ecore">
</parameter>
<parameter
name="kind"
value="xmi">
</parameter>
</describer>
</content-type>
</extension>

And we register the EcoreResourceFactoryImpl against that content type
identifier.

<extension
point="org.eclipse.emf.ecore.content_parser">
<parser

class="org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl "
contentTypeIdentifier="org.eclipse.emf.ecore">
</parser>
</extension>

So with EMF 2.4, you can use the above mechanism to register a factory
based the contents within the *.xml resource...


Will Horn wrote:
> I should add that the resources are XML files and all have the same
> ".xml" extension.
>
> Will Horn wrote:
>> I have multiple models being managed in the same ResourceSet. When a
>> resource is going to be created, I know from the URI which model I am
>> dealing with, but currently only by an EPackage reference.
>>
>> Is there a way to get the generated Resource.Factory from the
>> EPackage? Or do I need to map the URI to the Resource.Factory
>> separately.
>>
>> Thanks,
>> Will


--------------060908000706030105040802
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">
Will,<br>
<br>
It's quite possible for a given package's instance to be serialized in
multiple different ways.&nbsp; For example, an Ecore EPackage can be
serialized as a *.ecore the normal way, or using EMOF syntax in a
*.emof file that uses EMOFResourceFactoryImpl.&nbsp; So generally there is
no way to map from a package to a resource factory to be used for that
package.&nbsp; With the advent of content types in EMF 2.4, it will be
possible to register in a more flexible way.&nbsp; For example, in the xmi
plugin we register any resource ending with *.ecore or *.xmi that
contains a root element form the Ecore namespace to be considered to be
of type "<small>org.eclipse.emf.ecore"</small>
<blockquote><small>&nbsp; &lt;extension</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; point="org.eclipse.core.runtime.contentTypes"&gt;</small ><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp; &lt;content-type</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; base-type="org.eclipse.core.runtime.xml"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; file-extensions="ecore,xmi"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; id="org.eclipse.emf.ecore"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; name="%_UI_Ecore_content_type"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; priority="normal"&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;describer</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
class=" org.eclipse.emf.ecore.xmi.impl.RootXMLContentHandlerImpl$Des criber "&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;parameter</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; name="namespace"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
value=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a>&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/parameter&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;parameter</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; name="kind"</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; value="xmi"&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt;/parameter&gt;</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/describer&gt;</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp; &lt;/content-type&gt;</small><br>
<small>&nbsp; &lt;/extension&gt;</small><br>
</blockquote>
And we register the EcoreResourceFactoryImpl against that content type
identifier.<br>
<blockquote><small>&nbsp; &lt;extension<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; point="org.eclipse.emf.ecore.content_parser"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;parser<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
class="org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; contentTypeIdentifier="org.eclipse.emf.ecore"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/parser&gt;<br>
&nbsp; &lt;/extension&gt;</small><br>
</blockquote>
So with EMF 2.4, you can use the above mechanism to register a factory
based the contents within the *.xml resource...<br>
<br>
<br>
Will Horn wrote:
<blockquote cite="mid:fpv6o2$itt$2@build.eclipse.org" type="cite">I
should add that the resources are XML files and all have the same
".xml" extension.
<br>
<br>
Will Horn wrote:
<br>
<blockquote type="cite">I have multiple models being managed in the
same ResourceSet.&nbsp; When a resource is going to be created, I know from
the URI which model I am dealing with, but currently only by an
EPackage reference.
<br>
<br>
Is there a way to get the generated Resource.Factory from the EPackage?
Or do I need to map the URI to the Resource.Factory separately.
<br>
<br>
Thanks,
<br>
Will
<br>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------060908000706030105040802--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Getting the Resource.Factory from the EPackage [message #417076 is a reply to message #417073] Mon, 25 February 2008 21:26 Go to previous message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
Thanks Ed, that looks exactly like what I'm looking for.

Ed Merks wrote:
> Will,
>
> It's quite possible for a given package's instance to be serialized in
> multiple different ways. For example, an Ecore EPackage can be
> serialized as a *.ecore the normal way, or using EMOF syntax in a *.emof
> file that uses EMOFResourceFactoryImpl. So generally there is no way to
> map from a package to a resource factory to be used for that package.
> With the advent of content types in EMF 2.4, it will be possible to
> register in a more flexible way. For example, in the xmi plugin we
> register any resource ending with *.ecore or *.xmi that contains a root
> element form the Ecore namespace to be considered to be of type
> "org.eclipse.emf.ecore"
>
> <extension
> point="org.eclipse.core.runtime.contentTypes">
> <content-type
> base-type="org.eclipse.core.runtime.xml"
> file-extensions="ecore,xmi"
> id="org.eclipse.emf.ecore"
> name="%_UI_Ecore_content_type"
> priority="normal">
> <describer
>
> class=" org.eclipse.emf.ecore.xmi.impl.RootXMLContentHandlerImpl$Des criber ">
> <parameter
> name="namespace"
> value="http://www.eclipse.org/emf/2002/Ecore">
> </parameter>
> <parameter
> name="kind"
> value="xmi">
> </parameter>
> </describer>
> </content-type>
> </extension>
>
> And we register the EcoreResourceFactoryImpl against that content type
> identifier.
>
> <extension
> point="org.eclipse.emf.ecore.content_parser">
> <parser
>
> class="org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl "
> contentTypeIdentifier="org.eclipse.emf.ecore">
> </parser>
> </extension>
>
> So with EMF 2.4, you can use the above mechanism to register a factory
> based the contents within the *.xml resource...
>
>
> Will Horn wrote:
>> I should add that the resources are XML files and all have the same
>> ".xml" extension.
>>
>> Will Horn wrote:
>>> I have multiple models being managed in the same ResourceSet. When a
>>> resource is going to be created, I know from the URI which model I am
>>> dealing with, but currently only by an EPackage reference.
>>>
>>> Is there a way to get the generated Resource.Factory from the
>>> EPackage? Or do I need to map the URI to the Resource.Factory
>>> separately.
>>>
>>> Thanks,
>>> Will
>
Previous Topic:Proper way to reflectively add/remove value from multi-valued feature?
Next Topic:Is there any way to do custom proxy resolution?
Goto Forum:
  


Current Time: Sat Apr 20 03:02:49 GMT 2024

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

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

Back to the top