Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Getter/Setter methods when dynamically build the model
Getter/Setter methods when dynamically build the model [message #431896] Tue, 28 July 2009 20:40 Go to next message
Alick is currently offline AlickFriend
Messages: 10
Registered: July 2009
Junior Member
I successfully built a model programatically in the memory(A bunch of
EClass), then an instance tree is created according to the in-memory
model(A bunch of EObject). My issue is: I want those EObjects generated
to have all the getter/setters for the public attribute. How do I force
the model to generate getter/setter?
Re: Getter/Setter methods when dynamically build the model [message #431902 is a reply to message #431896] Tue, 28 July 2009 23:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Alick,

A dynamically created model must uses eGet/eSet to modify the state.
Only generated models support getters and setters so you'd have to
invoke the generator...


Alick wrote:
> I successfully built a model programatically in the memory(A bunch of
> EClass), then an instance tree is created according to the in-memory
> model(A bunch of EObject). My issue is: I want those EObjects
> generated to have all the getter/setters for the public attribute.
> How do I force the model to generate getter/setter?
Re: Getter/Setter methods when dynamically build the model [message #431917 is a reply to message #431902] Wed, 29 July 2009 14:10 Go to previous messageGo to next message
Alick is currently offline AlickFriend
Messages: 10
Registered: July 2009
Junior Member
Thanks Ed,

Just wondering how can I invoke the generator programatically, any sample
code?

My use case is: have core model pre-defined, and one program module will
dynamically extend around core model (in memory). There is another piece
of program that will refer to this in-memory extended model and create the
instance. I got this issue when I traverse the instance object tree,
where I don't have getter/setter when I step into the extended part. Your
help will be highly appreciated.
Re: Getter/Setter methods when dynamically build the model [message #431920 is a reply to message #431917] Wed, 29 July 2009 16:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Alick,

Comments below.

Alick wrote:
> Thanks Ed,
> Just wondering how can I invoke the generator programatically, any
> sample code?
There are Ant tasks that do this.
> My use case is: have core model pre-defined, and one program module
> will dynamically extend around core model (in memory).
Generating code and being dynamic sound like things that are at odds
with each other...
> There is another piece of program that will refer to this in-memory
> extended model and create the instance.
Why does it need generated code. I can't imagine how some existing code
can refer to methods in code that's generated dynamically...
> I got this issue when I traverse the instance object tree, where I
> don't have getter/setter when I step into the extended part.
I don't get this either. Everything you need to access is accessible
via the EObject API.
> Your help will be highly appreciated.
I think there is a huge gap in my understanding of what your real
problem is. You really don't need generated accessors to traverse any
arbitrary instance...
Re: Getter/Setter methods when dynamically build the model [message #431929 is a reply to message #431920] Wed, 29 July 2009 20:19 Go to previous messageGo to next message
Alick is currently offline AlickFriend
Messages: 10
Registered: July 2009
Junior Member
Appreciate your comments, let me try to put the question differently. My
intention is: After everything is done, in the program that is to
traverse the instance (EObject tree)which is spawn off the in-memory
extended model (EClass-es), it would be really intuitive that all the
accessors can be visible to the devlopers in the drop-down list.
Currently because the EClass from which the EObject is spawn off doesn't
have accessors(), the coder has no choice othen than eGet/eSet, but it
requires the coder to know the exact structure of the in-memory extended
model. Hope I explained clear this time, thanks

Alicl
Re: Getter/Setter methods when dynamically build the model [message #431950 is a reply to message #431929] Thu, 30 July 2009 13:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30687
Registered: July 2009
Senior Member
Alicl,

Comments below.

Alick wrote:
> Appreciate your comments, let me try to put the question differently.
> My intention is: After everything is done, in the program that is to
> traverse the instance (EObject tree)which is spawn off the in-memory
> extended model (EClass-es), it would be really intuitive that all the
> accessors can be visible to the devlopers in the drop-down list.
Use eObject.eClass().getEAllStructuralFeatures() to build that list.
> Currently because the EClass from which the EObject is spawn off
> doesn't have accessors(), the coder has no choice othen than
> eGet/eSet, but it requires the coder to know the exact structure of
> the in-memory extended model. Hope I explained clear this time, thanks
In the end, it sounds like you want to generate code and after that's
done, someone will use that generated model. The existing Ant tasks
suppose such a thing so you can reuse that directly or look at it as an
example of how to drive the generator programmatically.
>
> Alicl
Previous Topic:resource load with special epackage
Next Topic:Persisting ecore instance as XML only persists first node of model
Goto Forum:
  


Current Time: Tue Dec 10 08:01:52 GMT 2019

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

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

Back to the top