Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: How to solve this (reflective?) problem in EMF?
Re: How to solve this (reflective?) problem in EMF? [message #412718] Tue, 04 September 2007 12:49 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
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 #412719 is a reply to message #412718] 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:Updating Ecore with XML Schema
Next Topic:error using Validation in RCP app
Goto Forum:
  


Current Time: Fri Apr 19 08:26:48 GMT 2024

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

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

Back to the top