Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752071] |
Wed, 18 January 2017 14:54 |
Sam Ra 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 #1752287 is a reply to message #1752164] |
Fri, 20 January 2017 15:52 |
Sam Ra 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27015 seconds