Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF XMI Serialization
EMF XMI Serialization [message #622871] Tue, 11 May 2010 08: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);

}
}
Re: EMF XMI Serialization [message #622878 is a reply to message #622871] Tue, 11 May 2010 11:17 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26054
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);
>
> }
> }
>
Previous Topic:EMF Compare Start problem
Next Topic:SOS Please help me: EMF XMI Serialization
Goto Forum:
  


Current Time: Sat Sep 20 01:59:54 GMT 2014

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

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