Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Attaching EObject instance to serialized object
Attaching EObject instance to serialized object [message #474620] Wed, 05 August 2009 21:11 Go to next message
Bryan Banz is currently offline Bryan BanzFriend
Messages: 10
Registered: August 2009
Junior Member
I have a situation where I have an existing instance of a model object
(derived from EObject) in which I would like to load the contents of the
same type of object that has been previously persisted to a resource. Is
there a way to accomplish this?
Re: Attaching EObject instance to serialized object [message #478692 is a reply to message #474620] Thu, 06 August 2009 12:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30693
Registered: July 2009
Senior Member
Bryan,

ResourceSet.getEObject should do the trick if you have the URI for the
object you want to reference.


Bryan Banz wrote:
> I have a situation where I have an existing instance of a model object
> (derived from EObject) in which I would like to load the contents of
> the same type of object that has been previously persisted to a
> resource. Is there a way to accomplish this?
>
Re: Attaching EObject instance to serialized object [message #478720 is a reply to message #478692] Thu, 06 August 2009 14:26 Go to previous messageGo to next message
Bryan Banz is currently offline Bryan BanzFriend
Messages: 10
Registered: August 2009
Junior Member
I'm not sure I described my situation clearly enough. Correct me if I'm wrong, but wont getEObject() just create a new instance of an object from the resource containing it?

What I have is a modeled object that I'm trying to treat as a singleton. On that object I have a method that is sort of a "load from file" in which a URI is passed. So I already have an existing object and I'd like to fill out all its attributes and references so that it "becomes" the object that was persisted to the resource.

I know (I don't think) this would work, but perhaps it would get across what I'm trying to do:
EObject object = resource.getContents().get(0);

this = (MyObjectType)object;
Re: Attaching EObject instance to serialized object [message #478796 is a reply to message #478720] Fri, 07 August 2009 00:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30693
Registered: July 2009
Senior Member
Bryan,

Comments below.

Bryan Banz wrote:
> I'm not sure I described my situation clearly enough. Correct me if
> I'm wrong, but wont getEObject() just create a new instance of an
> object from the resource containing it?
It returns the object contained by the resource.
>
> What I have is a modeled object that I'm trying to treat as a
> singleton. On that object I have a method that is sort of a "load from
> file" in which a URI is passed.
That's what resource sets normally do. I'm not sure I understand how or
why a singleton is doing what you describe.
> So I already have an existing object and I'd like to fill out all its
> attributes and references so that it "becomes" the object that was
> persisted to the resource.
That's what proxies are normally used for.
>
> I know (I don't think) this would work, but perhaps it would get
> across what I'm trying to do:
>
> EObject object = resource.getContents().get(0);
>
> this = (MyObjectType)object;
No matter what you're trying to do, loading a resource into a resource
and getting the object from that resource is the way "load from file" is
normally supported.
Previous Topic:empty Resource?
Next Topic:Traingle
Goto Forum:
  


Current Time: Mon Dec 16 01:50:09 GMT 2019

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

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

Back to the top