Exporting multiple XSD schemas to ecore programmatically [message #1023999] |
Mon, 25 March 2013 12:02  |
Eclipse User |
|
|
|
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 12:54   |
Eclipse User |
|
|
|
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();
> }
> }
|
|
|
|
|
Re: Exporting multiple XSD schemas to ecore programmatically [message #1027696 is a reply to message #1024036] |
Wed, 27 March 2013 05:32  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03678 seconds