Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Generating Ecores/genmodel files for Multiple XSDs programatically(Multiple XSDs generating Multiple Ecore files and an .genmodel file)
Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752071] Wed, 18 January 2017 14:54 Go to next message
Sam Ra is currently offline Sam RaFriend
Messages: 9
Registered: January 2017
Junior Member
Hi EMF community!

Well I have this beginner issue of programatically converting XSDs to Ecores and generate code.

I'm trying to convert multiple XSD files into Ecore models and generate the genModel from that as well. I did this manually and selected the related Ecore files and the conversion resulted in multiple Ecore models with one genModel file. Now I need to do this programmatically, and I managed to do the first part of converting multiple XSD files into Ecores. I need to generate the genModel from this process now as well. This seems to me as a tough task as I don't know how. I saw proposed code snippet in the forum for getting the genModel for an XSD to ecore, but I had a problem then of filling out the different variables there, also I'm doing this for multiple interrelated XSDs/Ecores not only one to one.

Below is a code I had for transforming multiple XSDs to Ecore files which works:

	public void convertXSDToEcore()
	{
		String projPath = Paths.get("").toAbsolutePath().toString();
		String srcPath = projPath + "\\srcXSDs\\";
		File outputFile = new File(projPath + "\\genEcores\\");
	
		Collection<URI> schemaURIs = null;
		try {
			schemaURIs = this.getSchemaFileCollection(new File(srcPath));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		XSDEcoreBuilder xsdEcoreBuilder = new XSDEcoreBuilder();

		Collection<Resource> ecoreResources = xsdEcoreBuilder.generateResources(schemaURIs);
		
	    // for every resource found (includes eventually referenced XSDs)
	    for (Resource ecoreResource : ecoreResources) {
	        try {
	            if (ecoreResource.getClass().getName().contains("EcoreResourceFactoryImpl")) {
	            	String[] nameSegments = ecoreResource.getURI().toString().split(":");
	                ecoreResource.save(new FileOutputStream(outputFile.getAbsolutePath() + "\\"+ nameSegments[nameSegments.length-2]+ "_" + nameSegments[nameSegments.length-1] + ".ecore"), null);
	            }
	        } catch (IOException e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	    }

	    this.createGenModel2(ecoreResources.iterator().next());
	}


I had a look at other similar topics but none had this multiple XSDs/Ecores scenario. I'm trying out to have something to work, but in my opinion this should be a trivial recurring problem that should be obvious now to the community, documented and should be easy to reuse by others.

Any help would be appreciated,



[Updated on: Fri, 20 January 2017 15:55]

Report message to a moderator

Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752118 is a reply to message #1752071] Thu, 19 January 2017 03:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29594
Registered: July 2009
Senior Member
You could look in org.eclipse.emf.codegen.ecore.Generator.PlatformRunnable.run(Generator, Object) . It's mostly an issue of creating a GenModel and calling org.eclipse.emf.codegen.ecore.genmodel.GenModel.initialize(Collection<? extends EPackage>).
Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752119 is a reply to message #1752118] Thu, 19 January 2017 03:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29594
Registered: July 2009
Senior Member
No Message Body
Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752159 is a reply to message #1752118] Thu, 19 January 2017 10:15 Go to previous messageGo to next message
Sam Ra is currently offline Sam RaFriend
Messages: 9
Registered: January 2017
Junior Member
Would you mind elaborate on this? Do you mean to look into org.eclipse.emf.codegen.ecore.Generator.PlatformRunnable.run(Generator, Object) class documentation to figure out this or do you suggest better way? Any suggestion on how to put these things together? Tutorial/sourcecode/example/ any useful point guide me through?!
Thanks!
Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752160 is a reply to message #1752118] Thu, 19 January 2017 10:16 Go to previous messageGo to next message
Sam Ra is currently offline Sam RaFriend
Messages: 9
Registered: January 2017
Junior Member
No Message Body

[Updated on: Thu, 19 January 2017 10:17]

Report message to a moderator

Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752164 is a reply to message #1752160] Thu, 19 January 2017 11:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29594
Registered: July 2009
Senior Member
Of course it's open source, so the source code is all there for you to see. You could, for example, set a breakpoint in the GenModelImpl's initialize method, start a runtime Eclipse IDE, and import several XSDs in the wizard. Then you'll see exactly what it's all doing. There are no specialized tutorials to answer this question, and I'm traveling, so I can only give you a pointer. Most of the work I do with Eclipse involves using the debugger to see how other technologies work, because there most often isn't good documentation for how they work...
Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752287 is a reply to message #1752164] Fri, 20 January 2017 15:52 Go to previous messageGo to next message
Sam Ra is currently offline Sam RaFriend
Messages: 9
Registered: January 2017
Junior Member
I cloned http://git.eclipse.org/gitroot/emf/org.eclipse.emf.git and some compilation errors with some projects in org.eclipse.emf.gwt and org.eclipse.emf.rap... projects which I'm trying to resolve now... What other repositories do I need to clone (if any) for XSD import?
I was unable yet to figure out which plugin I need to run in headless or the parameters required my tasks. Which plugin transforms XSD to Ecore? which generates genmodel if I have ecore files?
I tried: ( -application org.eclipse.emf.codegen.ecore.Generator -ecore2GenModel c:\temp\emf -model -noSplash -consoleLog ) but failed as I still have compilation error problems I think in sourcecode.
Is the above the correct headless entry point to create genmodel? Then whats the one for XSD to ecore?

Thanks anyway for help!

[Updated on: Fri, 20 January 2017 15:59]

Report message to a moderator

Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752297 is a reply to message #1752287] Fri, 20 January 2017 17:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29594
Registered: July 2009
Senior Member
There's an Oomph setup for EMF and XSD, but you only need the EMF/XSD SDKs provisioned in the target platform to look at source code. And you can look at what the import wizard does launching a runtime workspace rather than trying to get the headless application to launch.
Re: Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752444 is a reply to message #1752297] Mon, 23 January 2017 19:53 Go to previous message
Sam Ra is currently offline Sam RaFriend
Messages: 9
Registered: January 2017
Junior Member
No Message Body

[Updated on: Thu, 26 January 2017 07:47]

Report message to a moderator

Previous Topic:(CDO-Server) Mongo DB
Next Topic:Xcore Code Generator
Goto Forum:
  


Current Time: Thu Oct 18 16:34:19 GMT 2018

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

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

Back to the top