Replace referenced href with full tree

49 views Asked by At

I've trying to write my EMF model to file. The model was originally created using Xtext.

URI uri = URI.createURI("file://c:/store/model.xmi");
ResourceSet resourceSet = new ResourceSetImpl();
XMLResource resource = (XMLResource) resourceSet.createResource(uri);
resource.getDefaultLoadOptions().put(XMLResource.OPTION_RESOURCE_ENTITY_HANDLER, Boolean.FALSE);
resourceSet.getResourceFactoryRegistry().
        getContentTypeToFactoryMap().
        put("xml", new XMIResourceFactoryImpl());
resource.getContents().add(theModel);
resource.save(null);

It writes the XMI to disk but instead of having the full tree (as I can see when I inspect the in-memory model before persisting) it writes references:

<ElementFeatures xsi:type="model:DataDictionaryReference">
  <referenced href="platform:/resource/AModel_Model/src/main/java/com/abc/Model_DataDictionary.dp#//@elements.0/@elements.0/@ElementFeatures.0/@element"/>
</ElementFeatures>

But, what I would like is for that reference to be filled with the full tree, for example:

<ElementFeatures xsi:type="model:Element" name="FOO" documentation="I'm a foo">
  <ElementType>
    <definedType xsi:type="model:ElementTypeInteger" type="integer"/>
  </ElementType>
</ElementFeatures>
...
...
...
1

There are 1 answers

0
Banoffee On

Not sure why you are using an XMLResource with an XMLResource Option with an XML file extension if you want to serialize your model using an XMI Factory to an XMI-suffixed URI. Adapting Vogella's EMF Persistence Tutorial to your case should work as you are expecting it to.