Generating Ecores/genmodel files for Multiple XSDs programatically [message #1752071] |
Wed, 18 January 2017 09:54  |
Eclipse User |
|
|
|
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 10:55] by Moderator
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05159 seconds