Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [XSD2ECore] EDataType / AnySimpleType Problem
[XSD2ECore] EDataType / AnySimpleType Problem [message #986360] Tue, 20 November 2012 08:51 Go to next message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member
Hey,

I am currently saving my ECore Files as XSD into my database, but while converting the xsd back to ECore all my EDataTypes are AnySimpleType and I don't know why.
The XSD should be okay:

  <xsd:complexType ecore:name="xxx" name="xxx">
    <xsd:sequence>
      <xsd:element ecore:name="Association" ecore:resolveProxies="true" name="Association" type="xxx:yyy"/>
    </xsd:sequence>
    <xsd:attribute ecore:name="Attribute1" name="Attribute1" type="ecore:EString"/>
    <xsd:attribute ecore:id="true" name="id" type="ecore:EString"/>
    <xsd:attribute name="createdOn" type="ecore:EDate"/>
    <xsd:attribute name="updatedOn" type="ecore:EDate"/>
    <xsd:attribute name="displayName" type="ecore:EString"/>
  </xsd:complexType>
  <xsd:complexType ecore:name="yyy" name="yyy">
    <xsd:attribute ecore:name="Attribute2" name="Attribute2" type="ecore:EString"/>
    <xsd:attribute ecore:id="true" name="id" type="ecore:EString"/>
    <xsd:attribute name="createdOn" type="ecore:EDate"/>
    <xsd:attribute name="updatedOn" type="ecore:EDate"/>
    <xsd:attribute name="displayName" type="ecore:EString"/>
  </xsd:complexType>


Since I have to create my ECore files by hand, I am creating the EAttributes by myself:
EAttribute eAttributeCreatedOn = theCoreFactory.createEAttribute();
         eAttributeCreatedOn.setName("createdOn");
         eAttributeCreatedOn.setEType(theCorePackage.getEDate());
         eClass.getEStructuralFeatures().add(eAttributeCreatedOn);


after saving the ECore as XSD (as seen above), the ECore is getting created out of XSD again:

// Create a resource
         Resource resource = new XSDResourceImpl(URI.createURI("gen/EPackageModel.xsd"));
        
         try
         {
            resource.load(new ByteArrayInputStream(this.xsd), new HashMap<Object,Object>());
         }
         catch (IOException e)
         {
            throw new RuntimeException(e);
         }
         
         // get(0), because there should be always only ONE XSDSchema. Anything else would be a bug.
         XSDSchema xsdSchema = (XSDSchemaImpl)resource.getContents().get(0);
         
         XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
         xsdEcoreBuilder.generate(xsdSchema);
         Map<String, EPackage> resultEPackage = xsdEcoreBuilder.getTargetNamespaceToEPackageMap();
         
         // next(), because there should be always only ONE EPackage. Anything else would be a bug.
         this.value = resultEPackage.values().iterator().next();


And after that all my EAttributes are of the EDataType "AnySimpleType", I just can't find out how to fix this since everything seems to be fine.

Any help is appreciated!
Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #986517 is a reply to message #986360] Tue, 20 November 2012 17:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Benjamin,

Comments below.

On 20/11/2012 9:51 AM, Benjamin M. wrote:
> Hey,
>
> I am currently saving my ECore Files as XSD into my database, but
> while converting the xsd back to ECore all my EDataTypes are
> AnySimpleType and I don't know why.
What does the import of Ecore.xsd look like?
> The XSD should be okay:
>
>
> <xsd:complexType ecore:name="xxx" name="xxx">
> <xsd:sequence>
> <xsd:element ecore:name="Association" ecore:resolveProxies="true"
> name="Association" type="xxx:yyy"/>
> </xsd:sequence>
> <xsd:attribute ecore:name="Attribute1" name="Attribute1"
> type="ecore:EString"/>
> <xsd:attribute ecore:id="true" name="id" type="ecore:EString"/>
> <xsd:attribute name="createdOn" type="ecore:EDate"/>
> <xsd:attribute name="updatedOn" type="ecore:EDate"/>
> <xsd:attribute name="displayName" type="ecore:EString"/>
> </xsd:complexType>
> <xsd:complexType ecore:name="yyy" name="yyy">
> <xsd:attribute ecore:name="Attribute2" name="Attribute2"
> type="ecore:EString"/>
> <xsd:attribute ecore:id="true" name="id" type="ecore:EString"/>
> <xsd:attribute name="createdOn" type="ecore:EDate"/>
> <xsd:attribute name="updatedOn" type="ecore:EDate"/>
> <xsd:attribute name="displayName" type="ecore:EString"/>
> </xsd:complexType>
>
> Since I have to create my ECore files by hand, I am creating the
> EAttributes by myself:
> EAttribute eAttributeCreatedOn = theCoreFactory.createEAttribute();
> eAttributeCreatedOn.setName("createdOn");
> eAttributeCreatedOn.setEType(theCorePackage.getEDate());
> eClass.getEStructuralFeatures().add(eAttributeCreatedOn);
>
> after saving the ECore as XSD (as seen above), the ECore is getting
> created out of XSD again:
>
> // Create a resource
> Resource resource = new
> XSDResourceImpl(URI.createURI("gen/EPackageModel.xsd"));
Using relative URIs for resources is a bad idea.
> try
> {
> resource.load(new ByteArrayInputStream(this.xsd), new
> HashMap<Object,Object>());
> }
> catch (IOException e)
> {
> throw new RuntimeException(e);
> }
> // get(0), because there should be always only ONE
> XSDSchema. Anything else would be a bug.
> XSDSchema xsdSchema =
> (XSDSchemaImpl)resource.getContents().get(0);
> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
> xsdEcoreBuilder.generate(xsdSchema);
> Map<String, EPackage> resultEPackage =
> xsdEcoreBuilder.getTargetNamespaceToEPackageMap();
> // next(), because there should be always only ONE
> EPackage. Anything else would be a bug.
> this.value = resultEPackage.values().iterator().next();
Your XSDResourceImpl isn't in a resource set so it's not going to be
able to resolve imports.
>
> And after that all my EAttributes are of the EDataType
> "AnySimpleType", I just can't find out how to fix this since
> everything seems to be fine.
>
> Any help is appreciated!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #986857 is a reply to message #986517] Thu, 22 November 2012 06:29 Go to previous messageGo to next message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member
First of all: Thanks for your reply!

Sadly the relative URI is a must in my project, but of course you're right.
Actually I try to don't have any xsd file saved on the file system, since the xsd itself is saved in an attribute and later saved as a Lob into the DB.

I solved the part about the missing resource set - but the result is the same, the ETypes from the EAttributes are all AnySimpleType.

Its pretty weird since I am using the exact code part from here:
http://wiki.eclipse.org/EMF/FAQ#How_can_I_load_a_XSDSchema_from_a_simple_Java_String_or_from_a_DOM_Tree.3F

And the above xsd part is the one saved in my DB. So there must be something going wrong while converting it back, but I cant figure out what.

Any thoughts, hints?

PS: I also compared the schema before/after.. after the converting the xsd looks like this:

<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:bla="bla" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ecore:nsPrefix="bla" ecore:package="bla" targetNamespace="bla">
  <xsd:complexType ecore:name="bla" name="bla">
    <xsd:attribute ecore:name="attribute2" name="Attribute2" type="xsd:anySimpleType"/>
    <xsd:attribute name="createdOn" type="xsd:anySimpleType"/>
    <xsd:attribute name="displayName" type="xsd:anySimpleType"/>
    <xsd:attribute ecore:id="true" name="id" type="xsd:anySimpleType"/>
    <xsd:attribute name="updatedOn" type="xsd:anySimpleType"/>
  </xsd:complexType>
  <xsd:complexType ecore:name="bla" name="bla">
    <xsd:sequence>
      <xsd:element ecore:name="association" ecore:resolveProxies="true" name="Association" type="bla"/>
    </xsd:sequence>
    <xsd:attribute ecore:name="attribute1" name="Attribute1" type="xsd:anySimpleType"/>
    <xsd:attribute name="createdOn" type="xsd:anySimpleType"/>
    <xsd:attribute name="displayName" type="xsd:anySimpleType"/>
    <xsd:attribute ecore:id="true" name="id" type="xsd:anySimpleType"/>
    <xsd:attribute name="updatedOn" type="xsd:anySimpleType"/>
  </xsd:complexType>
</xsd:schema>


Thanks,
Benjamin

[Updated on: Thu, 22 November 2012 06:53]

Report message to a moderator

Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #986874 is a reply to message #986857] Thu, 22 November 2012 08:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Benjamin,

Comments below.

On 22/11/2012 7:29 AM, Benjamin M. wrote:
> First of all: Thanks for your reply!
>
> Sadly the relative URI is a must in my project, but of course you're
> right.
A must? It's like saying you must have problems. That doesn't really
make sense.
> Actually I try to don't have any xsd file saved on the file system,
> since the xsd itself is saved in an attribute and later saved as a Lob
> into the DB.
You mean a reference to the XSD is saved, not the XSD itself...
>
> I solved the part about the missing resource set - but the result is
> the same, the ETypes from the EAttributes are all AnySimpleType.
This still doesn't answer the question about what the import statement
looks like. No doubt the problem is caused by failure to resolve the
schema, but if you don't show the import I can't provide more information.
>
> Its pretty weird since I am using the exact code part from here:
> http://wiki.eclipse.org/EMF/FAQ#How_can_I_load_a_XSDSchema_from_a_simple_Java_String_or_from_a_DOM_Tree.3F
>
>
> And the above xsd part is the one saved in my DB. So there must be
> something going wrong while converting it back, but I cant figure out
> what.
Failures to resolve the schemas is likely the cause, and using relative
URIs is likely a root factor.
>
> Any thoughts, hints?
What does the import of Ecore.xsd look like?
>
> Thanks,
> Benjamin
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #986887 is a reply to message #986874] Thu, 22 November 2012 09:22 Go to previous messageGo to next message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member

A must? It's like saying you must have problems. That doesn't really
make sense.

You are right. I dont know what was going on in my head, ha.

> Actually I try to don't have any xsd file saved on the file system,
> since the xsd itself is saved in an attribute and later saved as a Lob
> into the DB.
You mean a reference to the XSD is saved, not the XSD itself...
>

Thanks for the correction.


> I solved the part about the missing resource set - but the result is
> the same, the ETypes from the EAttributes are all AnySimpleType.
This still doesn't answer the question about what the import statement
looks like. No doubt the problem is caused by failure to resolve the
schema, but if you don't show the import I can't provide more information.
>

Argh, I had to delete the first lines because I was not able to post the eclipse links. Didnt know that I also deleted the import statement.

<xsd:import namespace="http://www.eclipse.org/emf/2002/Ecore" schemaLocation="http://www.eclipse.org/emf/2002/Ecore"/>

So the problem is like you said: The import statement is missing after converting it back.

I will check out why the imports are missing even after I added the resource set to the process.

Sorry for the noise, Ed!


Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #987773 is a reply to message #986360] Wed, 28 November 2012 05:47 Go to previous messageGo to next message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member
Hey,

Sorry for troubling again but this kinda "trivial" problem is driving me nuts.
The last days I really tried to find out why the import statement is always missing, but I just cant find out why. No loadOptions or absolute URIs helped to resolve this problem. Since the Code is not much and everything else is working fine, I am pretty clueless what the problem is.

Any help/hints are appreciated!

 
         // Obtain a new resource set
         ResourceSet resourceSet = new ResourceSetImpl();
         
         Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
         Map<String, Object> m = reg.getExtensionToFactoryMap();
         m.put("xsd", new XSDResourceFactoryImpl());
         
         // Create a resource
         Resource resource = (XSDResourceImpl) resourceSet.createResource(URI.createURI("EPackageModel.xsd"));
         
         try
         {
            resource.load(new ByteArrayInputStream(this.xsd), resourceSet.getLoadOptions());
         }
         catch (IOException e)
         {
            throw new RuntimeException(e);
         }
         
         // get(0), because there should be always only ONE XSDSchema. Anything else would be a bug.
         XSDSchema xsdSchema = (XSDSchemaImpl)resource.getContents().get(0);
         
         XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
         xsdEcoreBuilder.generate(xsdSchema);
         Map<String, EPackage> resultEPackage = xsdEcoreBuilder.getTargetNamespaceToEPackageMap();
         
         // next(), because there should be always only ONE EPackage. Anything else would be a bug.
         this.value = resultEPackage.values().iterator().next();
      }
   }

[Updated on: Wed, 28 November 2012 05:48]

Report message to a moderator

Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #987775 is a reply to message #987773] Wed, 28 November 2012 06:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Benjamin,

Comments below.

On 28/11/2012 6:47 AM, Benjamin M. wrote:
> Hey,
>
> Sorry for troubling again but this kinda "trivial" problem is driving
> me nuts.
> The last days I really tried to find out why the import statement is
> always missing, but I just cant find out why. No loadOptions or
> absolute URIs helped to resolve this problem. Since the Code is not
> much and everything else is working fine, I am pretty clueless what
> the problem is.
>
> Any help/hints are appreciated!
>
> public EPackage getValue()
> {
> if (this.value == null)
> {
> // Obtain a new resource set
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource.Factory.Registry reg =
> Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("xsd", new XSDResourceFactoryImpl());
> // Create a resource
> Resource resource = (XSDResourceImpl)
> resourceSet.createResource(URI.createURI("EPackageModel.xsd"));
A relative URI is generally likely to cause problems with cross document
references...

In your previous post you mentioned your import looks like this:

<xsd:import namespace="http://www.eclipse.org/emf/2002/Ecore"
schemaLocation="http://www.eclipse.org/emf/2002/Ecore"/>

EMF's exporter generally produces something more like this:

<xsd:import namespace="http://www.eclipse.org/emf/2002/Ecore"
schemaLocation="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.xsd"/>

The code you show me here tells me nothing about how you produce your
schemas, only how you consume them...


> try
> {
> resource.load(new ByteArrayInputStream(this.xsd),
> resourceSet.getLoadOptions());
> }
> catch (IOException e)
> {
> throw new RuntimeException(e);
> }
> // get(0), because there should be always only ONE
> XSDSchema. Anything else would be a bug.
> XSDSchema xsdSchema =
> (XSDSchemaImpl)resource.getContents().get(0);
> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
> xsdEcoreBuilder.generate(xsdSchema);
> Map<String, EPackage> resultEPackage =
> xsdEcoreBuilder.getTargetNamespaceToEPackageMap();
> // next(), because there should be always only ONE
> EPackage. Anything else would be a bug.
> this.value = resultEPackage.values().iterator().next();
> }
> return value;
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #988238 is a reply to message #987775] Thu, 29 November 2012 03:37 Go to previous messageGo to next message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member
Hey Ed,

Thanks for looking into my problem again. I was so concerned finding out why the import statement is missing, that I didn't thought it could have to do something with that.

Since my project is intended for many user accesses, I try to have all information only saved into the DB for long term storage. Below is my save procedure, based on this page that I found:
http://www.cct.lsu.edu/~rguidry/eclipse-doc36/src-html/org/eclipse/emf/servus/app/Ecore2XSD.html

I am still trying some stuff out, but no options actually made a difference.

// Obtain a new resource set
      ResourceSet resSet = new ResourceSetImpl();
      resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XSDResourceFactoryImpl());
      
      // Create a resource
      Resource xsdResource = (XSDResourceImpl) resSet.createResource(URI.createPlatformResourceURI("EPackageModel.xsd", true));

      // Add the model content
      EcoreSchemaBuilder schemaBuilder = new EcoreSchemaBuilder(new BasicExtendedMetaData());
      xsdResource.getContents().add(schemaBuilder.getSchema(EPackage));

      // Create a ByteArrayOutputStream for the xsd
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      
      try
      {
         xsdResource.save(os, Collections.EMPTY_MAP);
         LOGGER.info(os.toString());
      }
      catch (IOException e)
      {
         throw new RuntimeException(e);
      }

      this.xsd = os.toByteArray();


Re: [XSD2ECore] EDataType / AnySimpleType Problem [message #988246 is a reply to message #988238] Thu, 29 November 2012 05:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Benjamin,<br>
<br>
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 29/11/2012 4:37 AM, Benjamin M.
wrote:<br>
</div>
<blockquote cite="mid:k96la0$gor$1@xxxxxxxxe.org" type="cite">Hey
Ed,
<br>
<br>
Thanks for looking into my problem again. I was so concerned
finding out why the import statement is missing, that I didn't
thought it could have to do something with that.
<br>
</blockquote>
So the import isn't actually missing is it?  And if you look at the
results produced by Export Model...-&gt;XML Schema that result is
what you want, right?  It produces an import like this:<br>
<blockquote> &lt;xsd:import
namespace=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a>
schemaLocation="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.xsd"/&gt;<br>
</blockquote>
Because of the logic in
org.eclipse.xsd.ecore.exporter.XSDExporter.doExport(Monitor,
ExportData) which knows the mapping from the package's nsURI to the
package's exported schema's location and updates the schemaLocations
of the imports accordingly.<br>
<br>
<br>
<blockquote cite="mid:k96la0$gor$1@xxxxxxxxe.org" type="cite">
<br>
Since my project is intended for many user accesses, I try to have
all information only saved into the DB for long term storage.
Below is my save procedure, based on this page that I found:
<a class="moz-txt-link-freetext" href="http://www.cct.lsu.edu/~rguidry/eclipse-doc36/src-html/org/eclipse/emf/servus/app/Ecore2XSD.html">http://www.cct.lsu.edu/~rguidry/eclipse-doc36/src-html/org/eclipse/emf/servus/app/Ecore2XSD.html</a><br>
<br>
I am still trying some stuff out, but no options actually made a
difference.
<br>
<br>
// Obtain a new resource set
<br>
     ResourceSet resSet = new ResourceSetImpl();
<br>
    
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XSDResourceFactoryImpl());
<br>
          // Create a resource
<br>
     Resource xsdResource = (XSDResourceImpl)
resSet.createResource(URI.createPlatformResourceURI("EPackageModel.xsd",
true));
<br>
<br>
     // Add the model content
<br>
     EcoreSchemaBuilder schemaBuilder = new EcoreSchemaBuilder(new
BasicExtendedMetaData());
<br>
    
xsdResource.getContents().add(schemaBuilder.getSchema(EPackage));
<br>
<br>
     // Create a ByteArrayOutputStream for the xsd
<br>
     ByteArrayOutputStream os = new ByteArrayOutputStream();
<br>
          try
<br>
     {
<br>
        xsdResource.save(os, Collections.EMPTY_MAP);
<br>
        LOGGER.info(os.toString());
<br>
     }
<br>
     catch (IOException e)
<br>
     {
<br>
        throw new RuntimeException(e);
<br>
     }
<br>
<br>
     this.xsd = os.toByteArray();
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Xcore] instance type name?
Next Topic:[Teneo] Tutorial example invalid sql with MySQL 5.5
Goto Forum:
  


Current Time: Fri Apr 19 22:51:24 GMT 2024

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

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

Back to the top