|
Re: Retain original resource reference when copying entries between feature maps [message #531246 is a reply to message #531162] |
Tue, 04 May 2010 10:14 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
John,
Comments below.
John T.E. Timm wrote:
> I am loading in arbitrary XML content using the
> GenericXMLResourceFactoryImpl and URIConverter.ReadableInputStream:
>
>
> Resource.Factory factory = new GenericXMLResourceFactoryImpl();
> XMLResource resource = (XMLResource) factory.createResource(null);
> resource.load(new URIConverter.ReadableInputStream("<text>" +
> xmlString + "</text>"), null);
> XMLTypeDocumentRoot root = (XMLTypeDocumentRoot)
> resource.getContents().get(0);
> AnyType value = (AnyType) root.getMixed().getValue(0);
>
>
> Then I am adding the entries from value.getMixed() to a new FeatureMap
> that is part of an EObject graph that was created programmatically
> (not yet contained in a Resource).
>
>
> XYZClass obj = XYZFactory.eINSTANCE.createXYZClass();
> obj.getMixed().addAll(value.getMixed());
>
> assert value.eResource != null; // not here
> // ... return from method
> // ... do some other things
> assert value.eResource == null; // here it is null
>
>
> What I am noticing is that at some point value.eResource() gets set to
> null. What can I do to retain this original resource as long as
> possible (until obj gets added to a different resource)?
You can't. Once you remove the object from the document root that's in
a resource to a document root that's not in a resource then your object
is no longer in a resource.
> What mechanism is clearing out the reference from value to its
> original resource?
Making the value be contained as a child of another object will do
that. I.e., when the eContainer changes.
>
> Thanks,
>
> JT
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03389 seconds