Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Retain original resource reference when copying entries between feature maps
Retain original resource reference when copying entries between feature maps [message #531162] Mon, 03 May 2010 23:41 Go to next message
John T.E. Timm is currently offline John T.E. TimmFriend
Messages: 161
Registered: July 2009
Senior Member
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)? What mechanism is clearing out the reference from value to its original resource?

Thanks,

JT
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33147
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/
Previous Topic:[CDO] CDOFeatureDelta => ADD with null
Next Topic:Generic TreeView Editor just show attribute "name"
Goto Forum:
  


Current Time: Sun May 12 20:29:33 GMT 2024

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

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

Back to the top