|
Re: How to convert XMIResource to CDOResource [message #423097 is a reply to message #423096] |
Tue, 23 September 2008 07:05 |
|
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"> </font><font
color="#646464">@Override</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>protected </b></font><font
color="#7f0055"><b>void </b></font><font color="#000000">doRun</font><font
color="#000000">() </font><font color="#7f0055"><b>throws </b></font><font
color="#000000">Exception</font><br>
<font color="#ffffff"> </font><font color="#000000">{</font><br>
<font color="#ffffff"> </font ><font color="#000000"> CDOTransaction transaction = getT ransaction </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff"> </font ><font color="#3f7f5f">// Source ResourceSet</font ><br>
<font color="#ffffff"> </font ><font color="#000000">ResourceSet sourceSet = </font><font
color="#7f0055"><b>new </b></font><font color="#000000">ResourceSetImpl</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font ><font color="#000000"> Map<String, Object> map& 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"> </font ><font color="#000000">map.put</font><font
color="#000000">(</font><font color="#2a00ff">"*"</font><font
color="#000000">, </font><font color="#7f0055"><b>new </b></font><font
color="#000000">XMIResourceFactoryImpl</font><font color="#000000">())</font><font
color="#000000">;</font><br>
<font color="#ffffff"> </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"> </font ><font color="#3f7f5f">// Source Resource</font ><br>
<font color="#ffffff"> </font ><font color="#000000"> Resource source = sourceSet.getRe source </font><font
color="#000000">(</font><font color="#000000">sourceURI, </font><font
color="#7f0055"><b>true</b></font><font color="#000000">)</font><font
color="#000000">;</font><br>
<font color="#ffffff"> </font ><font color="#000000"> List<EObject> sourceContents  ;= </font><font
color="#7f0055"><b>new </b></font><font color="#000000">ArrayList<EObject></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"> </font ><font color="#3f7f5f">// Target Resource</font ><br>
<font color="#ffffff"> </font ><font color="#000000"> Resource target = 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"> </font ><font color="#000000"> EList<EObject> targetContents&nbs p;= target.getContents </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff"> </font ><font color="#3f7f5f">// Move contents over </font><br>
<font color="#ffffff"> </font ><font color="#7f0055"><b>for </b></font><font
color="#000000">(</font><font color="#000000">EObject root : sourceContents </font><font
color="#000000">)</font><br>
<font color="#ffffff"> </font ><font color="#000000">{</font><br>
<font color="#ffffff"> </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"> </font ><font color="#000000">}</font><br>
<font color="#ffffff"> </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--
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Powered by
FUDForum. Page generated in 0.03224 seconds