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 08:36 Go to next message
Ugur Kocak is currently offline Ugur KocakFriend
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 09:56]

Report message to a moderator

Re: EMF XMI Serialization [message #532853 is a reply to message #532777] Tue, 11 May 2010 11:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26235
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 12:58 Go to previous messageGo to next message
Ugur Kocak is currently offline Ugur KocakFriend
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 12:58 Go to previous message
Ugur Kocak is currently offline Ugur KocakFriend
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: Fri Nov 28 06:14:54 GMT 2014

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

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