Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Save a copy of a Resource - xmi:id missing
Save a copy of a Resource - xmi:id missing [message #1694619] Wed, 06 May 2015 17:10 Go to next message
Nikos Margaritis is currently offline Nikos MargaritisFriend
Messages: 65
Registered: September 2014
Member

Hello there,

I've implemented a multipage editor which combines EMF and xml tabs.
The concept is that the emf model is processed and is exported in the XML tab. (the xml has a custom structure).

However in order to avoid saving before moving to a new tab (so at to get the up-to-date editorinput) I would like to create a copy of the unsaved up-to-date resource and feed that to my exporter.

I have managed to implement this, however when I copy the resource and save it; I believe that I am missing something in the saveOptions which results in the xmi:id attribute missing from the resource model.


XMIResource xmiResource = new XMIResourceImpl(URI.createFileURI(tempFile2.getAbsolutePath())); 
...
//defining the outputstream etc
...
//copy the contents of the original resource to the newly added one
//where re.getContents() the contents of the original resource
xmiResource.getContents().addAll(EcoreUtil.copyAll(re.getContents())); 

final Map<Object, Object> saveOptions = xmiResource.getDefaultSaveOptions();		  
saveOptions.put(XMIResource.OPTION_DECLARE_XML,Boolean.TRUE);		  
saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF,XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD);			  
saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION,Boolean.TRUE);		 
saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI,Boolean.FALSE);
saveOptions.put(XMIResource.OPTION_ENCODING,"UTF-8");

//save the resource
xmiResource.save(outputStream, saveOptions);	



A resource model example..
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jsxm="jsxm">
 
<jsxm:SXM name="test">
    <state xsi:type="jsxm:State" name="intial" outgoingTransitions="/0/@transition.0"/>
    <state xsi:type="jsxm:State" name="open" incomingTransitions="/0/@transition.0"/>
....
</jsxm:SXM>


How can I force the xmi:id to appear in the copy of the resource model?

Best Regards,

[Updated on: Wed, 06 May 2015 17:24]

Report message to a moderator

Re: Save a copy of a Resource - xmi:id missing [message #1694649 is a reply to message #1694619] Wed, 06 May 2015 19:40 Go to previous message
Nikos Margaritis is currently offline Nikos MargaritisFriend
Messages: 65
Registered: September 2014
Member

Hello again,

I have solved this issue

In case anyone is interested you have to extend XMIResourceImpl like that and override the useUUIDs method like this (the previous code remains the same)

class XMIResourceImpl extends org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl {
        public XMIResourceImpl() { super(); }
        public XMIResourceImpl(URI uri) { super(uri); }
	 
	@Override
	protected boolean useUUIDs() {
		return true;
	}
}


Finally those are the save options that give you the exact result as in the original resource

final Map<Object, Object> saveOptions = xmiResource.getDefaultSaveOptions();
saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION,Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_ENCODING,"UTF-8");
saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE);
saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION,Boolean.TRUE);



Best Regards,
Previous Topic:Ecore defaultValue for EByteArray or EFloat with multiplicities
Next Topic:Prefix for Enums
Goto Forum:
  


Current Time: Tue Oct 15 21:30:47 GMT 2019

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

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

Back to the top