Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serialize ecore metamodel without eType prefix
Serialize ecore metamodel without eType prefix [message #1754792] Wed, 22 February 2017 13:03 Go to next message
Alex Burdusel is currently offline Alex BurduselFriend
Messages: 3
Registered: November 2016
Junior Member
Hello,

I am trying to programmatically load ecore metamodels, change their structure and then write the new versions back to disk.

I have the following code to load and save a metamodel:

	def loadMetamodel(){
		
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( 
				"ecore", new EcoreResourceFactoryImpl()); 

		this.resourceSet = new ResourceSetImpl();
		
		var resource = resourceSet.getResource(this.metamodelPath, true);
		var eObject = resource.getContents().get(0) as EPackage;
		
		EPackage.Registry.INSTANCE.put(eObject.getNsURI(), eObject);

		if (eObject instanceof EPackage) {
			this.metamodel = eObject as EPackage;
		}		
	}
	
	def saveMetamodel(String path){
		var resource = resourceSet.createResource(URI.createURI(path))
	
		resource.getContents().add(this.metamodel)
	
		var options = new HashMap<String, Boolean>();
		options.put(XMIResource.OPTION_SCHEMA_LOCATION, true);	
		
		try {
			var ostream = new FileOutputStream(new File(path));
			resource.save(ostream, options);
			
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}


The problem that I have is the following:

1. Loading an ecore file in this format:

  <eClassifiers xsi:type="ecore:EClass" name="Package" eSuperTypes="#//NamedElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="classes" ordered="false"
        upperBound="-1" eType="#//Class" containment="true"/>
  </eClassifiers>


2. Saving it, it gets serialized to this format (notice the different eType prefix):

  <eClassifiers xsi:type="ecore:EClass" name="Package" eSuperTypes="#//NamedElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="classes" ordered="false"
        upperBound="-1" eType="ecore:EClass metamodel.ecore#//Class" containment="true"/>
  </eClassifiers>



How should I do the serialization so that there is no eType prefix with the filename included.

Thanks.

[Updated on: Wed, 22 February 2017 15:08]

Report message to a moderator

Re: Serialize ecore metamodel without eType prefix [message #1754819 is a reply to message #1754792] Wed, 22 February 2017 17:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
I wonder what value does this.metamodelPath have? And what value does path in the save method? Note that the save method is removing the package from its containing resource and moving it to a different resource. Perhaps using this.metamodel.eResource().save(...) would be better. In the end, I expect such a serialization difference is caused by the fact that path is not an absolute hierarchical URI (with a scheme and an absolute path) so that references can't be made properly relative.

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Xcore][gradle] Two mysterious problems.
Next Topic:error in opening xmi file
Goto Forum:
  


Current Time: Fri Apr 26 14:01:04 GMT 2024

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

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

Back to the top