Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Exporting multiple XSD schemas to ecore programmatically
Exporting multiple XSD schemas to ecore programmatically [message #1023999] Mon, 25 March 2013 16:02 Go to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
Hi All,
I am trying to export a group of interrelated XSD schemas to ecore programmatically(in order to get an ecore annotated with proper extended metadata for XML serialization). I am using the XSDEcoreBuilder but in the resulting ecore models, the external inheritance links are lost. I tried using the XSDEcoreBuilder.generate(collection<URI>) but I also wanted to try XSDEcoreBuilder.generate(XSDSchema) but this method returns void, I didn't understand how to use it.
If anyone have any idea, it would be very helpful.

Here is my code using XSDEcoreBuilder.generate(collection<URI>):
public void exportXSDToEcore(Collection<URI> sourceXSDFilePaths_p) {

XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xsd", new XSDResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel", new EcoreResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());

Collection<Object> eCorePackages = xsdEcoreBuilder.generate(sourceXSDFilePaths_p);
Resource resource = resourceSet.createResource(URI.createFileURI("metamodel.generated.ecore"));
for (Object element : eCorePackages) {
if (element instanceof EObject) {
resource.getContents().add((EObject) element);
}

}
try {
resource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
Re: Exporting multiple XSD schemas to ecore programmatically [message #1024021 is a reply to message #1023999] Mon, 25 March 2013 16:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Skander,

Comments below.

On 25/03/2013 12:02 PM, Skander Turki wrote:
> Hi All,
> I am trying to export a group of interrelated XSD schemas to ecore
> programmatically(in order to get an ecore annotated with proper
> extended metadata for XML serialization). I am using the
> XSDEcoreBuilder but in the resulting ecore models, the external
> inheritance links are lost.
What do you mean by the external inheritance links?
> I tried using the XSDEcoreBuilder.generate(collection<URI>) but I also
> wanted to try XSDEcoreBuilder.generate(XSDSchema) but this method
> returns void, I didn't understand how to use it.
If you look at the implementations of these methods, you should get the
idea...
> If anyone have any idea, it would be very helpful.
>
> Here is my code using XSDEcoreBuilder.generate(collection<URI>):
> public void exportXSDToEcore(Collection<URI> sourceXSDFilePaths_p) {
> XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
> new XMIResourceFactoryImpl());
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xsd",
> new XSDResourceFactoryImpl());
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel",
> new EcoreResourceFactoryImpl());
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
>
> Collection<Object> eCorePackages =
> xsdEcoreBuilder.generate(sourceXSDFilePaths_p);
> Resource resource =
> resourceSet.createResource(URI.createFileURI("metamodel.generated.ecore"));
> for (Object element : eCorePackages) {
> if (element instanceof EObject) {
> resource.getContents().add((EObject) element);
> }
>
> }
> try {
> resource.save(null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Exporting multiple XSD schemas to ecore programmatically [message #1024029 is a reply to message #1024021] Mon, 25 March 2013 17:15 Go to previous messageGo to next message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
By external inheritance links, I meant inheritance links from a model element to model elements that are not in the element's XSD but in another XSD of my XSD-family.

So I obtain one ecore file with as many packages as XSD schemas but the references between them are broken, like inheritances or cross-references that become (AnySimpleType) instead of the initial type in the XSD.
Re: Exporting multiple XSD schemas to ecore programmatically [message #1024036 is a reply to message #1024029] Mon, 25 March 2013 17:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Skander,

Comments below.

On 25/03/2013 1:15 PM, Skander Turki wrote:
> By external inheritance links, I meant inheritance links from a model
> element to model elements that are not in the element's XSD but in
> another XSD of my XSD-family.
The exporter framework solves all these types of problem and you're
trying to handle all these same complexities with a different
implementation. All I can suggest is you look at how this works in the
IDE and use that as a basis because I don't have the time to help you
solve these same problems a second time.
>
> So I obtain one ecore file with as many packages as XSD schemas but
> the references between them are broken, like inheritances or
> cross-references that become (AnySimpleType) instead of the initial
> type in the XSD.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Exporting multiple XSD schemas to ecore programmatically [message #1027696 is a reply to message #1024036] Wed, 27 March 2013 09:32 Go to previous message
Skander TURKI is currently offline Skander TURKIFriend
Messages: 130
Registered: July 2009
Senior Member
I tried to look to what the plugins are doing when we use the wizard and I have found that they were using ModelImporter in org.eclipse.emf.importer, XSDImprter in org.eclipse.xsd.ecore.importer and ModelConverter in org.eclipse.emf.converter. I am trying the code inspired from the wizard. I'll post it as soon as I get it to work.
Previous Topic:Registering EMF EPackage for Xtext
Next Topic:Package: get EClass by name?
Goto Forum:
  


Current Time: Fri Apr 26 13:43:58 GMT 2024

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

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

Back to the top