Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to convert XMIResource to CDOResource
How to convert XMIResource to CDOResource [message #423096] Tue, 23 September 2008 06:18 Go to next message
Jasper is currently offline JasperFriend
Messages: 84
Registered: July 2009
Member
What's the best way to convert an XMIResource to a CDOResource? I mean,
how do I duplicate the contents of the former, in the latter?

Thanks,
/Jasper.
Re: How to convert XMIResource to CDOResource [message #423097 is a reply to message #423096] Tue, 23 September 2008 07:05 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000406020909080908000603
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Jasper,

You just need to copy/move the root objects over to the CDOResource.
There's a good example in
org.eclipse.emf.cdo.internal.ui.actions.ImportResourceAction .doRun():

| @Override
*protected **void *doRun() *throws *Exception
{
CDOTransaction transaction = getTransaction();

// Source ResourceSet
ResourceSet sourceSet = *new *ResourceSetImpl();
Map<String, Object> map = sourceSet.getResourceFactoryRegistry().getExtensionToFactory Map();
map.put("*", *new *XMIResourceFactoryImpl());
sourceSet.setPackageRegistry(transaction.getSession().getPac kageRegistry());

// Source Resource
Resource source = sourceSet.getResource(sourceURI, *true*);
List<EObject> sourceContents = *new *ArrayList<EObject>(source.getContents());

// Target Resource
Resource target = transaction.createResource(targetPath);
EList<EObject> targetContents = target.getContents();

// Move contents over
*for *(EObject root : sourceContents)
{
targetContents.add(root);
}
}|



Cheers
/Eike



Jasper schrieb:
> What's the best way to convert an XMIResource to a CDOResource? I
> mean, how do I duplicate the contents of the former, in the latter?
>
> Thanks,
> /Jasper.

--------------000406020909080908000603
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Jasper,<br>
<br>
You just need to copy/move the root objects over to the CDOResource.
There's a good example in
org.eclipse.emf.cdo.internal.ui.actions.ImportResourceAction .doRun(): <br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff">&nbsp;&nbsp;</font><font
color="#646464">@Override</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#7f0055"><b>protected&nbsp;</b></font><font
color="#7f0055"><b>void&nbsp;</b></font><font color="#000000">doRun</font><font
color="#000000">()&nbsp;</font><font color="#7f0055"><b>throws&nbsp;</b></font><font
color="#000000">Exception</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">{</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> CDOTransaction&nbsp;transaction&nbsp;=&nbsp;getT ransaction </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#3f7f5f">//&nbsp;Source&nbsp;ResourceSet</font ><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">ResourceSet&nbsp;sourceSet&nbsp;=&nbsp; </font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">ResourceSetImpl</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> Map&lt;String,&nbsp;Object&gt;&nbsp;map& nbsp;=&nbsp;sourceSet.getResourceFactoryRegistry </font><font
color="#000000">()</font><font color="#000000">.getExtensionToFactoryMap</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">map.put</font><font
color="#000000">(</font><font color="#2a00ff">"*"</font><font
color="#000000">,&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font
color="#000000">XMIResourceFactoryImpl</font><font color="#000000">())</font><font
color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">sourceSet.setPackageRegistry</font><font
color="#000000">(</font><font color="#000000">transaction.getSession</font><font
color="#000000">()</font><font color="#000000">.getPackageRegistry</font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#3f7f5f">//&nbsp;Source&nbsp;Resource</font ><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> Resource&nbsp;source&nbsp;=&nbsp;sourceSet.getRe source </font><font
color="#000000">(</font><font color="#000000">sourceURI,&nbsp;</font><font
color="#7f0055"><b>true</b></font><font color="#000000">)</font><font
color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> List&lt;EObject&gt;&nbsp;sourceContents&nbsp ;=&nbsp; </font><font
color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">ArrayList&lt;EObject&gt;</font><font
color="#000000">(</font><font color="#000000">source.getContents</font><font
color="#000000">())</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#3f7f5f">//&nbsp;Target&nbsp;Resource</font ><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> Resource&nbsp;target&nbsp;=&nbsp;transaction.cre ateResource </font><font
color="#000000">(</font><font color="#000000">targetPath</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000"> EList&lt;EObject&gt;&nbsp;targetContents&nbs p;=&nbsp;target.getContents </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#3f7f5f">//&nbsp;Move&nbsp;contents&nbsp;over </font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#7f0055"><b>for&nbsp;</b></font><font
color="#000000">(</font><font color="#000000">EObject&nbsp;root&nbsp;:&nbsp;sourceContents </font><font
color="#000000">)</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">{</font><br>
<font color="#ffffff"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#000000">targetContents.add</font><font
color="#000000">(</font><font color="#000000">root</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font ><font color="#000000">}</font><br>
<font color="#ffffff">&nbsp;&nbsp;</font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --><br>
<br>
Cheers<br>
/Eike<br>
<br>
<br>
<br>
Jasper schrieb:
<blockquote cite="mid:48D88A31.90608@yahoo.com" type="cite">What's the
best way to convert an XMIResource to a CDOResource? I mean, how do I
duplicate the contents of the former, in the latter?
<br>
<br>
Thanks,
<br>
/Jasper.
<br>
</blockquote>
</body>
</html>

--------------000406020909080908000603--


Re: How to convert XMIResource to CDOResource [message #423101 is a reply to message #423097] Tue, 23 September 2008 12:16 Go to previous message
Jasper is currently offline JasperFriend
Messages: 84
Registered: July 2009
Member
Eike -- Excellent, thanks a lot.

Eike Stepper wrote:
> Hi Jasper,
>
> You just need to copy/move the root objects over to the CDOResource.
> There's a good example in
> org.eclipse.emf.cdo.internal.ui.actions.ImportResourceAction .doRun():
>
> | @Override
> *protected **void *doRun() *throws *Exception
> {
> CDOTransaction transaction = getTransaction();
>
> // Source ResourceSet
> ResourceSet sourceSet = *new *ResourceSetImpl();
> Map<String, Object> map = sourceSet.getResourceFactoryRegistry().getExtensionToFactory Map();
> map.put("*", *new *XMIResourceFactoryImpl());
> sourceSet.setPackageRegistry(transaction.getSession().getPac kageRegistry());
>
> // Source Resource
> Resource source = sourceSet.getResource(sourceURI, *true*);
> List<EObject> sourceContents = *new *ArrayList<EObject>(source.getContents());
>
> // Target Resource
> Resource target = transaction.createResource(targetPath);
> EList<EObject> targetContents = target.getContents();
>
> // Move contents over
> *for *(EObject root : sourceContents)
> {
> targetContents.add(root);
> }
> }|
>
>
>
> Cheers
> /Eike
>
>
>
> Jasper schrieb:
>> What's the best way to convert an XMIResource to a CDOResource? I
>> mean, how do I duplicate the contents of the former, in the latter?
>>
>> Thanks,
>> /Jasper.
Previous Topic:To EMF or Not to EMF
Next Topic:[Query] Status of the EMF Query Component
Goto Forum:
  


Current Time: Thu Mar 28 06:45:28 GMT 2024

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

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

Back to the top