[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: How to convert XMIResource to CDOResource

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().getExtensionToFactoryMap();
    map.put("*", *new *XMIResourceFactoryImpl());
    sourceSet.setPackageRegistry(transaction.getSession().getPackageRegistry());

    // 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.