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