Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] load an XML stream, how to resolve the factory
[EMF] load an XML stream, how to resolve the factory [message #1441277] Thu, 09 October 2014 13:45 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

I am adding a RESTfull interface to NetXStudio to consume data from
remote ends. I Use the Jersey package to fire the requests. Jersey has
some API to process the result. I get the result in either XML or JSON
in an InputStream.

I am looking for options to load the XML varial in an EMF Resource.

Some ideas:

1 Use Dymanic EMF.

2 Having an EPackage/EFactory for the XML returned and load it in an EMF
Resource.

For the latter, I am a bit puzzle how to let the ResourceSetImpl resolve
the model factory, as there is no URI as such to load from. (What I have
is an inputstream). I haven't played with this extension yet
org.eclipse.emf.ecore.content_parser, but this could work out, still I
don't have a URI for the stream. (Unless I write the content to file,
set the extension and refer it, but that seems the long way home).

Any thoughs/ideas to bind the model factory to a bear InputStream?

Thanks Christophe
Re: [EMF] load an XML stream, how to resolve the factory [message #1441292 is a reply to message #1441277] Thu, 09 October 2014 14:16 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Hi Christophe,

On 09/10/2014 15:45, Christophe Bouhier wrote:
> Hi,
>
> I am adding a RESTfull interface to NetXStudio to consume data from
> remote ends. I Use the Jersey package to fire the requests. Jersey has
> some API to process the result. I get the result in either XML or JSON
> in an InputStream.
>
> I am looking for options to load the XML varial in an EMF Resource.
>
> Some ideas:
>
> 1 Use Dymanic EMF.
>
> 2 Having an EPackage/EFactory for the XML returned and load it in an EMF
> Resource.
>
> For the latter, I am a bit puzzle how to let the ResourceSetImpl resolve
> the model factory, as there is no URI as such to load from. (What I have
> is an inputstream). I haven't played with this extension yet
> org.eclipse.emf.ecore.content_parser, but this could work out, still I
> don't have a URI for the stream. (Unless I write the content to file,
> set the extension and refer it, but that seems the long way home).
>
> Any thoughs/ideas to bind the model factory to a bear InputStream?
>
> Thanks Christophe
I don't know what a varial is. Maybe I don't understand well. Can you
not use Resource.load(InputStream, Map)? The factory is derived from the
package is derived from the ns uri found in your stream so that should
just work no?
Re: [EMF] load an XML stream, how to resolve the factory [message #1441296 is a reply to message #1441277] Thu, 09 October 2014 14:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christophe,

Comments below.

On 09/10/2014 3:45 PM, Christophe Bouhier wrote:
> Hi,
>
> I am adding a RESTfull interface to NetXStudio to consume data from
> remote ends. I Use the Jersey package to fire the requests. Jersey has
> some API to process the result. I get the result in either XML or JSON
> in an InputStream.
>
> I am looking for options to load the XML varial in an EMF Resource.
>
> Some ideas:
>
> 1 Use Dymanic EMF.
EMF can read XML without a model using a resource as created by
org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl. Of course
with this approach, it's essentially equivalent to DOM.
>
> 2 Having an EPackage/EFactory for the XML returned and load it in an
> EMF Resource.
Is there an XML Schema for it? Do you want to use a generated model?
What kind of processing will you want to do?
>
> For the latter, I am a bit puzzle how to let the ResourceSetImpl
> resolve the model factory, as there is no URI as such to load from.
You're talking about loading an Ecore model or loading an instance?
> (What I have is an inputstream).
You can load directly from an input stream using
org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
> I haven't played with this extension yet
> org.eclipse.emf.ecore.content_parser, but this could work out, still I
> don't have a URI for the stream. (Unless I write the content to file,
> set the extension and refer it, but that seems the long way home).
It's always possible to directly create a resource and then load it from
a stream...
>
> Any thoughs/ideas to bind the model factory to a bear InputStream?
I don't think there is enough context to really answer this properly...
>
> Thanks Christophe


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] load an XML stream, how to resolve the factory [message #1441301 is a reply to message #1441296] Thu, 09 October 2014 14:32 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 09-10-14 16:21, Ed Merks wrote:
> Christophe,
>
> Comments below.
>
> On 09/10/2014 3:45 PM, Christophe Bouhier wrote:
>> Hi,
>>
>> I am adding a RESTfull interface to NetXStudio to consume data from
>> remote ends. I Use the Jersey package to fire the requests. Jersey has
>> some API to process the result. I get the result in either XML or JSON
>> in an InputStream.
>>
>> I am looking for options to load the XML varial in an EMF Resource.
>>
>> Some ideas:
>>
>> 1 Use Dymanic EMF.
> EMF can read XML without a model using a resource as created by
> org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl. Of course
> with this approach, it's essentially equivalent to DOM.
>>
>> 2 Having an EPackage/EFactory for the XML returned and load it in an
>> EMF Resource.
> Is there an XML Schema for it? Do you want to use a generated model?
> What kind of processing will you want to do?
Yes I have the schema, and I have generated the model code, so I have
the model package and the model factory.
>>
>> For the latter, I am a bit puzzle how to let the ResourceSetImpl
>> resolve the model factory, as there is no URI as such to load from.
> You're talking about loading an Ecore model or loading an instance?
Loading the instance.
>> (What I have is an inputstream).
> You can load directly from an input stream using
> org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
Yes, but how will it find the model factory?

>> I haven't played with this extension yet
>> org.eclipse.emf.ecore.content_parser, but this could work out, still I
>> don't have a URI for the stream. (Unless I write the content to file,
>> set the extension and refer it, but that seems the long way home).
> It's always possible to directly create a resource and then load it from
> a stream...

>>
>> Any thoughs/ideas to bind the model factory to a bear InputStream?
> I don't think there is enough context to really answer this properly...
>>
>> Thanks Christophe
>
Re: [EMF] load an XML stream, how to resolve the factory [message #1441318 is a reply to message #1441301] Thu, 09 October 2014 14:58 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 09/10/2014 16:32, Christophe Bouhier wrote:

>>> (What I have is an inputstream).
>> You can load directly from an input stream using
>> org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
> Yes, but how will it find the model factory?

The same way it finds it when loading from an xml file. The actual data
source doesn't matter for epackage resolution.
Re: [EMF] load an XML stream, how to resolve the factory [message #1441356 is a reply to message #1441318] Thu, 09 October 2014 16:02 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 09-10-14 16:58, Felix Dorner wrote:
> On 09/10/2014 16:32, Christophe Bouhier wrote:
>
>>>> (What I have is an inputstream).
>>> You can load directly from an input stream using
>>> org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
>> Yes, but how will it find the model factory?
>
> The same way it finds it when loading from an xml file. The actual data
> source doesn't matter for epackage resolution.
>
Yes, in this case the package (nsURI) is not in the returned XML. I get
a PackageNotFoundException.
, so I either need to inject it or what I was hoping for, to force the
Resource or the ResourceSet to use a certain epackage.

something like load(InputStream,EPackage,MAP<?,?> would be nice.

so this use case is about:

Creating a model instance for a given XML input (As InputStream) which
doesn't contain schema information (xmlns), but as the caller I know the
EPackage which could handle this XML. How to do this with EMF?


>
Re: [EMF] load an XML stream, how to resolve the factory [message #1441377 is a reply to message #1441356] Thu, 09 October 2014 16:42 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 09/10/2014 18:02, Christophe Bouhier wrote:
> On 09-10-14 16:58, Felix Dorner wrote:
>> On 09/10/2014 16:32, Christophe Bouhier wrote:
>>
>>>>> (What I have is an inputstream).
>>>> You can load directly from an input stream using
>>>> org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
>>> Yes, but how will it find the model factory?
>>
>> The same way it finds it when loading from an xml file. The actual data
>> source doesn't matter for epackage resolution.
>>
> Yes, in this case the package (nsURI) is not in the returned XML. I get
> a PackageNotFoundException.

Oh.

> , so I either need to inject it or what I was hoping for, to force the
> Resource or the ResourceSet to use a certain epackage.

Maybe if you load using a suitable ExtendedMetadata instance? Or look
XMLHelper.setNoNamespacePackage()? Maybe these two are even related
somehow, I'd check who calls setNoNamespacePackage in EMF runtime and
see if you can exploit that somehow.

Felix
Re: [EMF] load an XML stream, how to resolve the factory [message #1441826 is a reply to message #1441377] Fri, 10 October 2014 08:37 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 09-10-14 18:42, Felix Dorner wrote:
> On 09/10/2014 18:02, Christophe Bouhier wrote:
>> On 09-10-14 16:58, Felix Dorner wrote:
>>> On 09/10/2014 16:32, Christophe Bouhier wrote:
>>>
>>>>>> (What I have is an inputstream).
>>>>> You can load directly from an input stream using
>>>>> org.eclipse.emf.ecore.resource.Resource.load(InputStream, Map<?, ?>).
>>>> Yes, but how will it find the model factory?
>>>
>>> The same way it finds it when loading from an xml file. The actual data
>>> source doesn't matter for epackage resolution.
>>>
>> Yes, in this case the package (nsURI) is not in the returned XML. I get
>> a PackageNotFoundException.
>
> Oh.
>
>> , so I either need to inject it or what I was hoping for, to force the
>> Resource or the ResourceSet to use a certain epackage.
>
> Maybe if you load using a suitable ExtendedMetadata instance? Or look
> XMLHelper.setNoNamespacePackage()? Maybe these two are even related
> somehow, I'd check who calls setNoNamespacePackage in EMF runtime and
> see if you can exploit that somehow.
That's interresting. Looking at the code, I am not seeing, the XMLHelper
be set, so it seems, I need to extend XMLResource.

Something like this co do it perhaps?

final EPackage pkg = ...
XMLResource res = new XMLResourceImpl(){
@Override
protected XMLHelper createXMLHelper() {
XMLHelper helper = createXMLHelper();
helper.setNoNamespacePackage(pkg);
return helper;
}
};

>
> Felix
>
Re: [EMF] load an XML stream, how to resolve the factory [message #1441848 is a reply to message #1441826] Fri, 10 October 2014 09:09 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 10/10/2014 10:37, Christophe Bouhier wrote:

> Something like this co do it perhaps?
>
> final EPackage pkg = ...
> XMLResource res = new XMLResourceImpl(){
> @Override
> protected XMLHelper createXMLHelper() {
> XMLHelper helper = createXMLHelper();
> helper.setNoNamespacePackage(pkg);
> return helper;
> }
> };
>

Maybe. But the EMFish way would probably be something among:

ExtendedMetadata myMetadata = new BasicExtendedMetadata();
myMetadata.setPackage(null, myEPackage);

XMLResource.load(myStream,
Collections.singletonMap(XMLResource.OPTION_EXTENDED_METADATA, myMetadata);
Re: [EMF] load an XML stream, how to resolve the factory [message #1441933 is a reply to message #1441848] Fri, 10 October 2014 11:40 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 10-10-14 11:09, Felix Dorner wrote:
> myMetadata.setPackage(null, myEPackage);

that's not supported. There is an EPackageExtendedMetaData
implementation, but that one is used internally it seems. (As there is
an option to bind a namespace to an EPackage, but in my case there is no
namespace in the XML.
Re: [EMF] load an XML stream, how to resolve the factory [message #1441943 is a reply to message #1441933] Fri, 10 October 2014 11:52 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 10-10-14 13:40, Christophe Bouhier wrote:
> On 10-10-14 11:09, Felix Dorner wrote:
>> myMetadata.setPackage(null, myEPackage);
>
> that's not supported. There is an EPackageExtendedMetaData
> implementation, but that one is used internally it seems. (As there is
> an option to bind a namespace to an EPackage, but in my case there is no
> namespace in the XML.
>
>
How about this:

String OPTION_MISSING_PACKAGE_HANDLER = "MISSING_PACKAGE_HANDLER";
Re: [EMF] load an XML stream, how to resolve the factory [message #1441953 is a reply to message #1441943] Fri, 10 October 2014 12:02 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 10-10-14 13:52, Christophe Bouhier wrote:
> On 10-10-14 13:40, Christophe Bouhier wrote:
>> On 10-10-14 11:09, Felix Dorner wrote:
>>> myMetadata.setPackage(null, myEPackage);
>>
>> that's not supported. There is an EPackageExtendedMetaData
>> implementation, but that one is used internally it seems. (As there is
>> an option to bind a namespace to an EPackage, but in my case there is no
>> namespace in the XML.
>>
>>
> How about this:
>
> String OPTION_MISSING_PACKAGE_HANDLER = "MISSING_PACKAGE_HANDLER";
>

Ah finally this worked:

BasicExtendedMetaData basicExtendedMetaData = new BasicExtendedMetaData() {

@Override
public EPackage getPackage(String namespace) {
return package;
// TODO Auto-generated method stub
// return super.getPackage(namespace);
}

};

So, it is possible to receive XML which has no package reference, and
load it in a Resource with proper EPackage resolution. cool stuff.

The thing is that, the RESTFull service is described with a so called
..wadl schema, which connects the URI's with HTTP method and associated
..xsd. So to bind the RESTfull URI's to an EMF Entity model, would be to
bind the EMFPackage to a .wandl file. This requires additional
descriptor, but would work in dynamicly resolving EPackages when firing
RESTFull requests, which was my purpose.

Thanks all for your help.
Re: [EMF] load an XML stream, how to resolve the factory [message #1441954 is a reply to message #1441943] Fri, 10 October 2014 12:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christophe,

Given you have a schema and have generated the model, isn't there an
XyzResourceFactoryImpl? You should be using the resource created by
that factory; note now hit configures the right options for handling the
no-namespace package...

On 10/10/2014 1:52 PM, Christophe Bouhier wrote:
> On 10-10-14 13:40, Christophe Bouhier wrote:
>> On 10-10-14 11:09, Felix Dorner wrote:
>>> myMetadata.setPackage(null, myEPackage);
>>
>> that's not supported. There is an EPackageExtendedMetaData
>> implementation, but that one is used internally it seems. (As there is
>> an option to bind a namespace to an EPackage, but in my case there is no
>> namespace in the XML.
>>
>>
> How about this:
>
> String OPTION_MISSING_PACKAGE_HANDLER = "MISSING_PACKAGE_HANDLER";
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] load an XML stream, how to resolve the factory [message #1441957 is a reply to message #1441954] Fri, 10 October 2014 12:08 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 10-10-14 14:02, Ed Merks wrote:
> Christophe,
>
> Given you have a schema and have generated the model, isn't there an
> XyzResourceFactoryImpl?
YEs there is!
You should be using the resource created by
> that factory;
uh, but I receive the XML data as an InputStream. I don't have a URI to
feed:
@Override
public Resource createResource(URI uri) {

Perhaps that's not relevant when calling load(InputStream..)
But more importantly, I want some dynamic resolution of the EPackage,
and the EPackage Global Registry is the central place for this.

note now hit configures the right options for handling the
> no-namespace package...
hit??

>
> On 10/10/2014 1:52 PM, Christophe Bouhier wrote:
>> On 10-10-14 13:40, Christophe Bouhier wrote:
>>> On 10-10-14 11:09, Felix Dorner wrote:
>>>> myMetadata.setPackage(null, myEPackage);
>>>
>>> that's not supported. There is an EPackageExtendedMetaData
>>> implementation, but that one is used internally it seems. (As there is
>>> an option to bind a namespace to an EPackage, but in my case there is no
>>> namespace in the XML.
>>>
>>>
>> How about this:
>>
>> String OPTION_MISSING_PACKAGE_HANDLER = "MISSING_PACKAGE_HANDLER";
>>
>
Re: [EMF] load an XML stream, how to resolve the factory [message #1441966 is a reply to message #1441957] Fri, 10 October 2014 12:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christophe,

Comments below.

On 10/10/2014 2:08 PM, Christophe Bouhier wrote:
> On 10-10-14 14:02, Ed Merks wrote:
>> Christophe,
>>
>> Given you have a schema and have generated the model, isn't there an
>> XyzResourceFactoryImpl?
> YEs there is!
> You should be using the resource created by
>> that factory;
> uh, but I receive the XML data as an InputStream.
No, the resource itself receives that.
> I don't have a URI to feed:
> @Override
> public Resource createResource(URI uri) {
It's not the only way to create a resource. And besides, you can use
any dummy URI you want, so long as it creates the right type of resource
using the right factory. Then you can all load on that resource.
>
> Perhaps that's not relevant when calling load(InputStream..)
> But more importantly, I want some dynamic resolution of the EPackage,
> and the EPackage Global Registry is the central place for this.
That should all kick in as normal, but note there can only be one
package per namespace and the no-namespace is treated special because
many people might generate models for no-namespace schemas. But I don't
know what you mean by "dynamic"...
>
> note now hit configures the right options for handling the
>> no-namespace package...
> hit??
You've found the code in the generated XyzResourceFactoryImpl?

Note that you can invoke Generate Test Code to see how the
XyzExample.java uses this...
>
>>
>> On 10/10/2014 1:52 PM, Christophe Bouhier wrote:
>>> On 10-10-14 13:40, Christophe Bouhier wrote:
>>>> On 10-10-14 11:09, Felix Dorner wrote:
>>>>> myMetadata.setPackage(null, myEPackage);
>>>>
>>>> that's not supported. There is an EPackageExtendedMetaData
>>>> implementation, but that one is used internally it seems. (As there is
>>>> an option to bind a namespace to an EPackage, but in my case there
>>>> is no
>>>> namespace in the XML.
>>>>
>>>>
>>> How about this:
>>>
>>> String OPTION_MISSING_PACKAGE_HANDLER = "MISSING_PACKAGE_HANDLER";
>>>
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] load an XML stream, how to resolve the factory [message #1441993 is a reply to message #1441953] Fri, 10 October 2014 13:12 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 10/10/2014 14:02, Christophe Bouhier wrote:

> Ah finally this worked:
>
> BasicExtendedMetaData basicExtendedMetaData = new BasicExtendedMetaData() {
>
> @Override
> public EPackage getPackage(String namespace) {
> return package;
> // TODO Auto-generated method stub
> // return super.getPackage(namespace);
> }
>
> };
>

basicExtendedMetadata.setPackage(null, package) doesn't work then?
Re: [EMF] load an XML stream, how to resolve the factory [message #1443742 is a reply to message #1441993] Mon, 13 October 2014 06:43 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 10-10-14 15:12, Felix Dorner wrote:
> On 10/10/2014 14:02, Christophe Bouhier wrote:
>
>> Ah finally this worked:
>>
>> BasicExtendedMetaData basicExtendedMetaData = new
>> BasicExtendedMetaData() {
>>
>> @Override
>> public EPackage getPackage(String namespace) {
>> return package;
>> // TODO Auto-generated method stub
>> // return super.getPackage(namespace);
>> }
>>
>> };
>>
>
> basicExtendedMetadata.setPackage(null, package) doesn't work then?
>
There is no public setPackage(..) method.
Re: [EMF] load an XML stream, how to resolve the factory [message #1443767 is a reply to message #1443742] Mon, 13 October 2014 07:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Christophe,

Note that the template is like this:

<%if (genPackage.hasExtendedMetaData() &&
!genPackage.hasTargetNamespace()) {%>
extendedMetaData = new
<%=genModel.getImportedName("org.eclipse.emf.ecore.util.BasicExtendedMetaData")%>(new
<%=genModel.getImportedName("org.eclipse.emf.ecore.impl.EPackageRegistryImpl")%>(<%=genModel.getImportedName("org.eclipse.emf.ecore.EPackage")%>.Registry.INSTANCE));
extendedMetaData.putPackage(null,
<%=genPackage.getImportedPackageInterfaceName()%>.eINSTANCE);
<%}

I.e., it creates a new BasicExtendedMetaData that uses a new package
registry that delegates to the global package registry and uses the
public API setPackage to register the generated package for the null
namespace in that extended metadata's delegating registry.

I would have thought you had a generated resource factory for this
schema's model and that it would contain this (and that you would just
reuse that)...

On 13/10/2014 8:43 AM, Christophe Bouhier wrote:
> On 10-10-14 15:12, Felix Dorner wrote:
>> On 10/10/2014 14:02, Christophe Bouhier wrote:
>>
>>> Ah finally this worked:
>>>
>>> BasicExtendedMetaData basicExtendedMetaData = new
>>> BasicExtendedMetaData() {
>>>
>>> @Override
>>> public EPackage getPackage(String namespace) {
>>> return package;
>>> // TODO Auto-generated method stub
>>> // return super.getPackage(namespace);
>>> }
>>>
>>> };
>>>
>>
>> basicExtendedMetadata.setPackage(null, package) doesn't work then?
>>
> There is no public setPackage(..) method.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] load an XML stream, how to resolve the factory [message #1443788 is a reply to message #1443742] Mon, 13 October 2014 07:57 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 13/10/2014 08:43, Christophe Bouhier wrote:
> On 10-10-14 15:12, Felix Dorner wrote:
>> On 10/10/2014 14:02, Christophe Bouhier wrote:
>>
>>> Ah finally this worked:
>>>
>>> BasicExtendedMetaData basicExtendedMetaData = new
>>> BasicExtendedMetaData() {
>>>
>>> @Override
>>> public EPackage getPackage(String namespace) {
>>> return package;
>>> // TODO Auto-generated method stub
>>> // return super.getPackage(namespace);
>>> }
>>>
>>> };
>>>
>>
>> basicExtendedMetadata.setPackage(null, package) doesn't work then?
>>
> There is no public setPackage(..) method.

Oops I meant putPackage()
Re: [EMF] load an XML stream, how to resolve the factory [message #1444603 is a reply to message #1443767] Tue, 14 October 2014 09:52 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 13-10-14 09:25, Ed Merks wrote:
> Christophe,
>
> Note that the template is like this:
>
> <%if (genPackage.hasExtendedMetaData() &&
> !genPackage.hasTargetNamespace()) {%>
> extendedMetaData = new
> <%=genModel.getImportedName("org.eclipse.emf.ecore.util.BasicExtendedMetaData")%>(new
> <%=genModel.getImportedName("org.eclipse.emf.ecore.impl.EPackageRegistryImpl")%>(<%=genModel.getImportedName("org.eclipse.emf.ecore.EPackage")%>.Registry.INSTANCE));
>
> extendedMetaData.putPackage(null,
> <%=genPackage.getImportedPackageInterfaceName()%>.eINSTANCE);
> <%}
>
> I.e., it creates a new BasicExtendedMetaData that uses a new package
> registry that delegates to the global package registry and uses the
> public API setPackage to register the generated package for the null
> namespace in that extended metadata's delegating registry.
>
> I would have thought you had a generated resource factory for this
> schema's model and that it would contain this (and that you would just
> reuse that)
wow, after so many years working with EMF, I didn't know this.
Thanks Ed,Felix, very usefull stuff!


**** XXXResourceFactoryImpl constructor:

extendedMetaData = new BasicExtendedMetaData(new
EPackageRegistryImpl(EPackage.Registry.INSTANCE));
extendedMetaData.putPackage(null, TopologyPackage.eINSTANCE);



>
> On 13/10/2014 8:43 AM, Christophe Bouhier wrote:
>> On 10-10-14 15:12, Felix Dorner wrote:
>>> On 10/10/2014 14:02, Christophe Bouhier wrote:
>>>
>>>> Ah finally this worked:
>>>>
>>>> BasicExtendedMetaData basicExtendedMetaData = new
>>>> BasicExtendedMetaData() {
>>>>
>>>> @Override
>>>> public EPackage getPackage(String namespace) {
>>>> return package;
>>>> // TODO Auto-generated method stub
>>>> // return super.getPackage(namespace);
>>>> }
>>>>
>>>> };
>>>>
>>>
>>> basicExtendedMetadata.setPackage(null, package) doesn't work then?
>>>
>> There is no public setPackage(..) method.
>
Re: [EMF] load an XML stream, how to resolve the factory [message #1455942 is a reply to message #1444603] Wed, 29 October 2014 22:51 Go to previous message
Stephane  fournier is currently offline Stephane fournierFriend
Messages: 340
Registered: July 2009
Senior Member
Hi,
I faced the same issue you have and I found a quite good solution.
In my case, I would like to load an XML stream where the xmlns is not there but the content in XML matches my metamodel.

To do so, in my XmlResource I have overridden the createXMLLoad method to provide my XMLLoad implementation.

In your own XMLLoad Implementation, you have to override the makeDefaultHandler to provide your own SAXXMLHandler.
In your handler implementation you have to:
- override the handleTopLocations(String prefix, String name) method to store the name which is the name of the tag of the xml root element.
- override the handleMissingPackage method to do what you want from the name you stored in handleTopLocations. In my case based on the name, I retrieve the right EPackage because the uriString is missing due to the fact no xmlns is provided.

That's it,
Stéphane.
Previous Topic:Issue to load XML file provide with Edapt example project
Next Topic:[CDO] uri of repository resource
Goto Forum:
  


Current Time: Fri Apr 19 07:40:06 GMT 2024

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

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

Back to the top