Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » SOS Please help me: EMF XMI Serialization(How can I create a root element to put all my element under the root element)
SOS Please help me: EMF XMI Serialization [message #532777] Tue, 11 May 2010 04:36 Go to next message
Ugur Kocak is currently offline Ugur Kocak
Messages: 33
Registered: February 2010
Member
Hi,
can somebody explain me how I can create a XMI root element in my code to put all elements under this root element.

Thanks in advance!

Here is the sample code:

public class SerializationUtility {

public void serialize() throws IOException {

ResourceSet rs = new ResourceSetImpl();

XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
myXMResourceImpl.getDefaultSaveOptions().put( XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);

// Register the base XML resource factory implementation in the local resource factory registry.
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut( "xmi", new XMIResourceFactoryImpl());
URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");

Resource resource = rs.createResource( fileURI);
// add the root objects to the resource
Iterator<ComputerResources> itr = ComputerCollectionGenerator.computerResoucres.iterator();
while ( itr.hasNext()) {
ComputerResources next = itr.next();
resource.getContents().add( next);
}

resource.save( null);

}
}

[Updated on: Tue, 11 May 2010 05:56]

Report message to a moderator

Re: EMF XMI Serialization [message #532853 is a reply to message #532777] Tue, 11 May 2010 07:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25947
Registered: July 2009
Senior Member
Ugar,

If the resource's contents contain multiple elements, there will be an
XMI root element to hold them all. Otherwise, the one element in the
contents will be used as the root.


Ugur Kocak wrote:
> Hi,
> can somebody explain me how I can create a XMI root element in my code
> to put all elements under this root element.
>
> Thanks in advance!
>
> Here is the sample code:
>
> public class SerializationUtility {
>
> public void serialize() throws IOException {
>
> ResourceSet rs = new ResourceSetImpl();
>
> XMIResourceImpl myXMResourceImpl = new XMIResourceImpl();
> myXMResourceImpl.getDefaultSaveOptions().put(
> XMIResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
>
> // Register the base XML resource factory implementation in the
> local resource factory registry.
> rs.getResourceFactoryRegistry().getExtensionToFactoryMap().p ut(
> "xmi", new XMIResourceFactoryImpl());
> URI fileURI = URI.createFileURI( "ResourcesFZI.xmi");
>
> Resource resource = rs.createResource( fileURI);
> // add the root objects to the resource
> Iterator<ComputerResources> itr =
> ComputerCollectionGenerator.computerResoucres.iterator();
> while ( itr.hasNext()) {
> ComputerResources next = itr.next();
> resource.getContents().add( next);
> }
>
> resource.save( null);
>
> }
> }
>
Re: EMF XMI Serialization [message #532877 is a reply to message #532853] Tue, 11 May 2010 08:58 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur Kocak
Messages: 33
Registered: February 2010
Member
Hi Ed,

thank you for the hint.

Best regards
Ugur
Re: EMF XMI Serialization [message #622880 is a reply to message #532853] Tue, 11 May 2010 08:58 Go to previous message
Ugur Kocak is currently offline Ugur Kocak
Messages: 33
Registered: February 2010
Member
Hi Ed,

thank you for the hint.

Best regards
Ugur
Previous Topic:EMF XMI Serialization
Next Topic:[EMF Compare] UpdateReference: leftTarget or rightTarget?
Goto Forum:
  


Current Time: Thu Jul 31 11:39:45 EDT 2014

Powered by FUDForum. Page generated in 0.01860 seconds