Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Re: Reading multiple XML models of different XSD's
Re: Reading multiple XML models of different XSD's [message #641021] Tue, 23 November 2010 22:12 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Helge,

Comments below.

Helge wrote:
> Hi all,
>
> I am not sure if this is the right forum since my question is related
> to XSD, EMF, or MWE2. If it is not the right forum I apologize.
It's better to use a more specific one.
>
> My problem is: I have multiple XSD metamodels. For reading the XML
> model instances faster than with the XSDAdapter, I created an EMF
> plug-in for each of the metamodels (as described for example here:
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.emf/org .eclipse.emf/doc/org.eclipse.emf.doc/tutorials/xlibmod/xlibm od.html?root=Modeling_Project&view=co).
> Each plug-in contains a model reader which looks like this:
>
> public class _XSDNAME_Reader extends Reader {
> public _XSDNAME_Reader(){
> super();
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xml",
> new _XSDNAME_ResourceFactoryImpl());
>
> EPackage.Registry.INSTANCE.put("http://dk.itu.sdg._XSDNAME_/_XSDNAME_model",
> _XSDNAME_PackageImpl.init());
Try use use XyzPackage.eNS_URI and XyzPackage.eINSTANCE.
> }
> }
>
> where "_XSDNAME_" is the name of the corresponding XSD metamodel. Now,
> when using this readers in an MWE2 workflow everything works smoothly
> as long as only models of one metamodel are read. That is, the
> folowing workflow reads two entitymodels correctly:
>
> module workflow.Works
> Workflow {
>
> component = EntitymodelReader {
> modelSlot = "m1"
> uri = "... /entitymodel.xml"
> }
>
> component = EntitymodelReader {
> modelSlot = "m2"
> uri = "... /entitymodel2.xml"
> }
> }
>
> Whereas a workflow that tries to read models that are instances of
> more than one metamodel as shown here:
>
> module workflow.DoesNotWork
> Workflow {
>
> component = EntitymodelReader {
> modelSlot = "m1"
> uri = "... /entitymodel.xml"
> }
>
> component = EntityEcaReader {
> modelSlot = "m2"
> uri = "... /eecas.xml"
> }
> }
>
> results in an exception of the form:
>
> ..
> 327 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems
> running workflow workflow.A: Couldn't load resource under
> .../entitymodel.xml :
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'entitymodel' not found. (file://.../entitymodel.xml, 22, 82)
> java.lang.RuntimeException: Problems running workflow workflow.A:
> Couldn't load resource under
> /Users/ropf/Documents/eclipse/helios/runtime-modeling/ofbiz_ 9_4/applications/accounting/entitydef/entitymodel.xml
> : org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'entitymodel' not found. (file://.../entitymodel.xml, 22, 82)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:82)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:52)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Lau ncher.java:74)
>
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2La uncher.java:35)
>
> Caused by: org.eclipse.emf.mwe.core.WorkflowInterruptedException:
> Couldn't load resource under .../entitymodel.xml :
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'entitymodel' not found. (file://.../entitymodel.xml, 22, 82)
> at org.eclipse.emf.mwe.utils.Reader.load(Reader.java:75)
> at org.eclipse.emf.mwe.utils.Reader.invokeInternal(Reader.java: 40)
> at
> org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:126)
>
> at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.ja va:34)
> at
> org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invok e(AbstractWorkflowComponent.java:201)
>
> at
> org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkf lowComponent.invoke(AbstractCompositeWorkflowComponent.java: 31)
>
> at
> org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow. java:19)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:80)
> ... 3 more
>
> What is the reason for this? As mentioned, when reading multiple
> models that are instances of the same metamodel, everything works
> fine, I can even write them out to xmi files using the standard
> writer. That is, I assume that all features 'exist'. Is it the
> problem, that I register multiple resource factories to the same file
> extension in the readers? Or is there another reason? How to solve the
> problem?
This really is an mwe2 question. I think that's usually discussed in
the tmf newsgroup, so I've added that to the "to" list of the reply.
>
>
> Best regards,
> Helge
>
>
> PS: I abbreviated all pathes and file URIs with '...'
>
>
Re: Reading multiple XML models of different XSD's [message #641110 is a reply to message #641021] Wed, 24 November 2010 10:02 Go to previous messageGo to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi all,

Thank you Ed for pointing me to the right forum.

I changed the EPackage registration to EPackage.Registry.INSTANCE.put(_XSDNAME_Package.eNS_URI, _XSDNAME_Package.eINSTANCE) in the different readers. Unfortunatelly this does not seem to be the reason for my problem. I still get the same behavior and exception thrown of my workflow.

Best,
Helge
Re: Reading multiple XML models of different XSD's [message #641168 is a reply to message #641021] Wed, 24 November 2010 13:12 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
Am 11/23/10 11:12 PM, schrieb Ed Merks:

>> 327 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems
>> running workflow workflow.A: Couldn't load resource under
>> .../entitymodel.xml :
>> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>> 'entitymodel' not found. (file://.../entitymodel.xml, 22, 82)
>> java.lang.RuntimeException: Problems running workflow workflow.A:
>> Couldn't load resource under
>> /Users/ropf/Documents/eclipse/helios/runtime-modeling/ofbiz_ 9_4/applications/accounting/entitydef/entitymodel.xml
>> : org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
>> 'entitymodel' not found. (file://.../entitymodel.xml, 22, 82)
>> at
>> org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:82)
>> at
>> org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runne r.java:52)
>> at
>> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Lau ncher.java:74)
>>
>> at
>> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2La uncher.java:35)
>>

Looks like the EPackage used in the xml is not resolvable.
How does that xml model point to its EcorePackages (what kind of URI)?

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Reading multiple XML models of different XSD's [message #641227 is a reply to message #641168] Wed, 24 November 2010 15:29 Go to previous messageGo to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi,

The XML models point to their metamodels using an http URI. See the following headers.
<entity-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http:// ... /dtds/entity-eca.xsd">

<entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http:// ... /dtds/entitymodel.xsd">

Whereas the ecore metamodels that are generated out of the XSD metamodels point to the file using a file URI. Like this:
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="EntityEca"
    nsURI="file:/ ... /framework/entity/dtd/entity-eca.xsd"
    nsPrefix="EntityEca">

That is, in the package Code the nsURI line looks like this:
String eNS_URI = "file:/ ... /framework/entity/dtd/entity-eca.xsd";


Thus, I see that the ecore and XML models use different URIs and it is true the exception always points to the header in the XML files. But I do not know what to do now. I cannot change the metamodel URIs in the XML models, since they need to be unmodified. But the file URI gets generated automatically to the ecore packages by the emf wizard. I now tried to change the URI in the ecore package from the file to http URI manually and regenerated the code. But I still get the same exception...

Best,
Helge
Re: Reading multiple XML models of different XSD's [message #641283 is a reply to message #641227] Wed, 24 November 2010 18:04 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1771
Registered: July 2009
Senior Member
You need to make sure that the EPackages are registered in the
EPackage.Registry.

The StandalonSetup class is a ustility which helps you doing this from
within MWE2.
Workflow {
bean = org.eclipse.emf.mwe.utils.StandaloneSetup {
registerGeneratedEPackage = "my.generated.EPackageInterface"
}

...
}

Am 11/24/10 4:29 PM, schrieb Helge:
> Hi,
>
> The XML models point to their metamodels using an http URI. See the
> following headers.
>
> <entity-eca xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http:// ... /dtds/entity-eca.xsd">
>
> <entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http:// ... /dtds/entitymodel.xsd">
> Whereas the ecore metamodels that are generated out of the XSD
> metamodels point to the file using a file URI. Like this:
>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="EntityEca"
> nsURI="file:/ ... /framework/entity/dtd/entity-eca.xsd"
> nsPrefix="EntityEca">
> That is, in the package Code the nsURI line looks like this:
>
> String eNS_URI = "file:/ ... /framework/entity/dtd/entity-eca.xsd";
>
>
> Thus, I see that the ecore and XML models use different URIs and it is
> true the exception always points to the header in the XML files. But I
> do not know what to do now. I cannot change the metamodel URIs in the
> XML models, since they need to be unmodified. But the file URI gets
> generated automatically to the ecore packages by the emf wizard. I now
> tried to change the URI in the ecore package from the file to http URI
> manually and regenerated the code. But I still get the same exception...
>
> Best,
> Helge


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Reading multiple XML models of different XSD's [message #641306 is a reply to message #641283] Wed, 24 November 2010 20:22 Go to previous messageGo to next message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi Sven,

I am quite sure that I registered the EPackages. The readers contain a line like:
	EPackage.Registry.INSTANCE.put(EntityEcaPackage.eNS_URI, EntityEcaPackage.eINSTANCE);

And a similar line for the entitymodel package. However, I modified the workflow to register the packages in the standalonesetup. This still gives the same error message.
What makes me quite sure that the epackages are registered correctly, is that when runnning a workflow like this:
var out = "src-gen/output/eecas.xmi"
Workflow {	
	component = EntityEcaReader {
		modelSlot = "m2"
		uri = "... /entitydef/eecas.xml"
	}
	
	component = Writer {
		modelSlot = "m2"
		uri = out
	}	
}

The model is serialized without any erros and the XMI models header contains the correct URIs for the metamodel.
<?xml version="1.0" encoding="ASCII"?>
<EntityEca:DocumentRoot xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:EntityEca="http:// ... /dtds/entity-eca.xsd" xsi:schemaLocation="http:// ... /dtds/entity-eca.xsd java:// ... EntityEcaPackage">

And a similar line when reading and serializing an entitymodel.
Thus, I assume that there must be another reason for this behavior that only occurs when reading both models in the same workflow.

Best,
Helge
Re: Reading multiple XML models of different XSD's [message #641652 is a reply to message #641283] Fri, 26 November 2010 14:22 Go to previous message
Helge Mising name is currently offline Helge Mising nameFriend
Messages: 17
Registered: October 2010
Junior Member
Hi,

Sorry for bringing this up again. But I am still stuck with this problem and would really appreciate any hint that can point me into the right direction to find a solution.

I wrote a workflow component that dumps all EPackages that are registered in the workflow. That is, it writes out all entries of (EPackage.Registry.INSTANCE.entrySet()) and both EPackages are registered under the URI of the corresponding XSD metamodel. The following very basic workflow:
Workflow {
	bean = StandaloneSetup {
		registerGeneratedEPackage = "dk.itu.sdg.entityEca.EntityEca.EntityEcaPackage"
		registerGeneratedEPackage = "dk.itu.sdg.entitymodel.Entitymodel.EntitymodelPackage"
	}
	
	bean = org.eclipse.xtend.typesystem.emf.EmfMetaModel {
		metaModelPackage = "dk.itu.sdg.entitymodel.Entitymodel.EntitymodelPackage"
	}
	
	bean = org.eclipse.xtend.typesystem.emf.EmfMetaModel {
		metaModelPackage = "dk.itu.sdg.entityEca.EntityEca.EntityEcaPackage"
	}

	component = dk.itu.sdg.entitymodel.Entitymodel.util.RegistryChecker {
		printRegistryContents = true
	}

	component = dk.itu.sdg.entitymodel.Entitymodel.util.EntitymodelReader {
		modelSlot = "m1"
		uri = "/Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml"		
	}
	
	component = dk.itu.sdg.entityEca.EntityEca.util.EntityEcaReader {
		modelSlot = "m2"
		uri = "/Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/eecas.xml"
	}
}

generates this output:
0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'dk.itu.sdg.entityEca.EntityEca.EntityEcaPackage'
106  [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Adding generated EPackage 'dk.itu.sdg.entitymodel.Entitymodel.EntitymodelPackage'
121  [main] DEBUG .Entitymodel.util.EntitymodelReader  - Whoopti... reading dk.itu.sdg.entitymodel.Entitymodel.util.EntitymodelReader
140  [main] DEBUG yEca.EntityEca.util.EntityEcaReader  - Whoopti... reading dk.itu.sdg.entityEca.EntityEca.util.EntityEcaReader

http://dtds/entitymodel.xsd dk.itu.sdg.entitymodel.Entitymodel.impl.EntitymodelPackageImpl
http://www.eclipse.org/emf/2003/XMLType org.eclipse.emf.ecore.xml.type.impl.XMLTypePackageImpl
http://www.eclipse.org/2008/xtext/parsetree org.eclipse.xtext.parsetree.impl.ParsetreePackageImpl
http://www.eclipse.org/emf/2002/Ecore org.eclipse.emf.ecore.impl.EcorePackageImpl
http://www.eclipse.org/xtext/common/mwe2/Mwe2 org.eclipse.emf.mwe2.language.mwe2.impl.Mwe2PackageImpl
http://www.eclipse.org/2008/Xtext org.eclipse.xtext.impl.XtextPackageImpl
http://www.eclipse.org/xtext/common/JavaVMTypes org.eclipse.xtext.common.types.impl.TypesPackageImpl
http://dtds/entity-eca.xsd dk.itu.sdg.entityEca.EntityEca.impl.EntityEcaPackageImpl


330  [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems running workflow workflow.A: Couldn't load resource under /Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml : org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'entitymodel' not found. (file:///Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml, 22, 82)
java.lang.RuntimeException: Problems running workflow workflow.A: Couldn't load resource under /Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml : org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'entitymodel' not found. (file:///Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml, 22, 82)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:82)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: org.eclipse.emf.mwe.core.WorkflowInterruptedException: Couldn't load resource under /Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml : org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'entitymodel' not found. (file:///Documents/eclipse/helios/runtime-modeling/applications/accounting/entitydef/entitymodel.xml, 22, 82)
	at org.eclipse.emf.mwe.utils.Reader.load(Reader.java:75)
	at org.eclipse.emf.mwe.utils.Reader.invokeInternal(Reader.java:40)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
	at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
	at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
	at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:31)
	at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:80)
	... 3 more

That is the EPackages are registered. Do I oversee something very basic, that I have to do, to make this example run?

I have the impression that the problem is not, that the EPackages are not registered, but that there is an issue with the model element names, since they first get capitalized and second they are renamed to "_modelElementName_Type" ("Type" is attached). In the XML files that are read the model element names and package element names are still
But this does not really explain why I can read and seralize XML models of one metamodel but not of multiple metamodels.

a) Is there anyone who reads XML models not with the XSDAdapter but with, e.g., org.eclipse.emf.mwe.utils.Reader?
b) If so, how do you do this?
c) What did you do for populating your EMF Project?
I just followed the wizard. That is, created an EMF project from an XML schema. Then, I changed the URI in the EPackage from the file URI pointing to the XSD model to the same http URI that is used in the XML modles to refer to their metamodels. Subsequently I generated the model code.
d) Did you generate an xsd2ecore mapping model? Is this necessary? If so, how did you make your workflow aware of the mapping model?


Best,
Helge
Previous Topic:[SOLVED] Names unique across files of the same folder
Next Topic:Using \uXXXX in terminals?
Goto Forum:
  


Current Time: Fri Dec 19 00:48:46 GMT 2014

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

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