Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » I have a class. How do I get it's structural features?
I have a class. How do I get it's structural features? [message #495088] Tue, 03 November 2009 17:51 Go to next message
Tamar Cohen is currently offline Tamar Cohen
Messages: 100
Registered: July 2009
Senior Member
Hello --

I'm using reflection to do all sorts of cool automated things which I am HOPING I can contribute back to the open source world. However, I have one bit of ugliness:

I have a class. Not an EClass, just a plain class. I need to get its EStructuralFeatures. How do I do that? How can I look up a factory if I just have a class? Is there a way for me to get an EClass from a class? Mind you, I don't have an instance of the class, I just have the class itself.

thanks much

Tamar
Re: I have a class. How do I get it's structural features? [message #495095 is a reply to message #495088] Tue, 03 November 2009 18:12 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5545
Registered: July 2009
Senior Member
Hi Tamar,

Comments below...


Tamar Cohen schrieb:
> Hello --
>
> I'm using reflection to do all sorts of cool automated things which I
> am HOPING I can contribute back to the open source world.
I'm curious, what are you doing?

> However, I have one bit of ugliness:
> I have a class. Not an EClass, just a plain class.
Why don't you use EMF reflection?

> I need to get its EStructuralFeatures. How do I do that? How can I
> look up a factory if I just have a class?
What factory do you mean?

> Is there a way for me to get an EClass from a class? Mind you, I
> don't have an instance of the class, I just have the class itself.
I assume that you could determine the EClass of a java.lang.Class if you
have the GenModel of that EClass at hand. You'd have to traverse all
GenModels.

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: I have a class. How do I get it's structural features? [message #495100 is a reply to message #495095] Tue, 03 November 2009 18:29 Go to previous messageGo to next message
Tamar Cohen is currently offline Tamar Cohen
Messages: 100
Registered: July 2009
Senior Member
Hi Eike -- thanks for answering --
this is what I'm doing: Since 3.6 is not out and I couldn't get Tom's UFacekit to work I've made a simple widget generation framework. It uses introspection to generate widgets either for generic Java classes or for EMF EObjects, and you can customize the layout via Java Annotations or with code / extension points (customization includes validation and conversion and grouping and layout and read/only and and and)...

So my particular EObject instances have public constructors and it all works simply. I know that this is not always how the EMF code is generated, however, and I want to support the case where I have to look up EStructuralFeatures.

As some of these widgets will be created from classes that the developer did not write, I cannot rely on having the genmodel. How might I use EMF reflection? How can I get an EClass from a class? right now the class just implements EObject.

hopefully I will be permitted to publish my work, it's really nice for the low hanging fruit / simple UI generation.

Tamar
Re: I have a class. How do I get it's structural features? [message #495116 is a reply to message #495100] Tue, 03 November 2009 20:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Tamar,

You generally can't get an EClass given only a java.lang.Class. If you
assume there a public constructors---EMF has an option for generating
that--then you might create an instance, cast it to EObject, and ask for
the eClass(). Alternatively, if you know the collection of possible
packages that might define the corresponding EClass, you might walk all
those package's classifiers and check if the getInstanceClass() matches.


Tamar Cohen wrote:
> Hi Eike -- thanks for answering -- this is what I'm doing: Since 3.6
> is not out and I couldn't get Tom's UFacekit to work I've made a
> simple widget generation framework. It uses introspection to generate
> widgets either for generic Java classes or for EMF EObjects, and you
> can customize the layout via Java Annotations or with code / extension
> points (customization includes validation and conversion and grouping
> and layout and read/only and and and)...
>
> So my particular EObject instances have public constructors and it all
> works simply. I know that this is not always how the EMF code is
> generated, however, and I want to support the case where I have to
> look up EStructuralFeatures.
>
> As some of these widgets will be created from classes that the
> developer did not write, I cannot rely on having the genmodel. How
> might I use EMF reflection? How can I get an EClass from a class?
> right now the class just implements EObject.
>
> hopefully I will be permitted to publish my work, it's really nice for
> the low hanging fruit / simple UI generation.
>
> Tamar
Re: I have a class. How do I get it's structural features? [message #495120 is a reply to message #495116] Tue, 03 November 2009 20:14 Go to previous messageGo to next message
Tamar Cohen is currently offline Tamar Cohen
Messages: 100
Registered: July 2009
Senior Member
Hi Ed --

yes, thanks, that's exactly what I was doing (instantiating a temporary EObject and looking up what I want from that), and what I want to handle is the case where there is no public constructor. Hmm, looks like I may have to add support for looking up by EClass.

thank you!

Tamar

Re: I have a class. How do I get it's structural features? [message #495512 is a reply to message #495100] Thu, 05 November 2009 07:48 Go to previous message
Eike Stepper is currently offline Eike Stepper
Messages: 5545
Registered: July 2009
Senior Member
Hi Tamar,

I would not invest into own frameworks just because an upcoming
technology at Eclipse (or elsewhere) is not yet GA. Better collaborate
with the providing team to ensure that it goes into a direction that
suits your need and help stabilizing.

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Tamar Cohen schrieb:
> Hi Eike -- thanks for answering -- this is what I'm doing: Since 3.6
> is not out and I couldn't get Tom's UFacekit to work I've made a
> simple widget generation framework. It uses introspection to generate
> widgets either for generic Java classes or for EMF EObjects, and you
> can customize the layout via Java Annotations or with code / extension
> points (customization includes validation and conversion and grouping
> and layout and read/only and and and)...
>
> So my particular EObject instances have public constructors and it all
> works simply. I know that this is not always how the EMF code is
> generated, however, and I want to support the case where I have to
> look up EStructuralFeatures.
>
> As some of these widgets will be created from classes that the
> developer did not write, I cannot rely on having the genmodel. How
> might I use EMF reflection? How can I get an EClass from a class?
> right now the class just implements EObject.
>
> hopefully I will be permitted to publish my work, it's really nice for
> the low hanging fruit / simple UI generation.
>
> Tamar
Re: I have a class. How do I get it's structural features? [message #618272 is a reply to message #495095] Tue, 03 November 2009 18:29 Go to previous message
Tamar Cohen is currently offline Tamar Cohen
Messages: 100
Registered: July 2009
Senior Member
Hi Eike -- thanks for answering --
this is what I'm doing: Since 3.6 is not out and I couldn't get Tom's UFacekit to work I've made a simple widget generation framework. It uses introspection to generate widgets either for generic Java classes or for EMF EObjects, and you can customize the layout via Java Annotations or with code / extension points (customization includes validation and conversion and grouping and layout and read/only and and and)...

So my particular EObject instances have public constructors and it all works simply. I know that this is not always how the EMF code is generated, however, and I want to support the case where I have to look up EStructuralFeatures.

As some of these widgets will be created from classes that the developer did not write, I cannot rely on having the genmodel. How might I use EMF reflection? How can I get an EClass from a class? right now the class just implements EObject.

hopefully I will be permitted to publish my work, it's really nice for the low hanging fruit / simple UI generation.

Tamar
Re: I have a class. How do I get it's structural features? [message #618273 is a reply to message #618272] Tue, 03 November 2009 20:05 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Tamar,

You generally can't get an EClass given only a java.lang.Class. If you
assume there a public constructors---EMF has an option for generating
that--then you might create an instance, cast it to EObject, and ask for
the eClass(). Alternatively, if you know the collection of possible
packages that might define the corresponding EClass, you might walk all
those package's classifiers and check if the getInstanceClass() matches.


Tamar Cohen wrote:
> Hi Eike -- thanks for answering -- this is what I'm doing: Since 3.6
> is not out and I couldn't get Tom's UFacekit to work I've made a
> simple widget generation framework. It uses introspection to generate
> widgets either for generic Java classes or for EMF EObjects, and you
> can customize the layout via Java Annotations or with code / extension
> points (customization includes validation and conversion and grouping
> and layout and read/only and and and)...
>
> So my particular EObject instances have public constructors and it all
> works simply. I know that this is not always how the EMF code is
> generated, however, and I want to support the case where I have to
> look up EStructuralFeatures.
>
> As some of these widgets will be created from classes that the
> developer did not write, I cannot rely on having the genmodel. How
> might I use EMF reflection? How can I get an EClass from a class?
> right now the class just implements EObject.
>
> hopefully I will be permitted to publish my work, it's really nice for
> the low hanging fruit / simple UI generation.
>
> Tamar
Re: I have a class. How do I get it's structural features? [message #618274 is a reply to message #495116] Tue, 03 November 2009 20:14 Go to previous message
Tamar Cohen is currently offline Tamar Cohen
Messages: 100
Registered: July 2009
Senior Member
Hi Ed --

yes, thanks, that's exactly what I was doing (instantiating a temporary EObject and looking up what I want from that), and what I want to handle is the case where there is no public constructor. Hmm, looks like I may have to add support for looking up by EClass.

thank you!

Tamar
Re: I have a class. How do I get it's structural features? [message #618275 is a reply to message #618272] Thu, 05 November 2009 07:48 Go to previous message
Eike Stepper is currently offline Eike Stepper
Messages: 5545
Registered: July 2009
Senior Member
Hi Tamar,

I would not invest into own frameworks just because an upcoming
technology at Eclipse (or elsewhere) is not yet GA. Better collaborate
with the providing team to ensure that it goes into a direction that
suits your need and help stabilizing.

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Tamar Cohen schrieb:
> Hi Eike -- thanks for answering -- this is what I'm doing: Since 3.6
> is not out and I couldn't get Tom's UFacekit to work I've made a
> simple widget generation framework. It uses introspection to generate
> widgets either for generic Java classes or for EMF EObjects, and you
> can customize the layout via Java Annotations or with code / extension
> points (customization includes validation and conversion and grouping
> and layout and read/only and and and)...
>
> So my particular EObject instances have public constructors and it all
> works simply. I know that this is not always how the EMF code is
> generated, however, and I want to support the case where I have to
> look up EStructuralFeatures.
>
> As some of these widgets will be created from classes that the
> developer did not write, I cannot rely on having the genmodel. How
> might I use EMF reflection? How can I get an EClass from a class?
> right now the class just implements EObject.
>
> hopefully I will be permitted to publish my work, it's really nice for
> the low hanging fruit / simple UI generation.
>
> Tamar
Previous Topic:I have a class. How do I get it's structural features?
Next Topic:MAPPING
Goto Forum:
  


Current Time: Sun Oct 26 03:46:38 GMT 2014

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

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