Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » How to solve this (reflective?) problem in EMF?
How to solve this (reflective?) problem in EMF? [message #95828] Tue, 04 September 2007 11:20 Go to next message
Eclipse UserFriend
Originally posted by: paul.paul.com

Hallo,

I hope I can describe my problem in an understandable way:
I tried to create an Oultine Page using a set of classes (which are
extending EObjectImpl) as its content.
Now, the problem is that for the content I can only get the superclass
EObject and not the "real" class representing the object itself (e.g. ECar
extends EObject, EDoor extends EObject)
whereas I'd like to display the attributes of the objects as part of the
Outline Page (e.g. ECar.type, EDoor.color).

My codes look like below.
Because of some reasons, I'd like not to cast the EObject (to be able to
call ECar.getType()) , but it still somehow must diplay the attributes of
the "real" class behind it, instead of just displaying the name of the class
by calling e.eClass().getName(); so this should happen dynamically. It is
possible to use sort of reflective in EMF? Or is there any better solution
to this?

EObject e = null;

Outline o = null;

for(Iterator iter = ecoreRoot.eContents().iterator(); iter.hasNext();)

{

e = (EObject)iter.next();

if(e.eClass().getName() != null) {

a = new Outline(e, e.eClass().getName());

}

}

........................

Many thanks for ideas.

Best Regards
Re: How to solve this (reflective?) problem in EMF? [message #95858 is a reply to message #95828] Tue, 04 September 2007 12:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Paul,

This is just an EMF question for which you should use the EMF newsgroup,
not the EMFT newsgroup. I've added it to the "to" list of the reply.

You can use e.getClass().getName() to get the name of the actual
implementing class, or you can use e.eClass().getInstanceClassName() to
get the name of the generated or wrapped interface (if there is one).
Given the EClass, you can call EClass.getEAllStructureFeatures and for
each such feature, you can call e.eGet(feature) to get the value of that
feature.


Paul wrote:
> Hallo,
>
> I hope I can describe my problem in an understandable way:
> I tried to create an Oultine Page using a set of classes (which are
> extending EObjectImpl) as its content.
> Now, the problem is that for the content I can only get the superclass
> EObject and not the "real" class representing the object itself (e.g. ECar
> extends EObject, EDoor extends EObject)
> whereas I'd like to display the attributes of the objects as part of the
> Outline Page (e.g. ECar.type, EDoor.color).
>
> My codes look like below.
> Because of some reasons, I'd like not to cast the EObject (to be able to
> call ECar.getType()) , but it still somehow must diplay the attributes of
> the "real" class behind it, instead of just displaying the name of the class
> by calling e.eClass().getName(); so this should happen dynamically. It is
> possible to use sort of reflective in EMF? Or is there any better solution
> to this?
>
> EObject e = null;
>
> Outline o = null;
>
> for(Iterator iter = ecoreRoot.eContents().iterator(); iter.hasNext();)
>
> {
>
> e = (EObject)iter.next();
>
> if(e.eClass().getName() != null) {
>
> a = new Outline(e, e.eClass().getName());
>
> }
>
> }
>
> .......................
>
> Many thanks for ideas.
>
> Best Regards
>
>
>
Re: How to solve this (reflective?) problem in EMF? [message #95872 is a reply to message #95858] Tue, 04 September 2007 13:14 Go to previous message
Eclipse UserFriend
Originally posted by: paul.paul.com

Hi Ed,
thanks for the reply.

Before I used e.eClass().eGet and I couldn't get the value. didn't know that
I won't need the eclass() in between. Thanks a lot.

Regards
Paul

"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag
news:fbjk4r$lhd$1@build.eclipse.org...
> Paul,
>
> This is just an EMF question for which you should use the EMF newsgroup,
> not the EMFT newsgroup. I've added it to the "to" list of the reply.
>
> You can use e.getClass().getName() to get the name of the actual
> implementing class, or you can use e.eClass().getInstanceClassName() to
> get the name of the generated or wrapped interface (if there is one).
> Given the EClass, you can call EClass.getEAllStructureFeatures and for
> each such feature, you can call e.eGet(feature) to get the value of that
> feature.
>
>
> Paul wrote:
> > Hallo,
> >
> > I hope I can describe my problem in an understandable way:
> > I tried to create an Oultine Page using a set of classes (which are
> > extending EObjectImpl) as its content.
> > Now, the problem is that for the content I can only get the superclass
> > EObject and not the "real" class representing the object itself (e.g.
ECar
> > extends EObject, EDoor extends EObject)
> > whereas I'd like to display the attributes of the objects as part of the
> > Outline Page (e.g. ECar.type, EDoor.color).
> >
> > My codes look like below.
> > Because of some reasons, I'd like not to cast the EObject (to be able to
> > call ECar.getType()) , but it still somehow must diplay the attributes
of
> > the "real" class behind it, instead of just displaying the name of the
class
> > by calling e.eClass().getName(); so this should happen dynamically. It
is
> > possible to use sort of reflective in EMF? Or is there any better
solution
> > to this?
> >
> > EObject e = null;
> >
> > Outline o = null;
> >
> > for(Iterator iter = ecoreRoot.eContents().iterator(); iter.hasNext();)
> >
> > {
> >
> > e = (EObject)iter.next();
> >
> > if(e.eClass().getName() != null) {
> >
> > a = new Outline(e, e.eClass().getName());
> >
> > }
> >
> > }
> >
> > .......................
> >
> > Many thanks for ideas.
> >
> > Best Regards
> >
> >
> >
Re: How to solve this (reflective?) problem in EMF? [message #609641 is a reply to message #95828] Tue, 04 September 2007 12:49 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Paul,

This is just an EMF question for which you should use the EMF newsgroup,
not the EMFT newsgroup. I've added it to the "to" list of the reply.

You can use e.getClass().getName() to get the name of the actual
implementing class, or you can use e.eClass().getInstanceClassName() to
get the name of the generated or wrapped interface (if there is one).
Given the EClass, you can call EClass.getEAllStructureFeatures and for
each such feature, you can call e.eGet(feature) to get the value of that
feature.


Paul wrote:
> Hallo,
>
> I hope I can describe my problem in an understandable way:
> I tried to create an Oultine Page using a set of classes (which are
> extending EObjectImpl) as its content.
> Now, the problem is that for the content I can only get the superclass
> EObject and not the "real" class representing the object itself (e.g. ECar
> extends EObject, EDoor extends EObject)
> whereas I'd like to display the attributes of the objects as part of the
> Outline Page (e.g. ECar.type, EDoor.color).
>
> My codes look like below.
> Because of some reasons, I'd like not to cast the EObject (to be able to
> call ECar.getType()) , but it still somehow must diplay the attributes of
> the "real" class behind it, instead of just displaying the name of the class
> by calling e.eClass().getName(); so this should happen dynamically. It is
> possible to use sort of reflective in EMF? Or is there any better solution
> to this?
>
> EObject e = null;
>
> Outline o = null;
>
> for(Iterator iter = ecoreRoot.eContents().iterator(); iter.hasNext();)
>
> {
>
> e = (EObject)iter.next();
>
> if(e.eClass().getName() != null) {
>
> a = new Outline(e, e.eClass().getName());
>
> }
>
> }
>
> .......................
>
> Many thanks for ideas.
>
> Best Regards
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to solve this (reflective?) problem in EMF? [message #609642 is a reply to message #95858] Tue, 04 September 2007 13:14 Go to previous message
Paul is currently offline PaulFriend
Messages: 55
Registered: July 2009
Member
Hi Ed,
thanks for the reply.

Before I used e.eClass().eGet and I couldn't get the value. didn't know that
I won't need the eclass() in between. Thanks a lot.

Regards
Paul

"Ed Merks" <merks@ca.ibm.com> schrieb im Newsbeitrag
news:fbjk4r$lhd$1@build.eclipse.org...
> Paul,
>
> This is just an EMF question for which you should use the EMF newsgroup,
> not the EMFT newsgroup. I've added it to the "to" list of the reply.
>
> You can use e.getClass().getName() to get the name of the actual
> implementing class, or you can use e.eClass().getInstanceClassName() to
> get the name of the generated or wrapped interface (if there is one).
> Given the EClass, you can call EClass.getEAllStructureFeatures and for
> each such feature, you can call e.eGet(feature) to get the value of that
> feature.
>
>
> Paul wrote:
> > Hallo,
> >
> > I hope I can describe my problem in an understandable way:
> > I tried to create an Oultine Page using a set of classes (which are
> > extending EObjectImpl) as its content.
> > Now, the problem is that for the content I can only get the superclass
> > EObject and not the "real" class representing the object itself (e.g.
ECar
> > extends EObject, EDoor extends EObject)
> > whereas I'd like to display the attributes of the objects as part of the
> > Outline Page (e.g. ECar.type, EDoor.color).
> >
> > My codes look like below.
> > Because of some reasons, I'd like not to cast the EObject (to be able to
> > call ECar.getType()) , but it still somehow must diplay the attributes
of
> > the "real" class behind it, instead of just displaying the name of the
class
> > by calling e.eClass().getName(); so this should happen dynamically. It
is
> > possible to use sort of reflective in EMF? Or is there any better
solution
> > to this?
> >
> > EObject e = null;
> >
> > Outline o = null;
> >
> > for(Iterator iter = ecoreRoot.eContents().iterator(); iter.hasNext();)
> >
> > {
> >
> > e = (EObject)iter.next();
> >
> > if(e.eClass().getName() != null) {
> >
> > a = new Outline(e, e.eClass().getName());
> >
> > }
> >
> > }
> >
> > .......................
> >
> > Many thanks for ideas.
> >
> > Best Regards
> >
> >
> >
Previous Topic:How to solve this (reflective?) problem in EMF?
Next Topic:JET EXTENSION!
Goto Forum:
  


Current Time: Thu Apr 25 10:45:05 GMT 2024

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

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

Back to the top